|
@ -76,6 +76,15 @@ function ItemSet(body, options) { |
|
|
onMoving: function (item, callback) { |
|
|
onMoving: function (item, callback) { |
|
|
callback(item); |
|
|
callback(item); |
|
|
}, |
|
|
}, |
|
|
|
|
|
onAddGroup: function (item, callback) { |
|
|
|
|
|
callback(item); |
|
|
|
|
|
}, |
|
|
|
|
|
onMoveGroup: function (item, callback) { |
|
|
|
|
|
callback(item); |
|
|
|
|
|
}, |
|
|
|
|
|
onRemoveGroup: function (item, callback) { |
|
|
|
|
|
callback(item); |
|
|
|
|
|
}, |
|
|
|
|
|
|
|
|
margin: { |
|
|
margin: { |
|
|
item: { |
|
|
item: { |
|
@ -365,7 +374,7 @@ ItemSet.prototype.setOptions = function(options) { |
|
|
this.options[name] = fn; |
|
|
this.options[name] = fn; |
|
|
} |
|
|
} |
|
|
}).bind(this); |
|
|
}).bind(this); |
|
|
['onAdd', 'onUpdate', 'onRemove', 'onMove', 'onMoving'].forEach(addCallback); |
|
|
|
|
|
|
|
|
['onAdd', 'onUpdate', 'onRemove', 'onMove', 'onMoving', 'onAddGroup', 'onMoveGroup', 'onRemoveGroup'].forEach(addCallback); |
|
|
|
|
|
|
|
|
// force the itemSet to refresh: options like orientation and margins may be changed
|
|
|
// force the itemSet to refresh: options like orientation and margins may be changed
|
|
|
this.markDirty(); |
|
|
this.markDirty(); |
|
@ -1534,7 +1543,59 @@ ItemSet.prototype._onGroupDragEnd = function (event) { |
|
|
if (this.options.groupEditable.order && this.groupTouchParams.group) { |
|
|
if (this.options.groupEditable.order && this.groupTouchParams.group) { |
|
|
event.stopPropagation(); |
|
|
event.stopPropagation(); |
|
|
|
|
|
|
|
|
this.body.emitter.emit('groupDragged'); |
|
|
|
|
|
|
|
|
// update existing group
|
|
|
|
|
|
var me = this; |
|
|
|
|
|
var id = me.groupTouchParams.group.groupId; |
|
|
|
|
|
var dataset = me.groupsData.getDataSet(); |
|
|
|
|
|
var groupData = util.extend({}, dataset.get(id)); // clone the data
|
|
|
|
|
|
me.options.onMoveGroup(groupData, function (groupData) { |
|
|
|
|
|
if (groupData) { |
|
|
|
|
|
// apply changes
|
|
|
|
|
|
groupData[dataset._fieldId] = id; // ensure the group contains its id (can be undefined)
|
|
|
|
|
|
dataset.update(groupData); |
|
|
|
|
|
} |
|
|
|
|
|
else { |
|
|
|
|
|
|
|
|
|
|
|
// fetch current order of groups
|
|
|
|
|
|
var newOrder = dataset.getIds({ |
|
|
|
|
|
order: me.options.groupOrder |
|
|
|
|
|
}); |
|
|
|
|
|
|
|
|
|
|
|
// restore original order
|
|
|
|
|
|
if (!util.equalArray(newOrder, me.groupTouchParams.originalOrder)) { |
|
|
|
|
|
var origOrder = me.groupTouchParams.originalOrder; |
|
|
|
|
|
var numGroups = Math.min(origOrder.length, newOrder.length); |
|
|
|
|
|
var curPos = 0; |
|
|
|
|
|
while (curPos < numGroups) { |
|
|
|
|
|
// as long as the groups are where they should be step down along the groups order
|
|
|
|
|
|
while (curPos < numGroups && newOrder[curPos] == origOrder[curPos]) { |
|
|
|
|
|
curPos++; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// all ok
|
|
|
|
|
|
if (curPos >= numGroups) { |
|
|
|
|
|
break; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// found a group that has the wrong position -> switch with the
|
|
|
|
|
|
// group at the position where other one should be, fix index arrays and continue
|
|
|
|
|
|
var slippedPosition = newOrder.indexOf(origOrder[curPos]) |
|
|
|
|
|
var switchGroup = dataset.get(newOrder[curPos]); |
|
|
|
|
|
var shouldBeGroup = dataset.get(origOrder[curPos]); |
|
|
|
|
|
me.options.groupOrderSwap(switchGroup, shouldBeGroup, dataset); |
|
|
|
|
|
|
|
|
|
|
|
var switchGroupId = newOrder[curPos]; |
|
|
|
|
|
newOrder[curPos] = origOrder[curPos]; |
|
|
|
|
|
newOrder[slippedPosition] = switchGroupId; |
|
|
|
|
|
|
|
|
|
|
|
curPos++; |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
me.body.emitter.emit('groupDragged'); |
|
|
|
|
|
}); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|