From 06436c488af5f5760e9a72efd94c6a80a55ac60b Mon Sep 17 00:00:00 2001 From: Henry Date: Mon, 18 Apr 2016 19:05:46 -0700 Subject: [PATCH] [Edit Mode] #794 Modified policy to show remove action in context for non-editable domain object types --- platform/commonUI/edit/bundle.js | 12 +++++++- .../policies/EditContextualActionPolicy.js | 28 +++++++++++------ .../EditContextualActionPolicySpec.js | 30 +++++++++++++++++-- 3 files changed, 57 insertions(+), 13 deletions(-) diff --git a/platform/commonUI/edit/bundle.js b/platform/commonUI/edit/bundle.js index f2e684a69f..e766d96e56 100644 --- a/platform/commonUI/edit/bundle.js +++ b/platform/commonUI/edit/bundle.js @@ -207,7 +207,7 @@ define([ { "category": "action", "implementation": EditContextualActionPolicy, - "depends": ["navigationService"] + "depends": ["navigationService", "editModeBlacklist", "nonEditContextBlacklist"] }, { "category": "action", @@ -274,6 +274,16 @@ define([ { "implementation": EditToolbarRepresenter } + ], + "constants": [ + { + "key":"editModeBlacklist", + "value": ["copy", "follow", "window", "link", "locate"] + }, + { + "key": "nonEditContextBlacklist", + "value": ["copy", "follow", "properties", "move", "link", "remove", "locate"] + } ] } }); diff --git a/platform/commonUI/edit/src/policies/EditContextualActionPolicy.js b/platform/commonUI/edit/src/policies/EditContextualActionPolicy.js index 06fe9de640..6b6c22252e 100644 --- a/platform/commonUI/edit/src/policies/EditContextualActionPolicy.js +++ b/platform/commonUI/edit/src/policies/EditContextualActionPolicy.js @@ -29,17 +29,27 @@ define( /** * Policy controlling whether the context menu is visible when * objects are being edited - * @memberof platform/commonUI/edit + * @param navigationService + * @param editModeBlacklist A blacklist of actions disallowed from + * context menu when navigated object is being edited + * @param nonEditContextBlacklist A blacklist of actions disallowed + * from context menu of non-editable objects, when navigated object + * is being edited * @constructor - * @implements {Policy.} */ - function EditContextualActionPolicy(navigationService) { + function EditContextualActionPolicy(navigationService, editModeBlacklist, nonEditContextBlacklist) { this.navigationService = navigationService; + //The list of objects disallowed on target object when in edit mode - this.editBlacklist = ["copy", "follow", "window"]; + this.editModeBlacklist = editModeBlacklist; //The list of objects disallowed on target object that is not in // edit mode (ie. the context menu in the tree on the LHS). - this.nonEditBlacklist = ["copy", "follow", "properties", "move", "link", "remove"]; + this.nonEditContextBlacklist = nonEditContextBlacklist; + } + + function isParentEditable(object) { + var parent = object.hasCapability("context") && object.getCapability("context").getParent(); + return !!parent && parent.hasCapability("editor"); } EditContextualActionPolicy.prototype.allow = function (action, context) { @@ -48,11 +58,11 @@ define( actionMetadata = action.getMetadata ? action.getMetadata() : {}; if (navigatedObject.hasCapability('editor')) { - if (!selectedObject.hasCapability('editor')){ - //Target is in the context menu - return this.nonEditBlacklist.indexOf(actionMetadata.key) === -1; + if (selectedObject.hasCapability('editor') || isParentEditable(selectedObject)){ + return this.editModeBlacklist.indexOf(actionMetadata.key) === -1; } else { - return this.editBlacklist.indexOf(actionMetadata.key) === -1; + //Target is in the context menu + return this.nonEditContextBlacklist.indexOf(actionMetadata.key) === -1; } } else { return true; diff --git a/platform/commonUI/edit/test/policies/EditContextualActionPolicySpec.js b/platform/commonUI/edit/test/policies/EditContextualActionPolicySpec.js index 8dbf2c128c..f7ec5e1709 100644 --- a/platform/commonUI/edit/test/policies/EditContextualActionPolicySpec.js +++ b/platform/commonUI/edit/test/policies/EditContextualActionPolicySpec.js @@ -33,13 +33,15 @@ define( context, navigatedObject, mockDomainObject, - metadata; + metadata, + editModeBlacklist = ["copy", "follow", "window", "link", "locate"], + nonEditContextBlacklist = ["copy", "follow", "properties", "move", "link", "remove", "locate"]; beforeEach(function () { navigatedObject = jasmine.createSpyObj("navigatedObject", ["hasCapability"]); navigatedObject.hasCapability.andReturn(false); - mockDomainObject = jasmine.createSpyObj("domainObject", ["hasCapability"]); + mockDomainObject = jasmine.createSpyObj("domainObject", ["hasCapability", "getCapability"]); mockDomainObject.hasCapability.andReturn(false); navigationService = jasmine.createSpyObj("navigationService", ["getNavigation"]); @@ -51,7 +53,7 @@ define( context = {domainObject: mockDomainObject}; - policy = new EditContextualActionPolicy(navigationService); + policy = new EditContextualActionPolicy(navigationService, editModeBlacklist, nonEditContextBlacklist); }); it('Allows all actions when navigated object not in edit mode', function() { @@ -65,6 +67,28 @@ define( expect(policy.allow(mockAction, context)).toBe(true); }); + it('Allows "remove" action when navigated object in edit mode,' + + ' and selected object not editable, but its parent is.', + function() { + var mockParent = jasmine.createSpyObj("parentObject", ["hasCapability"]), + mockContextCapability = jasmine.createSpyObj("contextCapability", ["getParent"]); + + mockParent.hasCapability.andReturn(true); + mockContextCapability.getParent.andReturn(mockParent); + navigatedObject.hasCapability.andReturn(true); + + mockDomainObject.getCapability.andReturn(mockContextCapability); + mockDomainObject.hasCapability.andCallFake(function (capability) { + switch (capability) { + case "editor": return false; + case "context": return true; + } + }); + metadata.key = "remove"; + + expect(policy.allow(mockAction, context)).toBe(true); + }); + it('Disallows "move" action when navigated object in edit mode,' + ' but selected object not in edit mode ', function() { navigatedObject.hasCapability.andReturn(true);