wireless_modefreq.htm 4.1 KB

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