[Timeline] Use move action on drag-drop

...to avoid creating links when desired behavior is a move,
#679.
This commit is contained in:
Victor Woeltjen 2016-03-21 11:18:18 -07:00
parent ad4c456ca2
commit 5034e88656

View File

@ -106,6 +106,19 @@ define(
return swimlane.highlight() || expandedForDropInto(); return swimlane.highlight() || expandedForDropInto();
} }
// Choose an appropriate composition action for the drag-and-drop
function chooseAction(swimlane, domainObject) {
var actionCapability =
swimlane.domainObject.getCapability('action'),
actionKey = domainObject.hasCapability('editor') ?
'move' : 'link';
return actionCapability && actionCapability.getActions({
key: actionKey,
selectedObject: domainObject
})[0];
}
// Choose an index for insertion in a domain object's composition // Choose an index for insertion in a domain object's composition
function chooseTargetIndex(id, offset, composition) { function chooseTargetIndex(id, offset, composition) {
return Math.max( return Math.max(
@ -129,17 +142,18 @@ define(
}); });
} }
// Check if a compose action is allowed for the object in this function drop(domainObject, swimlane, indexOffset) {
// swimlane (we handle the link differently to set the index, var action = chooseAction(swimlane, domainObject);
// but check for the existence of the action to invole the return action.perform().then(function () {
// relevant policies.) return insert(
function allowsCompose(swimlane, domainObject) { domainObject.getId(),
var actionCapability = swimlane.domainObject,
swimlane.domainObject.getCapability('action'); indexOffset
return actionCapability && actionCapability.getActions({ );
key: 'compose', }).then(function () {
selectedObject: domainObject return swimlane.domainObject.getCapability('persistence')
}).length > 0; .persist();
});
} }
return { return {
@ -154,7 +168,7 @@ define(
return inEditMode() && return inEditMode() &&
!pathContains(swimlane, id) && !pathContains(swimlane, id) &&
!contains(swimlane, id) && !contains(swimlane, id) &&
allowsCompose(swimlane, domainObject); !!chooseAction(swimlane, domainObject);
}, },
/** /**
* Check if a drop-after should be allowed for this swimlane, * Check if a drop-after should be allowed for this swimlane,
@ -169,7 +183,7 @@ define(
return inEditMode() && return inEditMode() &&
target && target &&
!pathContains(target, id) && !pathContains(target, id) &&
allowsCompose(target, domainObject); !!chooseAction(target, domainObject);
}, },
/** /**
* Drop the provided domain object into a timeline. This is * Drop the provided domain object into a timeline. This is
@ -192,11 +206,7 @@ define(
Number.POSITIVE_INFINITY; Number.POSITIVE_INFINITY;
if (swimlane.highlight() || swimlane.highlightBottom()) { if (swimlane.highlight() || swimlane.highlightBottom()) {
// Remove the domain object from its original location... return drop(domainObject, dropTarget, dropIndexOffset);
return asPromise(remove(domainObject)).then(function () {
// ...then insert it at its new location.
insert(id, dropTarget, dropIndexOffset);
});
} }
} }
}; };