diff --git a/platform/commonUI/edit/src/actions/LinkAction.js b/platform/commonUI/edit/src/actions/LinkAction.js index 74abd2a93c..95ed9a8082 100644 --- a/platform/commonUI/edit/src/actions/LinkAction.js +++ b/platform/commonUI/edit/src/actions/LinkAction.js @@ -36,20 +36,11 @@ define( function LinkAction(context) { this.domainObject = (context || {}).domainObject; this.selectedObject = (context || {}).selectedObject; - this.selectedId = this.selectedObject && this.selectedObject.getId(); } LinkAction.prototype.perform = function () { var self = this; - // Add this domain object's identifier - function addId(model) { - if (Array.isArray(model.composition) && - model.composition.indexOf(self.selectedId) < 0) { - model.composition.push(self.selectedId); - } - } - // Persist changes to the domain object function doPersist() { var persistence = @@ -59,11 +50,13 @@ define( // Link these objects function doLink() { - return self.domainObject.useCapability("mutation", addId) - .then(doPersist); + var composition = self.domainObject && + self.domainObject.getCapability('composition'); + return composition && composition.add(self.selectedObject) + .then(doPersist); } - return this.selectedId && doLink(); + return this.selectedObject && doLink(); }; return LinkAction; diff --git a/platform/core/src/capabilities/CompositionCapability.js b/platform/core/src/capabilities/CompositionCapability.js index a2a269e0b8..c96a060986 100644 --- a/platform/core/src/capabilities/CompositionCapability.js +++ b/platform/core/src/capabilities/CompositionCapability.js @@ -63,7 +63,8 @@ define( */ CompositionCapability.prototype.add = function (domainObject, index) { var id = typeof domainObject === 'string' ? - domainObject : domainObject.getId(); + domainObject : domainObject.getId(), + $q = this.$q; function addIdToModel(model) { var composition = model.composition, @@ -71,9 +72,9 @@ define( // If no index has been specified already and the id is already // present, nothing to do. If the id is already at that index, - // also nothing to do. + // also nothing to do, so cancel mutation. if ((isNaN(index) && oldIndex !== -1) || (index === oldIndex) { - return; + return false; } // Pick a specific index if needed.