eeb1d5c5cbc7d1e137866fa3d84cf7542a5993c5
[project/luci.git] / modules / luci-base / luasrc / view / cbi / wireless_modefreq.htm
1 <%+cbi/valueheader%>
2
3 <script type="text/javascript">//<![CDATA[
4 var freqlist = <%= luci.http.write_json(self.iwinfo.freqlist) %>;
5 var hwmodes = <%= luci.http.write_json(self.iwinfo.hwmodelist or {}) %>;
6 var htmodes = <%= luci.http.write_json(self.iwinfo.htmodelist) %>;
7 var acs = <%= luci.http.write_json(self.hostapd_acs or 0) %>;
8
9 var channels = {
10 '11g': [
11 'auto', 'auto', true
12 ],
13 '11a': [
14 'auto', 'auto', true
15 ]
16 };
17
18 if (acs < 1) {
19 channels[(freqlist[freqlist.length - 1].mhz > 2484) ? '11a' : '11g'].length = 0;
20 }
21
22 for (var i = 0; i < freqlist.length; i++)
23 channels[(freqlist[i].mhz > 2484) ? '11a' : '11g'].push(
24 freqlist[i].channel,
25 '%d (%d MHz)'.format(freqlist[i].channel, freqlist[i].mhz),
26 !freqlist[i].restricted
27 );
28
29 var modes = [
30 '', 'Legacy', true,
31 'n', 'N', hwmodes.n,
32 'ac', 'AC', hwmodes.ac
33 ];
34
35 var htmodes = {
36 '': [
37 '', '-', true
38 ],
39 'n': [
40 'HT20', '20 MHz', htmodes.HT20,
41 'HT40', '40 MHz', htmodes.HT40
42 ],
43 'ac': [
44 'VHT20', '20 MHz', htmodes.VHT20,
45 'VHT40', '40 MHz', htmodes.VHT40,
46 'VHT80', '80 MHz', htmodes.VHT80,
47 'VHT160', '160 MHz', htmodes.VHT160
48 ]
49 };
50
51 var bands = {
52 '': [
53 '11g', '2.4 GHz', (channels['11g'].length > 3),
54 '11a', '5 GHz', (channels['11a'].length > 3)
55 ],
56 'n': [
57 '11g', '2.4 GHz', (channels['11g'].length > 3),
58 '11a', '5 GHz', (channels['11a'].length > 3)
59 ],
60 'ac': [
61 '11a', '5 GHz', true
62 ]
63 };
64
65 function cbi_set_values(sel, vals)
66 {
67 if (sel.vals)
68 sel.vals.selected = sel.selectedIndex;
69
70 while (sel.options[0])
71 sel.remove(0);
72
73 for (var i = 0; vals && i < vals.length; i += 3)
74 {
75 if (!vals[i+2])
76 continue;
77
78 var opt = document.createElement('option');
79 opt.value = vals[i+0];
80 opt.text = vals[i+1];
81
82 sel.add(opt);
83 }
84
85 if (!isNaN(vals.selected))
86 sel.selectedIndex = vals.selected;
87
88 sel.parentNode.style.display = (sel.options.length <= 1) ? 'none' : '';
89 sel.vals = vals;
90 }
91
92 function cbi_toggle_wifi_mode(id)
93 {
94 cbi_toggle_wifi_htmode(id);
95 cbi_toggle_wifi_band(id);
96 }
97
98 function cbi_toggle_wifi_htmode(id)
99 {
100 var mode = document.getElementById(id + '.mode');
101 var bwdt = document.getElementById(id + '.htmode');
102
103 cbi_set_values(bwdt, htmodes[mode.value]);
104 }
105
106 function cbi_toggle_wifi_band(id)
107 {
108 var mode = document.getElementById(id + '.mode');
109 var band = document.getElementById(id + '.band');
110
111 cbi_set_values(band, bands[mode.value]);
112 cbi_toggle_wifi_channel(id);
113 }
114
115 function cbi_toggle_wifi_channel(id)
116 {
117 var band = document.getElementById(id + '.band');
118 var chan = document.getElementById(id + '.channel');
119
120 cbi_set_values(chan, channels[band.value]);
121 }
122
123 function cbi_init_wifi(id)
124 {
125 var mode = document.getElementById(id + '.mode');
126 var band = document.getElementById(id + '.band');
127 var chan = document.getElementById(id + '.channel');
128 var bwdt = document.getElementById(id + '.htmode');
129
130 cbi_set_values(mode, modes);
131
132 if (/VHT20|VHT40|VHT80|VHT160/.test(<%= luci.http.write_json(self.map:get(section, "htmode")) %>))
133 mode.value = 'ac';
134 else if (/HT20|HT40/.test(<%= luci.http.write_json(self.map:get(section, "htmode")) %>))
135 mode.value = 'n';
136 else
137 mode.value = '';
138
139 cbi_toggle_wifi_mode(id);
140
141 if (/a/.test(<%= luci.http.write_json(self.map:get(section, "hwmode")) %>))
142 band.value = '11a';
143 else
144 band.value = '11g';
145
146 cbi_toggle_wifi_band(id);
147
148 bwdt.value = <%= luci.http.write_json(self.map:get(section, "htmode")) %>;
149 chan.value = <%= luci.http.write_json(self.map:get(section, "channel")) %>;
150 }
151 //]]></script>
152
153 <label style="float:left; margin-right:3px">
154 <%:Mode%><br />
155 <select style="width:auto" id="<%= cbid %>.mode" name="<%= cbid %>.mode" onchange="cbi_toggle_wifi_mode('<%= cbid %>')"></select>
156 </label>
157 <label style="float:left; margin-right:3px">
158 <%:Band%><br />
159 <select style="width:auto" id="<%= cbid %>.band" name="<%= cbid %>.band" onchange="cbi_toggle_wifi_band('<%= cbid %>')"></select>
160 </label>
161 <label style="float:left; margin-right:3px">
162 <%:Channel%><br />
163 <select style="width:auto" id="<%= cbid %>.channel" name="<%= cbid %>.channel"></select>
164 </label>
165 <label style="float:left; margin-right:3px">
166 <%:Width%><br />
167 <select style="width:auto" id="<%= cbid %>.htmode" name="<%= cbid %>.htmode"></select>
168 </label>
169 <br style="clear:left" />
170
171 <script type="text/javascript">cbi_init_wifi('<%= cbid %>');</script>
172
173 <%+cbi/valuefooter%>