[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:
47
platform/commonUI/edit/src/actions/LinkAction.js
Normal file
47
platform/commonUI/edit/src/actions/LinkAction.js
Normal 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;
|
||||||
|
}
|
||||||
|
);
|
||||||
Reference in New Issue
Block a user