[Code Style] Use prototypes in platform

WTD-1482
This commit is contained in:
Victor Woeltjen
2015-08-11 12:54:50 -07:00
parent f377c7cb71
commit b7765ff388
35 changed files with 1331 additions and 1379 deletions

View File

@@ -49,71 +49,69 @@ define(
* @constructor
*/
function ActionCapability($q, actionService, domainObject) {
this.$q = $q;
this.actionService = actionService;
this.domainObject = domainObject;
}
/**
* Perform an action. This will find and perform the
* first matching action available for the specified
* context or key.
*
* @param {ActionContext|string} context the context in which
* to perform the action; this is passed along to
* the action service to match against available
* actions. The "domainObject" field will automatically
* be populated with the domain object that exposed
* this capability. If given as a string, this will
* be taken as the "key" field to match against
* specific actions.
* @returns {Promise} the result of the action that was
* performed, or undefined if no matching action
* was found.
* @memberof platform/core.ActionCapability#
*/
ActionCapability.prototype.getActions = function (context) {
// Get all actions which are valid in this context;
// this simply redirects to the action service,
// but additionally adds a domainObject field.
function getActions(context) {
var baseContext = typeof context === 'string' ?
{ key: context } :
(context || {}),
actionContext = Object.create(baseContext);
var baseContext = typeof context === 'string' ?
{ key: context } : (context || {}),
actionContext = Object.create(baseContext);
actionContext.domainObject = domainObject;
actionContext.domainObject = this.domainObject;
return actionService.getActions(actionContext);
}
return this.actionService.getActions(actionContext);
};
/**
* Get actions which are available for this domain object,
* in this context.
*
* @param {ActionContext|string} context the context in which
* to perform the action; this is passed along to
* the action service to match against available
* actions. The "domainObject" field will automatically
* be populated with the domain object that exposed
* this capability. If given as a string, this will
* be taken as the "key" field to match against
* specific actions.
* @returns {Action[]} an array of matching actions
* @memberof platform/core.ActionCapability#
*/
ActionCapability.prototype.perform = function (context) {
// Alias to getActions(context)[0].perform, with a
// check for empty arrays.
function performAction(context) {
var actions = getActions(context);
var actions = this.getActions(context);
return $q.when(
(actions && actions.length > 0) ?
actions[0].perform() :
undefined
);
}
return this.$q.when(
(actions && actions.length > 0) ?
actions[0].perform() :
undefined
);
};
return {
/**
* Perform an action. This will find and perform the
* first matching action available for the specified
* context or key.
*
* @param {ActionContext|string} context the context in which
* to perform the action; this is passed along to
* the action service to match against available
* actions. The "domainObject" field will automatically
* be populated with the domain object that exposed
* this capability. If given as a string, this will
* be taken as the "key" field to match against
* specific actions.
* @returns {Promise} the result of the action that was
* performed, or undefined if no matching action
* was found.
* @memberof platform/core.ActionCapability#
*/
perform: performAction,
/**
* Get actions which are available for this domain object,
* in this context.
*
* @param {ActionContext|string} context the context in which
* to perform the action; this is passed along to
* the action service to match against available
* actions. The "domainObject" field will automatically
* be populated with the domain object that exposed
* this capability. If given as a string, this will
* be taken as the "key" field to match against
* specific actions.
* @returns {Action[]} an array of matching actions
* @memberof platform/core.ActionCapability#
*/
getActions: getActions
};
}
return ActionCapability;
}