applications/luci-upnp: javascript fixes
[project/luci.git] / applications / luci-upnp / luasrc / view / upnp_status.htm
1 <script type="text/javascript">//<![CDATA[
2         function upnp_delete_fwd(idx) {
3                 var dlxhr = new XHR();
4
5                 dlxhr.get('<%=luci.dispatcher.build_url("admin", "services", "upnp", "delete")%>/' + idx, null,
6                         function(x)
7                         {
8                                 var tb = document.getElementById('upnp_status_table');
9                                 if (tb && (idx < tb.rows.length))
10                                         tb.rows[0].parentNode.removeChild(tb.rows[idx]);
11                         }
12                 );
13         }
14
15         var stxhr = new XHR();
16         (function() {
17                 var func = arguments.callee;
18
19                 stxhr.get('<%=luci.dispatcher.build_url("admin", "services", "upnp", "status")%>', null,
20                         function(x, st)
21                         {
22                                 var tb = document.getElementById('upnp_status_table');
23                                 if (st && tb)
24                                 {
25                                         /* clear all rows */
26                                         while( tb.rows.length > 1 )
27                                                 tb.deleteRow(1);
28
29                                         for( var i = 0; i < st.length; i++ )
30                                         {
31                                                 var tr = tb.insertRow(-1);
32                                                         tr.className = 'cbi-section-table-row cbi-rowstyle-' + ((i % 2) + 1);
33
34                                                 tr.insertCell(-1).innerHTML = st[i].proto;
35                                                 tr.insertCell(-1).innerHTML = st[i].extport;
36                                                 tr.insertCell(-1).innerHTML = st[i].intaddr;
37                                                 tr.insertCell(-1).innerHTML = st[i].intport;
38
39                                                 tr.insertCell(-1).innerHTML = String.format(
40                                                         '<input class="cbi-button cbi-input-remove" type="button" value="<%:Delete Redirect%>" onclick="upnp_delete_fwd(%d)" />',
41                                                                 st[i].num
42                                                 );
43                                         }
44
45                                         if( tb.rows.length == 1 )
46                                         {
47                                                 var tr = tb.insertRow(-1);
48                                                         tr.className = 'cbi-section-table-row';
49
50                                                 var td = tr.insertCell(-1);
51                                                         td.colSpan = 5;
52                                                         td.innerHTML = '<em><br /><%:There are no active redirects.%></em>';
53                                         }
54                                 }
55
56                                 window.setTimeout(func, 5000);
57                         }
58                 )
59         })();
60 //]]></script>
61
62 <fieldset class="cbi-section">
63         <legend><%:Active UPnP Redirects%></legend>
64         <table class="cbi-section-table" id="upnp_status_table">
65                 <tr class="cbi-section-table-titles">
66                         <th class="cbi-section-table-cell"><%:Protocol%></th>
67                         <th class="cbi-section-table-cell"><%:External Port%></th>
68                         <th class="cbi-section-table-cell"><%:Client Address%></th>
69                         <th class="cbi-section-table-cell"><%:Client Port%></th>
70                         <th class="cbi-section-table-cell">&#160;</th>
71                 </tr>
72                 <tr class="cbi-section-table-row">
73                         <td colspan="5"><em><br /><%:Collecting data...%></em></td>
74                 </tr>
75         </table>
76 </fieldset>