From 0ce19ad75d11bbcdbb85a90ec00c99264324178a Mon Sep 17 00:00:00 2001 From: Henry Date: Thu, 10 Dec 2015 17:39:56 -0800 Subject: [PATCH] Disabled context menu for Location items in edit mode, and disabled context menu items for non-creatable objects --- .../edit/src/objects/EditableDomainObject.js | 1 - .../res/templates/object-inspector.html | 6 +++- platform/core/src/actions/ActionCapability.js | 29 +++++++++++++++---- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/platform/commonUI/edit/src/objects/EditableDomainObject.js b/platform/commonUI/edit/src/objects/EditableDomainObject.js index 98561e7e7d..2b764f7de7 100644 --- a/platform/commonUI/edit/src/objects/EditableDomainObject.js +++ b/platform/commonUI/edit/src/objects/EditableDomainObject.js @@ -56,7 +56,6 @@ define( context: EditableContextCapability, composition: EditableCompositionCapability, relationship: EditableRelationshipCapability, - action: EditableActionCapability, editor: EditorCapability }; diff --git a/platform/commonUI/general/res/templates/object-inspector.html b/platform/commonUI/general/res/templates/object-inspector.html index c056bcaeb4..7dd8d6a5b3 100644 --- a/platform/commonUI/general/res/templates/object-inspector.html +++ b/platform/commonUI/general/res/templates/object-inspector.html @@ -19,7 +19,11 @@ this source code distribution or the Licensing information page available at runtime from the About dialog for additional information. --> - +
diff --git a/platform/core/src/actions/ActionCapability.js b/platform/core/src/actions/ActionCapability.js index 2164969a05..a84e67e62d 100644 --- a/platform/core/src/actions/ActionCapability.js +++ b/platform/core/src/actions/ActionCapability.js @@ -28,7 +28,7 @@ define( [], function () { "use strict"; - + var DISALLOWED_ACTIONS = ["move", "copy", "link", "window", "follow"]; /** * The ActionCapability allows applicable Actions to be retrieved and * performed for specific domain objects, e.g.: @@ -54,6 +54,18 @@ define( this.domainObject = domainObject; } + function isEditable(domainObject){ + return domainObject.getCapability('status').get('editing'); + } + + function hasEditableParent(domainObject){ + return domainObject.hasCapability('context') && + domainObject.getCapability('context').getPath().reduce( + function(previous, domainObject){ + return domainObject.getCapability('status').get('editing') || previous; + }, false); + } + /** * Perform an action. This will find and perform the * first matching action available for the specified @@ -67,9 +79,6 @@ define( * 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) { @@ -78,11 +87,19 @@ define( // but additionally adds a domainObject field. var baseContext = typeof context === 'string' ? { key: context } : (context || {}), - actionContext = Object.create(baseContext); + actionContext = Object.create(baseContext), + actions; actionContext.domainObject = this.domainObject; - return this.actionService.getActions(actionContext); + actions = this.actionService.getActions(actionContext) || []; + if (isEditable(this.domainObject) || hasEditableParent(this.domainObject)){ + return actions.filter(function(action){ + return DISALLOWED_ACTIONS.indexOf(action.getMetadata().key) === -1; + }); + } else { + return actions; + } }; /**