]> jfr.im git - irc/unrealircd/unrealircd-webpanel.git/blob - js/unrealircd-admin.js
8c7ee0c867cfd89f893602a1f24777bf88e2b4c2
[irc/unrealircd/unrealircd-webpanel.git] / js / unrealircd-admin.js
1
2
3
4 /* TKL (un)select all checkbox */
5 function toggle_tkl(source) {
6 checkboxes = document.getElementsByName("tklch[]");
7 for (var i = 0, n = checkboxes.length; i < n; i++) {
8 checkboxes[i].checked = source.checked;
9 }
10 }
11
12
13 /* TKL (un)select all checkbox */
14 function toggle_user(source) {
15 checkboxes = document.getElementsByName("userch[]");
16 for (var i = 0, n = checkboxes.length; i < n; i++) {
17 checkboxes[i].checked = source.checked;
18 }
19 }
20
21
22 /* TKL (un)select all checkbox */
23 function toggle_server(source) {
24 checkboxes = document.getElementsByName("serverch[]");
25 for (var i = 0, n = checkboxes.length; i < n; i++) {
26 checkboxes[i].checked = source.checked;
27 }
28 }
29
30 /* TKL (un)select all checkbox */
31 function toggle_sf(source) {
32 checkboxes = document.getElementsByName("sf[]");
33 for (var i = 0, n = checkboxes.length; i < n; i++) {
34 checkboxes[i].checked = source.checked;
35 }
36 }
37
38 function toggle_chanbans(source) {
39 checkboxes = document.getElementsByName("cb_checkboxes[]");
40 for (var i = 0, n = checkboxes.length; i < n; i++) {
41 checkboxes[i].checked = source.checked;
42 }
43 }
44
45 function toggle_chanexs(source) {
46 checkboxes = document.getElementsByName("ce_checkboxes[]");
47 for (var i = 0, n = checkboxes.length; i < n; i++) {
48 checkboxes[i].checked = source.checked;
49 }
50 }
51
52 function toggle_chaninvs(source) {
53 checkboxes = document.getElementsByName("ci_checkboxes[]");
54 for (var i = 0, n = checkboxes.length; i < n; i++) {
55 checkboxes[i].checked = source.checked;
56 }
57 }
58
59 function toggle_checkbox(source) {
60 checkboxes = document.getElementsByName("checkboxes[]");
61 for (var i = 0, n = checkboxes.length; i < n; i++) {
62 checkboxes[i].checked = source.checked;
63 }
64 }
65
66 function generate_notif(title, body)
67 {
68 /* generate a random number between 1000 and 90000 to use as an id */
69 const min = 1000;
70 const max = 90000;
71 const id = Math.floor(Math.random() * (max - min + 1)) + min;
72
73 const toast = document.createElement('div');
74 toast.classList.add('position-fixed', 'bottom-0', 'right-0', 'p-4');
75 toast.style.right = 0;
76 toast.style.zIndex = 5;
77 toast.style.bottom = "50px";
78
79 const inner = document.createElement('div');
80 inner.classList.add('toast', 'hide');
81 inner.id = 'toast' + id;
82 inner.role = 'alert';
83 inner.ariaLive = 'assertive';
84 inner.ariaAtomic = 'true';
85 inner.setAttribute('data-delay', '5000');
86
87 const header = document.createElement('div');
88 header.classList.add('toast-header');
89
90 const theTitle = document.createElement('strong');
91 theTitle.classList.add('mr-auto');
92 theTitle.textContent = title;
93
94 const notiftime = document.createElement('small');
95 notiftime.textContent = "Just now"; // always just now I think right :D
96
97 const closebutton = document.createElement('button');
98 closebutton.type = 'button';
99 closebutton.classList.add('ml-2', 'mb-1', 'close');
100 closebutton.setAttribute('data-dismiss', 'toast');
101 closebutton.ariaLabel = 'Close';
102
103 const closebuttonspan = document.createElement('span');
104 closebuttonspan.ariaHidden = 'true';
105 closebuttonspan.innerHTML = "&times;";
106
107 const toastbody = document.createElement('div');
108 toastbody.classList.add('toast-body');
109 toastbody.textContent = body;
110
111
112 /* put it all together */
113 closebutton.appendChild(closebuttonspan);
114 header.appendChild(theTitle);
115 header.appendChild(notiftime);
116 header.appendChild(closebutton);
117 inner.appendChild(header);
118 inner.appendChild(toastbody);
119 toast.appendChild(inner);
120
121 document.body.appendChild(toast);
122 $('#' + inner.id).toast('show');
123 }
124 $("#myModal").on('shown.bs.modal', function(){
125 $("#CloseButton").focus();
126 });
127 function StreamNotifs(e)
128 {
129 var data;
130 try {
131 data = JSON.parse(e.data);
132 } catch(e) {
133 return;
134 }
135 title = data.subsystem + '.' + data.event_id;
136 msg = data.msg;
137 generate_notif(title, msg);
138 }
139 function StartStreamNotifs(url)
140 {
141 if (!!window.EventSource) {
142 var source = new EventSource(url);
143 source.addEventListener('message', StreamNotifs, false);
144 }
145 }