[Code Style] Use prototypes in containment bundle

WTD-1482.
This commit is contained in:
Victor Woeltjen
2015-08-11 11:01:13 -07:00
parent aa08db1050
commit f377c7cb71
6 changed files with 94 additions and 114 deletions

View File

@ -36,47 +36,48 @@ define(
* Angular's `$injector`.
* @constructor
* @memberof platform/containment
* @implements {Policy.<Action, ActionContext>}
*/
function ComposeActionPolicy($injector) {
var policyService;
function allowComposition(containerObject, selectedObject) {
// Get the object types involved in the compose action
var containerType = containerObject &&
containerObject.getCapability('type'),
selectedType = selectedObject &&
selectedObject.getCapability('type');
// Get a reference to the policy service if needed...
policyService = policyService || $injector.get('policyService');
// ...and delegate to the composition policy
return policyService.allow(
'composition',
containerType,
selectedType
);
}
return {
/**
* Check whether or not a compose action should be allowed
* in this context.
* @returns {boolean} true if it may be allowed
* @memberof platform/containment.ComposeActionPolicy#
*/
allow: function (candidate, context) {
if (candidate.getMetadata().key === 'compose') {
return allowComposition(
(context || {}).domainObject,
(context || {}).selectedObject
);
}
return true;
}
this.getPolicyService = function () {
return $injector.get('policyService');
};
}
ComposeActionPolicy.prototype.allowComposition = function (containerObject, selectedObject) {
// Get the object types involved in the compose action
var containerType = containerObject &&
containerObject.getCapability('type'),
selectedType = selectedObject &&
selectedObject.getCapability('type');
// Get a reference to the policy service if needed...
this.policyService = this.policyService || this.getPolicyService();
// ...and delegate to the composition policy
return this.policyService.allow(
'composition',
containerType,
selectedType
);
}
/**
* Check whether or not a compose action should be allowed
* in this context.
* @returns {boolean} true if it may be allowed
* @memberof platform/containment.ComposeActionPolicy#
*/
ComposeActionPolicy.prototype.allow = function (candidate, context) {
if (candidate.getMetadata().key === 'compose') {
return this.allowComposition(
(context || {}).domainObject,
(context || {}).selectedObject
);
}
return true;
};
return ComposeActionPolicy;
}