diff --git a/core/static/bundled/utils/notifications.ts b/core/static/bundled/utils/notifications.ts new file mode 100644 index 00000000..9d4426d2 --- /dev/null +++ b/core/static/bundled/utils/notifications.ts @@ -0,0 +1,24 @@ +export enum NotificationLevel { + Error = "error", + Warning = "warning", +} + +export function createNotification(message: string, level: NotificationLevel) { + const element = document.getElementById("notifications"); + if (element === null) { + return false; + } + return element.dispatchEvent( + new CustomEvent("notification-add", { + detail: { text: message, tag: level }, + }), + ); +} + +export function deleteNotifications() { + const element = document.getElementById("notifications"); + if (element === null) { + return false; + } + return element.dispatchEvent(new CustomEvent("notification-delete")); +} diff --git a/core/static/core/header.scss b/core/static/core/header.scss index 348d3796..7eca52f9 100644 --- a/core/static/core/header.scss +++ b/core/static/core/header.scss @@ -321,7 +321,6 @@ $hovered-red-text-color: #ff4d4d; >#header_notif { box-sizing: border-box; - display: none; position: absolute; margin: 0; background-color: whitesmoke; diff --git a/core/static/core/js/script.js b/core/static/core/js/script.js deleted file mode 100644 index 9be232dd..00000000 --- a/core/static/core/js/script.js +++ /dev/null @@ -1,38 +0,0 @@ -$(() => { - $("#quick_notif li").click(function () { - $(this).hide(); - }); -}); - -// biome-ignore lint/correctness/noUnusedVariables: used in other scripts -function createQuickNotif(msg) { - const el = document.createElement("li"); - el.textContent = msg; - el.addEventListener("click", () => el.parentNode.removeChild(el)); - document.getElementById("quick_notif").appendChild(el); -} - -// biome-ignore lint/correctness/noUnusedVariables: used in other scripts -function deleteQuickNotifs() { - const el = document.getElementById("quick_notif"); - while (el.firstChild) { - el.removeChild(el.firstChild); - } -} - -// biome-ignore lint/correctness/noUnusedVariables: used in other scripts -function displayNotif() { - $("#header_notif").toggle().parent().toggleClass("white"); -} - -// You can't get the csrf token from the template in a widget -// We get it from a cookie as a workaround, see this link -// https://docs.djangoproject.com/en/2.0/ref/csrf/#ajax -// Sadly, getting the cookie is not possible with CSRF_COOKIE_HTTPONLY or CSRF_USE_SESSIONS is True -// So, the true workaround is to get the token from the dom -// https://docs.djangoproject.com/en/2.0/ref/csrf/#acquiring-the-token-if-csrf-use-sessions-is-true -// biome-ignore lint/style/useNamingConvention: can't find it used anywhere but I will not play with the devil -// biome-ignore lint/correctness/noUnusedVariables: used in other scripts -function getCSRFToken() { - return $("[name=csrfmiddlewaretoken]").val(); -} diff --git a/core/templates/core/base.jinja b/core/templates/core/base.jinja index 5fb6fd5f..03db58d8 100644 --- a/core/templates/core/base.jinja +++ b/core/templates/core/base.jinja @@ -34,7 +34,6 @@ - {% block additional_css %}{% endblock %} {% block additional_js %}{% endblock %} @@ -74,11 +73,9 @@