diff --git a/platform/commonUI/browse/bundle.json b/platform/commonUI/browse/bundle.json index d4e7a85036..40b215fa2b 100644 --- a/platform/commonUI/browse/bundle.json +++ b/platform/commonUI/browse/bundle.json @@ -108,7 +108,8 @@ "templateUrl": "templates/items/items.html", "uses": [ "composition" ], "gestures": [ "drop" ], - "type": "folder" + "type": "folder", + "editable": false } ], "components": [ diff --git a/platform/commonUI/edit/bundle.json b/platform/commonUI/edit/bundle.json index 6a1f299747..9bb964f419 100644 --- a/platform/commonUI/edit/bundle.json +++ b/platform/commonUI/edit/bundle.json @@ -68,6 +68,12 @@ "depends": [ "$location" ] } ], + "policies": [ + { + "category": "action", + "implementation": "policies/EditActionPolicy.js" + } + ], "templates": [ { "key": "edit-library", diff --git a/platform/commonUI/edit/src/policies/EditActionPolicy.js b/platform/commonUI/edit/src/policies/EditActionPolicy.js new file mode 100644 index 0000000000..7467a01e63 --- /dev/null +++ b/platform/commonUI/edit/src/policies/EditActionPolicy.js @@ -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; + } +); \ No newline at end of file diff --git a/platform/core/src/actions/ActionProvider.js b/platform/core/src/actions/ActionProvider.js index 19b5504ad1..16976b51c8 100644 --- a/platform/core/src/actions/ActionProvider.js +++ b/platform/core/src/actions/ActionProvider.js @@ -89,7 +89,7 @@ define( // Convert to an array if necessary categories = Array.isArray(categories) ? - categories : [categories]; + categories : [categories]; // Store action under all relevant categories categories.forEach(function (category) {