modules/admin-full: add realtime iface status to config page
[project/luci.git] / modules / admin-full / luasrc / view / admin_network / wifi_status.htm
1 <%+cbi/valueheader%>
2
3 <script type="text/javascript"><![CDATA[
4         var iwxhr = new XHR();
5         (function() {
6                 iwxhr.get('<%=luci.dispatcher.build_url("admin", "network", "wireless_status", self.ifname)%>', null,
7                         function(x)
8                         {
9                                 var iw = x.responseText ? eval('(' + x.responseText + ')') : null;
10                                 if (iw)
11                                 {
12                                         var is_assoc = (iw.bssid && iw.channel);
13                                         var p = (100 / iw.quality_max * iw.quality);
14                                         var q = is_assoc ? p : -1;
15
16                                         var icon;
17                                         if (q < 0)
18                                                 icon = "<%=resource%>/icons/signal-none.png";
19                                         else if (q == 0)
20                                                 icon = "<%=resource%>/icons/signal-0.png";
21                                         else if (q < 25)
22                                                 icon = "<%=resource%>/icons/signal-0-25.png";
23                                         else if (q < 50)
24                                                 icon = "<%=resource%>/icons/signal-25-50.png";
25                                         else if (q < 75)
26                                                 icon = "<%=resource%>/icons/signal-50-75.png";
27                                         else
28                                                 icon = "<%=resource%>/icons/signal-75-100.png";
29
30                                         var s = document.getElementById('<%=self.option%>-iw-signal');
31                                         if (s)
32                                                 s.innerHTML = String.format(
33                                                         '<img src="%s" title="Signal: %d dBm / Noise: %d dBm" /><br />' +
34                                                         '<small>%d%%</small>', icon, iw.signal, iw.noise, p
35                                                 );
36
37                                         var d = document.getElementById('<%=self.option%>-iw-description');
38                                         if (d && is_assoc)
39                                                 d.innerHTML = String.format(
40                                                         '<strong><%:Mode%>:</strong> %s |' +
41                                                         '<strong><%:SSID%>:</strong> %s<br />' +
42                                                         '<strong><%:BSSID%>:</strong> %s |' +
43                                                         '<strong><%:Encryption%>:</strong> %s<br />' +
44                                                         '<strong><%:Channel%>:</strong> %d (%.3f GHz) |' +
45                                                         '<strong><%:Tx-Power%>:</strong> %d dBm<br />' +
46                                                         '<strong><%:Signal%>:</strong> %d dBm |' +
47                                                         '<strong><%:Noise%>:</strong> %d dBm<br />' +
48                                                         '<strong><%:Bit Rate%>:</strong> %.1f MBit/s |' +
49                                                         '<strong><%:Country%>:</strong> %s',
50                                                                 iw.mode, iw.ssid, iw.bssid,
51                                                                 iw.encryption ? iw.encryption.description : '<%:None%>',
52                                                                 iw.channel, iw.frequency ? (iw.frequency / 1000) : 0,
53                                                                 iw.txpower, iw.signal, iw.noise,
54                                                                 iw.bitrate ? (iw.bitrate / 1000) : 0, iw.country
55                                                 );
56                                         else if (d)
57                                                 d.innerHTML = '<%:Wireless is disabled or not associated%>';
58                                 }
59                         }
60                 )
61
62                 window.setTimeout(arguments.callee, 5000);
63         })();
64 ]]></script>
65
66 <table>
67         <tr class="cbi-section-table">
68                 <td></td>
69                 <td class="cbi-value-field" style="width:16px; padding:3px" id="<%=self.option%>-iw-signal">
70                         <img src="<%=resource%>/icons/signal-none.png" title="<%:Not associated%>" /><br />
71                         <small>0%</small>
72                 </td>
73                 <td class="cbi-value-field" style="vertical-align:middle; text-align:left; padding:3px" id="<%=self.option%>-iw-description">
74                         <em><%:Collecting data...%></em>
75                 </td>
76         </tr>
77 </table>
78
79 <%+cbi/valuefooter%>