From 4c8f60634e00bab776084a13688b73e47ef47e2d Mon Sep 17 00:00:00 2001 From: Sebastian Castro Date: Wed, 6 May 2020 14:09:39 +0200 Subject: [PATCH] ui: use gritter to display error messages nicely (instead of loading box) --- src/static/css/pad/gritter.css | 4 +++- src/static/js/pad_utils.js | 30 ++++++++++++++++++++++++------ 2 files changed, 27 insertions(+), 7 deletions(-) diff --git a/src/static/css/pad/gritter.css b/src/static/css/pad/gritter.css index 076062339..e17367efa 100644 --- a/src/static/css/pad/gritter.css +++ b/src/static/css/pad/gritter.css @@ -14,13 +14,15 @@ .gritter-item.popup { position: relative; - max-width: 450px; visibility: visible; right: auto !important; left: auto !important; top: auto; bottom: auto; } +.gritter-item.popup:not(.error) { + max-width: 450px; +} .gritter-item .popup-content { display: flex; diff --git a/src/static/js/pad_utils.js b/src/static/js/pad_utils.js index d42cbb022..fbbefdae4 100644 --- a/src/static/js/pad_utils.js +++ b/src/static/js/pad_utils.js @@ -526,12 +526,30 @@ function setupGlobalExceptionHandler() { { var errorId = randomString(20); var userAgent = padutils.escapeHtml(navigator.userAgent); - if ($("#editorloadingbox").attr("display") != "none"){ - //show javascript errors to the user - $("#editorloadingbox").css("padding", "10px"); - $("#editorloadingbox").css("padding-top", "45px"); - $("#editorloadingbox").html("
An error occurred
The error was reported with the following id: '" + errorId + "'

Please press and hold Ctrl and press F5 to reload this page, if the problem persists please send this error message to your webmaster:
'" - + "ErrorId: " + errorId + "
URL: " + padutils.escapeHtml(window.location.href) + "
UserAgent: " + userAgent + "
" + msg + " in " + url + " at line " + linenumber + "'
"); + + var msgAlreadyVisible = false; + $('.gritter-item .error-msg').each(function() { + if ($(this).text() === msg) { + msgAlreadyVisible = true; + } + }); + + if (!msgAlreadyVisible) { + errorMsg = "Please press and hold Ctrl and press F5 to reload this page
\ + If the problem persists please send this error message to your webmaster:

\ +
\ + ErrorId: " + errorId + "
\ + URL: " + padutils.escapeHtml(window.location.href) + "
\ + UserAgent: " + userAgent + "
\ + "+ msg + " in " + url + " at line " + linenumber + '
'; + + $.gritter.add({ + title: "An error occurred", + text: errorMsg, + class_name: "error", + position: 'bottom', + sticky: true, + }); } //send javascript errors to the server