From 5adcd3cd6de3029e6b4502732e67f44d340f6a78 Mon Sep 17 00:00:00 2001 From: Victor Woeltjen Date: Tue, 7 Apr 2015 20:20:56 -0700 Subject: [PATCH] [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. --- .../commonUI/edit/src/actions/LinkAction.js | 47 +++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 platform/commonUI/edit/src/actions/LinkAction.js diff --git a/platform/commonUI/edit/src/actions/LinkAction.js b/platform/commonUI/edit/src/actions/LinkAction.js new file mode 100644 index 0000000000..459fec0d5f --- /dev/null +++ b/platform/commonUI/edit/src/actions/LinkAction.js @@ -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; + } +); \ No newline at end of file