Add missing variable declarations in JavaScript code
[project/luci.git] / applications / luci-app-olsr / luasrc / view / status-olsr / hna.htm
1 <%#
2 Copyright 2008 Steven Barth <steven@midlink.org>
3 Copyright 2008 Jo-Philipp Wich <jow@openwrt.org>
4 Copyright 2011 Manuel Munz <freifunk at somakoma dot de>
5 Licensed to the public under the Apache License 2.0.
6 -%>
7
8 <%
9 local i = 1
10
11 if luci.http.formvalue("status") == "1" then
12 local rv = {}
13 for k, hna in ipairs(hna) do
14 rv[#rv+1] = {
15 proto = hna["proto"],
16 destination = hna["destination"],
17 genmask = hna["genmask"],
18 gateway = hna["gateway"],
19 hostname = hna["hostname"],
20 validityTime = hna["validityTime"]
21 }
22 end
23 luci.http.prepare_content("application/json")
24 luci.http.write_json(rv)
25 return
26 end
27 %>
28
29 <%+header%>
30
31 <script type="text/javascript">//<![CDATA[
32 XHR.poll(10, '<%=REQUEST_URI%>', { status: 1 },
33 function(x, info)
34 {
35 var hnadiv = document.getElementById('olsrd_hna');
36 if (hnadiv)
37 {
38 var s = '';
39 for (var idx = 0; idx < info.length; idx++)
40 {
41 var hna = info[idx];
42 var linkgw = ''
43 s += '<div class="tr cbi-section-table-row cbi-rowstyle-'+(1 + (idx % 2))+' proto-' + hna.proto + '">'
44 if (hna.proto == '6') {
45 linkgw = '<a href="http://[' + hna.gateway + ']/cgi-bin-status.html">' + hna.gateway + '</a>'
46 } else {
47 linkgw = '<a href="http://' + hna.gateway + '/cgi-bin-status.html">' + hna.gateway + '</a>'
48 }
49
50 var validity;
51 if (hna.validityTime != undefined) {
52 validity = hna.validityTime + 's'
53 } else {
54 validity = '-'
55 }
56
57 var hostname;
58 if (hna.hostname != undefined) {
59 hostname = ' / <a href="http://' + hna.hostname + '/cgi-bin-status.html">' + hna.hostname + '</a>'
60 } else {
61 hostname = ''
62 }
63
64 s += String.format(
65 '<div class="td cbi-section-table-cell">%s</div>' +
66 '<div class="td cbi-section-table-cell">%s</div>' +
67 '<div class="td cbi-section-table-cell">%s</div>', hna.destination + '/' + hna.genmask, linkgw + hostname, validity
68 )
69 s += '</div>'
70 }
71 hnadiv.innerHTML = s;
72 }
73 }
74 );
75 //]]></script>
76
77 <h2 name="content"><%:Active host net announcements%></h2>
78
79 <div id="togglebuttons"></div>
80 <fieldset class="cbi-section">
81
82 <legend><%:Overview of currently active OLSR host net announcements%></legend>
83 <div class="table cbi-section-table">
84 <div class="thead">
85 <div class="tr cbi-section-table-titles">
86 <div class="th cbi-section-table-cell"><%:Announced network%></div>
87 <div class="th cbi-section-table-cell"><%:OLSR gateway%></div>
88 <div class="th cbi-section-table-cell"><%:Validity Time%></div>
89 </div>
90
91 </div>
92 <div class="tbody" id="olsrd_hna">
93 <% for k, route in ipairs(hna) do %>
94
95 <div class="tr cbi-section-table-row cbi-rowstyle-<%=i%> proto-<%=hna[k].proto%>">
96 <div class="td cbi-section-table-cell"><%=hna[k].destination%>/<%=hna[k].genmask%> </div>
97 <div class="td cbi-section-table-cell">
98 <% if hna[k].proto == '6' then %>
99 <a href="http://[<%=hna[k].gateway%>]/cgi-bin-status.html"><%=hna[k].gateway%></a>
100 <% else %>
101 <a href="http://<%=hna[k].gateway%>/cgi-bin-status.html"><%=hna[k].gateway%></a>
102 <% end %>
103 <% if hna[k].hostname then %>
104 / <a href="http://<%=hna[k].hostname%>/cgi-bin-status.html"><%=hna[k].hostname%></a>
105 <% end %>
106 </div>
107 <% if hna[k].validityTime then
108 validity = hna[k].validityTime .. 's'
109 else
110 validity = '-'
111 end %>
112
113 <div class="td cbi-section-table-cell"><%=validity%></div>
114 </div>
115
116 <% i = ((i % 2) + 1)
117 end %>
118 </div>
119 </div>
120 </fieldset>
121
122 <%+status-olsr/common_js%>
123 <%+footer%>