[Edit Mode] #635 Removed Edit-related concerns from ContextMenuGesture

This commit is contained in:
Henry
2016-03-22 20:17:23 -07:00
parent c591ade479
commit 7f108c3b24
10 changed files with 225 additions and 100 deletions

View File

@@ -99,9 +99,7 @@ define([
"implementation": ContextMenuGesture,
"depends": [
"$timeout",
"$parse",
"agentService",
"navigationService"
"agentService"
]
}
],

View File

@@ -41,32 +41,16 @@ define(
* in the context menu will be performed
* @implements {Gesture}
*/
function ContextMenuGesture($timeout, $parse, agentService, navigationService, element, domainObject) {
function ContextMenuGesture($timeout, agentService, element, domainObject) {
var isPressing,
longTouchTime = 500,
parameters = element && element.attr('parameters') && $parse(element.attr('parameters'))();
function suppressMenu() {
return parameters
&& parameters.suppressMenuOnEdit
&& navigationService.getNavigation()
&& navigationService.getNavigation().hasCapability('editor');
}
longTouchTime = 500;
function showMenu(event) {
/**
* Some menu items should have the context menu action
* suppressed (eg. the navigation menu on the left)
*/
if (suppressMenu()){
return;
} else {
domainObject.getCapability('action').perform({
key: 'menu',
domainObject: domainObject,
event: event
});
}
domainObject.getCapability('action').perform({
key: 'menu',
domainObject: domainObject,
event: event
});
}
// When context menu event occurs, show object actions instead

View File

@@ -30,16 +30,14 @@ define(
function (ContextMenuGesture) {
"use strict";
var JQLITE_FUNCTIONS = [ "on", "off", "find", "append", "remove", "attr" ],
var JQLITE_FUNCTIONS = [ "on", "off", "find", "append", "remove" ],
DOMAIN_OBJECT_METHODS = [ "getId", "getModel", "getCapability", "hasCapability", "useCapability"];
describe("The 'context menu' gesture", function () {
var mockTimeout,
mockParse,
mockElement,
mockAgentService,
mockNavigationService,
mockDomainObject,
mockEvent,
mockTouchEvent,
@@ -53,7 +51,6 @@ define(
beforeEach(function () {
mockTimeout = jasmine.createSpy("$timeout");
mockParse = jasmine.createSpy("$parse");
mockElement = jasmine.createSpyObj("element", JQLITE_FUNCTIONS);
mockAgentService = jasmine.createSpyObj("agentService", ["isMobile"]);
mockDomainObject = jasmine.createSpyObj("domainObject", DOMAIN_OBJECT_METHODS);
@@ -62,17 +59,14 @@ define(
"action",
[ "perform", "getActions" ]
);
mockActionContext = jasmine.createSpyObj(
"actionContext",
[ "" ]
);
mockActionContext = {domainObject: mockDomainObject, event: mockEvent};
mockDomainObject.getCapability.andReturn(mockContextMenuAction);
mockContextMenuAction.perform.andReturn(jasmine.any(Function));
mockAgentService.isMobile.andReturn(false);
gesture = new ContextMenuGesture(mockTimeout, mockParse, mockAgentService, mockNavigationService, mockElement, mockDomainObject);
gesture = new ContextMenuGesture(mockTimeout, mockAgentService, mockElement, mockDomainObject);
// Capture the contextmenu callback
fireGesture = mockElement.on.mostRecentCall.args[1];
@@ -108,7 +102,7 @@ define(
mockAgentService.isMobile.andReturn(true);
// Then create new (mobile) gesture
gesture = new ContextMenuGesture(mockTimeout, mockParse, mockAgentService, mockNavigationService, mockElement, mockDomainObject);
gesture = new ContextMenuGesture(mockTimeout, mockAgentService, mockElement, mockDomainObject);
// Set calls for the touchstart and touchend gestures
fireTouchStartGesture = mockElement.on.calls[1].args[1];