]>
Commit | Line | Data |
---|---|---|
8cfa32c5 | 1 | |
76200e36 VP |
2 | |
3 | ||
4 | /* TKL (un)select all checkbox */ | |
26971737 | 5 | function toggle_tkl(source) { |
76200e36 VP |
6 | checkboxes = document.getElementsByName("tklch[]"); |
7 | for (var i = 0, n = checkboxes.length; i < n; i++) { | |
8 | checkboxes[i].checked = source.checked; | |
9 | } | |
26971737 VP |
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 | ||
f41baac8 VP |
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 | ||
26971737 VP |
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 | } | |
d1d9caa9 VP |
36 | } |
37 | ||
119fee10 VP |
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 | ||
a85c268f VP |
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 | } | |
2d62c85d | 64 | } |
2751c89d | 65 | |
0ba71cfd BM |
66 | /* Popup notifications */ |
67 | ||
2751c89d VP |
68 | function generate_notif(title, body) |
69 | { | |
70 | /* generate a random number between 1000 and 90000 to use as an id */ | |
71 | const min = 1000; | |
72 | const max = 90000; | |
73 | const id = Math.floor(Math.random() * (max - min + 1)) + min; | |
74 | ||
75 | const toast = document.createElement('div'); | |
1c363d5e VP |
76 | toast.classList.add('toast', 'hide'); |
77 | toast.id = 'toast' + id; | |
78 | toast.role = 'alert'; | |
79 | toast.ariaLive = 'assertive'; | |
80 | toast.ariaAtomic = 'true'; | |
e65f1f65 | 81 | toast.setAttribute('data-delay', '10000'); |
2751c89d VP |
82 | |
83 | const header = document.createElement('div'); | |
84 | header.classList.add('toast-header'); | |
85 | ||
86 | const theTitle = document.createElement('strong'); | |
87 | theTitle.classList.add('mr-auto'); | |
88 | theTitle.textContent = title; | |
89 | ||
52cc6126 VP |
90 | const notiftime = document.createElement('div'); |
91 | notiftime.classList.add('badge', 'rounded-pill', 'badge-primary', 'ml-1'); | |
92 | notiftime.textContent = 'Just now'; // always just now I think right :D | |
2751c89d VP |
93 | |
94 | const closebutton = document.createElement('button'); | |
95 | closebutton.type = 'button'; | |
96 | closebutton.classList.add('ml-2', 'mb-1', 'close'); | |
97 | closebutton.setAttribute('data-dismiss', 'toast'); | |
98 | closebutton.ariaLabel = 'Close'; | |
99 | ||
100 | const closebuttonspan = document.createElement('span'); | |
101 | closebuttonspan.ariaHidden = 'true'; | |
102 | closebuttonspan.innerHTML = "×"; | |
103 | ||
104 | const toastbody = document.createElement('div'); | |
105 | toastbody.classList.add('toast-body'); | |
106 | toastbody.textContent = body; | |
107 | ||
108 | ||
109 | /* put it all together */ | |
110 | closebutton.appendChild(closebuttonspan); | |
111 | header.appendChild(theTitle); | |
112 | header.appendChild(notiftime); | |
113 | header.appendChild(closebutton); | |
1c363d5e VP |
114 | toast.appendChild(header); |
115 | toast.appendChild(toastbody); | |
116 | document.getElementById('toaster').append(toast); | |
2751c89d | 117 | |
1c363d5e | 118 | $('#' + toast.id).toast('show'); |
2751c89d | 119 | } |
1c363d5e | 120 | |
2751c89d VP |
121 | function StreamNotifs(e) |
122 | { | |
123 | var data; | |
124 | try { | |
125 | data = JSON.parse(e.data); | |
126 | } catch(e) { | |
127 | return; | |
128 | } | |
129 | title = data.subsystem + '.' + data.event_id; | |
130 | msg = data.msg; | |
131 | generate_notif(title, msg); | |
132 | } | |
0ba71cfd | 133 | |
2751c89d VP |
134 | function StartStreamNotifs(url) |
135 | { | |
136 | if (!!window.EventSource) { | |
137 | var source = new EventSource(url); | |
138 | source.addEventListener('message', StreamNotifs, false); | |
139 | } | |
0ba71cfd BM |
140 | } |
141 | ||
142 | /* Log streamer */ | |
143 | function NewLogEntry(e) | |
144 | { | |
145 | var data; | |
146 | try { | |
147 | data = JSON.parse(e.data); | |
148 | } catch(e) { | |
149 | return; | |
150 | } | |
60ea42bf BM |
151 | |
152 | if (data.sync_option != "sync_now") | |
153 | { | |
3556818c BM |
154 | var sync = (data.sync_option == "no_sync") ? false : true; |
155 | delete data.sync_option; | |
156 | ||
60ea42bf BM |
157 | data_list_table.row.add({ |
158 | 'Time':data.timestamp, | |
159 | 'Level':data.level, | |
160 | 'Subsystem':data.subsystem, | |
161 | 'Event':data.event_id, | |
ff6f464f | 162 | 'Message':data.msg, |
0e8dc61e | 163 | 'Raw':JSON.stringify(data)}); |
3556818c BM |
164 | |
165 | if (!sync) | |
60ea42bf BM |
166 | return; |
167 | } | |
168 | data_list_table.draw(true); | |
0ba71cfd BM |
169 | data_list_table.rows().invalidate(); |
170 | data_list_table.searchPanes.rebuildPane(); | |
171 | } | |
172 | ||
173 | function StartLogStream(url) | |
174 | { | |
175 | var source = new EventSource(url); | |
176 | source.addEventListener('message', NewLogEntry, false); | |
177 | } |