Skip to content

Commit ec330f2

Browse files
author
Ihor Melnychenko
committed
Merge remote-tracking branch 'origin/PR2' into PR2
2 parents 2a3a399 + f66f299 commit ec330f2

File tree

7 files changed

+105
-25
lines changed

7 files changed

+105
-25
lines changed

app/code/Magento/Ui/view/base/web/js/form/components/button.js

Lines changed: 29 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2015 Magento. All rights reserved.
2+
* Copyright © 2015 Magento. All rights reserved.
33
* See COPYING.txt for license details.
44
*/
55

@@ -13,7 +13,11 @@ define([
1313

1414
return Element.extend({
1515
defaults: {
16-
template: 'ui/form/components/button'
16+
additionalClasses: {},
17+
displayArea: 'outsideGroup',
18+
displayAsLink: false,
19+
elementTmpl: 'ui/form/element/button',
20+
template: 'ui/form/components/button/simple'
1721
},
1822

1923
/**
@@ -22,7 +26,8 @@ define([
2226
* @returns {Object} Chainable.
2327
*/
2428
initialize: function () {
25-
return this._super();
29+
return this._super()
30+
._setClasses();
2631
},
2732

2833
/**
@@ -72,6 +77,27 @@ define([
7277
nodeTemplate: targetName
7378
});
7479
layout([child]);
80+
},
81+
82+
/**
83+
* Extends 'additionalClasses' object.
84+
*
85+
* @returns {Object} Chainable.
86+
*/
87+
_setClasses: function () {
88+
if (typeof this.additionalClasses === 'string') {
89+
this.additionalClasses = this.additionalClasses
90+
.trim()
91+
.split(' ')
92+
.reduce(function (classes, name) {
93+
classes[name] = true;
94+
95+
return classes;
96+
}, {}
97+
);
98+
}
99+
100+
return this;
75101
}
76102
});
77103
});

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

Lines changed: 50 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,14 @@ define([
1717
template: 'ui/modal/modal-component',
1818
options: {
1919
title: '',
20-
buttons: []
20+
buttons: [],
21+
keyEventHandlers: {}
2122
},
2223
valid: true,
2324
listens: {
2425
state: 'onState'
25-
}
26+
},
27+
modalClass: 'modal-component'
2628
},
2729

2830
/**
@@ -51,9 +53,32 @@ define([
5153
* @returns {Object} Chainable.
5254
*/
5355
initConfig: function () {
54-
this._super();
55-
this.modalClass = this.name.replace(/\./g, '_');
56-
this.rootSelector = '.' + this.modalClass;
56+
return this._super()
57+
.initSelector()
58+
.initModalEvents();
59+
},
60+
61+
/**
62+
* Configure modal selector
63+
*
64+
* @returns {Object} Chainable.
65+
*/
66+
initSelector: function () {
67+
this.contentSelector = '.' + this.modalClass;
68+
this.options.modalClass = this.name.replace(/\./g, '_');
69+
this.rootSelector = '.' + this.options.modalClass;
70+
71+
return this;
72+
},
73+
74+
/**
75+
* Configure modal keyboard handlers
76+
* and outer click
77+
*
78+
* @returns {Object} Chainable.
79+
*/
80+
initModalEvents: function () {
81+
this.options.keyEventHandlers.escapeKey = this.options.outerClickHandler = this.actionCancel.bind(this);
5782

5883
return this;
5984
},
@@ -62,7 +87,7 @@ define([
6287
* Initialize modal's content components
6388
*/
6489
initializeContent: function () {
65-
$.async(this.rootSelector, this, this.initModal);
90+
$.async(this.contentSelector, this, this.initModal);
6691
},
6792

6893
/**
@@ -202,6 +227,7 @@ define([
202227
*/
203228
setPrevValues: function (elem) {
204229
if (typeof elem.value === 'function') {
230+
this.modal.focus();
205231
elem.value(this.applied[elem.index]);
206232
} else if (elem.elems) {
207233
elem.elems().forEach(this.setPrevValues, this);
@@ -236,25 +262,31 @@ define([
236262

237263
if (buttons && buttons.length) {
238264
buttons.forEach(function (button) {
239-
button.click = this.getButtonClickHandler(button.click);
265+
button.click = this.getButtonClickHandler(button.actions);
240266
}, this);
241267
}
242268
},
243269

244270
/**
245-
* Override modal buttons callback placeholders with real callbacks
271+
* Generate button click handler based on button's 'actions' configuration
246272
*/
247-
getButtonClickHandler: function (clickConfig) {
248-
if (_.isObject(clickConfig)) {
249-
return clickConfig.closeAfter ?
250-
function () {
251-
this.triggerAction(clickConfig);
252-
this.closeModal();
253-
}.bind(this) :
254-
this.triggerAction.bind(this, clickConfig);
255-
}
273+
getButtonClickHandler: function (actionsConfig) {
274+
var actions = actionsConfig.map(
275+
function (actionConfig) {
276+
if (_.isObject(actionConfig)) {
277+
return this.triggerAction.bind(this, actionConfig);
278+
}
279+
280+
return this[actionConfig] ? this[actionConfig].bind(this) : function () {};
281+
}, this);
256282

257-
return this[clickConfig] ? this[clickConfig].bind(this) : function () {};
283+
return function () {
284+
actions.forEach(
285+
function (action) {
286+
action();
287+
}
288+
);
289+
};
258290
},
259291

260292
/**

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ define([
118118
'closeModal'
119119
);
120120

121+
_.extend(this.keyEventHandlers, this.options.keyEventHandlers);
121122
this.options.transitionEvent = transitionEvent;
122123
this._createWrapper();
123124
this._renderModal();
@@ -374,7 +375,8 @@ define([
374375
* Creates overlay, append it to wrapper, set previous click event on overlay.
375376
*/
376377
_createOverlay: function () {
377-
var events;
378+
var events,
379+
outerClickHandler = this.options.outerClickHandler || this.closeModal;
378380

379381
this.overlay = $('.' + this.options.overlayClass);
380382

@@ -386,7 +388,7 @@ define([
386388
}
387389
events = $._data(this.overlay.get(0), 'events');
388390
events ? this.prevOverlayHandler = events.click[0].handler : false;
389-
this.options.clickableOverlay ? this.overlay.unbind().on('click', this.closeModal) : false;
391+
this.options.clickableOverlay ? this.overlay.unbind().on('click', outerClickHandler) : false;
390392
},
391393

392394
/**

app/code/Magento/Ui/view/base/web/templates/form/components/button.html

Lines changed: 0 additions & 1 deletion
This file was deleted.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
<!--
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
-->
7+
<render args="elementTmpl"/>
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<!--
2+
/**
3+
* Copyright © 2015 Magento. All rights reserved.
4+
* See COPYING.txt for license details.
5+
*/
6+
-->
7+
<button type="button"
8+
css="
9+
'action-advanced': $data.displayAsLink,
10+
'action-secondary': !$data.displayAsLink
11+
"
12+
click="action"
13+
text="title">
14+
</button>

app/code/Magento/Ui/view/base/web/templates/modal/modal-component.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<!--
22
/**
3-
* Copyright 2015 Magento. All rights reserved.
3+
* Copyright © 2015 Magento. All rights reserved.
44
* See COPYING.txt for license details.
55
*/
66
-->

0 commit comments

Comments
 (0)