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