modules/admin-full: rework status javascript code to use XHR.poll()
[project/luci.git] / modules / admin-full / luasrc / view / admin_network / lease_status.htm
1 <script type="text/javascript">//<![CDATA[
2         XHR.poll(5, '<%=luci.dispatcher.build_url("admin", "network", "dhcplease_status")%>', null,
3                 function(x, st)
4                 {
5                         var tb = document.getElementById('lease_status_table');
6                         if (st && tb)
7                         {
8                                 /* clear all rows */
9                                 while( tb.rows.length > 1 )
10                                         tb.deleteRow(1);
11
12                                 for( var i = 0; i < st.length; i++ )
13                                 {
14                                         var timestr;
15
16                                         if (st[i].expires <= 0)
17                                         {
18                                                 timestr = '<em><%:expired%></em>';
19                                         }
20                                         else
21                                         {
22                                                 timestr = String.format('%t', st[i].expires);
23                                         }
24
25                                         var tr = tb.insertRow(-1);
26                                                 tr.className = 'cbi-section-table-row cbi-rowstyle-' + ((i % 2) + 1);
27
28                                         tr.insertCell(-1).innerHTML = st[i].hostname ? st[i].hostname : '?';
29                                         tr.insertCell(-1).innerHTML = st[i].ipaddr;
30                                         tr.insertCell(-1).innerHTML = st[i].macaddr;
31                                         tr.insertCell(-1).innerHTML = timestr;
32                                 }
33
34                                 if( tb.rows.length == 1 )
35                                 {
36                                         var tr = tb.insertRow(-1);
37                                                 tr.className = 'cbi-section-table-row';
38
39                                         var td = tr.insertCell(-1);
40                                                 td.colSpan = 4;
41                                                 td.innerHTML = '<em><br /><%:There are no active leases.%></em>';
42                                 }
43                         }
44                 }
45         );
46 //]]></script>
47
48 <fieldset class="cbi-section">
49         <legend><%:Active Leases%></legend>
50         <table class="cbi-section-table" id="lease_status_table">
51                 <tr class="cbi-section-table-titles">
52                         <th class="cbi-section-table-cell"><%:Hostname%></th>
53                         <th class="cbi-section-table-cell"><%:IPv4-Address%></th>
54                         <th class="cbi-section-table-cell"><%:MAC-Address%></th>
55                         <th class="cbi-section-table-cell"><%:Leasetime remaining%></th>
56                 </tr>
57                 <tr class="cbi-section-table-row">
58                         <td colspan="4"><em><br /><%:Collecting data...%></em></td>
59                 </tr>
60         </table>
61 </fieldset>