Skip to content

Commit 5ded892

Browse files
author
Olexandr Lysenko
committed
Merge remote-tracking branch 'origin/MAGETWO-50412' into bugfixes
2 parents e381231 + e346437 commit 5ded892

File tree

6 files changed

+138
-54
lines changed

6 files changed

+138
-54
lines changed

app/code/Magento/Catalog/view/adminhtml/templates/catalog/product/attribute/set/main.phtml

Lines changed: 40 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -208,6 +208,8 @@
208208
},
209209

210210
submit : function() {
211+
var i, child, newNode;
212+
211213
if( TreePanels.root.firstChild == TreePanels.root.lastChild ) {
212214
return;
213215
}
@@ -221,6 +223,7 @@
221223

222224
if( editSet.currentNode && editSet.currentNode.attributes.cls == 'folder' ) {
223225
TreePanels.root.removeChild(editSet.currentNode);
226+
224227
for( i in editSet.currentNode.childNodes ) {
225228
if( editSet.currentNode.childNodes[i].id ) {
226229
child = editSet.currentNode.childNodes[i];
@@ -231,12 +234,20 @@
231234
}
232235
}
233236
}
237+
234238
editSet.req.removeGroups[editSet.currentNode.id] = editSet.currentNode.id;
235239
editSet.currentNode = false;
236240
}
237241
},
238242

