From ac2b56e13a8f2652def27595f5baf38b71f3aec4 Mon Sep 17 00:00:00 2001 From: Piotr Gawron <piotr.gawron@uni.lu> Date: Fri, 26 Jan 2018 10:59:08 +0100 Subject: [PATCH] confirm dialog functionality --- frontend-js/src/main/js/GuiConnector.js | 29 +++++++++++++++++++ frontend-js/src/test/js/GuiConnector-test.js | 30 ++++++++++++++++++-- 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/frontend-js/src/main/js/GuiConnector.js b/frontend-js/src/main/js/GuiConnector.js index c3b4020606..d80ef002fa 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/test/js/GuiConnector-test.js b/frontend-js/src/test/js/GuiConnector-test.js index 3975a518f4..1a97eb1f9c 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 -- GitLab