Merge pull request #4444 from weblate/weblate-openwrt-luci
[project/luci.git] / applications / luci-app-travelmate / luasrc / view / travelmate / stations.htm
1 <%#
2 Copyright 2017-2019 Dirk Brenken (dev@brenken.org)
3 This is free software, licensed under the Apache License, Version 2.0
4 -%>
5
6 <%-
7 local uci = require("luci.model.uci").cursor()
8 local trmiface = uci:get("travelmate", "global", "trm_iface") or "trm_wwan"
9 -%>
10
11 <%+header%>
12
13 <script type="text/javascript">
14 //<![CDATA[
15 function status_update(json)
16 {
17 var i;
18 var j;
19 var search;
20 var view;
21 var list;
22 var status = json.data.travelmate_status;
23 var faulty = json.data.faulty_stations;
24
25 if (faulty)
26 {
27 var faulty_array = faulty.split(' ');
28 for (i = 0; i < faulty_array.length; i++)
29 {
30 for (j = 1; j <= 5; j++)
31 {
32 search = j + "_" + faulty_array[i];
33 view = document.getElementById(search);
34 if (view)
35 {
36 view.setAttribute("name", "station_nok");
37 view.setAttribute("style", "text-align: left !important; color: #a22; font-weight: bold");
38 }
39 }
40 }
41 }
42 else
43 {
44 list = document.getElementsByName("station_nok");
45 if (list.length > 0)
46 {
47 for (i = 0; i < list.length; i++)
48 {
49 list[i].removeAttribute("style");
50 }
51 }
52 }
53
54 if (status.startsWith("connected"))
55 {
56 for (i = 1; i <= 5; i++)
57 {
58 search = i + "_" + json.data.station_id;
59 view = document.getElementById(search);
60 if (view)
61 {
62 view.setAttribute("style", "text-align: left !important; color: #37c; font-weight: bold");
63 }
64 }
65 }
66 else
67 {
68 list = document.getElementsByName("station_ok");
69 if (list.length > 0)
70 {
71 for (i = 0; i < list.length; i++)
72 {
73 list[i].removeAttribute("style");
74 }
75 }
76 }
77 }
78
79 XHR.get('<%=luci.dispatcher.build_url("admin", "services", "travelmate", "status")%>', null,
80 function(x, json_info)
81 {
82 if (!x || !json_info)
83 {
84 return;
85 }
86 status_update(json_info)
87 });
88
89 XHR.poll(-1, '<%=luci.dispatcher.build_url("admin", "services", "travelmate", "status")%>', null,
90 function(x, json_info)
91 {
92 if (!x || !json_info)
93 {
94 return;
95 }
96 status_update(json_info)
97 });
98 //]]>
99 </script>
100
101 <div class="cbi-map">
102 <div class="cbi-map-descr">
103 <%=translatef("Provides an overview of all configured uplinks for the travelmate interface (%s). You can edit, remove or re-order/prioritize existing uplinks or scan for new ones. The currently used uplink is emphasized in blue, faulty stations in red.", trmiface)%>
104 </div>
105
106 <div class="cbi-section">
107 <div class="table cbi-section-table">
108 <div class="tr cbi-section-table-titles">
109 <div class="th left"><%:Device%></div>
110 <div class="th left"><%:SSID%></div>
111 <div class="th left"><%:BSSID%></div>
112 <div class="th left"><%:Encryption%></div>
113 <div class="th center"><%:Action%></div>
114 </div>
115 <%- uci:foreach("wireless", "wifi-iface", function(s)
116 local iface = s.network or ""
117 if iface == trmiface then
118 local section = s['.name'] or ""
119 local device = s.device or "-"
120 local ssid = s.ssid or "-"
121 local bssid = s.bssid or "-"
122 local encr = s.encryption or "-"
123 -%>
124 <div class="tr cbi-section-table-row cbi-rowstyle-1" name="station_ok" id="1_<%=device%>/<%=ssid%>/<%=bssid%>">
125 <div class="td left" style="text-align: left !important" name="station_ok" id="2_<%=device%>/<%=ssid%>/<%=bssid%>"><%=device%></div>
126 <div class="td left" style="text-align: left !important" name="station_ok" id="3_<%=device%>/<%=ssid%>/<%=bssid%>"><%=ssid%></div>
127 <div class="td left" style="text-align: left !important" name="station_ok" id="4_<%=device%>/<%=ssid%>/<%=bssid%>"><%=bssid%></div>
128 <div class="td left" style="text-align: left !important" name="station_ok" id="5_<%=device%>/<%=ssid%>/<%=bssid%>"><%=encr%></div>
129 <div class="td middle cbi-section-actions">
130 <div>
131 <input class="cbi-button cbi-button-up" type="button" value="<%:Up%>" onclick="location.href='<%=luci.dispatcher.build_url('admin/services/travelmate/wifiorder')%>?cfg=<%=section%>&amp;dir=up'" alt="<%:Move up%>" title="<%:Move up%>" />
132 <input class="cbi-button cbi-button-down" type="button" value="<%:Down%>" onclick="location.href='<%=luci.dispatcher.build_url('admin/services/travelmate/wifiorder')%>?cfg=<%=section%>&amp;dir=down'" alt="<%:Move down%>" title="<%:Move down%>" />
133 <input class="cbi-button cbi-button-edit" type="button" value="<%:Edit%>" onclick="location.href='<%=luci.dispatcher.build_url('admin/services/travelmate/wifiedit')%>?cfg=<%=section%>'" title="<%:Edit this Uplink%>" />
134 <input class="cbi-button cbi-button-remove" type="button" value="<%:Remove%>" onclick="location.href='<%=luci.dispatcher.build_url('admin/services/travelmate/wifidelete')%>?cfg=<%=section%>'" title="<%:Remove this Uplink%>" />
135 </div>
136 </div>
137 </div>
138 <%- end; end) -%>
139 </div>
140 </div>
141 <div class="cbi-page-actions right">
142 <%- uci:foreach("wireless", "wifi-device", function(s)
143 local device = s[".name"]
144 local hwmode = s.hwmode or "-" -%>
145 <form class="inline" action="<%=luci.dispatcher.build_url('admin/services/travelmate/wifiscan')%>" method="post">
146 <input type="hidden" name="device" value="<%=device%>" />
147 <input type="hidden" name="token" value="<%=token%>" />
148 <input type="submit" class="cbi-button cbi-button-action important" title="<%:Find and join network on%> <%=device%>" value="<%:Scan%> <%=device%> (<%=hwmode%>)" />
149 </form>
150 <%- end) -%>
151 </div>
152 </div>
153
154 <%+footer%>