Skip to content

Commit aeaac1d

Browse files
MAGETWO-53034: DnD in Dynamic Rows is not work
1 parent 7edfd0c commit aeaac1d

File tree

1 file changed

+30
-2
lines changed
  • app/code/Magento/Ui/view/base/web/js/dynamic-rows

1 file changed

+30
-2
lines changed

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

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,8 +58,12 @@ define([
5858
recordsCache: [],
5959
draggableElement: {},
6060
draggableElementClass: '_dragged',
61+
elemPositions: [],
6162
listens: {
6263
'${ $.recordsProvider }:elems': 'setCacheRecords'
64+
},
65+
modules: {
66+
parentComponent: '${ $.recordsProvider }'
6367
}
6468
},
6569

@@ -189,7 +193,9 @@ define([
189193
pageY = isTouchDevice ? event.originalEvent.touches[0].pageY : event.pageY,
190194
positionY = pageY - drEl.eventMousedownY;
191195

192-
drEl.depElement = this.getDepElement(drEl.instance, positionY);
196+
drEl.depElement = this.getDepElement(drEl.instance, positionY, this.draggableElement.originRow);
197+
198+
drEl.instance.remove();
193199

194200
if (drEl.depElement) {
195201
depElementCtx = this.getRecord(drEl.depElement.elem[0]);
@@ -210,7 +216,6 @@ define([
210216
this.body.unbind('mouseup', this.mouseupHandler);
211217
}
212218

213-
drEl.instance.remove();
214219
this.draggableElement = {};
215220
},
216221

@@ -224,11 +229,34 @@ define([
224229
setPosition: function (depElem, depElementCtx, dragData) {
225230
var depElemPosition = ~~depElementCtx.position;
226231

232+
this.cacheElementsPosition();
233+
227234
if (dragData.depElement.insert === 'after') {
228235
dragData.instanceCtx.position = depElemPosition + 1;
229236
} else if (dragData.depElement.insert === 'before') {
230237
dragData.instanceCtx.position = depElemPosition;
231238
}
239+
240+
this.normalizePositions();
241+
},
242+
243+
/**
244+
* Saves elements position from current elements
245+
*/
246+
cacheElementsPosition: function () {
247+
this.elemPositions = [];
248+
this.parentComponent().elems.each(function (elem) {
249+
this.elemPositions.push(elem.position);
250+
}, this);
251+
},
252+
253+
/**
254+
* Normalize position, uses start elements position
255+
*/
256+
normalizePositions: function () {
257+
this.parentComponent().elems.each(function (item, index) {
258+
item.position = this.elemPositions[index];
259+
}, this);
232260
},
233261

234262
/**

0 commit comments

Comments
 (0)