diff --git a/frontend-js/src/main/js/GuiConnector.js b/frontend-js/src/main/js/GuiConnector.js index c3b40206069b7aa812bba3f7df4999fd97bbcd54..d80ef002facdde63cba7fb4ddcf0a5b13670c7f1 100644 --- a/frontend-js/src/main/js/GuiConnector.js +++ b/frontend-js/src/main/js/GuiConnector.js @@ -247,6 +247,35 @@ GuiConnector.prototype.info = function (message) { }; +GuiConnector.prototype.showConfirmationDialog = function (params) { + var message = params.message; + var title = params.title; + if (title === undefined) { + title = "Confirm"; + } + return new Promise(function (resolve) { + $('<div></div>').appendTo('body') + .html('<div><h6>' + message + '</h6></div>') + .dialog({ + modal: true, title: title, zIndex: 10000, autoOpen: true, + width: 'auto', resizable: false, + buttons: { + Yes: function () { + $(this).dialog("close"); + resolve(true); + }, + No: function () { + $(this).dialog("close"); + resolve(false); + } + }, + close: function (event, ui) { + $(this).remove(); + } + }); + }); +}; + GuiConnector.prototype.destroy = function () { var self = returnThisOrSingleton(this); diff --git a/frontend-js/src/main/js/gui/leftPanel/OverlayPanel.js b/frontend-js/src/main/js/gui/leftPanel/OverlayPanel.js index 1300eb5498d110faf62b3b29a00bbe8323261c28..e9d7fedeb011dd4f9f52b6df1c992342f56b72d2 100644 --- a/frontend-js/src/main/js/gui/leftPanel/OverlayPanel.js +++ b/frontend-js/src/main/js/gui/leftPanel/OverlayPanel.js @@ -240,16 +240,16 @@ OverlayPanel.prototype.openEditOverlayDialog = function (overlay) { }, { text: "REMOVE", click: function () { - self.getMap().removeSelectedLayout(overlay.getId()); - var windowSelf = this; - return ServerConnector.removeOverlay({ - overlayId: overlay.getId() - }).then(function () { - return self.refresh(); - }).then(function () { - $(windowSelf).dialog("close"); - }).then(null, GuiConnector.alert); + return GuiConnector.showConfirmationDialog({ + message: "Do you want to delete overlay: " + overlay.getName() + "?" + }).then(function (confirmation) { + if (confirmation) { + return self.removeOverlay(overlay).then(function () { + $(windowSelf).dialog("close"); + }).then(null, GuiConnector.alert); + } + }); } }, { text: "CANCEL", @@ -400,6 +400,15 @@ OverlayPanel.prototype.init = function () { return this.refresh(showDefault); }; +OverlayPanel.prototype.removeOverlay = function (overlay) { + self = this; + return self.getMap().removeSelectedLayout(overlay.getId()).then(function () { + return ServerConnector.removeOverlay({overlayId: overlay.getId()}); + }).then(function () { + return self.refresh(); + }) +}; + OverlayPanel.prototype.destroy = function () { var self = this; Panel.prototype.destroy.call(this); diff --git a/frontend-js/src/test/js/GuiConnector-test.js b/frontend-js/src/test/js/GuiConnector-test.js index 3975a518f47a06918ebf3481f9fc92275698afb9..1a97eb1f9c6eeed7adc862805603426dcf6a0a29 100644 --- a/frontend-js/src/test/js/GuiConnector-test.js +++ b/frontend-js/src/test/js/GuiConnector-test.js @@ -42,14 +42,14 @@ describe('GuiConnector', function () { var connector = new (GuiConnector.constructor)(); ServerConnector.getSessionData().setLogin("testUser"); var message = connector.getErrorMessageForError(new SecurityError()); - assert.ok(message.indexOf("ask your administrator")>=0); + assert.ok(message.indexOf("ask your administrator") >= 0); connector.destroy(); }); it('SecurityError when not logged in', function () { var connector = new (GuiConnector.constructor)(); ServerConnector.getSessionData().setLogin("anonymous"); var message = connector.getErrorMessageForError(new SecurityError()); - assert.ok(message.indexOf("to access this resource")>=0); + assert.ok(message.indexOf("to access this resource") >= 0); connector.destroy(); }); }); @@ -91,4 +91,30 @@ describe('GuiConnector', function () { }); }); + describe('showConfirmationDialog', function () { + it('when answer is Yes', function () { + var connector = new (GuiConnector.constructor)(); + // click Yes button in coming ms + setTimeout(function () { + $("button:contains(Yes)").click() + }, 50); + + return connector.showConfirmationDialog({message: "hi there", title: "some"}).then(function (result) { + assert.ok(result); + }); + }); + it('when answer is No', function () { + var connector = new (GuiConnector.constructor)(); + // click Yes button in coming ms + setTimeout(function () { + $("button:contains(No)").click() + }, 50); + + return connector.showConfirmationDialog({message: "hi there", title: "some"}).then(function (result) { + assert.notOk(result); + }); + }); + }); + + }); \ No newline at end of file