[Timeline] Remove NULL_ACTION, clarify logic

Per code review feedback,
https://github.com/nasa/openmct/pull/775/files#r57229759
This commit is contained in:
Victor Woeltjen 2016-03-23 15:34:03 -07:00
parent cb655d486b
commit c13231b8e8

View File

@ -26,12 +26,6 @@ define(
function () { function () {
"use strict"; "use strict";
var NULL_ACTION = {
perform: function () {
return Promise.resolve(true);
}
};
/** /**
* Handles drop (from drag-and-drop) initiated changes to a swimlane. * Handles drop (from drag-and-drop) initiated changes to a swimlane.
* @constructor * @constructor
@ -112,15 +106,7 @@ define(
var actionCapability = var actionCapability =
targetObject.getCapability('action'), targetObject.getCapability('action'),
actionKey = droppedObject.hasCapability('editor') ? actionKey = droppedObject.hasCapability('editor') ?
'move' : 'link', 'move' : 'link';
droppedContext = droppedObject.getCapability('context'),
droppedParent =
droppedContext && droppedContext.getParent(),
droppedParentId = droppedParent && droppedParent.getId();
if (targetObject.getId() === droppedParentId) {
return NULL_ACTION;
}
return actionCapability && actionCapability.getActions({ return actionCapability && actionCapability.getActions({
key: actionKey, key: actionKey,
@ -155,12 +141,27 @@ define(
}); });
} }
function canDrop(targetObject, droppedObject) {
var droppedContext = droppedObject.getCapability('context'),
droppedParent =
droppedContext && droppedContext.getParent(),
droppedParentId = droppedParent && droppedParent.getId();
return (targetObject.getId() === droppedParentId) ||
!!chooseAction(targetObject, droppedObject);
}
function drop(domainObject, targetObject, indexOffset) { function drop(domainObject, targetObject, indexOffset) {
var action = chooseAction(targetObject, domainObject); var action = chooseAction(targetObject, domainObject);
return action.perform().then(function () {
function changeIndex() {
var id = domainObject.getId(); var id = domainObject.getId();
return insert(id, targetObject, indexOffset); return insert(id, targetObject, indexOffset);
}); }
return action ?
action.perform().then(changeIndex) :
changeIndex();
} }
return { return {
@ -175,7 +176,7 @@ define(
return inEditMode() && return inEditMode() &&
!pathContains(swimlane, id) && !pathContains(swimlane, id) &&
!contains(swimlane, id) && !contains(swimlane, id) &&
!!chooseAction(swimlane.domainObject, domainObject); canDrop(swimlane.domainObject, domainObject);
}, },
/** /**
* Check if a drop-after should be allowed for this swimlane, * Check if a drop-after should be allowed for this swimlane,
@ -190,7 +191,7 @@ define(
return inEditMode() && return inEditMode() &&
target && target &&
!pathContains(target, id) && !pathContains(target, id) &&
!!chooseAction(target.domainObject, domainObject); canDrop(target.domainObject, domainObject);
}, },
/** /**
* Drop the provided domain object into a timeline. This is * Drop the provided domain object into a timeline. This is