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