modules/admin-full: various javascript fixes in templates
[project/luci.git] / modules / admin-full / luasrc / view / admin_network / iface_status.htm
1 <%+cbi/valueheader%>
2
3 <script type="text/javascript">//<![CDATA[
4         var iwxhr = new XHR();
5
6         (function() {
7                 var func = arguments.callee;
8
9                 iwxhr.get('<%=luci.dispatcher.build_url("admin", "network", "iface_status", self.network)%>', null,
10                         function(x, ifc)
11                         {
12                                 if (ifc && (ifc = ifc[0]))
13                                 {
14                                         var html = '';
15
16                                         var s = document.getElementById('<%=self.option%>-ifc-signal');
17                                         if (s)
18                                                 s.innerHTML = String.format(
19                                                         '<img src="<%=resource%>/icons/%s%s.png" style="width:16px; height:16px" />' +
20                                                         '<br /><small>%s</small>',
21                                                                 ifc.type, ifc.is_up ? '' : '_disabled',
22                                                                 ifc.is_up ? ifc.ifname : '?'
23                                                 );
24
25                                         var d = document.getElementById('<%=self.option%>-ifc-description');
26                                         if (d && ifc.ifname && ifc.macaddr != '00:00:00:00:00:00')
27                                         {
28                                                 if (ifc.is_up)
29                                                 {
30                                                         html += String.format('<strong><%:Uptime%>:</strong> %t<br />', ifc.uptime);
31                                                 }
32
33                                                 if (ifc.type != 'tunnel')
34                                                 {
35                                                         html += String.format('<strong><%:MAC Address%>:</strong> %s<br />', ifc.macaddr);
36                                                 }
37
38                                                 html += String.format(
39                                                         '<strong><%:RX%></strong>: %.2mB (%d <%:Pkts.%>)<br />' +
40                                                         '<strong><%:TX%></strong>: %.2mB (%d <%:Pkts.%>)<br />',
41                                                                 ifc.rx_bytes, ifc.rx_packets,
42                                                                 ifc.tx_bytes, ifc.tx_packets
43                                                 );
44
45                                                 if (ifc.ipaddrs && ifc.ipaddrs.length)
46                                                 {
47                                                         html += '<strong><%:IPv4%>: </strong>';
48
49                                                         for (var i = 0; i < ifc.ipaddrs.length; i++)
50                                                                 html += String.format(
51                                                                         '%s%s/%d',
52                                                                         i ? ', ' : '',
53                                                                         ifc.ipaddrs[i].addr,
54                                                                         ifc.ipaddrs[i].prefix
55                                                                 );
56
57                                                         html += '<br />';
58                                                 }
59
60                                                 if (ifc.ip6addrs && ifc.ip6addrs.length)
61                                                 {
62                                                         html += '<strong><%:IPv6%>: </strong>';
63
64                                                         for (var i = 0; i < ifc.ip6addrs.length; i++)
65                                                                 html += String.format(
66                                                                         '%s%s/%d',
67                                                                         i ? ', ' : '',
68                                                                         ifc.ip6addrs[i].addr.toUpperCase(),
69                                                                         ifc.ip6addrs[i].prefix
70                                                                 );
71
72                                                         html += '<br />';
73                                                 }
74
75                                                 d.innerHTML = html;
76                                         }
77                                         else if (d)
78                                         {
79                                                 d.innerHTML = '<em><%:Interface not present or not connected yet.%></em>';
80                                         }
81                                 }
82
83                                 window.setTimeout(func, 5000);
84                         }
85                 )
86         })();
87 //]]></script>
88
89 <table>
90         <tr class="cbi-section-table">
91                 <td></td>
92                 <td class="cbi-value-field" style="min-width:16px; padding:3px; text-align:center" id="<%=self.option%>-ifc-signal">
93                         <img src="<%=resource%>/icons/ethernet_disabled.png" style="width:16px; height:16px" /><br />
94                         <small>?</small>
95                 </td>
96                 <td class="cbi-value-field" style="vertical-align:middle; text-align:left; padding:3px" id="<%=self.option%>-ifc-description">
97                         <em><%:Collecting data...%></em>
98                 </td>
99         </tr>
100 </table>
101
102 <%+cbi/valuefooter%>