Skip to content

Commit 988a367

Browse files
committed
Merge branch 'develop' of github.corp.magento.com:magento2/magento2ce into MAGETWO-48463
2 parents 1bb965e + 0d2000c commit 988a367

File tree

24 files changed

+843
-200
lines changed

24 files changed

+843
-200
lines changed

app/code/Magento/Ui/etc/ui_configuration.xsd

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
<xs:element type="button" name="button"/>
4949
<xs:element type="htmlContent" name="htmlContent"/>
5050
<xs:element type="actionDelete" name="actionDelete"/>
51+
<xs:element type="dynamicRowsConfiguration" name="dynamicRows"/>
5152
</xs:choice>
5253
</xs:extension>
5354
</xs:complexContent>
@@ -99,7 +100,6 @@
99100
<xs:element type="insertFormConfiguration" name="insertForm"/>
100101
<xs:element type="insertListingConfiguration" name="insertListing"/>
101102
<xs:element type="modalConfiguration" name="modal"/>
102-
<xs:element type="dynamicRowsConfiguration" name="dynamicRows"/>
103103
</xs:choice>
104104
</xs:extension>
105105
</xs:complexContent>
@@ -131,34 +131,26 @@
131131
</xs:complexType>
132132
<xs:complexType name="modalConfiguration">
133133
<xs:complexContent>
134-
<xs:extension base="modal">
135-
<xs:choice minOccurs="0" maxOccurs="unbounded">
136-
<xs:element type="field" name="field" />
137-
<xs:element type="fieldsetConfiguration" name="fieldset"/>
138-
<xs:element type="containerConfiguration" name="container"/>
139-
<xs:element type="modalConfiguration" name="modal"/>
140-
<xs:element type="dynamicRowsConfiguration" name="dynamicRows"/>
141-
<xs:element type="insertListingConfiguration" name="insertListing"/>
142-
<xs:element type="insertFormConfiguration" name="insertForm"/>
143-
</xs:choice>
134+
<xs:extension base="containerConfiguration">
135+
<xs:choice minOccurs="0" maxOccurs="unbounded"/>
144136
</xs:extension>
145137
</xs:complexContent>
146138
</xs:complexType>
147-
<xs:complexType name="dynamicRowsConfiguration">
139+
<xs:complexType name="massactionConfiguration">
148140
<xs:complexContent>
149-
<xs:extension base="dynamicRows">
141+
<xs:extension base="massaction">
150142
<xs:choice minOccurs="0" maxOccurs="unbounded">
151-
<xs:element type="containerConfiguration" name="container"/>
152-
<xs:element type="actionDelete" name="actionDelete"/>
143+
<xs:element name="action" type="action" />
153144
</xs:choice>
154145
</xs:extension>
155146
</xs:complexContent>
156147
</xs:complexType>
157-
<xs:complexType name="massactionConfiguration">
148+
<xs:complexType name="dynamicRowsConfiguration">
158149
<xs:complexContent>
159-
<xs:extension base="massaction">
150+
<xs:extension base="dynamicRows">
160151
<xs:choice minOccurs="0" maxOccurs="unbounded">
161-
<xs:element name="action" type="action" />
152+
<xs:element type="containerConfiguration" name="container"/>
153+
<xs:element type="actionDelete" name="actionDelete"/>
162154
</xs:choice>
163155
</xs:extension>
164156
</xs:complexContent>

app/code/Magento/Ui/view/base/ui_component/etc/definition.xml

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -206,25 +206,23 @@
206206
</item>
207207
</argument>
208208
</wysiwyg>
209-
<input class="Magento\Ui\Component\Form\Element\Input">
209+
<actionDelete class="Magento\Ui\Component\Form\Element\ActionDelete">
210210
<argument name="data" xsi:type="array">
211211
<item name="config" xsi:type="array">
212212
<item name="component" xsi:type="string">Magento_Ui/js/form/element/abstract</item>
213-
<item name="template" xsi:type="string">ui/form/field</item>
213+
<item name="elementTmpl" xsi:type="string">ui/dynamic-rows/cells/action-delete</item>
214+
<item name="template" xsi:type="string">ui/dynamic-rows/cells/action-delete</item>
214215
</item>
215216
</argument>
216-
</input>
217-
<actionDelete class="Magento\Ui\Component\Form\Element\ActionDelete">
217+
</actionDelete>
218+
<input class="Magento\Ui\Component\Form\Element\Input">
218219
<argument name="data" xsi:type="array">
219-
<item name="js_config" xsi:type="array">
220+
<item name="config" xsi:type="array">
220221
<item name="component" xsi:type="string">Magento_Ui/js/form/element/abstract</item>
221-
<item name="config" xsi:type="array">
222-
<item name="elementTmpl" xsi:type="string">ui/dynamic-rows/cells/action-delete</item>
223-
<item name="template" xsi:type="string">ui/dynamic-rows/cells/action-delete</item>
224-
</item>
222+
<item name="template" xsi:type="string">ui/form/field</item>
225223
</item>
226224
</argument>
227-
</actionDelete>
225+
</input>
228226
<hidden class="Magento\Ui\Component\Form\Element\Hidden">
229227
<argument name="data" xsi:type="array">
230228
<item name="config" xsi:type="array">

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

