Skip to content

Commit 173fbd9

Browse files
author
Bohdan Korablov
committed
MAGETWO-52386: JS validation is absent for "Configurations" and "Images And Videos" panels
1 parent 870bdfb commit 173fbd9

File tree

5 files changed

+46
-1
lines changed

5 files changed

+46
-1
lines changed

app/code/Magento/Catalog/view/adminhtml/layout/catalog_product_form.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
</argument>
2222
</arguments>
2323
<block class="Magento\Catalog\Block\Adminhtml\Product\Helper\Form\Gallery\Content" as="content">
24+
<arguments>
25+
<argument name="config" xsi:type="array">
26+
<item name="parentComponent" xsi:type="string">product_form.product_form.block_gallery.block_gallery</item>
27+
</argument>
28+
</arguments>
2429
<block class="Magento\ProductVideo\Block\Adminhtml\Product\Edit\NewVideo" name="new-video"
2530
template="Magento_ProductVideo::product/edit/slideout/form.phtml"/>
2631
</block>

app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/helper/gallery.phtml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,14 @@
99
/** @var $block \Magento\Catalog\Block\Adminhtml\Product\Helper\Form\Gallery\Content */
1010
$elementName = $block->getElement()->getName() . '[images]';
1111
$formName = $block->getFormName();
12+
$parentComponent = $block->getData('config/parentComponent')
13+
? 'data-parent-component="' . $block->getData('config/parentComponent') . '"'
14+
: '';
1215
?>
1316
<div id="<?php echo $block->getHtmlId() ?>"
1417
class="gallery"
1518
data-mage-init='{"productGallery":{"template":"#<?php echo $block->getHtmlId() ?>-template"}}'
19+
<?php echo $parentComponent ?>
1620
data-images="<?php echo $block->escapeHtml($block->getImagesJson()) ?>"
1721
data-types="<?php echo $block->escapeHtml(
1822
$this->helper('Magento\Framework\Json\Helper\Data')->jsonEncode($block->getImageTypes())

app/code/Magento/Catalog/view/adminhtml/web/js/product-gallery.js

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,10 @@ define([
77
'jquery',
88
'underscore',
99
'mage/template',
10+
'uiRegistry',
1011
'jquery/ui',
1112
'baseImage'
12-
], function ($, _, mageTemplate) {
13+
], function ($, _, mageTemplate, registry) {
1314
'use strict';
1415

1516
/**
@@ -53,6 +54,7 @@ define([
5354
_create: function () {
5455
this.options.types = this.options.types || this.element.data('types');
5556
this.options.images = this.options.images || this.element.data('images');
57+
this.options.parentComponent = this.options.parentComponent || this.element.data('parent-component');
5658

5759
this.imgTmpl = mageTemplate(this.element.find(this.options.template).html().trim());
5860

@@ -153,6 +155,19 @@ define([
153155
}).first();
154156
},
155157

158+
/**
159+
* Mark parent fieldset that content was updated
160+
*/
161+
_contentUpdated: function () {
162+
if (this.options.initialized && this.options.parentComponent) {
163+
registry.async(this.options.parentComponent)(
164+
function (parentComponent) {
165+
parentComponent.bubble('update', true);
166+
}
167+
);
168+
}
169+
},
170+
156171
/**
157172
* Add image
158173
* @param event
@@ -205,6 +220,7 @@ define([
205220
}, this));
206221

207222
this._updateImagesRoles();
223+
this._contentUpdated();
208224
},
209225

210226
/**
@@ -284,6 +300,8 @@ define([
284300
imageData.label;
285301

286302
$title.text(value);
303+
304+
this._contentUpdated();
287305
},
288306

289307
/**
@@ -297,6 +315,8 @@ define([
297315

298316
imageData.isRemoved = true;
299317
$imageContainer.addClass('removed').hide().find('.is-removed').val(1);
318+
319+
this._contentUpdated();
300320
},
301321

302322
/**
@@ -321,6 +341,7 @@ define([
321341
}
322342
this.element.find('.image-' + data.type).val(this.options.types[data.type].value || 'no_selection');
323343
this._updateImagesRoles();
344+
this._contentUpdated();
324345
},
325346

326347
/**
@@ -339,6 +360,8 @@ define([
339360
$(element).val(index);
340361
}
341362
}, this));
363+
364+
this._contentUpdated();
342365
},
343366

344367
/**
@@ -362,6 +385,8 @@ define([
362385
}
363386
this.element.trigger('resort');
364387
}
388+
389+
this._contentUpdated();
365390
}
366391
});
367392

@@ -572,6 +597,8 @@ define([
572597

573598
$imageContainer.find('[name*="disabled"]').val(disabled);
574599
imageData.disabled = disabled;
600+
601+
this._contentUpdated();
575602
},
576603

577604
/**

app/code/Magento/ProductVideo/view/adminhtml/layout/catalog_product_form.xml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,11 @@
1919
</argument>
2020
</arguments>
2121
<block class="Magento\Catalog\Block\Adminhtml\Product\Helper\Form\Gallery\Content" as="content">
22+
<arguments>
23+
<argument name="config" xsi:type="array">
24+
<item name="parentComponent" xsi:type="string">product_form.product_form.block_gallery.block_gallery</item>
25+
</argument>
26+
</arguments>
2227
<block class="Magento\ProductVideo\Block\Adminhtml\Product\Edit\NewVideo" name="new-video" template="Magento_ProductVideo::product/edit/slideout/form.phtml"/>
2328
</block>
2429
</block>

app/code/Magento/ProductVideo/view/adminhtml/templates/helper/gallery.phtml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
/** @var $block \Magento\Catalog\Block\Adminhtml\Product\Helper\Form\Gallery\Content */
1010
$elementName = $block->getElement()->getName() . '[images]';
1111
$formName = $block->getFormName();
12+
$parentComponent = $block->getData('config/parentComponent')
13+
? 'data-parent-component="' . $block->getData('config/parentComponent') . '"'
14+
: '';
1215
?>
1316

1417
<div class="row">
@@ -33,6 +36,7 @@ $elementToggleCode = $element->getToggleCode() ? $element->getToggleCode() : 'to
3336
<div id="<?php echo $block->getHtmlId() ?>"
3437
class="gallery"
3538
data-mage-init='{"openVideoModal":{}}'
39+
<?php echo $parentComponent ?>
3640
data-images="<?php echo $block->escapeHtml($block->getImagesJson()) ?>"
3741
data-types="<?php echo $block->escapeHtml(
3842
$this->helper('Magento\Framework\Json\Helper\Data')->jsonEncode($block->getImageTypes())

0 commit comments

Comments
 (0)