From b388c76e457bae87d0b94207a34433f0d4ce54fc Mon Sep 17 00:00:00 2001 From: Henry Date: Thu, 3 Dec 2015 18:24:38 -0800 Subject: [PATCH] [copy] #338 Modified check to set object location, added setLocation flag, Removed unused parameter --- .../entanglement/src/services/CopyTask.js | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/platform/entanglement/src/services/CopyTask.js b/platform/entanglement/src/services/CopyTask.js index 6ac6bcc6a8..d20c233b42 100644 --- a/platform/entanglement/src/services/CopyTask.js +++ b/platform/entanglement/src/services/CopyTask.js @@ -47,14 +47,14 @@ define( this.clones = []; } - function composeChild(child, parent) { + function composeChild(child, parent, setLocation) { //Once copied, associate each cloned // composee with its parent clone parent.getModel().composition.push(child.getId()); - //Check if the object being composed is a link - if (!child.getCapability("location").isLink()) { + //If a location is not specified, set it. + if (setLocation && child.getModel().location === undefined) { child.getModel().location = parent.getId(); } } @@ -113,13 +113,16 @@ define( CopyTask.prototype.copyComposees = function(composees, clonedParent, originalParent){ var self = this; - return (composees || []).reduce(function(promise, composee){ + return (composees || []).reduce(function(promise, originalComposee){ //If the composee is composed of other // objects, chain a promise.. return promise.then(function(){ // ...to recursively copy it (and its children) - return self.copy(composee, originalParent).then(function(composee){ - return composeChild(composee, clonedParent); + return self.copy(originalComposee, originalParent).then(function(clonedComposee){ + //Compose the child within its parent. Cloned + // objects will need to also have their location + // set, however linked objects will not. + return composeChild(clonedComposee, clonedParent, clonedComposee !== originalComposee); }); });}, self.$q.when(undefined) ); @@ -132,11 +135,11 @@ define( * cloning objects, and composing them with their child clones * as it goes * @private - * @param originalObject - * @param originalParent - * @returns {*} + * @returns {DomainObject} If the type of the original object allows for + * duplication, then a duplicate of the object, otherwise the object + * itself (to allow linking to non duplicatable objects). */ - CopyTask.prototype.copy = function(originalObject, originalParent) { + CopyTask.prototype.copy = function(originalObject) { var self = this, clone;