Skip to content

Commit 7c969f9

Browse files
committed
Merge remote-tracking branch 'origin/MAGETWO-54256' into NORD-FIXES
2 parents 11a384f + a404b97 commit 7c969f9

File tree

19 files changed

+296
-10
lines changed

19 files changed

+296
-10
lines changed

app/code/Magento/Backend/Block/System/Store/Edit.php

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55
*/
66
namespace Magento\Backend\Block\System\Store;
77

8+
use Magento\Framework\App\ObjectManager;
9+
use Magento\Framework\Serialize\SerializerInterface;
10+
811
/**
12+
* @api
13+
*
914
* Adminhtml store edit
1015
*/
1116
class Edit extends \Magento\Backend\Block\Widget\Form\Container
@@ -17,17 +22,25 @@ class Edit extends \Magento\Backend\Block\Widget\Form\Container
1722
*/
1823
protected $_coreRegistry = null;
1924

25+
/**
26+
* @var SerializerInterface
27+
*/
28+
private $serializer;
29+
2030
/**
2131
* @param \Magento\Backend\Block\Widget\Context $context
2232
* @param \Magento\Framework\Registry $registry
2333
* @param array $data
34+
* @param SerializerInterface|null $serializer
2435
*/
2536
public function __construct(
2637
\Magento\Backend\Block\Widget\Context $context,
2738
\Magento\Framework\Registry $registry,
28-
array $data = []
39+
array $data = [],
40+
SerializerInterface $serializer = null
2941
) {
3042
$this->_coreRegistry = $registry;
43+
$this->serializer = $serializer ?: ObjectManager::getInstance()->get(SerializerInterface::class);
3144
parent::__construct($context, $data);
3245
}
3346

