[Code Style] Use prototypes in Edit bundle

WTD-1482.
This commit is contained in:
Victor Woeltjen
2015-08-10 16:38:13 -07:00
parent efc42aa8f2
commit be5cad212a
25 changed files with 766 additions and 790 deletions

View File

@@ -39,68 +39,64 @@ define(
* @param {ActionContext} context the context in which this action is performed
* @memberof platform/commonUI/edit
* @constructor
* @implements {Action}
*/
function RemoveAction($q, context) {
var object = (context || {}).domainObject;
this.domainObject = (context || {}).domainObject;
this.$q = $q;
}
/**
/**
* Perform this action.
* @return {Promise} a promise which will be
* fulfilled when the action has completed.
*/
RemoveAction.prototype.perform = function () {
var $q = this.$q,
domainObject = this.domainObject;
/*
* Check whether an object ID matches the ID of the object being
* removed (used to filter a parent's composition to handle the
* removal.)
* @memberof platform/commonUI/edit.RemoveAction#
*/
function isNotObject(otherObjectId) {
return otherObjectId !== object.getId();
return otherObjectId !== domainObject.getId();
}
/**
/*
* Mutate a parent object such that it no longer contains the object
* which is being removed.
* @memberof platform/commonUI/edit.RemoveAction#
*/
function doMutate(model) {
model.composition = model.composition.filter(isNotObject);
}
/**
/*
* Invoke persistence on a domain object. This will be called upon
* the removed object's parent (as its composition will have changed.)
* @memberof platform/commonUI/edit.RemoveAction#
*/
function doPersist(domainObject) {
var persistence = domainObject.getCapability('persistence');
return persistence && persistence.persist();
}
/**
/*
* Remove the object from its parent, as identified by its context
* capability.
* @param {ContextCapability} contextCapability the "context" capability
* of the domain object being removed.
* @memberof platform/commonUI/edit.RemoveAction#
*/
function removeFromContext(contextCapability) {
var parent = contextCapability.getParent();
$q.when(
parent.useCapability('mutation', doMutate)
).then(function () {
return doPersist(parent);
});
return $q.when(
parent.useCapability('mutation', doMutate)
).then(function () {
return doPersist(parent);
});
}
return {
/**
* Perform this action.
* @return {module:core/promises.Promise} a promise which will be
* fulfilled when the action has completed.
* @memberof platform/commonUI/edit.RemoveAction#
*/
perform: function () {
return $q.when(object.getCapability('context'))
.then(removeFromContext);
}
};
}
return $q.when(this.domainObject.getCapability('context'))
.then(removeFromContext);
};
// Object needs to have a parent for Remove to be applicable
RemoveAction.appliesTo = function (context) {