Skip to content

Commit c64122b

Browse files
committed
Merge branch 'MAGETWO-71425' of github.com:magento-trigger/magento2ce into MAGETWO-71425
2 parents cde5322 + 5c277cf commit c64122b

File tree

1 file changed

+39
-5
lines changed

1 file changed

+39
-5
lines changed

app/code/Magento/Rule/view/adminhtml/web/conditions-data-normalizer.js

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,15 @@ define([
77
'jquery',
88
'underscore'
99
], function ($, _) {
10+
'use strict';
11+
1012
var ConditionsDataNormalizer = new Class.create();
1113

1214
ConditionsDataNormalizer.prototype = {
15+
16+
/**
17+
* Initializes component.
18+
*/
1319
initialize: function () {
1420
this.patterns = {
1521
validate: /^[a-z0-9_-][a-z0-9_-]*(?:\[(?:\d*|[a-z0-9_-]+)\])*$/i,
@@ -46,13 +52,13 @@ define([
4652
*
4753
*/
4854
normalize: function normalize(value) {
49-
var _this = this;
55+
var el, _this = this;
5056

5157
this.pushes = {};
5258
this.data = {};
5359

5460
_.each(value, function (e, i) {
55-
var el = {};
61+
el = {};
5662
el[i] = e;
5763

5864
_this._addPair({
@@ -64,20 +70,33 @@ define([
6470
return this.data;
6571
},
6672

73+
/**
74+
* @param {Object} base
75+
* @param {String} key
76+
* @param {String} value
77+
* @return {Object}
78+
* @private
79+
*/
6780
_build: function build(base, key, value) {
6881
base[key] = value;
6982

7083
return base;
7184
},
7285

86+
/**
87+
* @param {Object} root
88+
* @param {String} value
89+
* @return {*}
90+
* @private
91+
*/
7392
_makeObject: function makeObject(root, value) {
7493
var keys = root.match(this.patterns.key),
75-
k; // nest, nest, ..., nest
94+
k, idx; // nest, nest, ..., nest
7695

7796
while ((k = keys.pop()) !== undefined) {
7897
// foo[]
7998
if (this.patterns.push.test(k)) {
80-
var idx = this._incrementPush(root.replace(/\[\]$/, ''));
99+
idx = this._incrementPush(root.replace(/\[\]$/, ''));
81100
value = this._build([], idx, value);
82101
} // foo[n]
83102
else if (this.patterns.fixed.test(k)) {
@@ -91,6 +110,11 @@ define([
91110
return value;
92111
},
93112

113+
/**
114+
* @param {String} key
115+
* @return {Number}
116+
* @private
117+
*/
94118
_incrementPush: function incrementPush(key) {
95119
if (this.pushes[key] === undefined) {
96120
this.pushes[key] = 0;
@@ -99,10 +123,20 @@ define([
99123
return this.pushes[key]++;
100124
},
101125

126+
/**
127+
* @param {Object} pair
128+
* @return {Object}
129+
* @private
130+
*/
102131
_addPair: function addPair(pair) {
103-
if (!this.patterns.validate.test(pair.name)) return this;
104132
var obj = this._makeObject(pair.name, pair.value);
133+
134+
if (!this.patterns.validate.test(pair.name)) {
135+
return this;
136+
}
137+
105138
this.data = $.extend(true, this.data, obj);
139+
106140
return this;
107141
}
108142
};

0 commit comments

Comments
 (0)