239243
SystemNodesExists : function(currentNode) {
244+
if (!currentNode) {
245+
alert({
246+
content: '<?php echo $block->escapeJs(__('Please select a node.')) ?>'
247+
});
248+
return;
249+
}
250+
240251
for (i in currentNode.childNodes) {
241252
if (currentNode.childNodes[i].id) {
242253
child = editSet.currentNode.childNodes[i];
@@ -253,31 +264,40 @@
253264

254265
addGroup : function() {
255266
prompt({
267+
title: "<?php /* @escapeNotVerified */ echo __('Add New Group') ?>",
256268
content: "<?php /* @escapeNotVerified */ echo __('Please enter a new group name.') ?>",
257269
value: "",
270+
validation: true,
271+
validationRules: ['required-entry'],
272+
attributesForm: {
273+
novalidate: 'novalidate',
274+
action: ''
275+
},
276+
attributesField: {
277+
name: 'name',
278+
'data-validate': '{required:true}',
279+
maxlength: '255'
280+
},
258281
actions: {
259282
confirm: function (group_name) {
260283
group_name = group_name.strip();
261-
if( group_name == '' ) {
262-
self.addGroup();
263-
} else if( group_name != false && group_name != null && group_name != '' ) {
264-
265-
if (!editSet.validateGroupName(group_name, 0)) {
266-
return;
267-
}
268-
269-
var newNode = new Ext.tree.TreeNode({
270-
text : group_name.escapeHTML(),
271-
cls : 'folder',
272-
allowDrop : true,
273-
allowDrag : true
274-
});
275-
TreePanels.root.appendChild(newNode);
276-
newNode.addListener('beforemove', editSet.groupBeforeMove);
277-
newNode.addListener('beforeinsert', editSet.groupBeforeInsert);
278-
newNode.addListener('beforeappend', editSet.groupBeforeInsert);
279-
newNode.addListener('click', editSet.register);
284+
285+
if (!editSet.validateGroupName(group_name, 0)) {
286+
return;
280287
}
288+
289+
var newNode = new Ext.tree.TreeNode({
290+
text : group_name.escapeHTML(),
291+
cls : 'folder',
292+
allowDrop : true,
293+
allowDrag : true
294+
});
295+
296+
TreePanels.root.appendChild(newNode);
297+
newNode.addListener('beforemove', editSet.groupBeforeMove);
298+
newNode.addListener('beforeinsert', editSet.groupBeforeInsert);
299+
newNode.addListener('beforeappend', editSet.groupBeforeInsert);
300+
newNode.addListener('click', editSet.register);
281301
}
282302
}
283303
});
@@ -302,7 +322,7 @@
302322
}
303323
for (var i=0; i < TreePanels.root.childNodes.length; i++) {
304324
if (TreePanels.root.childNodes[i].text.toLowerCase() == name.toLowerCase() && TreePanels.root.childNodes[i].id != exceptNodeId) {
305-
errorText = '<?php /* @escapeNotVerified */ echo __('An attribute group named "/name/" already exists".') ?>';
325+
errorText = '<?php /* @escapeNotVerified */ echo __('An attribute group named "/name/" already exists.') ?>';
306326
alert({
307327
content: errorText.replace("/name/",name)
308328
});
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!--
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
-->
7+
<form <%= formAttr %>>
8+
<fieldset class="admin__fieldset">
9+
<div class="admin__field admin__field-wide">
10+
<% if(data.label){ %>
11+
<label for="prompt-field-<%- data.id %>" class="admin__field-label">
12+
<span><%= data.label %></span>
13+
</label>
14+
<% } %>
15+
<div class="admin__field-control">
16+
<input type="text" data-role="prompt-field" id="prompt-field-<%- data.id %>" class="admin__control-text" <%= inputAttr %>/>
17+
</div>
18+
</div>
19+
</fieldset>
20+
</form>

app/code/Magento/Ui/view/base/web/js/modal/modal.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ define([
4242
*/
4343
$.widget('mage.modal', {
4444
options: {
45+
id: null,
4546
type: 'popup',
4647
title: '',
4748
subTitle: '',
@@ -121,6 +122,7 @@ define([
121122
'closeModal'
122123
);
123124

125+
this.options.id = this.uuid;
124126
this.options.transitionEvent = transitionEvent;
125127
this._createWrapper();
126128
this._renderModal();

app/code/Magento/Ui/view/base/web/js/modal/prompt.js

Lines changed: 55 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,24 @@
66
define([
77
'jquery',
88
'underscore',
9+
'mage/template',
10+
'text!ui/template/modal/modal-prompt-content.html',
911
'jquery/ui',
1012
'Magento_Ui/js/modal/modal',
1113
'mage/translate'
12-
], function ($, _) {
14+
], function ($, _, template, promptContentTmpl) {
1315
'use strict';
1416

1517
$.widget('mage.prompt', $.mage.modal, {
1618
options: {
1719
modalClass: 'prompt',
18-
promptField: '[data-role="promptField"]',
20+
promptContentTmpl: promptContentTmpl,
21+
promptField: '[data-role="prompt-field"]',
1922
attributesForm: {},
2023
attributesField: {},
2124
value: '',
25+
validation: false,
26+
validationRules: [],
2227
actions: {
2328

2429
/**
@@ -64,61 +69,73 @@ define([
6469
*/
6570
_create: function () {
6671
this.options.focus = this.options.promptField;
72+
this.options.validation = this.options.validation && this.options.validationRules.length;
6773
this._super();
68-
this.modal.find(this.options.modalContent).append(this.getFieldTemplate());
74+
this.modal.find(this.options.modalContent).append(this.getFormTemplate());
6975
this.modal.find(this.options.modalCloseBtn).off().on('click', _.bind(this.closeModal, this, false));
76+
77+
if (this.options.validation) {
78+
this.setValidationClasses();
79+
}
80+
7081
this.openModal();
7182
},
7283

7384
/**
74-
* Field template getter.
85+
* Form template getter.
7586
*
76-
* @returns {Object} Field template
87+
* @returns {Object} Form template.
7788
*/
78-
getFieldTemplate: function () {
79-
var input = '<input data-role="promptField" id="prompt-field" class="admin__control-text" type="text"/>',
80-
form = '<form/>',
81-
wrapper = '<div class="prompt-message"/>',
82-
$wrapper = $(wrapper),
83-
$form = $(form),
84-
$input = $(input),
89+
getFormTemplate: function () {
90+
var formTemplate,
91+
formAttr = '',
92+
inputAttr = '',
8593
attributeName;
8694

87-
for (attributeName in this.options.attributesField) {
88-
if (this.options.attributesField.hasOwnProperty(attributeName)) {
89-
$input.attr(attributeName, this.options.attributesField[attributeName]);
95+
for (attributeName in this.options.attributesForm) {
96+
if (this.options.attributesForm.hasOwnProperty(attributeName)) {
97+
formAttr = formAttr + ' ' + attributeName + '="' +
98+
this.options.attributesForm[attributeName] + '"';
9099
}
91100
}
92101

93-
for (attributeName in this.options.attributesForm) {
94-
if (this.options.attributesForm.hasOwnProperty(attributeName)) {
95-
$form.attr(attributeName, this.options.attributesForm[attributeName]);
102+
for (attributeName in this.options.attributesField) {
103+
if (this.options.attributesField.hasOwnProperty(attributeName)) {
104+
inputAttr = inputAttr + ' ' + attributeName + '="' +
105+
this.options.attributesField[attributeName] + '"';
96106
}
97107
}
98108

99-
$form.append($input);
109+
formTemplate = $(template(this.options.promptContentTmpl, {
110+
data: this.options,
111+
formAttr: formAttr,
112+
inputAttr: inputAttr
113+
}));
100114

101-
return $wrapper.append($form);
115+
return formTemplate;
102116
},
103117

104118
/**
105-
* Compile template and append to wrapper.
119+
* Remove widget
106120
*/
107-
_renderModal: function () {
108-
this._super();
109-
110-
if (this.options.label) {
111-
this.element.append(this.options.label);
112-
}
121+
_remove: function () {
122+
this.modal.remove();
123+
},
113124

114-
this.element.wrap('<label for="prompt-field"></label>');
125+
/**
126+
* Validate prompt field
127+
*/
128+
validate: function () {
129+
return $.validator.validateSingleElement(this.options.promptField);
115130
},
116131

117132
/**
118-
* Remove widget
133+
* Add validation classes to prompt field
119134
*/
120-
_remove: function () {
121-
this.modal.remove();
135+
setValidationClasses: function () {
136+
this.modal.find(this.options.promptField).attr('class', $.proxy(function (i, val) {
137+
return val + ' ' + this.options.validationRules.join(' ');
138+
}, this));
122139
},
123140

124141
/**
@@ -136,11 +153,16 @@ define([
136153
var value;
137154

138155
if (result) {
156+
if (this.options.validation && !this.validate()) {
157+
return false;
158+
}
159+
139160
value = this.modal.find(this.options.promptField).val();
140-
this.options.actions.confirm(value);
161+
this.options.actions.confirm.call(this, value);
141162
} else {
142163
this.options.actions.cancel.call(this, result);
143164
}
165+
144166
this.options.actions.always();
145167
this.element.bind('promptclosed', _.bind(this._remove, this));
146168

@@ -149,6 +171,6 @@ define([
149171
});
150172

151173
return function (config) {
152-
return $('<div></div>').html(config.content).prompt(config);
174+
return $('<div class="prompt-message"></div>').html(config.content).prompt(config);
153175
};
154176
});
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
<!--
2+
/**
3+
* Copyright © 2016 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
-->
7+
<form <%= formAttr %>>
8+
<fieldset class="fieldset">
9+
<div class="field">
10+
<% if(data.label){ %>
11+
<label for="prompt-field-<%- data.id %>" class="label">
12+
<span><%= data.label %></span>
13+
</label>
14+
<% } %>
15+
<div class="control">
16+
<input type="text" data-role="prompt-field" id="prompt-field-<%- data.id %>" class="input-text" <%= inputAttr %>/>
17+
</div>
18+
</div>
19+
</fieldset>
20+
</form>

app/design/adminhtml/Magento/backend/web/css/source/components/_modals_extend.less

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@
6969
.modal-popup {
7070
&.prompt {
7171
.prompt-message {
72-
padding: @modal-prompt-message__padding 0;
72+
padding-bottom: @modal-prompt-message__padding;
7373

7474
input {
7575
width: 100%;

0 commit comments

Comments
 (0)