Merge branch 'open277' into open199

This commit is contained in:
Henry
2015-11-27 14:16:59 -08:00
6 changed files with 33 additions and 36 deletions

View File

@ -39,6 +39,7 @@
class="mobile-hide" class="mobile-hide"
key="'label'" key="'label'"
mct-object="domainObject" mct-object="domainObject"
parameters="{suppressMenuOnEdit: true}"
ng-click="treeNode.select()" ng-click="treeNode.select()"
> >
</mct-representation> </mct-representation>

View File

@ -27,7 +27,8 @@
{ {
"key": "menu", "key": "menu",
"implementation": "gestures/ContextMenuGesture.js", "implementation": "gestures/ContextMenuGesture.js",
"depends": ["$timeout", "agentService"] "depends": ["$timeout", "$parse", "agentService",
"navigationService"]
} }
], ],
"components": [ "components": [
@ -66,8 +67,7 @@
"$document", "$document",
"$rootScope", "$rootScope",
"popupService", "popupService",
"agentService", "agentService"
"navigationService"
] ]
} }
] ]

View File

@ -55,14 +55,12 @@ define(
$rootScope, $rootScope,
popupService, popupService,
agentService, agentService,
navigationService,
actionContext actionContext
) { ) {
this.$compile = $compile; this.$compile = $compile;
this.agentService = agentService; this.agentService = agentService;
this.actionContext = actionContext; this.actionContext = actionContext;
this.popupService = popupService; this.popupService = popupService;
this.navigationService = navigationService;
this.getDocument = function () { return $document; }; this.getDocument = function () { return $document; };
this.getRootScope = function () { return $rootScope; }; this.getRootScope = function () { return $rootScope; };
} }
@ -84,10 +82,6 @@ define(
menu, menu,
popup; popup;
if (this.navigationService.getNavigation() && this.navigationService.getNavigation().hasCapability('editor')){
return;
}
// Remove the context menu // Remove the context menu
function dismiss() { function dismiss() {
if (popup) { if (popup) {

View File

@ -41,17 +41,33 @@ define(
* in the context menu will be performed * in the context menu will be performed
* @implements {Gesture} * @implements {Gesture}
*/ */
function ContextMenuGesture($timeout, agentService, element, domainObject) { function ContextMenuGesture($timeout, $parse, agentService, navigationService, element, domainObject) {
var isPressing, var isPressing,
longTouchTime = 500; longTouchTime = 500,
parameters = element && element.attr('parameters') && $parse(element.attr('parameters'))()
function suppressMenu(){
return parameters
&& parameters.suppressMenuOnEdit
&& navigationService.getNavigation()
&& navigationService.getNavigation().hasCapability('editor');
}
function showMenu(event) { 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({ domainObject.getCapability('action').perform({
key: 'menu', key: 'menu',
domainObject: domainObject, domainObject: domainObject,
event: event event: event
}); });
} }
}
// When context menu event occurs, show object actions instead // When context menu event occurs, show object actions instead
if (!agentService.isMobile()) { if (!agentService.isMobile()) {

View File

@ -47,8 +47,6 @@ define(
mockScope, mockScope,
mockElement, mockElement,
mockDomainObject, mockDomainObject,
mockNavigatedObject,
mockNavigationService,
mockEvent, mockEvent,
mockPopup, mockPopup,
mockActionContext, mockActionContext,
@ -69,11 +67,9 @@ define(
]); ]);
mockRootScope = jasmine.createSpyObj("$rootScope", ["$new"]); mockRootScope = jasmine.createSpyObj("$rootScope", ["$new"]);
mockAgentService = jasmine.createSpyObj("agentService", ["isMobile"]); mockAgentService = jasmine.createSpyObj("agentService", ["isMobile"]);
mockNavigationService = jasmine.createSpyObj("navigationService", ["getNavigation"]);
mockScope = jasmine.createSpyObj("scope", ["$destroy"]); mockScope = jasmine.createSpyObj("scope", ["$destroy"]);
mockElement = jasmine.createSpyObj("element", JQLITE_FUNCTIONS); mockElement = jasmine.createSpyObj("element", JQLITE_FUNCTIONS);
mockDomainObject = jasmine.createSpyObj("domainObject", DOMAIN_OBJECT_METHODS); mockDomainObject = jasmine.createSpyObj("domainObject", DOMAIN_OBJECT_METHODS);
mockNavigatedObject = jasmine.createSpyObj("domainObject", DOMAIN_OBJECT_METHODS);
mockEvent = jasmine.createSpyObj("event", ["preventDefault", "stopPropagation"]); mockEvent = jasmine.createSpyObj("event", ["preventDefault", "stopPropagation"]);
mockEvent.pageX = 123; mockEvent.pageX = 123;
mockEvent.pageY = 321; mockEvent.pageY = 321;
@ -83,7 +79,6 @@ define(
mockDocument.find.andReturn(mockBody); mockDocument.find.andReturn(mockBody);
mockRootScope.$new.andReturn(mockScope); mockRootScope.$new.andReturn(mockScope);
mockPopupService.display.andReturn(mockPopup); mockPopupService.display.andReturn(mockPopup);
mockNavigationService.getNavigation.andReturn(mockNavigatedObject);
mockActionContext = {key: 'menu', domainObject: mockDomainObject, event: mockEvent}; mockActionContext = {key: 'menu', domainObject: mockDomainObject, event: mockEvent};
@ -93,7 +88,6 @@ define(
mockRootScope, mockRootScope,
mockPopupService, mockPopupService,
mockAgentService, mockAgentService,
mockNavigationService,
mockActionContext mockActionContext
); );
}); });
@ -188,15 +182,6 @@ define(
expect(mockBody.off).not.toHaveBeenCalled(); 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 () { it("keeps a menu when menu is clicked on mobile", function () {
mockAgentService.isMobile.andReturn(true); mockAgentService.isMobile.andReturn(true);
action = new ContextMenuAction( action = new ContextMenuAction(
@ -205,7 +190,6 @@ define(
mockRootScope, mockRootScope,
mockPopupService, mockPopupService,
mockAgentService, mockAgentService,
mockNavigationService,
mockActionContext mockActionContext
); );
action.perform(); action.perform();

View File

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