From 3548cde9c44076c687038f20ebeec77939fd91e7 Mon Sep 17 00:00:00 2001 From: Henry Date: Wed, 21 Sep 2016 16:12:09 -0700 Subject: [PATCH] [Edit Mode] Fixed issue with save dialog not being displayed for new objects after mutation. Fixes 1080 --- .../browse/src/navigation/NavigateAction.js | 26 +++++++--- .../test/navigation/NavigateActionSpec.js | 49 +++++++++++++++++-- .../commonUI/edit/src/actions/EditAction.js | 8 +-- .../edit/src/services/TransactionService.js | 2 +- .../edit/test/actions/EditActionSpec.js | 7 --- 5 files changed, 69 insertions(+), 23 deletions(-) diff --git a/platform/commonUI/browse/src/navigation/NavigateAction.js b/platform/commonUI/browse/src/navigation/NavigateAction.js index b3d935812a..efdfb270f4 100644 --- a/platform/commonUI/browse/src/navigation/NavigateAction.js +++ b/platform/commonUI/browse/src/navigation/NavigateAction.js @@ -48,20 +48,34 @@ define( */ NavigateAction.prototype.perform = function () { var self = this, - navigationAllowed = true; + navigateTo = this.domainObject, + currentObject = self.navigationService.getNavigation(), + editing = currentObject.hasCapability('editor') && + currentObject.getCapability('editor').isEditContextRoot(); function allow() { - self.policyService.allow("navigation", self.navigationService.getNavigation(), self.domainObject, function (message) { + var navigationAllowed = true; + self.policyService.allow("navigation", currentObject, navigateTo, function (message) { navigationAllowed = self.$window.confirm(message + "\r\n\r\n" + " Are you sure you want to continue?"); }); return navigationAllowed; } - // Set navigation, and wrap like a promise - return this.$q.when( - allow() && this.navigationService.setNavigation(this.domainObject) - ); + function cancelIfEditing() { + return self.$q.when(editing && currentObject.getCapability("editor").cancel()); + } + + function navigate() { + return self.navigationService.setNavigation(navigateTo); + } + + if (allow()) { + return cancelIfEditing().then(navigate); + } else { + return this.$q.when(false); + } + }; /** diff --git a/platform/commonUI/browse/test/navigation/NavigateActionSpec.js b/platform/commonUI/browse/test/navigation/NavigateActionSpec.js index 003012372b..b769d7dce1 100644 --- a/platform/commonUI/browse/test/navigation/NavigateActionSpec.js +++ b/platform/commonUI/browse/test/navigation/NavigateActionSpec.js @@ -32,7 +32,9 @@ define( mockQ, mockDomainObject, mockPolicyService, + mockNavigatedObject, mockWindow, + capabilities, action; function mockPromise(value) { @@ -44,6 +46,29 @@ define( } beforeEach(function () { + capabilities = {}; + + mockQ = { when: mockPromise }; + mockNavigatedObject = jasmine.createSpyObj( + "domainObject", + [ + "getId", + "getModel", + "hasCapability", + "getCapability" + ] + ); + + capabilities.editor = jasmine.createSpyObj("editorCapability", [ + "isEditContextRoot", + "cancel" + ]); + + mockNavigatedObject.getCapability.andCallFake(function (capability) { + return capabilities[capability]; + }); + mockNavigatedObject.hasCapability.andReturn(false); + mockNavigationService = jasmine.createSpyObj( "navigationService", [ @@ -51,11 +76,14 @@ define( "getNavigation" ] ); - mockNavigationService.getNavigation.andReturn({}); - mockQ = { when: mockPromise }; + mockNavigationService.getNavigation.andReturn(mockNavigatedObject); + mockDomainObject = jasmine.createSpyObj( "domainObject", - ["getId", "getModel", "getCapability"] + [ + "getId", + "getModel" + ] ); mockPolicyService = jasmine.createSpyObj("policyService", @@ -112,6 +140,21 @@ define( }); }); + describe("in edit more", function () { + beforeEach(function () { + mockNavigatedObject.hasCapability.andCallFake(function (capability) { + return capability === "editor"; + }); + capabilities.editor.isEditContextRoot.andReturn(true); + }); + + it("cancels editing if in edit mode", function () { + action.perform(); + expect(capabilities.editor.cancel) + .toHaveBeenCalled(); + }); + }); + it("is only applicable when a domain object is in context", function () { expect(NavigateAction.appliesTo({})).toBeFalsy(); expect(NavigateAction.appliesTo({ diff --git a/platform/commonUI/edit/src/actions/EditAction.js b/platform/commonUI/edit/src/actions/EditAction.js index bd30968289..9c1afd3e28 100644 --- a/platform/commonUI/edit/src/actions/EditAction.js +++ b/platform/commonUI/edit/src/actions/EditAction.js @@ -69,18 +69,14 @@ define( * Enter edit mode. */ EditAction.prototype.perform = function () { - var self = this; - function cancelEditing() { - self.domainObject.getCapability('editor').cancel(); - self.navigationService.removeListener(cancelEditing); - } + //If this is not the currently navigated object, then navigate // to it. if (this.navigationService.getNavigation() !== this.domainObject) { this.navigationService.setNavigation(this.domainObject); } - this.navigationService.addListener(cancelEditing); + //this.navigationService.addListener(cancelEditing); this.domainObject.useCapability("editor"); }; diff --git a/platform/commonUI/edit/src/services/TransactionService.js b/platform/commonUI/edit/src/services/TransactionService.js index 119e314b17..df0a051f0d 100644 --- a/platform/commonUI/edit/src/services/TransactionService.js +++ b/platform/commonUI/edit/src/services/TransactionService.js @@ -138,7 +138,7 @@ define( try { results.push(onCancel()); } catch (error) { - this.$log.error("Error committing transaction."); + this.$log.error("Error cancelling transaction."); } } return this.$q.all(results).then(function () { diff --git a/platform/commonUI/edit/test/actions/EditActionSpec.js b/platform/commonUI/edit/test/actions/EditActionSpec.js index c896e83dd1..0e70e571c3 100644 --- a/platform/commonUI/edit/test/actions/EditActionSpec.js +++ b/platform/commonUI/edit/test/actions/EditActionSpec.js @@ -98,13 +98,6 @@ define( expect(EditAction.appliesTo(actionContext)).toBe(false); }); - it ("cancels editing when user navigates away", function () { - action.perform(); - expect(mockNavigationService.addListener).toHaveBeenCalled(); - mockNavigationService.addListener.mostRecentCall.args[0](); - expect(mockEditor.cancel).toHaveBeenCalled(); - }); - it ("invokes the Edit capability on the object", function () { action.perform(); expect(mockDomainObject.useCapability).toHaveBeenCalledWith("editor");