Skip to content

Commit 9aad31b

Browse files
author
Volodymyr Zaets
committed
Merge remote-tracking branch 'origin/MAGETWO-51925' into PR
2 parents f071704 + b34b2de commit 9aad31b

File tree

13 files changed

+178
-104
lines changed

13 files changed

+178
-104
lines changed

app/code/Magento/Backend/view/adminhtml/web/template/dynamic-rows/grid.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
<table class="admin__dynamic-rows data-grid" data-role="grid">
4747
<thead if="element.columnsHeader">
4848
<tr>
49-
<th if="dndConfig.enabled"
49+
<th if="$data.dndConfig.enabled"
5050
class="data-grid-draggable-row-cell"/>
5151

5252
<th repeat="foreach: labels, item: '$label'"
@@ -67,7 +67,7 @@
6767
class="data-grid-draggable-row-cell"
6868
template="name: dndConfig.template, data: dnd"/>
6969

70-
<!-- ko fastForEach: { data: $record().elems, as: 'elem'} -->
70+
<!-- ko foreach: { data: $record().elems(), as: 'elem'} -->
7171
<td if="elem.template"
7272
visible="elem.visible"
7373
disable="elem.disabled"

app/code/Magento/Bundle/Ui/DataProvider/Product/Form/Modifier/BundlePanel.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ protected function getBundleHeader()
246246
[
247247
'targetName' => 'product_form.product_form.'
248248
. self::CODE_BUNDLE_DATA . '.' . self::CODE_BUNDLE_OPTIONS,
249-
'actionName' => 'addChild',
249+
'actionName' => 'processingAddChild',
250250
]
251251
],
252252
],
@@ -330,12 +330,19 @@ protected function getBundleOptions()
330330
'recordTemplate' => 'record',
331331
'provider' => 'product_form.product_form_data_source',
332332
'dataProvider' => '${ $.dataScope }' . '.bundle_button_proxy',
333+
'identificationDRProperty' => 'product_id',
334+
'identificationProperty' => 'product_id',
333335
'map' => [
334-
'id' => 'entity_id',
335336
'product_id' => 'entity_id',
336337
'name' => 'name',
337338
'sku' => 'sku',
338339
'price' => 'price',
340+
'delete' => '',
341+
'selection_can_change_qty' => '',
342+
'selection_id' => '',
343+
'selection_price_type' => '',
344+
'selection_price_value' => '',
345+
'selection_qty' => '',
339346
],
340347
'links' => [
341348
'insertData' => '${ $.provider }:${ $.dataProvider }'

app/code/Magento/Bundle/Ui/DataProvider/Product/Form/Modifier/Composite.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ public function modifyData(array $data)
124124
'selection_can_change_qty' => $productLink->getCanChangeQuantity(),
125125
'selection_qty_is_integer' => (bool)$integerQty,
126126
'position' => $productLink->getPosition(),
127+
'delete' => '',
127128
];
128129
}
129130
$data[$modelId][BundlePanel::CODE_BUNDLE_OPTIONS][BundlePanel::CODE_BUNDLE_OPTIONS][] = [

app/code/Magento/Catalog/Ui/DataProvider/Product/Form/Modifier/CustomOptions.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -320,7 +320,7 @@ protected function getHeaderContainerConfig($sortOrder)
320320
'actions' => [
321321
[
322322
'targetName' => 'ns = ${ $.ns }, index = ' . static::GRID_OPTIONS_NAME,
323-
'actionName' => 'addChild',
323+
'actionName' => 'processingAddChild',
324324
]
325325
]
326326
]

app/code/Magento/Ui/view/base/web/js/dynamic-rows/dnd.js

