From c34bd624a7b742a19bc277cf4d8dac85c76edb40 Mon Sep 17 00:00:00 2001 From: Volodymyr Zaets Date: Tue, 17 May 2016 13:39:07 +0300 Subject: [PATCH 01/47] MAGETWO-52788: [UI Component] Dynamic Rows: support status being changed - and fix dnd --- .../Ui/view/base/web/js/dynamic-rows/dnd.js | 5 +- .../web/js/dynamic-rows/dynamic-rows-grid.js | 2 +- .../base/web/js/dynamic-rows/dynamic-rows.js | 111 +++++++++++++++++- 3 files changed, 112 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dnd.js b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dnd.js index e52177f74e461..594e300145b3a 100644 --- a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dnd.js +++ b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dnd.js @@ -131,7 +131,8 @@ define([ drEl.instance = recordNode = this.processingStyles(recordNode, elem); drEl.instanceCtx = this.getRecord(originRecord[0]); drEl.eventMousedownY = isTouchDevice ? event.originalEvent.touches[0].pageY : event.pageY; - drEl.minYpos = $table.offset().top - originRecord.offset().top + $table.find('thead').outerHeight(); + drEl.minYpos = + $table.offset().top - originRecord.offset().top + $table.find('thead').outerHeight(); drEl.maxYpos = drEl.minYpos + $table.find('tbody').outerHeight() - originRecord.outerHeight(); $tableWrapper.append(recordNode); @@ -189,7 +190,7 @@ define([ pageY = isTouchDevice ? event.originalEvent.touches[0].pageY : event.pageY, positionY = pageY - drEl.eventMousedownY; - drEl.depElement = this.getDepElement(drEl.instance, positionY); + drEl.depElement = this.getDepElement(drEl.instance, positionY, this.draggableElement.originRow); if (drEl.depElement) { depElementCtx = this.getRecord(drEl.depElement.elem[0]); diff --git a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows-grid.js b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows-grid.js index bbc6033df0041..90e12a2bce357 100644 --- a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows-grid.js +++ b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows-grid.js @@ -22,7 +22,7 @@ define([ identificationDRProperty: 'id', listens: { 'insertData': 'processingInsertData', - 'recordData': 'initElements setToInsertData' + 'recordData': 'initElements setToInsertData, checkDefaultState' } }, diff --git a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js index 37df101b208fb..7c7b57b48df74 100644 --- a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js +++ b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js @@ -36,6 +36,8 @@ define([ deleteValue: true, showSpinner: true, isDifferedFromDefault: false, + defaultState: [], + isDefaultState: true, fallbackResetTpl: 'ui/form/element/helper/fallback-reset-link', dndConfig: { name: '${ $.name }_dnd', @@ -60,9 +62,10 @@ define([ disabled: 'setDisabled', childTemplate: 'initHeader', recordTemplate: 'onUpdateRecordTemplate', - recordData: 'setDifferedFromDefault parsePagesData', + recordData: 'setDifferedFromDefault parsePagesData checkDefaultState', currentPage: 'changePage', - elems: 'checkSpinner' + elems: 'checkSpinner', + isDefaultState: 'updateTrigger' }, modules: { dnd: '${ $.dndConfig.name }' @@ -83,6 +86,7 @@ define([ */ initialize: function () { this._super() + .initDefaultState() .initChildren() .initDnd() .setColumnsHeaderListener() @@ -109,7 +113,8 @@ define([ 'disabled', 'labels', 'showSpinner', - 'isDifferedFromDefault' + 'isDifferedFromDefault', + 'isDefaultState' ]); return this; @@ -142,6 +147,106 @@ define([ return this; }, + /** + * Check default component state or not + * + * @param {Array} data - records data + */ + checkDefaultState: function (data) { + var result = true, + recordsData = utils.copy(this.recordData()) || data, + i = 0, + length = this.defaultState.length, + currentData = this.deleteProperty ? + _.filter(recordsData, function (elem) { + return elem[this.deleteProperty] !== this.deleteValue; + }, this) : recordsData; + + if (length !== currentData.length) { + this.isDefaultState(false); + + return; + } + + for (i; i < length; i++) { + if (!this._compareObject(this.defaultState[i], currentData[i])) { + result = false; + break; + } + } + + this.isDefaultState(result); + }, + + /** + * Compare objects. Compared only properties from origin object, + * if current object has more properties - they are not considered + * + * @param {Object} origin - first object + * @param {Object} current - second object + * + * @returns {Boolean} result - is equal this objects or not + */ + _compareObject: function (origin, current) { + var prop, + result = true; + + for (prop in origin) { + if (this._castValue(origin[prop]) != this._castValue(current[prop])) { + result = false; + break; + } + } + + return result; + }, + + /** + * Check value type and cast to boolean if needed + * + * @param {*} value + * + * @returns {Boolean|*} casted or origin value + */ + _castValue: function (value) { + if (_.isUndefined(value) || value === '' || _.isNull(value)) { + return false; + } else { + return value; + } + }, + + /** + * Init default component state + * + * @param {Array} data + * + * @returns Chainable. + */ + initDefaultState: function (data) { + var defaultState = data || utils.copy(this.recordData()); + + this.defaultState = defaultState; + + return this; + }, + + /** + * Triggered update event + * + * @param {Boolean} val + */ + updateTrigger: function (val) { + this.trigger('update', !val); + }, + + /** + * Was changes or not + */ + hasChanged: function () { + return !this.isDefaultState(); + }, + /** * Render column header */ From 2490db2e3c5315dbdd97b41a55cb553fc721ffef Mon Sep 17 00:00:00 2001 From: Volodymyr Zaets Date: Tue, 17 May 2016 14:29:04 +0300 Subject: [PATCH 02/47] MAGETWO-52788: [UI Component] Dynamic Rows: support status being changed --- .../Ui/view/base/web/js/dynamic-rows/dynamic-rows.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js index 7c7b57b48df74..d3c468895e800 100644 --- a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js +++ b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js @@ -148,7 +148,7 @@ define([ }, /** - * Check default component state or not + * Checks whether component's state is default or not * * @param {Array} data - records data */ @@ -192,7 +192,11 @@ define([ result = true; for (prop in origin) { - if (this._castValue(origin[prop]) != this._castValue(current[prop])) { + if (_.isObject(origin[prop]) && _.isObject(current[prop])) { + if (!this._compareObject(origin[prop], current[prop])) { + return false; + } + } else if (this._castValue(origin[prop]) != this._castValue(current[prop])) { result = false; break; } From 04364c7ad8913a129e21595c18cea84f2a43a752 Mon Sep 17 00:00:00 2001 From: Volodymyr Zaets Date: Tue, 17 May 2016 14:33:28 +0300 Subject: [PATCH 03/47] MAGETWO-52788: [UI Component] Dynamic Rows: support status being changed --- .../Ui/view/base/web/js/dynamic-rows/dynamic-rows.js | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js index d3c468895e800..0e9d354109106 100644 --- a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js +++ b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js @@ -188,8 +188,7 @@ define([ * @returns {Boolean} result - is equal this objects or not */ _compareObject: function (origin, current) { - var prop, - result = true; + var prop; for (prop in origin) { if (_.isObject(origin[prop]) && _.isObject(current[prop])) { @@ -197,12 +196,11 @@ define([ return false; } } else if (this._castValue(origin[prop]) != this._castValue(current[prop])) { - result = false; - break; + return false; } } - return result; + return true; }, /** From 3a53abee9d82990757bc3881d56ee6365c958405 Mon Sep 17 00:00:00 2001 From: Volodymyr Zaets Date: Tue, 17 May 2016 16:30:36 +0300 Subject: [PATCH 04/47] MAGETWO-52788: [UI Component] Dynamic Rows: support status being changed --- .../base/web/js/dynamic-rows/dynamic-rows.js | 20 +++++++++---------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js index 0e9d354109106..dc8dd0ee42f89 100644 --- a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js +++ b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js @@ -121,7 +121,7 @@ define([ }, /** - * Init DND module + * Inits DND module * * @returns {Object} Chainable. */ @@ -134,7 +134,7 @@ define([ }, /** - * Check columnsHeaderAfterRender property, + * Checks columnsHeaderAfterRender property, * and set listener on elems if needed * * @returns {Object} Chainable. @@ -149,12 +149,10 @@ define([ /** * Checks whether component's state is default or not - * - * @param {Array} data - records data */ - checkDefaultState: function (data) { + checkDefaultState: function () { var result = true, - recordsData = utils.copy(this.recordData()) || data, + recordsData = utils.copy(this.recordData()), i = 0, length = this.defaultState.length, currentData = this.deleteProperty ? @@ -179,7 +177,7 @@ define([ }, /** - * Compare objects. Compared only properties from origin object, + * Compares objects. Compares only properties from origin object, * if current object has more properties - they are not considered * * @param {Object} origin - first object @@ -204,7 +202,7 @@ define([ }, /** - * Check value type and cast to boolean if needed + * Checks value type and cast to boolean if needed * * @param {*} value * @@ -219,7 +217,7 @@ define([ }, /** - * Init default component state + * Inits default component state * * @param {Array} data * @@ -234,7 +232,7 @@ define([ }, /** - * Triggered update event + * Triggers update event * * @param {Boolean} val */ @@ -243,7 +241,7 @@ define([ }, /** - * Was changes or not + * Returns component state */ hasChanged: function () { return !this.isDefaultState(); From 8b4500055c69c62b02a23be664b06174d34d0ba0 Mon Sep 17 00:00:00 2001 From: Volodymyr Zaets Date: Mon, 23 May 2016 10:36:07 +0300 Subject: [PATCH 05/47] MAGETWO-52788: [UI Component] Dynamic Rows: support status being changed --- .../base/web/js/dynamic-rows/dynamic-rows.js | 52 ++++++++++++++----- 1 file changed, 39 insertions(+), 13 deletions(-) diff --git a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js index dc8dd0ee42f89..2446b124ab254 100644 --- a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js +++ b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js @@ -153,27 +153,49 @@ define([ checkDefaultState: function () { var result = true, recordsData = utils.copy(this.recordData()), - i = 0, - length = this.defaultState.length, currentData = this.deleteProperty ? _.filter(recordsData, function (elem) { return elem[this.deleteProperty] !== this.deleteValue; }, this) : recordsData; - if (length !== currentData.length) { - this.isDefaultState(false); + if (_.isArray(this.defaultState)) { + result = this._compareArrays(this.defaultState, currentData); + } + + this.isDefaultState(result); + }, + + /** + * Compares arrays. + * + * @param {Object} origin - first array + * @param {Object} current - second array + * + * @returns {Boolean} result - is equal this arrays or not + */ + _compareArrays: function (origin, current) { + var index = 0, + length = origin.length; - return; + if (origin.length !== current.length) { + return false; } - for (i; i < length; i++) { - if (!this._compareObject(this.defaultState[i], currentData[i])) { - result = false; - break; + for (index; index < length; index++) { + if (_.isArray(origin[index]) && _.isArray(current[index])) { + if (!this._compareArrays(origin[index], current[index])) { + return false; + } + } else if (typeof origin[index] === 'object' && typeof current[index] === 'object') { + if (!this._compareObject(origin[index], current[index])) { + return false; + } + } else if (this._castValue(origin[index]) != this._castValue(current[index])){ + return false } } - this.isDefaultState(result); + return true; }, /** @@ -189,12 +211,16 @@ define([ var prop; for (prop in origin) { - if (_.isObject(origin[prop]) && _.isObject(current[prop])) { + if (_.isArray(origin[prop]) && _.isArray(current[prop])) { + if (!this._compareArrays(origin[prop], current[prop])) { + return false; + } + } else if (typeof origin[prop] === 'object' && typeof current[prop] === 'object') { if (!this._compareObject(origin[prop], current[prop])) { return false; } - } else if (this._castValue(origin[prop]) != this._castValue(current[prop])) { - return false; + } else if (this._castValue(origin[prop]) != this._castValue(current[prop])){ + return false } } From 65e7a6dd2b0eb2a598fb109b5d4fff89dbb1ea79 Mon Sep 17 00:00:00 2001 From: Volodymyr Zaets Date: Mon, 23 May 2016 11:37:13 +0300 Subject: [PATCH 06/47] MAGETWO-52788: [UI Component] Dynamic Rows: support status being changed - fix codestyle --- .../base/web/js/dynamic-rows/dynamic-rows.js | 22 ++++++++++--------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js index 2446b124ab254..e7fbf182f0866 100644 --- a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js +++ b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js @@ -181,6 +181,7 @@ define([ return false; } + /*eslint-disable max-depth, eqeqeq */ for (index; index < length; index++) { if (_.isArray(origin[index]) && _.isArray(current[index])) { if (!this._compareArrays(origin[index], current[index])) { @@ -190,10 +191,10 @@ define([ if (!this._compareObject(origin[index], current[index])) { return false; } - } else if (this._castValue(origin[index]) != this._castValue(current[index])){ - return false + } else if (this._castValue(origin[index]) != this._castValue(current[index])) { + return false; } - } + }/*eslint-enable max-depth, eqeqeq */ return true; }, @@ -210,6 +211,7 @@ define([ _compareObject: function (origin, current) { var prop; + /*eslint-disable max-depth, eqeqeq*/ for (prop in origin) { if (_.isArray(origin[prop]) && _.isArray(current[prop])) { if (!this._compareArrays(origin[prop], current[prop])) { @@ -219,10 +221,10 @@ define([ if (!this._compareObject(origin[prop], current[prop])) { return false; } - } else if (this._castValue(origin[prop]) != this._castValue(current[prop])){ - return false + } else if (this._castValue(origin[prop]) != this._castValue(current[prop])) { + return false; } - } + }/*eslint-enable max-depth, eqeqeq */ return true; }, @@ -237,9 +239,9 @@ define([ _castValue: function (value) { if (_.isUndefined(value) || value === '' || _.isNull(value)) { return false; - } else { - return value; } + + return value; }, /** @@ -251,7 +253,7 @@ define([ */ initDefaultState: function (data) { var defaultState = data || utils.copy(this.recordData()); - + this.defaultState = defaultState; return this; @@ -270,7 +272,7 @@ define([ * Returns component state */ hasChanged: function () { - return !this.isDefaultState(); + return !this.isDefaultState(); }, /** From 5e00e7695d3e27ad8dce3c65a68f01277df14399 Mon Sep 17 00:00:00 2001 From: Volodymyr Zaets Date: Tue, 24 May 2016 15:30:42 +0300 Subject: [PATCH 07/47] MAGETWO-52788: [UI Component] Dynamic Rows: support status being changed --- .../base/web/js/dynamic-rows/dynamic-rows.js | 157 +++++++++--------- 1 file changed, 78 insertions(+), 79 deletions(-) diff --git a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js index e7fbf182f0866..324e429e67f58 100644 --- a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js +++ b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js @@ -14,6 +14,83 @@ define([ ], function (ko, utils, _, layout, uiCollection, registry, $t) { 'use strict'; + /** + * Compares arrays. + * + * @param {Array} base - array as method bases its decision on first argument. + * @param {Array} current - second array + * + * @returns {Boolean} result - is current array equal to base array + */ + function compareArrays(base, current) { + var index = 0, + length = base.length; + + if (base.length !== current.length) { + return false; + } + + /*eslint-disable max-depth, eqeqeq */ + for (index; index < length; index++) { + if (_.isArray(base[index]) && _.isArray(current[index])) { + if (!compareArrays(base[index], current[index])) { + return false; + } + } else if (typeof base[index] === 'object' && typeof current[index] === 'object') { + if (!compareObjects(base[index], current[index])) { + return false; + } + } else if (castValue(base[index]) != castValue(current[index])) { + return false; + } + }/*eslint-enable max-depth, eqeqeq */ + + return true; + } + + /** + * Compares objects. Compares only properties from origin object, + * if current object has more properties - they are not considered + * + * @param {Object} base - first object + * @param {Object} current - second object + * + * @returns {Boolean} result - is current object equal to base object + */ + function compareObjects(base, current) { + var prop; + + /*eslint-disable max-depth, eqeqeq*/ + for (prop in base) { + if (_.isArray(base[prop]) && _.isArray(current[prop])) { + if (!compareArrays(base[prop], current[prop])) { + return false; + } + } else if (typeof base[prop] === 'object' && typeof current[prop] === 'object') { + if (!compareObjects(base[prop], current[prop])) { + return false; + } + } else if (castValue(base[prop]) != castValue(current[prop])) { + return false; + } + }/*eslint-enable max-depth, eqeqeq */ + } + + /** + * Checks value type and cast to boolean if needed + * + * @param {*} value + * + * @returns {Boolean|*} casted or origin value + */ + function castValue(value) { + if (_.isUndefined(value) || value === '' || _.isNull(value)) { + return false; + } + + return value; + } + return uiCollection.extend({ defaults: { defaultRecord: false, @@ -159,90 +236,12 @@ define([ }, this) : recordsData; if (_.isArray(this.defaultState)) { - result = this._compareArrays(this.defaultState, currentData); + result = compareArrays(this.defaultState, currentData); } this.isDefaultState(result); }, - /** - * Compares arrays. - * - * @param {Object} origin - first array - * @param {Object} current - second array - * - * @returns {Boolean} result - is equal this arrays or not - */ - _compareArrays: function (origin, current) { - var index = 0, - length = origin.length; - - if (origin.length !== current.length) { - return false; - } - - /*eslint-disable max-depth, eqeqeq */ - for (index; index < length; index++) { - if (_.isArray(origin[index]) && _.isArray(current[index])) { - if (!this._compareArrays(origin[index], current[index])) { - return false; - } - } else if (typeof origin[index] === 'object' && typeof current[index] === 'object') { - if (!this._compareObject(origin[index], current[index])) { - return false; - } - } else if (this._castValue(origin[index]) != this._castValue(current[index])) { - return false; - } - }/*eslint-enable max-depth, eqeqeq */ - - return true; - }, - - /** - * Compares objects. Compares only properties from origin object, - * if current object has more properties - they are not considered - * - * @param {Object} origin - first object - * @param {Object} current - second object - * - * @returns {Boolean} result - is equal this objects or not - */ - _compareObject: function (origin, current) { - var prop; - - /*eslint-disable max-depth, eqeqeq*/ - for (prop in origin) { - if (_.isArray(origin[prop]) && _.isArray(current[prop])) { - if (!this._compareArrays(origin[prop], current[prop])) { - return false; - } - } else if (typeof origin[prop] === 'object' && typeof current[prop] === 'object') { - if (!this._compareObject(origin[prop], current[prop])) { - return false; - } - } else if (this._castValue(origin[prop]) != this._castValue(current[prop])) { - return false; - } - }/*eslint-enable max-depth, eqeqeq */ - - return true; - }, - - /** - * Checks value type and cast to boolean if needed - * - * @param {*} value - * - * @returns {Boolean|*} casted or origin value - */ - _castValue: function (value) { - if (_.isUndefined(value) || value === '' || _.isNull(value)) { - return false; - } - - return value; - }, /** * Inits default component state From 0812f6f8f4f3af957168bc9f8ec527e4eb0ab529 Mon Sep 17 00:00:00 2001 From: Volodymyr Zaets Date: Tue, 24 May 2016 16:51:59 +0300 Subject: [PATCH 08/47] MAGETWO-52788: [UI Component] Dynamic Rows: support status being changed --- .../Ui/view/base/web/js/dynamic-rows/dynamic-rows-grid.js | 4 ++-- .../Ui/view/base/web/js/dynamic-rows/dynamic-rows.js | 6 ++++++ .../base/web/templates/dynamic-rows/templates/default.html | 3 ++- 3 files changed, 10 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows-grid.js b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows-grid.js index 90e12a2bce357..16ce4e1620f7c 100644 --- a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows-grid.js +++ b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows-grid.js @@ -22,7 +22,7 @@ define([ identificationDRProperty: 'id', listens: { 'insertData': 'processingInsertData', - 'recordData': 'initElements setToInsertData, checkDefaultState' + 'recordData': 'initElements setToInsertData checkDefaultState' } }, @@ -46,7 +46,7 @@ define([ setToInsertData: function () { var insertData = [], obj; - + if (this.recordData().length && !this.update) { this.recordData.each(function (recordData) { obj = {}; diff --git a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js index 324e429e67f58..4412388596eaa 100644 --- a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js +++ b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js @@ -74,6 +74,8 @@ define([ return false; } }/*eslint-enable max-depth, eqeqeq */ + + return true; } /** @@ -210,6 +212,10 @@ define([ return this; }, + compareArrays: function (o, r) { + return compareArrays(o,r); + }, + /** * Checks columnsHeaderAfterRender property, * and set listener on elems if needed diff --git a/app/code/Magento/Ui/view/base/web/templates/dynamic-rows/templates/default.html b/app/code/Magento/Ui/view/base/web/templates/dynamic-rows/templates/default.html index b69c6b0de652a..b5f4541b64882 100644 --- a/app/code/Magento/Ui/view/base/web/templates/dynamic-rows/templates/default.html +++ b/app/code/Magento/Ui/view/base/web/templates/dynamic-rows/templates/default.html @@ -51,7 +51,8 @@ - + diff --git a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js index 7c312d0745206..62aef71a4e428 100644 --- a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js +++ b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js @@ -420,6 +420,17 @@ define([ return this.relatedData.slice(this.startIndex, this.startIndex + this.pageSize); }, + /** + * Get record count with filtered delete property. + * + * @returns {Number} count + */ + getRecordCount: function () { + return _.filter(this.recordData(), function (record) { + return record[this.deleteProperty] !== this.deleteValue; + }, this).length; + }, + /** * Get number of columns * diff --git a/app/code/Magento/Ui/view/base/web/js/form/components/fieldset.js b/app/code/Magento/Ui/view/base/web/js/form/components/fieldset.js index c400fcac43a9a..b7031f1df85c2 100644 --- a/app/code/Magento/Ui/view/base/web/js/form/components/fieldset.js +++ b/app/code/Magento/Ui/view/base/web/js/form/components/fieldset.js @@ -85,6 +85,7 @@ define([ hasChanged = _.some(this.delegate('hasChanged')); } + this.bubble('update', hasChanged); this.changed(hasChanged); }, diff --git a/app/code/Magento/Ui/view/base/web/templates/dynamic-rows/templates/collapsible.html b/app/code/Magento/Ui/view/base/web/templates/dynamic-rows/templates/collapsible.html index 84a4114254830..bfe935086e5bb 100644 --- a/app/code/Magento/Ui/view/base/web/templates/dynamic-rows/templates/collapsible.html +++ b/app/code/Magento/Ui/view/base/web/templates/dynamic-rows/templates/collapsible.html @@ -10,7 +10,7 @@
-
+
diff --git a/app/code/Magento/Ui/view/base/web/templates/dynamic-rows/templates/default.html b/app/code/Magento/Ui/view/base/web/templates/dynamic-rows/templates/default.html index b5f4541b64882..52e8988e66ddf 100644 --- a/app/code/Magento/Ui/view/base/web/templates/dynamic-rows/templates/default.html +++ b/app/code/Magento/Ui/view/base/web/templates/dynamic-rows/templates/default.html @@ -60,7 +60,7 @@ -
+
diff --git a/app/code/Magento/Ui/view/base/web/templates/dynamic-rows/templates/grid.html b/app/code/Magento/Ui/view/base/web/templates/dynamic-rows/templates/grid.html index 13f1bed36d297..450a49ba04052 100644 --- a/app/code/Magento/Ui/view/base/web/templates/dynamic-rows/templates/grid.html +++ b/app/code/Magento/Ui/view/base/web/templates/dynamic-rows/templates/grid.html @@ -15,7 +15,7 @@
-
+
From 3e7c489e776d2199ed6bfca679fec5243470a3d2 Mon Sep 17 00:00:00 2001 From: Olga Nakonechna Date: Mon, 6 Jun 2016 14:20:28 +0300 Subject: [PATCH 29/47] MAGETWO-53852: Event update works incorrectly --- .../js/components/custom-options-price-type.js | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/ConfigurableProduct/view/adminhtml/web/js/components/custom-options-price-type.js b/app/code/Magento/ConfigurableProduct/view/adminhtml/web/js/components/custom-options-price-type.js index 107fa05af1d3d..49fb47b0a6057 100644 --- a/app/code/Magento/ConfigurableProduct/view/adminhtml/web/js/components/custom-options-price-type.js +++ b/app/code/Magento/ConfigurableProduct/view/adminhtml/web/js/components/custom-options-price-type.js @@ -15,7 +15,10 @@ define([ isFiltered: null, defaultOptions: null, filteredOptions: null, - bannedOptions: [] + bannedOptions: [], + listens: { + 'visible': 'updateValue' + } }, /** @@ -71,6 +74,18 @@ define([ } return this.filteredOptions; + }, + + /** + * Clears value of hidden select + * @param {Boolean} visible + */ + updateValue: function (visible) { + if (visible) { + this.updateOptions(); + } else { + this.value(null); + } } }); }); From 1a004029ec5f4060d9312bd5dcd6431b66f4f900 Mon Sep 17 00:00:00 2001 From: Volodymyr Zaets Date: Tue, 7 Jun 2016 10:00:28 +0300 Subject: [PATCH 30/47] MAGETWO-53852: Event update works incorrectly --- .../Ui/view/base/web/js/dynamic-rows/dnd.js | 30 ++++++++++++++++++- 1 file changed, 29 insertions(+), 1 deletion(-) diff --git a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dnd.js b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dnd.js index 594e300145b3a..2e0cbff3c21e0 100644 --- a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dnd.js +++ b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dnd.js @@ -58,8 +58,12 @@ define([ recordsCache: [], draggableElement: {}, draggableElementClass: '_dragged', + elemPositions: [], listens: { '${ $.recordsProvider }:elems': 'setCacheRecords' + }, + modules: { + parentComponent: '${ $.recordsProvider }' } }, @@ -192,6 +196,8 @@ define([ drEl.depElement = this.getDepElement(drEl.instance, positionY, this.draggableElement.originRow); + drEl.instance.remove(); + if (drEl.depElement) { depElementCtx = this.getRecord(drEl.depElement.elem[0]); drEl.depElement.elem.removeClass(drEl.depElement.className); @@ -211,7 +217,6 @@ define([ this.body.unbind('mouseup', this.mouseupHandler); } - drEl.instance.remove(); this.draggableElement = {}; }, @@ -225,11 +230,34 @@ define([ setPosition: function (depElem, depElementCtx, dragData) { var depElemPosition = ~~depElementCtx.position; + this.cacheElementsPosition(); + if (dragData.depElement.insert === 'after') { dragData.instanceCtx.position = depElemPosition + 1; } else if (dragData.depElement.insert === 'before') { dragData.instanceCtx.position = depElemPosition; } + + this.normalizePositions(); + }, + + /** + * Saves elements position from current elements + */ + cacheElementsPosition: function () { + this.elemPositions = []; + this.parentComponent().elems.each(function (elem) { + this.elemPositions.push(elem.position); + }, this); + }, + + /** + * Normalize position, uses start elements position + */ + normalizePositions: function () { + this.parentComponent().elems.each(function (item, index) { + item.position = this.elemPositions[index]; + }, this); }, /** From 4c74b6112bc5119a62045469ff36f769dc679181 Mon Sep 17 00:00:00 2001 From: Oleksandr Miroshnichenko Date: Wed, 8 Jun 2016 10:32:46 +0300 Subject: [PATCH 31/47] MAGETWO-53852: Event update works incorrectly --- .../view/base/ui_component/etc/definition.xml | 3 +- .../base/web/js/dynamic-rows/action-delete.js | 28 +++++++++++++++++++ .../base/web/js/dynamic-rows/dynamic-rows.js | 24 ++++++++++++++++ .../dynamic-rows/cells/action-delete.html | 2 +- 4 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 app/code/Magento/Ui/view/base/web/js/dynamic-rows/action-delete.js diff --git a/app/code/Magento/Ui/view/base/ui_component/etc/definition.xml b/app/code/Magento/Ui/view/base/ui_component/etc/definition.xml index 105f6dd8dcd3b..7426ce9ddf21e 100755 --- a/app/code/Magento/Ui/view/base/ui_component/etc/definition.xml +++ b/app/code/Magento/Ui/view/base/ui_component/etc/definition.xml @@ -211,8 +211,7 @@ - Magento_Ui/js/form/element/abstract - ui/dynamic-rows/cells/action-delete + Magento_Ui/js/dynamic-rows/action-delete ui/dynamic-rows/cells/action-delete diff --git a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/action-delete.js b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/action-delete.js new file mode 100644 index 0000000000000..6643639f59961 --- /dev/null +++ b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/action-delete.js @@ -0,0 +1,28 @@ +/** + * Copyright © 2016 Magento. All rights reserved. + * See COPYING.txt for license details. + */ + +define([ + 'Magento_Ui/js/form/element/abstract' +], function (Abstract) { + 'use strict'; + + return Abstract.extend({ + defaults: { + links: { + value: false + } + }, + + /** + * Delete record handler. + * + * @param {Number} index + * @param {Number} id + */ + deleteRecord: function (index, id) { + this.bubble('deleteRecord', index, id); + } + }); +}); diff --git a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js index 62aef71a4e428..5abfdf6f5a74e 100644 --- a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js +++ b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js @@ -164,6 +164,7 @@ define([ * @returns {Object} Chainable. */ initialize: function () { + _.bindAll(this, 'processingDeleteRecord'); this._super() .initDefaultState() .initChildren() @@ -199,6 +200,29 @@ define([ return this; }, + /** + * @inheritdoc + */ + initElement: function (elem) { + this._super(); + elem.on({ + 'deleteRecord': this.processingDeleteRecord + }); + + return this; + }, + + /** + * @inheritdoc + */ + bubble: function (event) { + if (event === 'deleteRecord') { + return false; + } + + return this._super(); + }, + /** * Inits DND module * diff --git a/app/code/Magento/Ui/view/base/web/templates/dynamic-rows/cells/action-delete.html b/app/code/Magento/Ui/view/base/web/templates/dynamic-rows/cells/action-delete.html index a8a77d593fe98..7d4c5373aed8f 100644 --- a/app/code/Magento/Ui/view/base/web/templates/dynamic-rows/cells/action-delete.html +++ b/app/code/Magento/Ui/view/base/web/templates/dynamic-rows/cells/action-delete.html @@ -7,7 +7,7 @@ From aa2840ce1a099b51c878243fa1462dba641d8e70 Mon Sep 17 00:00:00 2001 From: Volodymyr Zaets Date: Thu, 23 Jun 2016 12:41:25 +0300 Subject: [PATCH 35/47] MAGETWO-53852: Event update works incorrectly --- .../web/template/dynamic-rows/grid.html | 2 +- .../base/web/js/dynamic-rows/dynamic-rows.js | 217 +++++++++++------- .../dynamic-rows/templates/default.html | 6 +- .../dynamic-rows/templates/grid.html | 2 +- 4 files changed, 135 insertions(+), 92 deletions(-) diff --git a/app/code/Magento/Backend/view/adminhtml/web/template/dynamic-rows/grid.html b/app/code/Magento/Backend/view/adminhtml/web/template/dynamic-rows/grid.html index f3642eedf6fc9..d1830f5d7e22a 100644 --- a/app/code/Magento/Backend/view/adminhtml/web/template/dynamic-rows/grid.html +++ b/app/code/Magento/Backend/view/adminhtml/web/template/dynamic-rows/grid.html @@ -51,10 +51,10 @@ + diff --git a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js index 2279503e57df6..63904800b3fcc 100644 --- a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js +++ b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js @@ -117,7 +117,6 @@ define([ isDifferedFromDefault: false, defaultState: [], changed: false, - isDefaultState: true, fallbackResetTpl: 'ui/form/element/helper/fallback-reset-link', dndConfig: { name: '${ $.name }_dnd', @@ -151,7 +150,7 @@ define([ dnd: '${ $.dndConfig.name }' }, pages: 1, - pageSize: 20, + pageSize: 5, relatedData: [], currentPage: 1, startIndex: 0 @@ -165,22 +164,46 @@ define([ * @returns {Object} Chainable. */ initialize: function () { - _.bindAll(this, 'processingDeleteRecord', 'onChildrenUpdate'); + _.bindAll(this, + 'processingDeleteRecord', + 'onChildrenUpdate', + 'checkDefaultState', + 'renderColumnsHeader' + ); + this._super() .initChildren() .initDnd() - .setColumnsHeaderListener() .initDefaultRecord() + .setInitialProperty() + .setColumnsHeaderListener() .checkSpinner(); - if (_.isArray(this.recordData())) { - this.recordData.each(function (data, index) { - this.source.set(this.dataScope + '.' + this.index + '.' + index + '.initialize', true); - }, this); + this.on('recordData', this.checkDefaultState); - } + return this; + }, + + /** + * @inheritdoc + */ + bubble: function (event) { + if (event === 'deleteRecord' || event === 'update') { + return false; + } + + return this._super(); + }, - this.on('recordData', this.checkDefaultState.bind(this)); + /** + * Inits DND module + * + * @returns {Object} Chainable. + */ + initDnd: function () { + if (this.dndConfig.enabled) { + layout([this.dndConfig]); + } return this; }, @@ -215,7 +238,7 @@ define([ initElement: function (elem) { this._super(); elem.on({ - 'deleteRecord': function(index, id){ + 'deleteRecord': function (index, id) { this.deleteHandler(index, id); }.bind(this), 'update': function (state) { @@ -226,45 +249,77 @@ define([ return this; }, + /** + * Handler for deleteRecord event + * + * @param {Number|String} index - element index + * @param {Number|String} id + */ deleteHandler: function (index, id) { - this.getDefaultState(); + this.setDefaultState(); this.processingDeleteRecord(index, id); - this.changed(!compareArrays(this.defaultState, this.arrFilter(this.relatedData))); + this.changed(!compareArrays(this.defaultState, this.arrayFilter(this.relatedData))); }, - compare: function(ar1, ar2) { - return compareArrays(ar1, ar2) + /** + * Set initial property to records data + * + * @returns {Object} Chainable. + */ + setInitialProperty: function () { + if (_.isArray(this.recordData())) { + this.recordData.each(function (data, index) { + this.source.set(this.dataScope + '.' + this.index + '.' + index + '.initialize', true); + }, this); + } + + return this; }, + /** + * Handler for update event + * + * @param {Boolean} state + */ onChildrenUpdate: function (state) { var changed, dataScope, - elemDataScope; - - if (state && !this.initialState) { - this.initialState = true; - this.defaultState = utils.copy(this.recordData()); + changedElemDataScope; - changed = this.findChangedElems(this.elems()); + if (state && !this.hasInitialState) { + this.setDefaultState(); + changed = this.getChangedElems(this.elems()); dataScope = this.elems()[0].dataScope.split('.'); dataScope.splice(dataScope.length - 1, 1); - changed.forEach(function (elem) { - elemDataScope = elem.dataScope.split('.'); - elemDataScope.splice(0, dataScope.length); - - this.setValueByPath(this.defaultState, elemDataScope, elem.initialValue); + changedElemDataScope = elem.dataScope.split('.'); + changedElemDataScope.splice(0, dataScope.length); + this.setValueByPath(this.defaultState, changedElemDataScope, elem.initialValue); }, this); } + + this.changed(!compareArrays(this.defaultState, this.arrayFilter(this.relatedData))); }, - getDefaultState: function () { - if (!this.initialState) { - this.initialState = true; - this.defaultState = utils.copy(this.arrFilter(this.recordData())); + /** + * Set default dynamic-rows state + * + * @param {Array} data - defaultState data + */ + setDefaultState: function (data) { + if (!this.hasInitialState) { + this.hasInitialState = true; + this.defaultState = data ? data : utils.copy(this.arrayFilter(this.recordData())); } }, + /** + * Sets value to object by string path + * + * @param {Object} obj + * @param {Array|String} path + * @param {*} value + */ setValueByPath: function (obj, path, value) { var prop; @@ -274,21 +329,26 @@ define([ if (path.length - 1) { prop = obj[path[0]]; - path.splice(0,1); - - this.setValueByPath(prop, path , value); + path.splice(0, 1); + this.setValueByPath(prop, path, value); } else if (path.length) { obj[path[0]] = value; } - }, - findChangedElems: function (array, changed) { + /** + * Returns elements which changed self state + * + * @param {Array} array - data array + * @param {Array} changed - array with changed elements + * @returns {Array} changed - array with changed elements + */ + getChangedElems: function (array, changed) { changed = changed || []; array.forEach(function (elem) { if (_.isFunction(elem.elems)) { - this.findChangedElems(elem.elems(), changed) + this.getChangedElems(elem.elems(), changed); } else if (elem.hasChanged()) { changed.push(elem); } @@ -297,30 +357,6 @@ define([ return changed; }, - /** - * @inheritdoc - */ - bubble: function (event) { - if (event === 'deleteRecord') { - return false; - } - - return this._super(); - }, - - /** - * Inits DND module - * - * @returns {Object} Chainable. - */ - initDnd: function () { - if (this.dndConfig.enabled) { - layout([this.dndConfig]); - } - - return this; - }, - /** * Checks columnsHeaderAfterRender property, * and set listener on elems if needed @@ -329,7 +365,11 @@ define([ */ setColumnsHeaderListener: function () { if (this.columnsHeaderAfterRender) { - this.on('recordData', this.renderColumnsHeader.bind(this)); + this.on('recordData', this.renderColumnsHeader); + + if (_.isArray(this.recordData()) && this.recordData().length) { + this.renderColumnsHeader(); + } } return this; @@ -339,35 +379,37 @@ define([ * Checks whether component's state is default or not */ checkDefaultState: function () { - if ( - !this.initialState && - _.isArray(this.recordData()) && - !this.recordData().filter(function (data) { + var isRecordDataArray = _.isArray(this.recordData()), + initialize, + hasNotDefaultRecords = isRecordDataArray ? !!this.recordData().filter(function (data) { return !data.initialize; - }).length - ) { - this.initialState = true; - this.defaultState = utils.copy(this.recordData().filter(function (data) { - return data.initialize; - })); + }).length : false; - this.defaultState.forEach(function(data){ + if (!this.hasInitialState && isRecordDataArray && !hasNotDefaultRecords) { + this.hasInitialState = true; + this.defaultState = utils.copy(this.recordData().filter(function (data) { + initialize = data.initialize; delete data.initialize; - }) - } else if ( !this.initialState && - _.isArray(this.recordData()) && - this.recordData().filter(function (data) { - return !data.initialize; - }).length - ) { - this.initialState = true; + + return initialize; + })); + } else if (!this.hasInitialState && isRecordDataArray && hasNotDefaultRecords) { + this.hasInitialState = true; } - this.changed(!compareArrays(this.defaultState, this.arrFilter(this.relatedData))); + + this.changed(!compareArrays(this.defaultState, this.arrayFilter(this.relatedData))); }, - arrFilter: function (data) { + /** + * Filters out deleted items from array + * + * @param {Array} data + * @returns {Array} filtered array + */ + arrayFilter: function (data) { var prop; + /*eslint-disable no-loop-func*/ data.forEach(function (elem) { for (prop in elem) { if (_.isArray(elem[prop])) { @@ -377,13 +419,15 @@ define([ elem[prop].forEach(function (elemProp) { if (_.isArray(elemProp)) { - elem[prop] = this.arrFilter(elemProp); + elem[prop] = this.arrayFilter(elemProp); } - }, this) + }, this); } } }, this); + /*eslint-enable no-loop-func*/ + return data; }, @@ -449,12 +493,11 @@ define([ if (!this.labels().length) { _.each(this.childTemplate.children, function (cell) { data = this.createHeaderTemplate(cell.config); - cell.config.labelVisible = false; _.extend(data, { label: cell.config.label, name: cell.name, - required: cell.required, + required: !!cell.config.validation, columnsHeaderClasses: cell.config.columnsHeaderClasses }); @@ -609,7 +652,7 @@ define([ * @param {Number} page - current page */ changePage: function (page) { - this.getDefaultState() + this.setDefaultState(); if (page === 1 && !this.recordData().length) { return false; diff --git a/app/code/Magento/Ui/view/base/web/templates/dynamic-rows/templates/default.html b/app/code/Magento/Ui/view/base/web/templates/dynamic-rows/templates/default.html index 52e8988e66ddf..d25a107e82177 100644 --- a/app/code/Magento/Ui/view/base/web/templates/dynamic-rows/templates/default.html +++ b/app/code/Magento/Ui/view/base/web/templates/dynamic-rows/templates/default.html @@ -24,11 +24,11 @@ + disable="$label().disabled"> + diff --git a/app/code/Magento/Ui/view/base/web/templates/dynamic-rows/templates/grid.html b/app/code/Magento/Ui/view/base/web/templates/dynamic-rows/templates/grid.html index 450a49ba04052..5b09d5fca407b 100644 --- a/app/code/Magento/Ui/view/base/web/templates/dynamic-rows/templates/grid.html +++ b/app/code/Magento/Ui/view/base/web/templates/dynamic-rows/templates/grid.html @@ -40,10 +40,10 @@ + From 8509cef36df413c11aa783a1e7d5f04e3f04ab12 Mon Sep 17 00:00:00 2001 From: Volodymyr Zaets Date: Thu, 23 Jun 2016 18:28:39 +0300 Subject: [PATCH 36/47] MAGETWO-53852: Event update works incorrectly --- .../dynamic-rows-import-custom-options.js | 6 ++++++ .../js/components/custom-options-price-type.js | 17 +---------------- .../base/web/js/dynamic-rows/dynamic-rows.js | 5 +++-- .../dynamic-rows/templates/default.html | 4 ++-- 4 files changed, 12 insertions(+), 20 deletions(-) diff --git a/app/code/Magento/Catalog/view/adminhtml/web/js/components/dynamic-rows-import-custom-options.js b/app/code/Magento/Catalog/view/adminhtml/web/js/components/dynamic-rows-import-custom-options.js index 7c5fd3bcb9742..10e498ff47497 100644 --- a/app/code/Magento/Catalog/view/adminhtml/web/js/components/dynamic-rows-import-custom-options.js +++ b/app/code/Magento/Catalog/view/adminhtml/web/js/components/dynamic-rows-import-custom-options.js @@ -91,7 +91,13 @@ define([ processingAddChild: function (ctx, index, prop) { if (ctx && !_.isNumber(ctx['option_id'])) { ctx['option_id'] = ++maxId; + } else if (!ctx) { + this.showSpinner(true); + this.addChild(ctx, index, prop); + + return; } + this._super(ctx, index, prop); }, diff --git a/app/code/Magento/ConfigurableProduct/view/adminhtml/web/js/components/custom-options-price-type.js b/app/code/Magento/ConfigurableProduct/view/adminhtml/web/js/components/custom-options-price-type.js index 49fb47b0a6057..107fa05af1d3d 100644 --- a/app/code/Magento/ConfigurableProduct/view/adminhtml/web/js/components/custom-options-price-type.js +++ b/app/code/Magento/ConfigurableProduct/view/adminhtml/web/js/components/custom-options-price-type.js @@ -15,10 +15,7 @@ define([ isFiltered: null, defaultOptions: null, filteredOptions: null, - bannedOptions: [], - listens: { - 'visible': 'updateValue' - } + bannedOptions: [] }, /** @@ -74,18 +71,6 @@ define([ } return this.filteredOptions; - }, - - /** - * Clears value of hidden select - * @param {Boolean} visible - */ - updateValue: function (visible) { - if (visible) { - this.updateOptions(); - } else { - this.value(null); - } } }); }); diff --git a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js index 63904800b3fcc..9635f9046bcb0 100644 --- a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js +++ b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js @@ -385,7 +385,7 @@ define([ return !data.initialize; }).length : false; - if (!this.hasInitialState && isRecordDataArray && !hasNotDefaultRecords) { + if (!this.hasInitialState && isRecordDataArray && hasNotDefaultRecords) { this.hasInitialState = true; this.defaultState = utils.copy(this.recordData().filter(function (data) { initialize = data.initialize; @@ -393,11 +393,12 @@ define([ return initialize; })); + + this.changed(!compareArrays(this.defaultState, this.arrayFilter(this.relatedData))); } else if (!this.hasInitialState && isRecordDataArray && hasNotDefaultRecords) { this.hasInitialState = true; } - this.changed(!compareArrays(this.defaultState, this.arrayFilter(this.relatedData))); }, /** diff --git a/app/code/Magento/Ui/view/base/web/templates/dynamic-rows/templates/default.html b/app/code/Magento/Ui/view/base/web/templates/dynamic-rows/templates/default.html index d25a107e82177..6492e5cee9d81 100644 --- a/app/code/Magento/Ui/view/base/web/templates/dynamic-rows/templates/default.html +++ b/app/code/Magento/Ui/view/base/web/templates/dynamic-rows/templates/default.html @@ -52,7 +52,7 @@ + visible="element.addButton || pages() > 1"> -
+
From e4154987c7dd070ebaf8adbb6748bbf4cd6e537d Mon Sep 17 00:00:00 2001 From: Volodymyr Zaets Date: Fri, 24 Jun 2016 12:01:08 +0300 Subject: [PATCH 37/47] MAGETWO-53852: Event update works incorrectly --- .../base/web/js/dynamic-rows/dynamic-rows.js | 5 +---- .../view/base/web/js/dynamic-rows/record.js | 22 +++++++++++++++++-- 2 files changed, 21 insertions(+), 6 deletions(-) diff --git a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js index 9635f9046bcb0..d07711b28a75d 100644 --- a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js +++ b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js @@ -349,7 +349,7 @@ define([ array.forEach(function (elem) { if (_.isFunction(elem.elems)) { this.getChangedElems(elem.elems(), changed); - } else if (elem.hasChanged()) { + } else if (elem.hasOwnProperty('hasChanged') && elem.hasChanged()) { changed.push(elem); } }, this); @@ -395,10 +395,7 @@ define([ })); this.changed(!compareArrays(this.defaultState, this.arrayFilter(this.relatedData))); - } else if (!this.hasInitialState && isRecordDataArray && hasNotDefaultRecords) { - this.hasInitialState = true; } - }, /** diff --git a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/record.js b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/record.js index 305de77d47dd8..cdb74f39c7034 100644 --- a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/record.js +++ b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/record.js @@ -5,8 +5,9 @@ define([ 'underscore', - 'uiCollection' -], function (_, uiCollection) { + 'uiCollection', + 'uiRegistry' +], function (_, uiCollection, registry) { 'use strict'; return uiCollection.extend({ @@ -34,6 +35,23 @@ define([ } }, + initialize: function () { + this._super(); + + registry.async(this.name + '.' + this.positionProvider)(function(component){ + component.hasChanged = function () { + return this.value().toString() != this.initialValue.toString(); + }; + + if (!component.initialValue) { + component.initialValue = self.parentComponent().maxPosition; + component.bubble('update', component.hasChanged()); + } + }); + + return this; + }, + /** * Init config * From 66e095566dce1971dc0bcb2bbbed6d39d84554a2 Mon Sep 17 00:00:00 2001 From: Volodymyr Zaets Date: Fri, 24 Jun 2016 13:14:16 +0300 Subject: [PATCH 38/47] MAGETWO-53852: Event update works incorrectly --- app/code/Magento/Ui/view/base/web/js/dynamic-rows/record.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/record.js b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/record.js index cdb74f39c7034..5c9a51e43427a 100644 --- a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/record.js +++ b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/record.js @@ -36,6 +36,8 @@ define([ }, initialize: function () { + var self = this; + this._super(); registry.async(this.name + '.' + this.positionProvider)(function(component){ From f51b382f7017c85b7e317516f4ad2f2ce6cc69b2 Mon Sep 17 00:00:00 2001 From: Volodymyr Zaets Date: Fri, 24 Jun 2016 16:06:03 +0300 Subject: [PATCH 39/47] MAGETWO-53852: Event update works incorrectly --- .../Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js index d07711b28a75d..dce3c6d1517fa 100644 --- a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js +++ b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js @@ -394,6 +394,8 @@ define([ return initialize; })); + this.changed(!compareArrays(this.defaultState, this.arrayFilter(this.relatedData))); + } else if (this.hasInitialState) { this.changed(!compareArrays(this.defaultState, this.arrayFilter(this.relatedData))); } }, From deaee8b1d0af68af17a5dcf15182dbc85ef59fb7 Mon Sep 17 00:00:00 2001 From: Volodymyr Zaets Date: Fri, 24 Jun 2016 16:57:45 +0300 Subject: [PATCH 40/47] MAGETWO-53852: Event update works incorrectly --- .../Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js index dce3c6d1517fa..0c520c2e624d1 100644 --- a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js +++ b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js @@ -349,7 +349,7 @@ define([ array.forEach(function (elem) { if (_.isFunction(elem.elems)) { this.getChangedElems(elem.elems(), changed); - } else if (elem.hasOwnProperty('hasChanged') && elem.hasChanged()) { + } else if (_.isFunction(elem.hasChanged) && elem.hasChanged()) { changed.push(elem); } }, this); From f9197e909f578dde486252732db3b40a48e4120a Mon Sep 17 00:00:00 2001 From: Volodymyr Zaets Date: Mon, 27 Jun 2016 11:52:37 +0300 Subject: [PATCH 41/47] MAGETWO-53852: Event update works incorrectly --- .../view/base/web/js/dynamic-rows/dynamic-rows.js | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js index 0c520c2e624d1..cc712cb6a74db 100644 --- a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js +++ b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js @@ -141,7 +141,7 @@ define([ disabled: 'setDisabled', childTemplate: 'initHeader', recordTemplate: 'onUpdateRecordTemplate', - recordData: 'setDifferedFromDefault parsePagesData', + recordData: 'setDifferedFromDefault parsePagesData setRecordDataToCache', currentPage: 'changePage', elems: 'checkSpinner', changed: 'updateTrigger' @@ -153,9 +153,15 @@ define([ pageSize: 5, relatedData: [], currentPage: 1, + recordDataCache: [], startIndex: 0 }, + setRecordDataToCache: function (data) { + this.recordDataCache = this.recordDataCache && data.length > this.recordDataCache.length ? + data : this.recordDataCache; + }, + /** * Extends instance with default config, calls initialize of parent * class, calls initChildren method, set observe variable. @@ -307,9 +313,11 @@ define([ * @param {Array} data - defaultState data */ setDefaultState: function (data) { + var componentData = this.recordData().length ? this.recordData() : this.recordDataCache; + if (!this.hasInitialState) { this.hasInitialState = true; - this.defaultState = data ? data : utils.copy(this.arrayFilter(this.recordData())); + this.defaultState = data ? data : utils.copy(this.arrayFilter(componentData)); } }, @@ -574,7 +582,7 @@ define([ this.relatedData = this.deleteProperty ? _.filter(data, function (elem) { - return elem[this.deleteProperty] !== this.deleteValue; + return elem && elem[this.deleteProperty] !== this.deleteValue; }, this) : data; pages = Math.ceil(this.relatedData.length / this.pageSize) || 1; From 9e9e16acda67e31eed9db09a17105f3f40736d27 Mon Sep 17 00:00:00 2001 From: Volodymyr Zaets Date: Wed, 29 Jun 2016 15:31:57 +0300 Subject: [PATCH 42/47] MAGETWO-53852: Event update works incorrectly --- .../base/web/js/dynamic-rows/dynamic-rows.js | 43 +++++++++++-------- 1 file changed, 26 insertions(+), 17 deletions(-) diff --git a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js index cc712cb6a74db..e8c3b143c0957 100644 --- a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js +++ b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js @@ -116,6 +116,9 @@ define([ showSpinner: true, isDifferedFromDefault: false, defaultState: [], + defaultPagesState: {}, + pagesChanged: {}, + hasInitialPagesState: {}, changed: false, fallbackResetTpl: 'ui/form/element/helper/fallback-reset-link', dndConfig: { @@ -158,7 +161,7 @@ define([ }, setRecordDataToCache: function (data) { - this.recordDataCache = this.recordDataCache && data.length > this.recordDataCache.length ? + this.recordDataCache = this.recordDataCache && data.length > this.recordDataCache.length ? data : this.recordDataCache; }, @@ -264,7 +267,8 @@ define([ deleteHandler: function (index, id) { this.setDefaultState(); this.processingDeleteRecord(index, id); - this.changed(!compareArrays(this.defaultState, this.arrayFilter(this.relatedData))); + this.pagesChanged[this.currentPage()] = !compareArrays(this.defaultPagesState[this.currentPage()], this.arrayFilter(this.getChildItems())); + this.changed(_.some(this.pagesChanged)); }, /** @@ -292,7 +296,7 @@ define([ dataScope, changedElemDataScope; - if (state && !this.hasInitialState) { + if (state && !this.hasInitialPagesState[this.currentPage()]) { this.setDefaultState(); changed = this.getChangedElems(this.elems()); dataScope = this.elems()[0].dataScope.split('.'); @@ -300,11 +304,17 @@ define([ changed.forEach(function (elem) { changedElemDataScope = elem.dataScope.split('.'); changedElemDataScope.splice(0, dataScope.length); - this.setValueByPath(this.defaultState, changedElemDataScope, elem.initialValue); + changedElemDataScope[0] = (parseInt(changedElemDataScope[0], 10) - this.pageSize * (this.currentPage() - 1)).toString(); + this.setValueByPath(this.defaultPagesState[this.currentPage()], changedElemDataScope, elem.initialValue); }, this); } - this.changed(!compareArrays(this.defaultState, this.arrayFilter(this.relatedData))); + this.pagesChanged[this.currentPage()] = !compareArrays(this.defaultPagesState[this.currentPage()], this.arrayFilter(this.getChildItems())); + this.changed(_.some(this.pagesChanged)); + }, + + compare: function (a1,a2) { + return compareArrays(a1,a2) }, /** @@ -313,11 +323,11 @@ define([ * @param {Array} data - defaultState data */ setDefaultState: function (data) { - var componentData = this.recordData().length ? this.recordData() : this.recordDataCache; + var componentData = this.getChildItems().length ? this.getChildItems() : this.recordDataCache; - if (!this.hasInitialState) { - this.hasInitialState = true; - this.defaultState = data ? data : utils.copy(this.arrayFilter(componentData)); + if (!this.hasInitialPagesState[this.currentPage()]) { + this.hasInitialPagesState[this.currentPage()] = true; + this.defaultPagesState[this.currentPage()] = data ? data : utils.copy(this.arrayFilter(componentData)); } }, @@ -393,18 +403,19 @@ define([ return !data.initialize; }).length : false; - if (!this.hasInitialState && isRecordDataArray && hasNotDefaultRecords) { - this.hasInitialState = true; - this.defaultState = utils.copy(this.recordData().filter(function (data) { + if (!this.hasInitialPagesState[this.currentPage()] && isRecordDataArray && hasNotDefaultRecords) { + this.hasInitialPagesState[this.currentPage()] = true; + this.defaultPagesState[this.currentPage()] = utils.copy(this.getChildItems().filter(function (data) { initialize = data.initialize; delete data.initialize; return initialize; })); - this.changed(!compareArrays(this.defaultState, this.arrayFilter(this.relatedData))); - } else if (this.hasInitialState) { - this.changed(!compareArrays(this.defaultState, this.arrayFilter(this.relatedData))); + this.pagesChanged[this.currentPage()] = !compareArrays(this.defaultPagesState[this.currentPage()], this.arrayFilter(this.getChildItems())); + this.changed(_.some(this.pagesChanged)); + } else if (this.hasInitialPagesState[this.currentPage()]) { + this.changed(_.some(this.pagesChanged)); } }, @@ -660,8 +671,6 @@ define([ * @param {Number} page - current page */ changePage: function (page) { - this.setDefaultState(); - if (page === 1 && !this.recordData().length) { return false; } From f37bf56048311ec3c96be1afeb3a58121009a2d0 Mon Sep 17 00:00:00 2001 From: Volodymyr Zaets Date: Mon, 4 Jul 2016 12:51:29 +0300 Subject: [PATCH 43/47] MAGETWO-53852: Event update works incorrectly --- .../base/web/js/dynamic-rows/dynamic-rows.js | 34 ++++++++++++++++--- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js index e8c3b143c0957..4534f78ba3198 100644 --- a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js +++ b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js @@ -252,6 +252,9 @@ define([ }.bind(this), 'update': function (state) { this.onChildrenUpdate(state); + }.bind(this), + 'addChild': function () { + this.setDefaultState(); }.bind(this) }); @@ -323,11 +326,22 @@ define([ * @param {Array} data - defaultState data */ setDefaultState: function (data) { - var componentData = this.getChildItems().length ? this.getChildItems() : this.recordDataCache; + var componentData, + childItems; if (!this.hasInitialPagesState[this.currentPage()]) { + childItems = this.getChildItems(); + componentData = childItems.length ? + utils.copy(childItems) : + utils.copy(this.getChildItems(this.recordDataCache)); + componentData.forEach(function (dataObj) { + if (dataObj.hasOwnProperty('initialize')) { + delete dataObj.initialize; + } + }); + this.hasInitialPagesState[this.currentPage()] = true; - this.defaultPagesState[this.currentPage()] = data ? data : utils.copy(this.arrayFilter(componentData)); + this.defaultPagesState[this.currentPage()] = data ? data : this.arrayFilter(componentData); } }, @@ -349,7 +363,7 @@ define([ prop = obj[path[0]]; path.splice(0, 1); this.setValueByPath(prop, path, value); - } else if (path.length) { + } else if (path.length && obj) { obj[path[0]] = value; } }, @@ -415,6 +429,7 @@ define([ this.pagesChanged[this.currentPage()] = !compareArrays(this.defaultPagesState[this.currentPage()], this.arrayFilter(this.getChildItems())); this.changed(_.some(this.pagesChanged)); } else if (this.hasInitialPagesState[this.currentPage()]) { + this.pagesChanged[this.currentPage()] = !compareArrays(this.defaultPagesState[this.currentPage()], this.arrayFilter(this.getChildItems())); this.changed(_.some(this.pagesChanged)); } }, @@ -605,10 +620,15 @@ define([ * * @returns {Array} data */ - getChildItems: function () { + getChildItems: function (data, page) { + var dataRecord = data || this.relatedData, + startIndex; + this.startIndex = (~~this.currentPage() - 1) * this.pageSize; - return this.relatedData.slice(this.startIndex, this.startIndex + this.pageSize); + startIndex = page || this.startIndex; + + return dataRecord.slice(startIndex, this.startIndex + this.pageSize); }, /** @@ -639,6 +659,10 @@ define([ * @param {Number|String} prop - additional property to element */ processingAddChild: function (ctx, index, prop) { + console.log('3', this.name); + + this.bubble('addChild', false); + if (this.relatedData.length && this.relatedData.length % this.pageSize === 0) { this.clear(); this.pages(this.pages() + 1); From 7633c21075ec8f04fad606075e4dfb4741f6ebc1 Mon Sep 17 00:00:00 2001 From: Volodymyr Zaets Date: Mon, 8 Aug 2016 14:13:08 +0300 Subject: [PATCH 44/47] MAGETWO-53852: Event update works incorrectly --- .../base/web/templates/dynamic-rows/templates/default.html | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/app/code/Magento/Ui/view/base/web/templates/dynamic-rows/templates/default.html b/app/code/Magento/Ui/view/base/web/templates/dynamic-rows/templates/default.html index 0031bc75651aa..cf93e5fa23f3d 100644 --- a/app/code/Magento/Ui/view/base/web/templates/dynamic-rows/templates/default.html +++ b/app/code/Magento/Ui/view/base/web/templates/dynamic-rows/templates/default.html @@ -49,7 +49,7 @@ - + @@ -60,7 +60,7 @@ -
+
From 0548f22e0e90adef4d7ffd7a8df32a2a50eda962 Mon Sep 17 00:00:00 2001 From: Volodymyr Zaets Date: Mon, 8 Aug 2016 14:22:00 +0300 Subject: [PATCH 45/47] MAGETWO-53852: Event update works incorrectly --- .../Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js index 035a115cd124c..7d173cec0bf50 100644 --- a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js +++ b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js @@ -153,7 +153,7 @@ define([ dnd: '${ $.dndConfig.name }' }, pages: 1, - pageSize: 5, + pageSize: 20, relatedData: [], currentPage: 1, recordDataCache: [], @@ -659,8 +659,6 @@ define([ * @param {Number|String} prop - additional property to element */ processingAddChild: function (ctx, index, prop) { - console.log('3', this.name); - this.bubble('addChild', false); if (this.relatedData.length && this.relatedData.length % this.pageSize === 0) { From 632d8fb8ab92f2de8b00a9e491fe884b6f1536db Mon Sep 17 00:00:00 2001 From: Volodymyr Zaets Date: Mon, 8 Aug 2016 16:04:02 +0300 Subject: [PATCH 46/47] MAGETWO-53852: Event update works incorrectly --- .../base/web/js/dynamic-rows/dynamic-rows.js | 44 ++++++++++--------- .../view/base/web/js/dynamic-rows/record.js | 19 +++++++- 2 files changed, 42 insertions(+), 21 deletions(-) diff --git a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js index 7d173cec0bf50..041501b7410e4 100644 --- a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js +++ b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js @@ -160,6 +160,9 @@ define([ startIndex: 0 }, + /** + * Sets record data to cache + */ setRecordDataToCache: function (data) { this.recordDataCache = this.recordDataCache && data.length > this.recordDataCache.length ? data : this.recordDataCache; @@ -177,7 +180,9 @@ define([ 'processingDeleteRecord', 'onChildrenUpdate', 'checkDefaultState', - 'renderColumnsHeader' + 'renderColumnsHeader', + 'deleteHandler', + 'setDefaultState' ); this._super() @@ -247,15 +252,9 @@ define([ initElement: function (elem) { this._super(); elem.on({ - 'deleteRecord': function (index, id) { - this.deleteHandler(index, id); - }.bind(this), - 'update': function (state) { - this.onChildrenUpdate(state); - }.bind(this), - 'addChild': function () { - this.setDefaultState(); - }.bind(this) + 'deleteRecord': this.deleteHandler, + 'update': this.onChildrenUpdate, + 'addChild': this.setDefaultState }); return this; @@ -270,7 +269,8 @@ define([ deleteHandler: function (index, id) { this.setDefaultState(); this.processingDeleteRecord(index, id); - this.pagesChanged[this.currentPage()] = !compareArrays(this.defaultPagesState[this.currentPage()], this.arrayFilter(this.getChildItems())); + this.pagesChanged[this.currentPage()] = + !compareArrays(this.defaultPagesState[this.currentPage()], this.arrayFilter(this.getChildItems())); this.changed(_.some(this.pagesChanged)); }, @@ -307,19 +307,20 @@ define([ changed.forEach(function (elem) { changedElemDataScope = elem.dataScope.split('.'); changedElemDataScope.splice(0, dataScope.length); - changedElemDataScope[0] = (parseInt(changedElemDataScope[0], 10) - this.pageSize * (this.currentPage() - 1)).toString(); - this.setValueByPath(this.defaultPagesState[this.currentPage()], changedElemDataScope, elem.initialValue); + changedElemDataScope[0] = + (parseInt(changedElemDataScope[0], 10) - this.pageSize * (this.currentPage() - 1)).toString(); + this.setValueByPath( + this.defaultPagesState[this.currentPage()], + changedElemDataScope, elem.initialValue + ); }, this); } - this.pagesChanged[this.currentPage()] = !compareArrays(this.defaultPagesState[this.currentPage()], this.arrayFilter(this.getChildItems())); + this.pagesChanged[this.currentPage()] = + !compareArrays(this.defaultPagesState[this.currentPage()], this.arrayFilter(this.getChildItems())); this.changed(_.some(this.pagesChanged)); }, - compare: function (a1,a2) { - return compareArrays(a1,a2) - }, - /** * Set default dynamic-rows state * @@ -426,10 +427,12 @@ define([ return initialize; })); - this.pagesChanged[this.currentPage()] = !compareArrays(this.defaultPagesState[this.currentPage()], this.arrayFilter(this.getChildItems())); + this.pagesChanged[this.currentPage()] = + !compareArrays(this.defaultPagesState[this.currentPage()], this.arrayFilter(this.getChildItems())); this.changed(_.some(this.pagesChanged)); } else if (this.hasInitialPagesState[this.currentPage()]) { - this.pagesChanged[this.currentPage()] = !compareArrays(this.defaultPagesState[this.currentPage()], this.arrayFilter(this.getChildItems())); + this.pagesChanged[this.currentPage()] = + !compareArrays(this.defaultPagesState[this.currentPage()], this.arrayFilter(this.getChildItems())); this.changed(_.some(this.pagesChanged)); } }, @@ -438,6 +441,7 @@ define([ * Filters out deleted items from array * * @param {Array} data + * * @returns {Array} filtered array */ arrayFilter: function (data) { diff --git a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/record.js b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/record.js index 5c9a51e43427a..595031a329b5d 100644 --- a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/record.js +++ b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/record.js @@ -35,14 +35,31 @@ define([ } }, + /** + * Extends instance with default config, calls initialize of parent + * class, calls initChildren method, set observe variable. + * Use parent "track" method - wrapper observe array + * + * @returns {Object} Chainable. + */ initialize: function () { var self = this; this._super(); - registry.async(this.name + '.' + this.positionProvider)(function(component){ + registry.async(this.name + '.' + this.positionProvider)(function (component) { + + /** + * Overwrite hasChanged method + * + * @returns {Boolean} + */ component.hasChanged = function () { + + /* eslint-disable eqeqeq */ return this.value().toString() != this.initialValue.toString(); + + /* eslint-enable eqeqeq */ }; if (!component.initialValue) { From a6de866f3853562ff6b4b27f911b87e23f08b9f0 Mon Sep 17 00:00:00 2001 From: Volodymyr Zaets Date: Fri, 26 Aug 2016 12:14:53 +0300 Subject: [PATCH 47/47] MAGETWO-52788: Dynamic Rows: support status being changed --- .../Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js index 041501b7410e4..51f5973372d69 100644 --- a/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js +++ b/app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows.js @@ -441,7 +441,7 @@ define([ * Filters out deleted items from array * * @param {Array} data - * + * * @returns {Array} filtered array */ arrayFilter: function (data) {