From 9eb8158c4e75b4fcb1b3d90b5b071e4a090d549e Mon Sep 17 00:00:00 2001 From: Henry Date: Wed, 25 Nov 2015 14:44:31 -0800 Subject: [PATCH] [Edit Mode] Disallow context menu actions on tree items during edit mode. #277 --- platform/representation/bundle.json | 3 ++- .../src/actions/ContextMenuAction.js | 6 ++++++ .../test/actions/ContextMenuActionSpec.js | 16 ++++++++++++++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/platform/representation/bundle.json b/platform/representation/bundle.json index 4017033ad6..c1ec13fd6c 100644 --- a/platform/representation/bundle.json +++ b/platform/representation/bundle.json @@ -66,7 +66,8 @@ "$document", "$rootScope", "popupService", - "agentService" + "agentService", + "navigationService" ] } ] diff --git a/platform/representation/src/actions/ContextMenuAction.js b/platform/representation/src/actions/ContextMenuAction.js index 82e11713f9..53cc51a253 100644 --- a/platform/representation/src/actions/ContextMenuAction.js +++ b/platform/representation/src/actions/ContextMenuAction.js @@ -55,12 +55,14 @@ define( $rootScope, popupService, agentService, + navigationService, actionContext ) { this.$compile = $compile; this.agentService = agentService; this.actionContext = actionContext; this.popupService = popupService; + this.navigationService = navigationService; this.getDocument = function () { return $document; }; this.getRootScope = function () { return $rootScope; }; } @@ -82,6 +84,10 @@ define( menu, popup; + if (this.navigationService.getNavigation() && this.navigationService.getNavigation().hasCapability('editor')){ + return; + } + // Remove the context menu function dismiss() { if (popup) { diff --git a/platform/representation/test/actions/ContextMenuActionSpec.js b/platform/representation/test/actions/ContextMenuActionSpec.js index ba24076fbb..bef35bbcc0 100644 --- a/platform/representation/test/actions/ContextMenuActionSpec.js +++ b/platform/representation/test/actions/ContextMenuActionSpec.js @@ -47,6 +47,8 @@ define( mockScope, mockElement, mockDomainObject, + mockNavigatedObject, + mockNavigationService, mockEvent, mockPopup, mockActionContext, @@ -67,9 +69,11 @@ define( ]); mockRootScope = jasmine.createSpyObj("$rootScope", ["$new"]); mockAgentService = jasmine.createSpyObj("agentService", ["isMobile"]); + mockNavigationService = jasmine.createSpyObj("navigationService", ["getNavigation"]); mockScope = jasmine.createSpyObj("scope", ["$destroy"]); mockElement = jasmine.createSpyObj("element", JQLITE_FUNCTIONS); mockDomainObject = jasmine.createSpyObj("domainObject", DOMAIN_OBJECT_METHODS); + mockNavigatedObject = jasmine.createSpyObj("domainObject", DOMAIN_OBJECT_METHODS); mockEvent = jasmine.createSpyObj("event", ["preventDefault", "stopPropagation"]); mockEvent.pageX = 123; mockEvent.pageY = 321; @@ -79,6 +83,7 @@ define( mockDocument.find.andReturn(mockBody); mockRootScope.$new.andReturn(mockScope); mockPopupService.display.andReturn(mockPopup); + mockNavigationService.getNavigation.andReturn(mockNavigatedObject); mockActionContext = {key: 'menu', domainObject: mockDomainObject, event: mockEvent}; @@ -88,6 +93,7 @@ define( mockRootScope, mockPopupService, mockAgentService, + mockNavigationService, mockActionContext ); }); @@ -182,6 +188,15 @@ define( expect(mockBody.off).not.toHaveBeenCalled(); }); + it("is not active when in edit mode", function () { + mockNavigatedObject.hasCapability.andReturn(true); + + // Show the menu + action.perform(); + + expect(mockPopupService.display).not.toHaveBeenCalled(); + }); + it("keeps a menu when menu is clicked on mobile", function () { mockAgentService.isMobile.andReturn(true); action = new ContextMenuAction( @@ -190,6 +205,7 @@ define( mockRootScope, mockPopupService, mockAgentService, + mockNavigationService, mockActionContext ); action.perform();