wireless_modefreq.htm 4.0 KB

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