Lines changed: 32 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,12 @@ define([
4949

5050
return Element.extend({
5151
defaults: {
52-
rootSelector: '${ $.recordsProvider }:div.admin__field',
53-
tableClass: 'table.admin__dynamic-rows',
54-
tableSelector: '${ $.rootSelector } -> ${ $.tableClass }',
5552
separatorsClass: {
5653
top: '_dragover-top',
5754
bottom: '_dragover-bottom'
5855
},
5956
step: 'auto',
57+
tableClass: 'table.admin__dynamic-rows',
6058
recordsCache: [],
6159
draggableElement: {},
6260
draggableElementClass: '_dragged',
@@ -73,14 +71,12 @@ define([
7371
initialize: function () {
7472
_.bindAll(
7573
this,
76-
'initTable',
7774
'mousemoveHandler',
7875
'mouseupHandler'
7976
);
8077

8178
this._super()
8279
.body = $('body');
83-
$.async(this.tableSelector, this.initTable);
8480

8581
return this;
8682
},
@@ -100,18 +96,6 @@ define([
10096
return this;
10197
},
10298

103-
/**
104-
* Initialize table
105-
*
106-
* @param {Object} table - table element
107-
*/
108-
initTable: function (table) {
109-
if (!this.table) {
110-
this.table = $(table);
111-
this.tableWrapper = this.table.parent();
112-
}
113-
},
114-
11599
/**
116100
* Init listens to start drag
117101
*
@@ -135,8 +119,10 @@ define([
135119
*/
136120
mousedownHandler: function (data, elem, event) {
137121
var recordNode = this.getRecordNode(elem),
138-
originRecord = $(elem).parents('tr'),
139-
drEl = this.draggableElement;
122+
originRecord = $(elem).parents('tr').eq(0),
123+
drEl = this.draggableElement,
124+
$table = $(elem).parents('table').eq(0),
125+
$tableWrapper = $table.parent();
140126

141127
$(recordNode).addClass(this.draggableElementClass);
142128
$(originRecord).addClass(this.draggableElementClass);
@@ -146,10 +132,10 @@ define([
146132
drEl.instanceCtx = this.getRecord(originRecord[0]);
147133
drEl.eventMousedownY = isTouchDevice ? event.originalEvent.touches[0].pageY : event.pageY;
148134
drEl.minYpos =
149-
this.table.offset().top - originRecord.offset().top +
150-
this.table.outerHeight() - this.table.find('tbody').outerHeight();
151-
drEl.maxYpos = drEl.minYpos + this.table.find('tbody').outerHeight() - originRecord.outerHeight();
152-
this.tableWrapper.append(recordNode);
135+
$table.offset().top - originRecord.offset().top +
136+
$table.outerHeight() - $table.find('tbody').outerHeight();
137+
drEl.maxYpos = drEl.minYpos + $table.find('tbody').outerHeight() - originRecord.outerHeight();
138+
$tableWrapper.append(recordNode);
153139

154140
if (isTouchDevice) {
155141
this.body.bind('touchmove', this.mousemoveHandler);
@@ -173,7 +159,7 @@ define([
173159
processingPositionY = positionY + 'px',
174160
processingMaxYpos = depEl.maxYpos + 'px',
175161
processingMinYpos = depEl.minYpos + 'px',
176-
depElement = this.getDepElement(depEl.instance, positionY);
162+
depElement = this.getDepElement(depEl.instance, positionY, depEl.originRow);
177163

178164
event.stopPropagation();
179165
event.preventDefault();
@@ -234,7 +220,7 @@ define([
234220
* @param {Object} dragData - data draggable element
235221
*/
236222
setPosition: function (depElem, depElementCtx, dragData) {
237-
var depElemPosition = parseInt(depElementCtx.position, 10);
223+
var depElemPosition = ~~depElementCtx.position;
238224

239225
if (dragData.depElement.insert === 'after') {
240226
dragData.instanceCtx.position = depElemPosition + 1;
@@ -249,14 +235,17 @@ define([
249235
* @param {Object} curInstance - current element instance
250236
* @param {Number} position
251237
*/
252-
253-
getDepElement: function (curInstance, position) {
238+
getDepElement: function (curInstance, position, row) {
254239
var tableSelector = this.tableClass + ' tr',
255-
recordsCollection = this.table.find('tbody > tr').filter(function (index, elem) {
256-
return !$(elem).parents(tableSelector).length;
257-
}),
258-
curInstancePositionTop = $(curInstance).position().top,
259-
curInstancePositionBottom = curInstancePositionTop + $(curInstance).height();
240+
$table = $(row).parents('table').eq(0),
241+
$curInstance = $(curInstance),
242+
recordsCollection = $table.find('table').length ?
243+
$table.find('tbody > tr').filter(function (index, elem) {
244+
return !$(elem).parents(tableSelector).length;
245+
}) :
246+
$table.find('tbody > tr'),
247+
curInstancePositionTop = $curInstance.position().top,
248+
curInstancePositionBottom = curInstancePositionTop + $curInstance.height();
260249

261250
if (position < 0) {
262251
return this._getDepElement(recordsCollection, 'before', curInstancePositionTop);
@@ -313,7 +302,7 @@ define([
313302
* @param {Object} data - current element data
314303
*/
315304
_setDefaultPosition: function (elem, data) {
316-
var originRecord = $(elem).parents('tr'),
305+
var originRecord = $(elem).parents('tr').eq(0),
317306
position = originRecord.position();
318307

319308
++position.top;
@@ -337,7 +326,7 @@ define([
337326
* @returns {Object} instance data.
338327
*/
339328
processingStyles: function (data, elem) {
340-
var table = this.table,
329+
var table = $(elem).parents('table').eq(0),
341330
columns = table.find('th'),
342331
recordColumns = $(data).find('td');
343332

@@ -380,10 +369,12 @@ define([
380369
* @returns {Object} draggable record instance
381370
*/
382371
getRecordNode: function (record) {
383-
var table = this.table[0].cloneNode(true);
372+
var $record = $(record),
373+
table = $record.parents('table')[0].cloneNode(true),
374+
$table = $(table);
384375

385-
$(table).find('tr').remove();
386-
$(table).append($(record).parents('tr')[0].cloneNode(true));
376+
$table.find('tr').remove();
377+
$table.append($record.parents('tr')[0].cloneNode(true));
387378

388379
return table;
389380
},
@@ -395,7 +386,10 @@ define([
395386
* @returns {Object} draggable record context
396387
*/
397388
getRecord: function (elem) {
398-
return this.recordsCache()[getContext(elem).$index];
389+
var ctx = getContext(elem),
390+
index = _.isFunction(ctx.$index) ? ctx.$index() : ctx.$index;
391+
392+
return this.recordsCache()[index];
399393
}
400394

401395
});

app/code/Magento/Ui/view/base/web/js/dynamic-rows/dynamic-rows-grid.js

Lines changed: 44 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,10 @@ define([
1616
map: null,
1717
cacheGridData: [],
1818
deleteProperty: false,
19+
positionProvider: 'position',
1920
dataLength: 0,
2021
identificationProperty: 'id',
22+
identificationDRProperty: 'id',
2123
listens: {
2224
'insertData': 'processingInsertData',
2325
'recordData': 'initElements setToInsertData'
@@ -63,7 +65,7 @@ define([
6365
*/
6466
initChildren: function () {
6567
this.getChildItems().each(function (data, index) {
66-
this.processingAddChild(data, this.startIndex + index, data.id);
68+
this.processingAddChild(data, this.startIndex + index, data[this.identificationDRProperty]);
6769
}, this);
6870

6971
return this;
@@ -83,7 +85,7 @@ define([
8385

8486
if (newData.length) {
8587
if (this.insertData().length) {
86-
this.processingAddChild(newData[0], data.length - 1, newData[0].id);
88+
this.processingAddChild(newData[0], data.length - 1, newData[0][this.identificationProperty]);
8789
}
8890
}
8991

@@ -98,11 +100,12 @@ define([
98100
* @param {String|Number} recordId
99101
*/
100102
deleteRecord: function (index, recordId) {
101-
var data = this.getElementData(this.insertData(), recordId);
103+
var data = this.getElementData(this.insertData(), recordId),
104+
prop = this.map[this.identificationDRProperty];
102105

103106
this._super();
104107
this.insertData(_.reject(this.source.get(this.dataProvider), function (recordData) {
105-
return parseInt(recordData[this.map.id], 10) === parseInt(data[this.map.id], 10);
108+
return ~~recordData[prop] === ~~data[prop];
106109
}, this));
107110
},
108111

@@ -119,9 +122,15 @@ define([
119122
var obj = {},
120123
result;
121124

122-
property ? obj[property] = index : obj[this.map.id] = index;
125+
property ? obj[property] = index : obj[this.map[this.identificationDRProperty]] = index;
123126
result = _.findWhere(array, obj);
124-
!result ? property ? obj[property] = index.toString() : obj[this.map.id] = index.toString() : false;
127+
128+
if (!result) {
129+
property ?
130+
obj[property] = index.toString() :
131+
obj[this.map[this.identificationDRProperty]] = index.toString();
132+
}
133+
125134
result = _.findWhere(array, obj);
126135

127136
return result;
@@ -151,13 +160,14 @@ define([
151160
* @returns {Array} changed data
152161
*/
153162
getNewData: function (data) {
154-
var changes = [];
163+
var changes = [],
164+
tmpObj = {};
155165

156166
if (data.length !== this.relatedData) {
157167
data.each(function (obj) {
158-
if (!_.findWhere(this.relatedData, {
159-
id: obj.id
160-
})) {
168+
tmpObj[this.identificationDRProperty] = obj[this.identificationDRProperty];
169+
170+
if (!_.findWhere(this.relatedData, tmpObj)) {
161171
changes.push(obj);
162172
}
163173
}, this);
@@ -172,14 +182,23 @@ define([
172182
* @param {Array} data
173183
*/
174184
processingInsertData: function (data) {
175-
var changes;
185+
var changes,
186+
obj = {};
176187

177188
changes = this._checkGridData(data);
178189
this.cacheGridData = data;
179190

180-
changes.each(function (changedObject) {
181-
this.mappingValue(changedObject);
182-
}, this);
191+
if (changes.length) {
192+
obj[this.identificationDRProperty] = changes[0][this.map[this.identificationProperty]];
193+
194+
if (_.findWhere(this.recordData(), obj)) {
195+
return false;
196+
}
197+
198+
changes.each(function (changedObject) {
199+
this.mappingValue(changedObject);
200+
}, this);
201+
}
183202
},
184203

185204
/**
@@ -188,16 +207,21 @@ define([
188207
* @param {Array} data
189208
*/
190209
mappingValue: function (data) {
191-
var obj = {};
210+
var obj = {},
211+
tmpObj = {};
192212

193213
_.each(this.map, function (prop, index) {
194-
obj[index] = data[prop];
214+
obj[index] = !_.isUndefined(data[prop]) ? data[prop] : '';
195215
}, this);
196216

197-
if (_.findWhere(this.recordData(), {
198-
id: obj.id
199-
})) {
217+
tmpObj[this.identificationDRProperty] = obj[this.identificationDRProperty];
218+
219+
if (!obj.hasOwnProperty(this.positionProvider)) {
220+
this.setMaxPosition();
221+
obj[this.positionProvider] = this.maxPosition;
222+
}
200223

224+
if (_.findWhere(this.recordData(), tmpObj)) {
201225
return false;
202226
}
203227

@@ -218,7 +242,7 @@ define([
218242
obj = {};
219243

220244
max.each(function (record, index) {
221-
obj[this.map.id] = record[this.map.id];
245+
obj[this.map[this.identificationDRProperty]] = record[this.map[this.identificationDRProperty]];
222246

223247
if (!_.where(this.cacheGridData, obj).length) {
224248
changes.push(data[index]);

0 commit comments

Comments
 (0)