Lines changed: 95 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,11 @@ define([
5050
defaults: {
5151
rootSelector: '${ $.recordsProvider }:div.admin__field',
5252
tableSelector: '${ $.rootSelector } -> table.admin__dynamic-rows',
53+
separatorsClass: {
54+
top: '_dragover-top',
55+
bottom: '_dragover-bottom'
56+
},
57+
step: 'auto',
5358
recordsCache: [],
5459
draggableElement: {},
5560
draggableElementClass: '_dragged',
@@ -115,22 +120,21 @@ define([
115120
*/
116121
mousedownHandler: function (data, elem, event) {
117122
var recordNode = this.getRecordNode(elem),
118-
originRecord = $(elem).parents('tr');
123+
originRecord = $(elem).parents('tr'),
124+
drEl = this.draggableElement;
119125

120126
$(recordNode).addClass(this.draggableElementClass);
121127
$(originRecord).addClass(this.draggableElementClass);
122-
this.draggableElement.originRow = originRecord;
123-
this.draggableElement.instance = recordNode = this.processingStyles(recordNode, elem);
124-
this.draggableElement.instanceCtx = this.getRecord(originRecord[0]);
125-
this.draggableElement.eventMousedownY = event.pageY;
126-
this.draggableElement.minYpos =
128+
this.step = this.step === 'auto' ? originRecord.height() / 2 : this.step;
129+
drEl.originRow = originRecord;
130+
drEl.instance = recordNode = this.processingStyles(recordNode, elem);
131+
drEl.instanceCtx = this.getRecord(originRecord[0]);
132+
drEl.eventMousedownY = event.pageY;
133+
drEl.minYpos =
127134
this.table.offset().top - originRecord.offset().top +
128135
this.table.outerHeight() - this.table.find('tbody').outerHeight();
129-
this.draggableElement.maxYpos =
130-
this.draggableElement.minYpos +
131-
this.table.find('tbody').outerHeight() - originRecord.outerHeight();
136+
drEl.maxYpos = drEl.minYpos + this.table.find('tbody').outerHeight() - originRecord.outerHeight();
132137
this.tableWrapper.append(recordNode);
133-
134138
this.body.bind('mousemove', this.mousemoveHandler);
135139
this.body.bind('mouseup', this.mouseupHandler);
136140
},
@@ -141,32 +145,51 @@ define([
141145
* @param {Object} event - mouse move event
142146
*/
143147
mousemoveHandler: function (event) {
144-
var positionY = event.pageY - this.draggableElement.eventMousedownY,
148+
var depEl = this.draggableElement,
149+
positionY = event.pageY - depEl.eventMousedownY,
145150
processingPositionY = positionY + 'px',
146-
processingMaxYpos = this.draggableElement.maxYpos + 'px',
147-
processingMinYpos = this.draggableElement.minYpos + 'px';
148-
149-
if (positionY > this.draggableElement.minYpos && positionY < this.draggableElement.maxYpos) {
150-
$(this.draggableElement.instance)[0].style[transformProp] = 'translateY(' + processingPositionY + ')';
151-
} else if (positionY < this.draggableElement.minYpos) {
152-
$(this.draggableElement.instance)[0].style[transformProp] = 'translateY(' + processingMinYpos + ')';
153-
} else if (positionY >= this.draggableElement.maxYpos) {
154-
$(this.draggableElement.instance)[0].style[transformProp] = 'translateY(' + processingMaxYpos + ')';
151+
processingMaxYpos = depEl.maxYpos + 'px',
152+
processingMinYpos = depEl.minYpos + 'px',
153+
depElement = this.getDepElement(depEl.instance, positionY);
154+
155+
if (depElement) {
156+
depEl.depElement ? depEl.depElement.elem.removeClass(depEl.depElement.className) : false;
157+
depEl.depElement = depElement;
158+
depEl.depElement.insert !== 'none' ? depEl.depElement.elem.addClass(depElement.className) : false;
159+
} else if (depEl.depElement && depEl.depElement.insert !== 'none') {
160+
depEl.depElement.elem.removeClass(depEl.depElement.className);
161+
depEl.depElement.insert = 'none';
162+
}
163+
164+
if (positionY > depEl.minYpos && positionY < depEl.maxYpos) {
165+
$(depEl.instance)[0].style[transformProp] = 'translateY(' + processingPositionY + ')';
166+
} else if (positionY < depEl.minYpos) {
167+
$(depEl.instance)[0].style[transformProp] = 'translateY(' + processingMinYpos + ')';
168+
} else if (positionY >= depEl.maxYpos) {
169+
$(depEl.instance)[0].style[transformProp] = 'translateY(' + processingMaxYpos + ')';
155170
}
156171
},
157172

158173
/**
159174
* Mouse up handler
160175
*/
161176
mouseupHandler: function () {
162-
var depElement = this._getDepElement(this.draggableElement.instance),
163-
depElementCtx = this.getRecord(depElement[0]);
177+
var depElementCtx,
178+
drEl = this.draggableElement;
179+
180+
if (drEl.depElement) {
181+
depElementCtx = this.getRecord(drEl.depElement.elem[0]);
182+
drEl.depElement.elem.removeClass(drEl.depElement.className);
164183

165-
this.setPosition(depElement, depElementCtx, this.draggableElement);
166-
this.draggableElement.originRow.removeClass(this.draggableElementClass);
184+
if (drEl.depElement.insert !== 'none') {
185+
this.setPosition(drEl.depElement.elem, depElementCtx, drEl);
186+
}
187+
}
188+
189+
drEl.originRow.removeClass(this.draggableElementClass);
167190
this.body.unbind('mousemove', this.mousemoveHandler);
168191
this.body.unbind('mouseup', this.mouseupHandler);
169-
this.draggableElement.instance.remove();
192+
drEl.instance.remove();
170193
this.draggableElement = {};
171194
},
172195

@@ -178,64 +201,69 @@ define([
178201
* @param {Object} dragData - data draggable element
179202
*/
180203
setPosition: function (depElem, depElementCtx, dragData) {
181-
var prevElem = depElem.prev(),
182-
nextElem = depElem.next(),
183-
depElemPosition = parseInt(depElementCtx.position, 10),
184-
prevElemCtx,
185-
prevElemPosition;
186-
187-
if (prevElem[0] === dragData.originRow[0]) {
188-
dragData.instanceCtx.position = depElemPosition;
189-
depElementCtx.position = depElemPosition - 1;
190-
191-
return false;
192-
}
204+
var depElemPosition = parseInt(depElementCtx.position, 10);
193205

194-
if (!prevElem.length) {
195-
depElemPosition = --depElemPosition ? depElemPosition : 1;
206+
if (dragData.depElement.insert === 'after') {
207+
dragData.instanceCtx.position = depElemPosition + 1;
208+
} else if (dragData.depElement.insert === 'before') {
196209
dragData.instanceCtx.position = depElemPosition;
197-
198-
return false;
199210
}
211+
},
200212

201-
if (!nextElem.length) {
202-
depElemPosition = ++depElemPosition;
203-
dragData.instanceCtx.position = depElemPosition;
204-
205-
return false;
206-
}
213+
/**
214+
* Get dependency element
215+
*
216+
* @param {Object} curInstance - current element instance
217+
* @param {Number} position
218+
*/
207219

208-
prevElemCtx = this.getRecord(prevElem[0]);
209-
prevElemPosition = prevElemCtx.position;
220+
getDepElement: function (curInstance, position) {
221+
var recordsCollection = this.table.find('tbody > tr'),
222+
curInstancePositionTop = $(curInstance).position().top,
223+
curInstancePositionBottom = curInstancePositionTop + $(curInstance).height();
210224

211-
if (prevElemPosition === depElemPosition - 1) {
212-
dragData.instanceCtx.position = depElemPosition;
213-
} else {
214-
dragData.instanceCtx.position = --depElemPosition;
225+
if (position < 0) {
226+
return this._getDepElement(recordsCollection, 'before', curInstancePositionTop);
227+
} else if (position > 0) {
228+
return this._getDepElement(recordsCollection, 'after', curInstancePositionBottom);
215229
}
216-
217230
},
218231

219232
/**
220-
* Get dependency element
233+
* Get dependency element private
221234
*
222-
* @param {Object} curInstance - current element instance
235+
* @param {Array} collection - record collection
236+
* @param {String} position - position to add
237+
* @param {Number} dragPosition - position drag element
223238
*/
224-
_getDepElement: function (curInstance) {
225-
var recordsCollection = this.table.find('tbody > tr'),
226-
curInstancePosition = $(curInstance).position().top,
227-
i = 0,
228-
length = recordsCollection.length,
229-
result,
239+
_getDepElement: function (collection, position, dragPosition) {
240+
var rec,
241+
rangeEnd,
230242
rangeStart,
231-
rangeEnd;
243+
result,
244+
className,
245+
i = 0,
246+
length = collection.length;
232247

233248
for (i; i < length; i++) {
234-
rangeStart = recordsCollection.eq(i).position().top;
235-
rangeEnd = rangeStart + recordsCollection.eq(i).height();
249+
rec = collection.eq(i);
250+
251+
if (position === 'before') {
252+
rangeStart = collection.eq(i).position().top;
253+
rangeEnd = rangeStart + this.step;
254+
className = this.separatorsClass.top;
255+
} else if (position === 'after') {
256+
rangeEnd = rec.position().top + rec.height();
257+
rangeStart = rangeEnd - this.step;
258+
className = this.separatorsClass.bottom;
259+
}
236260

237-
if (curInstancePosition > rangeStart && curInstancePosition < rangeEnd) {
238-
result = recordsCollection.eq(i);
261+
if (dragPosition > rangeStart && dragPosition < rangeEnd) {
262+
result = {
263+
elem: rec,
264+
insert: rec[0] === this.draggableElement.originRow[0] ? 'none' : position,
265+
className: className
266+
};
239267
}
240268
}
241269

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

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,9 @@
44
*/
55

66
define([
7-
'ko',
8-
'mageUtils',
97
'underscore',
10-
'uiLayout',
118
'./dynamic-rows'
12-
], function (ko, utils, _, layout, dynamicRows) {
9+
], function (_, dynamicRows) {
1310
'use strict';
1411

1512
return dynamicRows.extend({

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

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ define([
7474
this._super()
7575
.initChildren()
7676
.initDnd()
77-
.isColumnsHeader()
77+
.setColumnsHeaderListener()
7878
.initDefaultRecord();
7979

8080
return this;
@@ -118,7 +118,7 @@ define([
118118
*
119119
* @returns {Object} Chainable.
120120
*/
121-
isColumnsHeader: function () {
121+
setColumnsHeaderListener: function () {
122122
if (this.columnsHeaderAfterRender) {
123123
this.on('elems', this.renderColumnsHeader.bind(this));
124124
}
@@ -217,6 +217,7 @@ define([
217217
sorted = this.elems().sort(function (propOne, propTwo) {
218218
return parseInt(propOne.position, 10) - parseInt(propTwo.position, 10);
219219
});
220+
220221
updatedCollection = this.updatePosition(sorted, position, elem.name);
221222
this.elems(updatedCollection);
222223
},
@@ -317,9 +318,9 @@ define([
317318
this.removeMaxPosition();
318319
recordsData = this._getDataByProp(recordId);
319320
this._updateData(recordsData);
320-
this._sortAfterDelete();
321321
--this.recordIterator;
322322
}
323+
this._sort();
323324
},
324325

325326
/**
@@ -339,7 +340,7 @@ define([
339340
/**
340341
* Sort elems by position property
341342
*/
342-
_sortAfterDelete: function () {
343+
_sort: function () {
343344
this.elems(this.elems().sort(function (propOne, propTwo) {
344345
return parseInt(propOne.position, 10) - parseInt(propTwo.position, 10);
345346
}));

0 commit comments

Comments
 (0)