]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blobdiff - js/unrealircd-admin.js
Users: Scratch the "Secure" column, as it's less useful nowadays that
[irc/unrealircd/unrealircd-webpanel.git] / js / unrealircd-admin.js
index 2fbe970b7dad0e49243d99c05c36ee8d3d70e1f9..4aa5fa1427968421120b733d512d18b706878ccb 100644 (file)
@@ -63,20 +63,75 @@ function toggle_checkbox(source) {
     }
 }
 
-function generate_bs_notif(id, title, body)
+function generate_notif(title, body)
 {
-    document.write('<div class="position-fixed bottom-0 right-0 p-3" style="z-index: 5; right: 0; bottom: 50px;">');
-    document.write('    <div id="' + id + '" class="toast hide" role="alert" aria-live="assertive" aria-atomic="true" data-delay="10000">');
-    document.write('        <div class="toast-header">');
-    document.write('            <strong class="mr-auto">' + title + '</strong>');
-    document.write('            <small>11 mins ago</small>');
-    document.write('            <button type="button" class="ml-2 mb-1 close" data-dismiss="toast" aria-label="Close">');
-    document.write('                <span aria-hidden="true">&times;</span>');
-    document.write('            </button>');
-    document.write('        </div>');
-    document.write('        <div class="toast-body">');
-    document.write(body);
-    document.write('        </div>');
-    document.write('        </div>');
-    document.write('</div>');
+    /* generate a random number between 1000 and 90000 to use as an id */
+    const min = 1000;
+    const max = 90000;
+    const id = Math.floor(Math.random() * (max - min + 1)) + min;
+
+    const toast = document.createElement('div');
+    toast.classList.add('toast', 'hide');
+    toast.id = 'toast' + id;
+    toast.role = 'alert';
+    toast.ariaLive = 'assertive';
+    toast.ariaAtomic = 'true';
+    toast.setAttribute('data-delay', '10000');
+
+    const header = document.createElement('div');
+    header.classList.add('toast-header');
+
+    const theTitle = document.createElement('strong');
+    theTitle.classList.add('mr-auto');
+    theTitle.textContent = title;
+    
+    const notiftime = document.createElement('div');
+    notiftime.classList.add('badge', 'rounded-pill', 'badge-primary', 'ml-1');
+    notiftime.textContent = 'Just now'; // always just now I think right :D
+
+    const closebutton = document.createElement('button');
+    closebutton.type = 'button';
+    closebutton.classList.add('ml-2', 'mb-1', 'close');
+    closebutton.setAttribute('data-dismiss', 'toast');
+    closebutton.ariaLabel = 'Close';
+
+    const closebuttonspan = document.createElement('span');
+    closebuttonspan.ariaHidden = 'true';
+    closebuttonspan.innerHTML = "&times;";
+
+    const toastbody = document.createElement('div');
+    toastbody.classList.add('toast-body');
+    toastbody.textContent = body;
+
+
+    /* put it all together */
+    closebutton.appendChild(closebuttonspan);
+    header.appendChild(theTitle);
+    header.appendChild(notiftime);
+    header.appendChild(closebutton);
+    toast.appendChild(header);
+    toast.appendChild(toastbody);
+    document.getElementById('toaster').append(toast);
+
+    $('#' + toast.id).toast('show');
+}
+
+function StreamNotifs(e)
+{
+    var data;
+    try {
+        data = JSON.parse(e.data);
+    } catch(e) {
+        return;
+    }
+    title = data.subsystem + '.' + data.event_id;
+    msg = data.msg;
+    generate_notif(title, msg);
+}
+function StartStreamNotifs(url)
+{
+    if (!!window.EventSource) {
+        var source = new EventSource(url);
+        source.addEventListener('message', StreamNotifs, false);
+    }
 }
\ No newline at end of file