modules/admin-full: xhr fixes
[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> %s<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 = '<%:Wireless is disabled or not associated%>';
57 }
58
59 window.setTimeout(update_status, 5000);
60 }
61 )
62 };
63
64 update_status();
65 ]]></script>
66
67 <table>
68 <tr class="cbi-section-table">
69 <td></td>
70 <td class="cbi-value-field" style="width:16px; padding:3px" id="<%=self.option%>-iw-signal">
71 <img src="<%=resource%>/icons/signal-none.png" title="<%:Not associated%>" /><br />
72 <small>0%</small>
73 </td>
74 <td class="cbi-value-field" style="vertical-align:middle; text-align:left; padding:3px" id="<%=self.option%>-iw-description">
75 <em><%:Collecting data...%></em>
76 </td>
77 </tr>
78 </table>
79
80 <%+cbi/valuefooter%>