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 @@
- + {% block notifications %} + {% include "core/base/notifications.jinja" %} + {% endblock %}
{%- block tabs -%} diff --git a/core/templates/core/base/header.jinja b/core/templates/core/base/header.jinja index 4454aedb..59fb6035 100644 --- a/core/templates/core/base/header.jinja +++ b/core/templates/core/base/header.jinja @@ -74,9 +74,9 @@ {% endif %} >
-
- - +
+ + {% set notification_count = user.notifications.filter(viewed=False).count() %} {% if notification_count > 0 %} @@ -89,7 +89,7 @@ {% endif %} -
+
    {% if user.notifications.filter(viewed=False).count() > 0 %} {% for n in user.notifications.filter(viewed=False).order_by('-date') %} diff --git a/core/templates/core/base/notifications.jinja b/core/templates/core/base/notifications.jinja new file mode 100644 index 00000000..44673488 --- /dev/null +++ b/core/templates/core/base/notifications.jinja @@ -0,0 +1,24 @@ +
    + +
    diff --git a/eboutic/templates/eboutic/eboutic_billing_info.jinja b/eboutic/templates/eboutic/eboutic_billing_info.jinja index 8a5c8a83..429240b8 100644 --- a/eboutic/templates/eboutic/eboutic_billing_info.jinja +++ b/eboutic/templates/eboutic/eboutic_billing_info.jinja @@ -31,12 +31,4 @@

- - {% if messages %} - {% for message in messages %} -
- {{ message }} -
- {% endfor %} - {% endif %}
diff --git a/eboutic/templates/eboutic/eboutic_main.jinja b/eboutic/templates/eboutic/eboutic_main.jinja index 1809d0b7..3ee0d745 100644 --- a/eboutic/templates/eboutic/eboutic_main.jinja +++ b/eboutic/templates/eboutic/eboutic_main.jinja @@ -22,14 +22,6 @@ {% block content %}

{% trans %}Eboutic{% endtrans %}

- {% if messages %} - {% for message in messages %} -
- {{ message }} -
- {% endfor %} - {% endif %} -

Panier

diff --git a/eboutic/templates/eboutic/eboutic_payment_result.jinja b/eboutic/templates/eboutic/eboutic_payment_result.jinja index 719ebc58..6c03754d 100644 --- a/eboutic/templates/eboutic/eboutic_payment_result.jinja +++ b/eboutic/templates/eboutic/eboutic_payment_result.jinja @@ -4,14 +4,6 @@

{% trans %}Eboutic{% endtrans %}

- {% if messages %} - {% for message in messages %} -
- {{ message }} -
- {% endfor %} - {% endif %} - {% if success %} {% trans %}Payment successful{% endtrans %} {% else %} diff --git a/pedagogy/templates/pedagogy/uv_edit.jinja b/pedagogy/templates/pedagogy/uv_edit.jinja index b4869e14..c0709419 100644 --- a/pedagogy/templates/pedagogy/uv_edit.jinja +++ b/pedagogy/templates/pedagogy/uv_edit.jinja @@ -21,11 +21,6 @@ {{ field.errors }} {{ field }} - - - {% if field.name == 'code' %} - - {% endif %}

{% endif %} @@ -36,48 +31,3 @@

{% endblock %} - -{% block script %} - {{ super() }} - - -{% endblock %}