Compare commits

...

1 Commits

Author SHA1 Message Date
297e25759f add confirmation dialog 2018-07-26 17:45:37 -07:00
3 changed files with 33 additions and 7 deletions

View File

@ -188,7 +188,8 @@ define([
"name": "Remove",
"description": "Remove this object from its containing object.",
"depends": [
"navigationService"
"navigationService",
"dialogService"
]
},
{

View File

@ -39,9 +39,12 @@ define(
* @constructor
* @implements {Action}
*/
function RemoveAction(navigationService, context) {
function RemoveAction(navigationService, dialogService, context) {
this.domainObject = (context || {}).domainObject;
this.navigationService = navigationService;
this.dialogService = dialogService;
this.delete = this.delete.bind(this);
}
/**
@ -49,7 +52,7 @@ define(
* @return {Promise} a promise which will be
* fulfilled when the action has completed.
*/
RemoveAction.prototype.perform = function () {
RemoveAction.prototype.delete = function () {
var navigationService = this.navigationService,
domainObject = this.domainObject;
/*
@ -114,6 +117,28 @@ define(
return removeFromContext(domainObject);
};
RemoveAction.prototype.perform = function () {
var self = this;
var confirmationDialog = this.dialogService.showBlockingMessage({
severity: "error",
title: "Warning! This action will permanently remove this object. Are you sure you want to continue?",
minimized: true, // want the notification to be minimized initially (don't show banner)
options: [{
label: "OK",
callback: function () {
self.delete().then(function () {
confirmationDialog.dismiss();
});
}
},{
label: "Cancel",
callback: function () {
confirmationDialog.dismiss();
}
}]
});
};
// Object needs to have a parent for Remove to be applicable
RemoveAction.appliesTo = function (context) {
var object = (context || {}).domainObject,

View File

@ -128,14 +128,14 @@ define(
});
it("mutates the parent when performed", function () {
action.perform();
action.delete();
expect(mockMutation.invoke)
.toHaveBeenCalledWith(jasmine.any(Function));
});
it("changes composition from its mutation function", function () {
var mutator, result;
action.perform();
action.delete();
mutator = mockMutation.invoke.calls.mostRecent().args[0];
result = mutator(model);
@ -170,7 +170,7 @@ define(
mockType.hasFeature.and.returnValue(true);
action.perform();
action.delete();
// Expects navigation to parent of domainObject (removed object)
expect(mockNavigationService.setNavigation).toHaveBeenCalledWith(mockParent);
@ -198,7 +198,7 @@ define(
mockType.hasFeature.and.returnValue(true);
action.perform();
action.delete();
// Expects no navigation to occur
expect(mockNavigationService.setNavigation).not.toHaveBeenCalled();