wireless_modefreq.htm 4.3 KB

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