mirror of
https://github.com/ae-utbm/sith.git
synced 2025-10-09 16:24:39 +00:00
Create unified notification system
This commit is contained in:
24
core/static/bundled/utils/notifications.ts
Normal file
24
core/static/bundled/utils/notifications.ts
Normal file
@@ -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"));
|
||||
}
|
@@ -321,7 +321,6 @@ $hovered-red-text-color: #ff4d4d;
|
||||
|
||||
>#header_notif {
|
||||
box-sizing: border-box;
|
||||
display: none;
|
||||
position: absolute;
|
||||
margin: 0;
|
||||
background-color: whitesmoke;
|
||||
|
@@ -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();
|
||||
}
|
Reference in New Issue
Block a user