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