diff options
author | Deep Tailor <deep.j.tailor@nasa.gov> | 2018-07-27 03:45:37 +0300 |
---|---|---|
committer | Deep Tailor <deep.j.tailor@nasa.gov> | 2018-07-27 03:45:37 +0300 |
commit | 297e25759fe7ee2e7839d0d902c309a5e17100ca (patch) | |
tree | 218b22d48f4050eb6a5cb160cd72a0fb68a889da | |
parent | 15a75ac134f063352e9b303ffc286792dfb69898 (diff) |
add confirmation dialogremove-confirmation-dialog
-rw-r--r-- | platform/commonUI/edit/bundle.js | 3 | ||||
-rw-r--r-- | platform/commonUI/edit/src/actions/RemoveAction.js | 29 | ||||
-rw-r--r-- | platform/commonUI/edit/test/actions/RemoveActionSpec.js | 8 |
3 files changed, 33 insertions, 7 deletions
diff --git a/platform/commonUI/edit/bundle.js b/platform/commonUI/edit/bundle.js index 8e20c283c..cfb038b30 100644 --- a/platform/commonUI/edit/bundle.js +++ b/platform/commonUI/edit/bundle.js @@ -188,7 +188,8 @@ define([ "name": "Remove", "description": "Remove this object from its containing object.", "depends": [ - "navigationService" + "navigationService", + "dialogService" ] }, { diff --git a/platform/commonUI/edit/src/actions/RemoveAction.js b/platform/commonUI/edit/src/actions/RemoveAction.js index ee03c8e62..35bc40c37 100644 --- a/platform/commonUI/edit/src/actions/RemoveAction.js +++ b/platform/commonUI/edit/src/actions/RemoveAction.js @@ -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, diff --git a/platform/commonUI/edit/test/actions/RemoveActionSpec.js b/platform/commonUI/edit/test/actions/RemoveActionSpec.js index f9b5089d7..99781e196 100644 --- a/platform/commonUI/edit/test/actions/RemoveActionSpec.js +++ b/platform/commonUI/edit/test/actions/RemoveActionSpec.js @@ -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(); |