[Location] Use parent id as location
Use the parent id as the location for a model. This greatly reduces the recursive work that must be done during move operations to keep the location accurate. Additionally, the locationService now implements a method `persistLocation` which can be used to persist the current object location as it's original location.
This commit is contained in:
@@ -9,6 +9,23 @@ define(
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Persist the current location of the current domain object as it's
|
||||
* primary location. Returns a promise.
|
||||
*/
|
||||
LocationCapability.prototype.persistLocation = function () {
|
||||
return this.domainObject.useCapability(
|
||||
'mutation',
|
||||
function (model) {
|
||||
model.location = this.getLocation();
|
||||
}.bind(this)
|
||||
).then(function () {
|
||||
return this.domainObject
|
||||
.getCapability('persistence')
|
||||
.persist();
|
||||
}.bind(this));
|
||||
};
|
||||
|
||||
/**
|
||||
* Return the current location of the current domain object. Only
|
||||
* valid for domain objects that have a context capability.
|
||||
@@ -19,19 +36,10 @@ define(
|
||||
pathIds;
|
||||
|
||||
if (!context) {
|
||||
return this.domainObject.getId();
|
||||
return '';
|
||||
}
|
||||
|
||||
pathObjects = context.getPath();
|
||||
if (!pathObjects) {
|
||||
pathObjects = [];
|
||||
}
|
||||
|
||||
pathIds = pathObjects.map(function (object) {
|
||||
return object.getId();
|
||||
});
|
||||
|
||||
return pathIds.join('/');
|
||||
return context.getParent().getId();
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -64,17 +72,6 @@ define(
|
||||
return new LocationCapability(domainObject);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the LocationCapability can apply to a given
|
||||
* domainObject, otherwise return false.
|
||||
*/
|
||||
createLocationCapability.appliesTo = function (domainObject) {
|
||||
// if (!domainObject.hasCapability) {
|
||||
// return false;
|
||||
// }
|
||||
// return domainObject.hasCapability('context');
|
||||
};
|
||||
|
||||
return createLocationCapability;
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user