[Timeline] Handle drops for reordering

...as these would be disallowed by Move, normally.
This commit is contained in:
Victor Woeltjen
2016-03-21 11:51:51 -07:00
parent 7f3ac4077c
commit e7a6c34bcc

View File

@ -110,14 +110,26 @@ define(
// Choose an appropriate composition action for the drag-and-drop // Choose an appropriate composition action for the drag-and-drop
function chooseAction(targetObject, droppedObject) { function chooseAction(targetObject, droppedObject) {
var actionCapability = var actionCapability =
targetObject.getCapability('action'), targetObject.getCapability('action'),
actionKey = droppedObject.hasCapability('editor') ? actionKey = droppedObject.hasCapability('editor') ?
'move' : 'link', 'move' : 'link',
actions = actionCapability && actionCapability.getActions({ droppedContext = droppedObject.getCapability('context'),
key: actionKey, droppedParent =
selectedObject: droppedObject droppedContext && droppedContext.getParent(),
}); droppedParentId = droppedParent && droppedParent.getId();
return actions[0];
if (targetObject.getId() === droppedParentId) {
return {
perform: function () {
return Promise.resolve(true);
}
};
}
return actionCapability && actionCapability.getActions({
key: actionKey,
selectedObject: droppedObject
})[0];
} }
// Choose an index for insertion in a domain object's composition // Choose an index for insertion in a domain object's composition
@ -135,9 +147,10 @@ define(
function insert(id, target, indexOffset) { function insert(id, target, indexOffset) {
var myId = swimlane.domainObject.getId(); var myId = swimlane.domainObject.getId();
return doMutate(target, function (model) { return doMutate(target, function (model) {
model.composition = model.composition.filter(function (i) { model.composition =
return i !== id; model.composition.filter(function (compId) {
}); return compId !== id;
});
model.composition.splice( model.composition.splice(
chooseTargetIndex(myId, indexOffset, model.composition), chooseTargetIndex(myId, indexOffset, model.composition),
0, 0,