modules: Make luci-base sufficient to use luci apps
[project/luci.git] / modules / luci-mod-admin-full / luasrc / view / admin_network / switch_status.htm
1 <script type="text/javascript">//<![CDATA[
2 var switches = [ '<%=table.concat(self.switches, "', '")%>' ],
3 tables = document.querySelectorAll('.cbi-section-table');
4
5 function add_status_row(table) {
6 var first_row = table.querySelector('.cbi-section-table-row');
7 if (first_row.classList.contains('port-status'))
8 return first_row;
9
10 var status_row = first_row.parentNode.insertBefore(
11 E('div', { 'class': first_row.className }), first_row);
12
13 first_row.querySelectorAll('.td').forEach(function(td) {
14 status_row.appendChild(td.cloneNode(false));
15 status_row.lastElementChild.removeAttribute('data-title');
16 });
17
18 status_row.firstElementChild.innerHTML = '<%:Port status:%>';
19 status_row.classList.add('port-status') ;
20
21 return status_row;
22 }
23
24 XHR.poll(5, '<%=url('admin/network/switch_status')%>/' + switches.join(','), null,
25 function(x, st)
26 {
27 for (var i = 0; i < switches.length; i++)
28 {
29 var ports = st[switches[i]];
30 var tr = add_status_row(tables[i]);
31
32 if (tr && ports && ports.length)
33 {
34 for (var j = 0; j < ports.length; j++)
35 {
36 var th = tr.querySelector('[data-name="%d"]'.format(j));
37
38 if (!th)
39 continue;
40
41 if (ports[j].link)
42 {
43 th.innerHTML = String.format(
44 '<small><img src="<%=resource%>/icons/port_up.png" />' +
45 '<br />%d<%:baseT%><br />%s</small>',
46 ports[j].speed, ports[j].duplex
47 ? '<%:full-duplex%>' : '<%:half-duplex%>'
48 );
49 }
50 else
51 {
52 th.innerHTML = String.format(
53 '<small><img src="<%=resource%>/icons/port_down.png" />' +
54 '<br /><%:no link%></small>'
55 );
56 }
57 }
58 }
59 }
60 }
61 );
62 //]]></script>