[Containment] Implement Link

Implement link as a basic action, to separate it out from
drop gesture such that it can be controlled by policy. For
WTD-962.
This commit is contained in:
Victor Woeltjen 2015-04-07 20:20:56 -07:00
parent 870ff6af32
commit 5adcd3cd6d

View File

@ -0,0 +1,47 @@
/*global define*/
define(
[],
function () {
"use strict";
/**
* Add one domain object to another's composition.
*/
function LinkAction(context) {
var domainObject = (context || {}).domainObject,
selectedObject = (context || {}).selectedObject,
selectedId = selectedObject && selectedObject.getId();
// Add this domain object's identifier
function addId(model) {
model.composition = model.composition || [];
model.composition.push(selectedId);
}
// Persist changes to the domain object
function doPersist() {
var persistence = domainObject.getCapability('persistence');
return persistence.persist();
}
// Link these objects
function doLink() {
return domainObject.useCapability("mutation", addId)
.then(doPersist);
}
return {
/**
* Perform this action.
*/
perform: function () {
return selectedId && doLink();
}
};
}
return LinkAction;
}
);