mirror of
https://github.com/nasa/openmct.git
synced 2025-06-17 22:58:14 +00:00
Merge branch 'open-master' into open962
Merge in latest from open-master into topic branch for WTD-962
This commit is contained in:
@ -51,6 +51,11 @@ define(
|
||||
// some special behavior for its context capability.
|
||||
root = root || domainObject;
|
||||
|
||||
// Avoid double-wrapping (WTD-1017)
|
||||
if (domainObject.hasCapability('editor')) {
|
||||
return domainObject;
|
||||
}
|
||||
|
||||
// Provide an editable form of the object
|
||||
return new EditableDomainObject(
|
||||
domainObject,
|
||||
|
61
platform/commonUI/edit/src/policies/EditActionPolicy.js
Normal file
61
platform/commonUI/edit/src/policies/EditActionPolicy.js
Normal file
@ -0,0 +1,61 @@
|
||||
/*global define*/
|
||||
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Policy controlling when the `edit` and/or `properties` actions
|
||||
* can appear as applicable actions of the `view-control` category
|
||||
* (shown as buttons in the top-right of browse mode.)
|
||||
* @constructor
|
||||
*/
|
||||
function EditActionPolicy() {
|
||||
// Get a count of views which are not flagged as non-editable.
|
||||
function countEditableViews(context) {
|
||||
var domainObject = (context || {}).domainObject,
|
||||
views = domainObject && domainObject.useCapability('view'),
|
||||
count = 0;
|
||||
|
||||
// A view is editable unless explicitly flagged as not
|
||||
(views || []).forEach(function (view) {
|
||||
count += (view.editable !== false) ? 1 : 0;
|
||||
});
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
return {
|
||||
/**
|
||||
* Check whether or not a given action is allowed by this
|
||||
* policy.
|
||||
* @param {Action} action the action
|
||||
* @param context the context
|
||||
* @returns {boolean} true if not disallowed
|
||||
*/
|
||||
allow: function (action, context) {
|
||||
var key = action.getMetadata().key,
|
||||
category = (context || {}).category;
|
||||
|
||||
// Only worry about actions in the view-control category
|
||||
if (category === 'view-control') {
|
||||
// Restrict 'edit' to cases where there are editable
|
||||
// views (similarly, restrict 'properties' to when
|
||||
// the converse is true)
|
||||
if (key === 'edit') {
|
||||
return countEditableViews(context) > 0;
|
||||
} else if (key === 'properties') {
|
||||
return countEditableViews(context) < 1;
|
||||
}
|
||||
}
|
||||
|
||||
// Like all policies, allow by default.
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return EditActionPolicy;
|
||||
}
|
||||
);
|
36
platform/commonUI/edit/src/policies/EditableViewPolicy.js
Normal file
36
platform/commonUI/edit/src/policies/EditableViewPolicy.js
Normal file
@ -0,0 +1,36 @@
|
||||
/*global define*/
|
||||
|
||||
define(
|
||||
[],
|
||||
function () {
|
||||
"use strict";
|
||||
|
||||
/**
|
||||
* Policy controlling which views should be visible in Edit mode.
|
||||
* @constructor
|
||||
*/
|
||||
function EditableViewPolicy() {
|
||||
return {
|
||||
/**
|
||||
* Check whether or not a given action is allowed by this
|
||||
* policy.
|
||||
* @param {Action} action the action
|
||||
* @param domainObject the domain object which will be viewed
|
||||
* @returns {boolean} true if not disallowed
|
||||
*/
|
||||
allow: function (view, domainObject) {
|
||||
// If a view is flagged as non-editable, only allow it
|
||||
// while we're not in Edit mode.
|
||||
if ((view || {}).editable === false) {
|
||||
return !domainObject.hasCapability('editor');
|
||||
}
|
||||
|
||||
// Like all policies, allow by default.
|
||||
return true;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
return EditableViewPolicy;
|
||||
}
|
||||
);
|
Reference in New Issue
Block a user