mirror of
https://github.com/nasa/openmct.git
synced 2025-06-21 00:23:01 +00:00
[Code Style] Use prototypes in containment bundle
WTD-1482.
This commit is contained in:
@ -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;
|
||||
|
||||
}
|
||||
|
Reference in New Issue
Block a user