custom.js 6.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226
  1. /* Wifi Hotspot app for YunoHost
  2. * Copyright (C) 2015 Julien Vaubourg <julien@vaubourg.com>
  3. * Contribute at https://github.com/jvaubourg/hotspot_ynh
  4. *
  5. * This program is free software: you can redistribute it and/or modify
  6. * it under the terms of the GNU Affero General Public License as published by
  7. * the Free Software Foundation, either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU Affero General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Affero General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. function wifiSecureBtn() {
  19. if($(this).parent().hasClass('off')) {
  20. $(this).closest('.form-group').next().hide('slow');
  21. } else {
  22. $(this).closest('.form-group').next().show('slow');
  23. }
  24. }
  25. function tabsClick() {
  26. var ssid = $(this).closest('.ssid');
  27. var tab = $(this).parent().attr('data-tab');
  28. ssid.find('li.active').removeClass('active');
  29. $(this).parent().addClass('active');
  30. ssid.find('.tabs').hide();
  31. ssid.find('.tab' + tab).show();
  32. return false;
  33. }
  34. function dropDownClick() {
  35. var menu = $(this).parent();
  36. var items = menu.children();
  37. var button = menu.prev();
  38. var input = button.prev();
  39. items.removeClass('active');
  40. $(this).addClass('active');
  41. button.text($(this).text());
  42. button.append(' <span class="caret"></span>');
  43. input.val($(this).text());
  44. }
  45. function updateNbSsidRemaining() {
  46. multissid = $('#devlist .active').data('multissid');
  47. current = $('.ssid').length;
  48. remaining = multissid - current;
  49. $('.ssid').each(function(i) {
  50. if(i >= multissid) {
  51. $(this).removeClass('panel-default');
  52. $(this).addClass('panel-danger');
  53. } else {
  54. $(this).removeClass('panel-danger');
  55. $(this).addClass('panel-default');
  56. }
  57. });
  58. $('.ssid').find('.deletessid').hide();
  59. $('.ssid').last().find('.deletessid').show();
  60. $('.ssid').first().find('.deletessid').hide();
  61. if(remaining <= 0) {
  62. $('#newssid').attr('disabled', true);
  63. $('#newssid').removeClass('btn-success');
  64. $('#newssid').addClass('btn-danger');
  65. } else {
  66. $('#newssid').attr('disabled', false);
  67. $('#newssid').removeClass('btn-danger');
  68. $('#newssid').addClass('btn-success');
  69. }
  70. $('#newssid span').text(remaining);
  71. }
  72. function deleteClick() {
  73. $(this).closest('.ssid').remove();
  74. updateNbSsidRemaining();
  75. }
  76. $(document).ready(function() {
  77. $('.btn-group').button();
  78. $('[data-toggle="tooltip"]').tooltip();
  79. $('.dropdown-menu li').click(dropDownClick);
  80. $('.switch').bootstrapToggle();
  81. $('#save').click(function() {
  82. $(this).prop('disabled', true);
  83. $('#save-loading').show();
  84. $('#form').submit();
  85. });
  86. $('#saveconfirm').click(function() {
  87. $(this).hide();
  88. $('#saveconfirmation').show();
  89. });
  90. $('#status .close').click(function() {
  91. $(this).parent().hide();
  92. });
  93. $('#statusbtn').click(function() {
  94. if($('#status-loading').is(':hidden')) {
  95. $('#status').hide();
  96. $('#status-loading').show();
  97. $.ajax({
  98. url: '?/status',
  99. }).done(function(data) {
  100. $('#status-loading').hide();
  101. $('#status-text').html('<ul>' + data + '</ul>');
  102. $('#status').show('slow');
  103. });
  104. }
  105. });
  106. $('.wifiparty').click(function() {
  107. $('#wifiparty_screen').show('slow');
  108. });
  109. $('#wifiparty_zoomin_ssid').mousedown(function() {
  110. $('#wifiparty_ssid').css('fontSize', (parseInt($('#wifiparty_ssid').css('fontSize')) + 5) + "px");
  111. });
  112. $('#wifiparty_zoomout_ssid').mousedown(function() {
  113. $('#wifiparty_ssid').css('fontSize', (parseInt($('#wifiparty_ssid').css('fontSize')) - 5) + "px");
  114. });
  115. $('#wifiparty_zoomin_passphrase').mousedown(function() {
  116. $('#wifiparty_passphrase').css('fontSize', (parseInt($('#wifiparty_passphrase').css('fontSize')) + 7) + "px");
  117. });
  118. $('#wifiparty_zoomout_passphrase').mousedown(function() {
  119. $('#wifiparty_passphrase').css('fontSize', (parseInt($('#wifiparty_passphrase').css('fontSize')) - 7) + "px");
  120. });
  121. $('#wifiparty_close').click(function() {
  122. $('#wifiparty_screen').hide();
  123. });
  124. $('.wifi_secure').change(wifiSecureBtn);
  125. $('#service_enabled').change(function() {
  126. if($('#service_enabled').parent().hasClass('off')) {
  127. $('.enabled').hide('slow');
  128. } else {
  129. $('.enabled').show('slow');
  130. }
  131. });
  132. $('.nav-tabs a').click(tabsClick);
  133. $('#newssid').click(function() {
  134. var clone = $('#ssids').children().first().clone();
  135. var id = parseInt($('.ssid').length);
  136. clone.find('.dropdownmenu').each(function(i) {
  137. var initial = $('#ssids').children().first().find('.dropdownmenu');
  138. var clone = initial.eq(i).clone(true, true);
  139. $(this).after(clone);
  140. $(this).remove();
  141. });
  142. clone.find('[name]').each(function() {
  143. $(this).attr('name', $(this).attr('name').replace('[0]', '[' + id + ']'));
  144. });
  145. clone.find('[data-toggle="tooltip"]').tooltip();
  146. clone.find('.deletessid').click(deleteClick);
  147. clone.find('input[type=text]').each(function() {
  148. if($(this).attr('name').match('dns')) {
  149. $(this).val($(this).attr('placeholder'));
  150. } else {
  151. $(this).val('');
  152. }
  153. });
  154. clone.find('input[type=checkbox]').each(function() {
  155. $(this).parent().after($(this));
  156. $(this).prev().remove();
  157. $(this).attr('checked', false);
  158. });
  159. clone.find('.switch').bootstrapToggle();
  160. clone.find('.wifi_secure').change(wifiSecureBtn);
  161. clone.find('.nav-tabs a').click(tabsClick);
  162. clone.find('.dropdown-menu li').click(dropDownClick);
  163. clone.find('.wifi_passphrase').hide();
  164. clone.find('h3').each(function() {
  165. $(this).text($(this).data('label') + ' ' + (id + 1));
  166. });
  167. $('#ssids').append(clone);
  168. updateNbSsidRemaining();
  169. });
  170. $('.deletessid').click(deleteClick);
  171. updateNbSsidRemaining();
  172. });
  173. $(document).keydown(function(e) {
  174. if(e.keyCode == 27) {
  175. $('#wifiparty_close').click();
  176. }
  177. });