Skip to content

Commit 0bb4dab

Browse files
committed
fixes
1 parent 9e9f2ed commit 0bb4dab

File tree

6 files changed

+76
-25
lines changed

6 files changed

+76
-25
lines changed

app/site/controllers/Admin/Cms/Media.php

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -358,7 +358,7 @@ public function getFormDefinition(FAPI\Form $form, array &$form_state): FAPI\For
358358
]);
359359
}
360360

361-
if ($this->getRequest()->query->get('product_type') == 'downloadable' && $this->getRequest()->query->get('product_id')) {
361+
if ($this->getRequest()->query->get('product_type') == 'book' && $this->getRequest()->query->get('product_id')) {
362362
/** @var Book $product */
363363
$product = $this->containerCall([Book::class, 'load'], ['id' => $this->getRequest()->query->get('product_id')]);
364364
$form->addField('product_id', [
@@ -484,7 +484,8 @@ function ($product) use ($not_in) {
484484
break;
485485
case 'downloadable_product_deassoc':
486486
/** @var DownloadableProduct $product */
487-
$product = $this->containerCall([DownloadableProduct::class, 'load'], ['id' => $this->getRequest()->query->get('product_id')]);
487+
$product_id = $this->getRequest()->query->get('product_id') ?? $form_state['input_values']['product_id'];
488+
$product = $this->containerCall([DownloadableProduct::class, 'load'], ['id' => $product_id]);
488489
$form->addField('product_id', [
489490
'type' => 'hidden',
490491
'default_value' => $product->getId(),
@@ -536,7 +537,8 @@ function ($product) use ($not_in) {
536537
break;
537538
case 'book_deassoc':
538539
/** @var Book $product */
539-
$product = $this->containerCall([Book::class, 'load'], ['id' => $this->getRequest()->query->get('product_id')]);
540+
$product_id = $this->getRequest()->query->get('product_id') ?? $form_state['input_values']['product_id'];
541+
$product = $this->containerCall([Book::class, 'load'], ['id' => $product_id]);
540542
$form->addField('product_id', [
541543
'type' => 'hidden',
542544
'default_value' => $product->getId(),
@@ -690,7 +692,7 @@ public function formSubmitted(FAPI\Form $form, &$form_state): mixed
690692
break;
691693
case 'downloadable_product_deassoc':
692694
if ($values['product_id']) {
693-
/** @var DownloadableProduct $page */
695+
/** @var DownloadableProduct $product */
694696
$product = $this->containerCall([DownloadableProduct::class, 'load'], ['id' => $values['product_id']]);
695697
$product->removeMedia($media);
696698
}
@@ -702,6 +704,20 @@ public function formSubmitted(FAPI\Form $form, &$form_state): mixed
702704
$product->addMedia($media);
703705
}
704706
break;
707+
case 'book_deassoc':
708+
if ($values['product_id']) {
709+
/** @var Book $product */
710+
$product = $this->containerCall([Book::class, 'load'], ['id' => $values['product_id']]);
711+
$product->removeMedia($media);
712+
}
713+
break;
714+
case 'book_assoc':
715+
if ($values['product_id']) {
716+
/** @var Book $product */
717+
$product = $this->containerCall([Book::class, 'load'], ['id' => $values['product_id']]);
718+
$product->addMedia($media);
719+
}
720+
break;
705721
case 'delete':
706722
if ($media->isDirectory()) {
707723
$deletedElements = $this->deleteMediaFolder($media);

app/site/controllers/Admin/Json/BookMedia.php

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,19 @@ protected function getJsonData(): array
6060

6161
$gallery = array_map(
6262
function ($el) use ($product) {
63-
return '<div class="gallery-elem">' .
63+
return '<div class="gallery-elem card h-100 mr-2">' .
64+
'<div class="card-header text-right p-2">' .
65+
' <a class="deassoc_lnk" data-product_id="' . $product->id . '" data-media_id="' . $el->id . '" href="' . $this->getUrl('crud.app.site.controllers.admin.json.bookmedia', ['id' => $product->id]) . '?product_id=' . $product->id . '&media_id=' . $el->id . '&action=book_deassoc">&times;</a>' .
66+
'</div>' .
67+
'<div class="card-body text-center d-flex align-items-center justify-content-center">' .
6468
$el->getThumb("150x100", null, 'img-fluid img-thumbnail') .
65-
' <a class="deassoc_lnk" data-product_id="' . $product->id . '" data-media_id="' . $el->id . '" href="' . $this->getUrl('crud.app.site.controllers.admin.json.bookmedia', ['id' => $product->id]) . '?product_id=' . $product->id . '&media_id=' . $el->id . '&action=book_deassoc">&times;</a>' .
66-
'</div>';
69+
'</div>' .
70+
'</div>';
6771
},
6872
$product->getGallery()
6973
);
7074

75+
7176
$galleryData = array_map(
7277
function ($el) {
7378
return $el->getData();
@@ -79,6 +84,13 @@ function ($el) {
7984
$form = $mediaController->getForm();
8085

8186
$form->setAction($this->getUrl('admin.cms.media') . '?action=' . $this->getRequest()->query->get('action'). ($this->getRequest()->query->get('media_id') ? '&media_id=' . $this->getRequest()->query->get('media_id') : ''));
87+
$form->addField(
88+
'product_type',
89+
[
90+
'type' => 'hidden',
91+
'default_value' => 'book',
92+
]
93+
);
8294
$form->addField(
8395
'product_id',
8496
[
@@ -91,7 +103,7 @@ function ($el) {
91103
'success' => true,
92104
'params' => $this->getRequest()->query->all(),
93105
'gallery' => $galleryData,
94-
'html' => ($this->getRequest()->query->get('action') == 'new' ? "<div class=\"page-gallery\">" . implode("", $gallery) . "</div><hr />" : '') . $form->render(),
106+
'html' => ($this->getRequest()->query->get('action') == 'new' ? "<div class=\"d-flex justify-content-start book-gallery\">" . implode("", $gallery) . "</div><hr />" : '') . $form->render(),
95107
'js' => "",
96108
];
97109
}

app/site/controllers/Admin/Json/DownloadableMedia.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,14 @@ protected function getJsonData(): array
6060

6161
$gallery = array_map(
6262
function ($el) use ($product) {
63-
return '<div class="gallery-elem">' .
63+
return '<div class="gallery-elem card h-100 mr-2">' .
64+
'<div class="card-header text-right p-2">' .
65+
' <a class="deassoc_lnk" data-product_id="' . $product->id . '" data-media_id="' . $el->id . '" href="' . $this->getUrl('crud.app.site.controllers.admin.json.downloadablemedia', ['id' => $product->id]) . '?product_id=' . $product->id . '&media_id=' . $el->id . '&action=downloadable_product_deassoc">&times;</a>' .
66+
'</div>' .
67+
'<div class="card-body text-center d-flex align-items-center justify-content-center">' .
6468
$el->getThumb("150x100", null, 'img-fluid img-thumbnail') .
65-
' <a class="deassoc_lnk" data-product_id="' . $product->id . '" data-media_id="' . $el->id . '" href="' . $this->getUrl('crud.app.site.controllers.admin.json.downloadablemedia', ['id' => $product->id]) . '?product_id=' . $product->id . '&media_id=' . $el->id . '&action=downloadable_product_deassoc">&times;</a>' .
66-
'</div>';
69+
'</div>' .
70+
'</div>';
6771
},
6872
$product->getGallery()
6973
);
@@ -79,6 +83,13 @@ function ($el) {
7983
$form = $mediaController->getForm();
8084

8185
$form->setAction($this->getUrl('admin.cms.media') . '?action=' . $this->getRequest()->query->get('action'). ($this->getRequest()->query->get('media_id') ? '&media_id=' . $this->getRequest()->query->get('media_id') : ''));
86+
$form->addField(
87+
'product_type',
88+
[
89+
'type' => 'hidden',
90+
'default_value' => 'downloadable',
91+
]
92+
);
8293
$form->addField(
8394
'product_id',
8495
[
@@ -91,7 +102,7 @@ function ($el) {
91102
'success' => true,
92103
'params' => $this->getRequest()->query->all(),
93104
'gallery' => $galleryData,
94-
'html' => ($this->getRequest()->query->get('action') == 'new' ? "<div class=\"page-gallery\">" . implode("", $gallery) . "</div><hr />" : '') . $form->render(),
105+
'html' => ($this->getRequest()->query->get('action') == 'new' ? "<div class=\"d-flex justify-content-start downloadable-gallery\">" . implode("", $gallery) . "</div><hr />" : '') . $form->render(),
95106
'js' => "",
96107
];
97108
}

app/site/controllers/Admin/Json/PageMedia.php

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,14 @@ protected function getJsonData(): array
6060

6161
$gallery = array_map(
6262
function ($el) use ($page) {
63-
return '<div class="gallery-elem">' .
63+
return '<div class="gallery-elem card h-100 mr-2">' .
64+
'<div class="card-header text-right p-2">' .
65+
' <a class="deassoc_lnk" data-page_id="' . $page->id . '" data-media_id="' . $el->id . '" href="' . $this->getUrl('crud.app.site.controllers.admin.json.pagemedia', ['id' => $page->id]) . '?page_id=' . $page->id . '&media_id=' . $el->id . '&action=page_deassoc">&times;</a>' .
66+
'</div>' .
67+
'<div class="card-body text-center d-flex align-items-center justify-content-center">' .
6468
$el->getThumb("150x100", null, 'img-fluid img-thumbnail') .
65-
' <a class="deassoc_lnk" data-page_id="' . $page->id . '" data-media_id="' . $el->id . '" href="' . $this->getUrl('crud.app.site.controllers.admin.json.pagemedia', ['id' => $page->id]) . '?page_id=' . $page->id . '&media_id=' . $el->id . '&action=page_deassoc">&times;</a>' .
66-
'</div>';
69+
'</div>' .
70+
'</div>';
6771
},
6872
$page->getGallery()
6973
);
@@ -91,7 +95,7 @@ function ($el) {
9195
'success' => true,
9296
'params' => $this->getRequest()->query->all(),
9397
'gallery' => $galleryData,
94-
'html' => ($this->getRequest()->query->get('action') == 'new' ? "<div class=\"page-gallery\">" . implode("", $gallery) . "</div><hr />" : '') . $form->render(),
98+
'html' => ($this->getRequest()->query->get('action') == 'new' ? "<div class=\"d-flex justify-content-start page-gallery\">" . implode("", $gallery) . "</div><hr />" : '') . $form->render(),
9599
'js' => "",
96100
];
97101
}

app/site/tools/FAPI/Fields/Gallery.php

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ public function renderField(Form $form) // renders html
6161
'tag' => 'div',
6262
'id' => $id,
6363
'attributes' => [
64-
'class' => 'row row-cols-4',
64+
'class' => 'row row-cols-6 p-4',
6565
],
6666
]]);
6767

@@ -83,7 +83,7 @@ public function renderField(Form $form) // renders html
8383
$field->addChild(
8484
App::getInstance()->containerMake(TagElement::class, ['options' => [
8585
'tag' => 'div',
86-
'attributes' => ['class' => 'col text-center'],
86+
'attributes' => ['class' => 'col text-center h-100 align-bottom d-flex flex-column justify-content-center', 'style' => 'min-height: 100px;'],
8787
'text' => $this->renderMediaElement(
8888
$grandparent, App::getInstance()->getHtmlRenderer()->getIcon('corner-left-up') . ' ' . __('Up')
8989
),
@@ -96,7 +96,7 @@ public function renderField(Form $form) // renders html
9696
$field->addChild(
9797
App::getInstance()->containerMake(TagElement::class, ['options' => [
9898
'tag' => 'div',
99-
'attributes' => ['class' => 'col text-center'],
99+
'attributes' => ['class' => 'col text-center h-100 align-bottom d-flex flex-column justify-content-center', 'style' => 'min-height: 100px;'],
100100
'text' => $this->renderMediaElement($media),
101101
]])
102102
);
@@ -155,6 +155,17 @@ protected function renderMediaElement(?MediaElement $media, ?string $labelText =
155155
{
156156
$text = ($labelText ?? '<abbr title="' . $media?->getFilename() . '">' . substr("" . $media?->getFilename(), 0, $maxLength) . (strlen("".$media?->getFilename()) > $maxLength ? '...' : '') . '</abbr>');
157157
$label = '<label class="text-nowrap" for="media-selector-'.$media?->getId().'"><input type="checkbox" class="media-selector" id="media-selector-'.$media?->getId().'" value="' . $media?->getId() . '" />' . $text . '</label>';
158+
159+
$label = '<div class="pretty p-icon p-smooth p-primary p-curve">
160+
<input class="media-selector" type="checkbox" id="media-selector-'.$media?->getId().'" value="' . $media?->getId() . '" />
161+
<div class="state">
162+
<i class="icon fa fa-check"></i>
163+
<label for="media-selector-'.$media?->getId().'">' . $text . '</label>
164+
</div>
165+
</div>';
166+
167+
168+
158169
if (is_null($media) || $media->isDirectory()) {
159170
$uri = App::getInstance()->getEnvironment()->getRequest()->getUri();
160171
$parsed = parse_url($uri);
@@ -164,7 +175,7 @@ protected function renderMediaElement(?MediaElement $media, ?string $labelText =
164175

165176
$label = '<label class="text-nowrap"><a class="inToolSidePanel" href="'.$uri.'&parent_id='.$media?->getId().'">' . $text . '</a></label>';
166177
}
167-
178+
168179
return match (true) {
169180
is_null($media), $media?->isDirectory() => '<div class="media-element media-directory"><h2 style="height: 50px; margin: 0;">'.App::getInstance()->getHtmlRenderer()->getFAIcon('folder', 'regular').'</h2></div>',
170181
$media?->isImage() => '<div class="media-element media-image">' . $media->getThumb('50x50') . '</div>',

scss/admin.scss

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -229,17 +229,14 @@ body {
229229
}
230230
}
231231

232+
.downloadable-gallery,
233+
.book-gallery,
232234
.page-gallery {
233235
.gallery-elem {
234236
position: relative;
235237
width: 150px;
236-
display: inline-block;
237-
padding-top: 10px;
238238

239239
.deassoc_lnk {
240-
position: absolute;
241-
top: 5px;
242-
left: 100px;
243240
text-decoration: none;
244241
font-weight: 900;
245242
font-size: 18px;

0 commit comments

Comments
 (0)