From 02cba2aecd22da017b8d59469a51b2e37b8755aa Mon Sep 17 00:00:00 2001 From: Juno Date: Fri, 15 Sep 2023 14:09:48 -0400 Subject: [PATCH] move toasts to toasts.js and add error toast --- src/main/resources/static/editor.html | 1 + src/main/resources/static/index.html | 2 ++ src/main/resources/static/toast.js | 26 ++++++++++++++++++++++++++ 3 files changed, 29 insertions(+) create mode 100644 src/main/resources/static/toast.js diff --git a/src/main/resources/static/editor.html b/src/main/resources/static/editor.html index 9a357ed..5de4d90 100644 --- a/src/main/resources/static/editor.html +++ b/src/main/resources/static/editor.html @@ -38,5 +38,6 @@

Edit User

+ \ No newline at end of file diff --git a/src/main/resources/static/index.html b/src/main/resources/static/index.html index c34ea71..ebda1d4 100644 --- a/src/main/resources/static/index.html +++ b/src/main/resources/static/index.html @@ -25,10 +25,12 @@ +
+ \ No newline at end of file diff --git a/src/main/resources/static/toast.js b/src/main/resources/static/toast.js new file mode 100644 index 0000000..32416b8 --- /dev/null +++ b/src/main/resources/static/toast.js @@ -0,0 +1,26 @@ +var toast_timeout; + +/* Show a regular grey toast */ +function show_toast(message) { + clearTimeout(toast_timeout); + var td = document.getElementById("TOAST_MESSAGE"); + td.innerHTML = message; + td.className = "show"; + toast_timeout = setTimeout(hide_toast, 3000); +} + +/* Show a red toast for errors */ +function show_error(message) { + clearTimeout(toast_timeout); + var td = document.getElementById("TOAST_MESSAGE"); + td.innerHTML = message; + td.className = "show error"; + toast_timeout = setTimeout(hide_toast, 3000); +} + +/* Used by show_toast, + can also be invoked manually to hide the current toast */ +function hide_toast() { + var td = document.getElementById("TOAST_MESSAGE"); + td.className = td.className.replace("show", "hide"); +} \ No newline at end of file