diff --git a/platform/entanglement/src/capabilities/LocationCapability.js b/platform/entanglement/src/capabilities/LocationCapability.js index 67dc02a626..99e8a63f59 100644 --- a/platform/entanglement/src/capabilities/LocationCapability.js +++ b/platform/entanglement/src/capabilities/LocationCapability.js @@ -6,6 +6,7 @@ define( function LocationCapability(domainObject) { this.domainObject = domainObject; + return this; } /** @@ -38,6 +39,9 @@ define( * original. */ LocationCapability.prototype.isLink = function () { + if (this.getId() === "mine") { + return false; + } var model = this.domainObject.getModel(); return model.location !== this.getLocation(); @@ -48,19 +52,29 @@ define( * link. */ LocationCapability.prototype.isOriginal = function () { + if (this.getId() === "mine") { + return true; + } var model = this.domainObject.getModel(); return model.location === this.getLocation(); }; + function createLocationCapability(domainObject) { + return new LocationCapability(domainObject); + } + /** * Return true if the LocationCapability can apply to a given * domainObject, otherwise return false. */ - LocationCapability.appliesTo = function (domainObject) { - return domainObject.hasCapability('context'); + createLocationCapability.appliesTo = function (domainObject) { + // if (!domainObject.hasCapability) { + // return false; + // } + // return domainObject.hasCapability('context'); }; - return LocationCapability; + return createLocationCapability; } ); diff --git a/platform/entanglement/src/services/MoveService.js b/platform/entanglement/src/services/MoveService.js index e91d381453..1099821aa9 100644 --- a/platform/entanglement/src/services/MoveService.js +++ b/platform/entanglement/src/services/MoveService.js @@ -69,6 +69,22 @@ define( perform: function (object, parentObject) { return linkService .perform(object, parentObject) + .then(function setOriginalLocation(objectInNewContext) { + var locationCapability = + object.getCapability('location'); + + if (!locationCapability.isOriginal()) { + return objectInNewContext; + } + + return objectInNewContext.useCapability( + 'mutation', + function (model) { + model.location = + locationCapability.getLocation(); + } + ); + }) .then(function () { return object .getCapability('action') diff --git a/platform/entanglement/test/services/MoveServiceSpec.js b/platform/entanglement/test/services/MoveServiceSpec.js index d1ffb52bc1..2cf82c48ac 100644 --- a/platform/entanglement/test/services/MoveServiceSpec.js +++ b/platform/entanglement/test/services/MoveServiceSpec.js @@ -25,7 +25,8 @@ define( [ '../../src/services/MoveService', '../services/MockLinkService', - '../DomainObjectFactory' + '../DomainObjectFactory', + '../ControlledPromise' ], function (MoveService, MockLinkService, domainObjectFactory) { "use strict"; @@ -141,7 +142,8 @@ define( var object, parentObject, - actionCapability; + actionCapability, + locationCapability; beforeEach(function () { actionCapability = jasmine.createSpyObj( @@ -149,10 +151,16 @@ define( ['perform'] ); + locationCapability = jasmine.createSpyObj( + 'locationCapability', + ['isOriginal'] + ); + object = domainObjectFactory({ name: 'object', capabilities: { - action: actionCapability + action: actionCapability, + location: locationCapability } }); @@ -175,8 +183,9 @@ define( .toHaveBeenCalledWith(jasmine.any(Function)); }); + it("removes object when link is completed", function () { - linkService.perform.mostRecentCall.resolve(); + linkService.perform.mostRecentCall.promise.resolve() expect(object.getCapability) .toHaveBeenCalledWith('action'); expect(actionCapability.perform) @@ -185,5 +194,6 @@ define( }); }); + } );