@@ -127,4 +140,14 @@ protected function _buildFormClassName()
127140
{
128141
return parent::_buildFormClassName() . '\\' . ucwords($this->_coreRegistry->registry('store_type'));
129142
}
143+
144+
/**
145+
* Get data for store edit
146+
*
147+
* @return string
148+
*/
149+
public function getStoreData()
150+
{
151+
return $this->serializer->serialize($this->_coreRegistry->registry('store_data')->getData());
152+
}
130153
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
9+
<update handle="formkey"/>
10+
<body>
11+
<referenceContainer name="content">
12+
<block class="Magento\Backend\Block\Widget\Container" name="adminhtml_admin_delete_confirm" template="Magento_Backend::admin/delete_confirm.phtml"/>
13+
</referenceContainer>
14+
</body>
15+
</page>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
<?xml version="1.0"?>
2+
<!--
3+
/**
4+
* Copyright © Magento, Inc. All rights reserved.
5+
* See COPYING.txt for license details.
6+
*/
7+
-->
8+
<page xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:View/Layout/etc/page_configuration.xsd">
9+
<update handle="formkey"/>
10+
<body>
11+
<referenceContainer name="content">
12+
<block class="Magento\Backend\Block\System\Store\Edit" name="adminhtml_admin_save_confirm" template="Magento_Backend::admin/save_confirm.phtml"/>
13+
</referenceContainer>
14+
</body>
15+
</page>
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
?>
7+
<script type="text/x-magento-init">
8+
{
9+
"#edit_form": {
10+
"Magento_Backend/js/delete-with-confirm": {}
11+
}
12+
}
13+
</script>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
/**
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
7+
/** @var \Magento\Backend\Block\System\Store\Edit $block */
8+
9+
?>
10+
<script type="text/x-magento-init">
11+
{
12+
"#edit_form": {
13+
"Magento_Backend/js/save-with-confirm": {
14+
"storeData": <?= /* @noEscape */ $block->getStoreData() ?>
15+
}
16+
}
17+
}
18+
</script>
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
/**
2+
*
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
define([
7+
'jquery',
8+
'Magento_Backend/js/validate-store'
9+
], function ($, validateStore) {
10+
'use strict';
11+
12+
$.widget('mage.deleteWithConfirm', validateStore, {});
13+
14+
return $.mage.deleteWithConfirm;
15+
});
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/**
2+
*
3+
* Copyright © Magento, Inc. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
define([
7+
'jquery',
8+
'Magento_Backend/js/validate-store'
9+
], function ($, validateStore) {
10+
'use strict';
11+
12+
$.widget('mage.saveWithConfirm', validateStore, {
13+
14+
/**
15+
* Check is it need to show confirmation popup
16+
*
17+
* @returns {Boolean}
18+
*/
19+
_needConfirm: function () {
20+
21+
var storeData = this.settings.storeData,
22+
23+
/* edit store view*/
24+
storeViewEdit = $('[name="store[store_id]"]').length,
25+
groupId = $('[name="store[group_id]"]').val(),
26+
isNewStoreView = !$('[name="store[store_id]"]').val(),
27+
28+
/* edit store */
29+
storeEdit = $('[name="group[group_id]"]').length,
30+
storeId = $('[name="group[group_id]"]').val(),
31+
rootCategoryId = $('[name="group[root_category_id]"]').val(),
32+
defaultStoreView = $('[name="group[default_store_id]"]').val(),
33+
34+
/* edit website */
35+
websiteEdit = $('[name="website[website_id]"]').length,
36+
defaultStore = $('[name="website[default_group_id]"]').val(),
37+
38+
/* conditions */
39+
storeViewUpdated = storeViewEdit && (isNewStoreView || storeData['group_id'] !== groupId),
40+
storeUpdated = storeEdit && storeId &&
41+
(rootCategoryId !== null && storeData['root_category_id'] !== rootCategoryId ||
42+
defaultStoreView !== null && storeData['default_store_id'] !== defaultStoreView),
43+
websiteUpdated = websiteEdit && defaultStore !== null && storeData['default_group_id'] !== defaultStore;
44+
45+
return storeViewUpdated || storeUpdated || websiteUpdated;
46+
}
47+
});
48+
49+
return $.mage.saveWithConfirm;
50+
});
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
/**
2+
* Copyright © Magento, Inc. All rights reserved.
3+
* See COPYING.txt for license details.
4+
*/
5+
define([
6+
'jquery',
7+
'jquery/ui',
8+
'mage/dataPost',
9+
'mage/backend/validation',
10+
'Magento_Ui/js/modal/confirm'
11+
], function ($, jqueryUi, dataPost, validation, modalConfirm) {
12+
'use strict';
13+
14+
$.widget('mage.storeValidation', {
15+
16+
/**
17+
* Validation creation
18+
* @protected
19+
*/
20+
_create: function () {
21+
var form = this.element[0],
22+
validator = $.data(form, 'validator');
23+
24+
if (validator && validator.settings) {
25+
validator.settings.submitHandler = this._saveHandler;
26+
validator.settings.confirmCallback = this._needConfirm;
27+
$.extend(validator.settings, this.options);
28+
$.data(form, 'validator', validator);
29+
}
30+
},
31+
32+
/**
33+
* Check is it need to show confirmation popup
34+
*
35+
* @returns {Boolean}
36+
*/
37+
_needConfirm: function () {
38+
return true;
39+
},
40+
41+
/**
42+
* Save form with confirmation if needed
43+
*
44+
* @param {Object} form
45+
* @private
46+
*/
47+
_saveHandler: function (form) {
48+
var formData = {},
49+
requestData = {},
50+
options = $.data(form, 'validator').settings;
51+
52+
if ($(form).validation('isValid')) {
53+
$.each($(form).serializeArray(), function () {
54+
formData[this.name] = this.value || '';
55+
});
56+
requestData = {
57+
action: $(form).attr('action'),
58+
data: formData
59+
};
60+
61+
if (options.confirmCallback.call(this)) {
62+
modalConfirm({
63+
title: $.mage.__('Warning message'),
64+
content: $.mage.__('This operation can take a long time'),
65+
actions: {
66+
/**
67+
* 'Confirm' action handler.
68+
*/
69+
confirm: function () {
70+
dataPost().postData(requestData);
71+
}
72+
}
73+
});
74+
} else {
75+
dataPost().postData(requestData);
76+
}
77+
}
78+
}
79+
});
80+
81+
return $.mage.storeValidation;
82+
});

dev/tests/functional/tests/app/Magento/Backend/Test/Page/Adminhtml/EditGroup.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,5 +9,6 @@
99
<page name="EditGroup" area="Adminhtml" mca="system_store/editGroup" module="Magento_Backend">
1010
<block name="formPageActions" class="Magento\Backend\Test\Block\System\Store\FormPageActions" locator=".page-main-actions" strategy="css selector"/>
1111
<block name="editFormGroup" class="Magento\Backend\Test\Block\System\Store\Edit\Form\GroupForm" locator="#edit_form" strategy="css selector"/>
12+
<block name="modalBlock" class="Magento\Ui\Test\Block\Adminhtml\Modal" locator="._show[data-role=modal]" strategy="css selector"/>
1213
</page>
1314
</config>

dev/tests/functional/tests/app/Magento/Backend/Test/Page/Adminhtml/EditStore.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,6 @@
1010
<block name="formPageActions" class="Magento\Backend\Test\Block\System\Store\FormPageActions" locator=".page-main-actions" strategy="css selector"/>
1111
<block name="storeForm" class="Magento\Backend\Test\Block\System\Store\Edit\Form\StoreForm" locator="[id='page:main-container']" strategy="css selector"/>
1212
<block name="messagesBlock" class="Magento\Backend\Test\Block\Messages" locator="#messages" strategy="css selector"/>
13+
<block name="modalBlock" class="Magento\Ui\Test\Block\Adminhtml\Modal" locator="._show[data-role=modal]" strategy="css selector"/>
1314
</page>
1415
</config>

0 commit comments

Comments
 (0)