diff --git a/frontend-js/src/main/js/GuiConnector.js b/frontend-js/src/main/js/GuiConnector.js index 922e962c0572e9bce98f349f983bd231abb19676..adecc20e2a0f1a4b5db66fa983e3c8ba1918692e 100644 --- a/frontend-js/src/main/js/GuiConnector.js +++ b/frontend-js/src/main/js/GuiConnector.js @@ -264,6 +264,37 @@ GuiConnector.prototype.hideProcessing = function () { $(self._processingDialog).dialog("close"); }; +GuiConnector.prototype.showErrorDialog = function (title, content) { + var dialog = document.createElement('div'); + dialog.title = title; + var dialogBody = document.createElement('p'); + dialogBody.innerHTML = content; + dialog.appendChild(dialogBody); + $(dialog).dialog({ + modal: true, + classes: { + "ui-dialog": "ui-state-error" + }, + close: function () { + $(this).dialog('destroy').remove(); + } + }).siblings('.ui-dialog-titlebar').css("background", "red"); +}; + +GuiConnector.prototype.showSuccessDialog = function (title, content) { + var dialog = document.createElement('div'); + dialog.title = title; + var dialogBody = document.createElement('p'); + dialogBody.innerHTML = content; + dialog.appendChild(dialogBody); + $(dialog).dialog({ + modal: true, + close: function () { + $(this).dialog('destroy').remove(); + } + }).siblings('.ui-dialog-titlebar').css("background", "green"); +}; + /** * Gather information that are presented to the user before submission to MinervaNet. * @@ -308,26 +339,9 @@ GuiConnector.prototype.alert = function (error, redirectIfSecurityError) { } else { var self = returnThisOrSingleton(this); logger.error(error); - var errorData = self.getErrorMessageForError(error); if (!errorData.showReport) { - // legacy dialog (no report) - self._errorDialog = document.createElement("div"); - self._errorDialogContent = document.createElement("div"); - self._errorDialog.appendChild(self._errorDialogContent); - document.body.appendChild(self._errorDialog); - $(self._errorDialog).dialog({ - classes: { - "ui-dialog": "ui-state-error" - }, - modal: true, - title: "ERROR", - close: function () { - $(this).dialog('destroy').remove(); - } - }).siblings('.ui-dialog-titlebar').css("background", "red"); - self._errorDialogContent.innerHTML = errorData.message; - $(self._errorDialog).dialog("open"); + self.showErrorDialog("An error occurred!", errorData.message); } else { self._errorDialog = document.createElement('div'); self._errorDialog.innerHTML = '<span class="ui-icon ui-icon-info" style="float: right;" title="The error message. This might not be human readable. If this issue persists you should should contact your administrator."></span>' + @@ -396,14 +410,22 @@ GuiConnector.prototype.alert = function (error, redirectIfSecurityError) { report[check.attr('data-key')] = check.attr('data-value'); } }); - ServerConnector.submitErrorToMinervaNet(report); - $(this).dialog('close'); + ServerConnector.submitErrorToMinervaNet(report, function (error, response) { + if (error || response.statusCode !== 200) { + self.showErrorDialog('Report could not be submitted.', + 'Please contact your system administrator if this issue persists.'); + } else { + self.showSuccessDialog('Report has been submitted!', + 'Thank you very much for helping us to improve Minerva.'); + } + }); + $(this).dialog('destroy').remove(); }, 'Cancel': function () { - $(this).dialog('close'); + $(this).dialog('destroy').remove(); } } - }).dialog("open").siblings('.ui-dialog-titlebar').css("background", "red"); + }).siblings('.ui-dialog-titlebar').css("background", "red"); } } }; diff --git a/frontend-js/src/main/js/ServerConnector.js b/frontend-js/src/main/js/ServerConnector.js index 77514d3eb81b1a8427954c02d3245724640b0736..cbec64df630dabda7c62ed3c8ce9575992e57e40 100644 --- a/frontend-js/src/main/js/ServerConnector.js +++ b/frontend-js/src/main/js/ServerConnector.js @@ -2683,7 +2683,7 @@ ServerConnector.getSubmapConnections = function () { }); }; -ServerConnector.submitErrorToMinervaNet = function (report) { +ServerConnector.submitErrorToMinervaNet = function (report, callback) { var self = this; return request(self.getSubmitErrorToMinervaNetUrl(), { method: 'POST', @@ -2691,7 +2691,7 @@ ServerConnector.submitErrorToMinervaNet = function (report) { 'Content-type': 'application/json' }, body: JSON.stringify(report) - }); + }, callback); };