[Edit Mode] Fixed issue with save dialog not being displayed for new objects after mutation. Fixes 1080

This commit is contained in:
Henry 2016-09-21 16:12:09 -07:00
parent e0b6986851
commit 3548cde9c4
5 changed files with 69 additions and 23 deletions

View File

@ -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);
}
};
/**

View File

@ -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({

View File

@ -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");
};

View File

@ -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 () {

View File

@ -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");