custom.js 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180
  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. $(document).ready(function() {
  46. $('.btn-group').button();
  47. $('[data-toggle="tooltip"]').tooltip();
  48. $('.dropdown-menu li').click(dropDownClick);
  49. $('.switch').bootstrapToggle();
  50. $('#save').click(function() {
  51. $(this).prop('disabled', true);
  52. $('#save-loading').show();
  53. $('#form').submit();
  54. });
  55. $('#saveconfirm').click(function() {
  56. $(this).hide();
  57. $('#saveconfirmation').show();
  58. });
  59. $('#status .close').click(function() {
  60. $(this).parent().hide();
  61. });
  62. $('#statusbtn').click(function() {
  63. if($('#status-loading').is(':hidden')) {
  64. $('#status').hide();
  65. $('#status-loading').show();
  66. $.ajax({
  67. url: '?/status',
  68. }).done(function(data) {
  69. $('#status-loading').hide();
  70. $('#status-text').html('<ul>' + data + '</ul>');
  71. $('#status').show('slow');
  72. });
  73. }
  74. });
  75. $('.wifiparty').click(function() {
  76. $('#wifiparty_screen').show('slow');
  77. });
  78. $('#wifiparty_zoomin_ssid').mousedown(function() {
  79. $('#wifiparty_ssid').css('fontSize', (parseInt($('#wifiparty_ssid').css('fontSize')) + 5) + "px");
  80. });
  81. $('#wifiparty_zoomout_ssid').mousedown(function() {
  82. $('#wifiparty_ssid').css('fontSize', (parseInt($('#wifiparty_ssid').css('fontSize')) - 5) + "px");
  83. });
  84. $('#wifiparty_zoomin_passphrase').mousedown(function() {
  85. $('#wifiparty_passphrase').css('fontSize', (parseInt($('#wifiparty_passphrase').css('fontSize')) + 7) + "px");
  86. });
  87. $('#wifiparty_zoomout_passphrase').mousedown(function() {
  88. $('#wifiparty_passphrase').css('fontSize', (parseInt($('#wifiparty_passphrase').css('fontSize')) - 7) + "px");
  89. });
  90. $('#wifiparty_close').click(function() {
  91. $('#wifiparty_screen').hide();
  92. });
  93. $('.wifi_secure').change(wifiSecureBtn);
  94. $('#service_enabled').change(function() {
  95. if($('#service_enabled').parent().hasClass('off')) {
  96. $('.enabled').hide('slow');
  97. } else {
  98. $('.enabled').show('slow');
  99. }
  100. });
  101. $('.nav-tabs a').click(tabsClick);
  102. $('#newssid').click(function() {
  103. var clone = $('#ssids').children().first().clone();
  104. var id = parseInt($('.ssid').length);
  105. clone.find('.dropdownmenu').each(function(i) {
  106. var initial = $('#ssids').children().first().find('.dropdownmenu');
  107. var clone = initial.eq(i).clone(true, true);
  108. $(this).after(clone);
  109. $(this).remove();
  110. });
  111. clone.find('[name]').each(function() {
  112. $(this).attr('name', $(this).attr('name').replace('[0]', '[' + id + ']'));
  113. });
  114. clone.find('[data-toggle="tooltip"]').tooltip();
  115. clone.find('input[type=text]').each(function() {
  116. if($(this).attr('name').match('dns')) {
  117. $(this).val($(this).attr('placeholder'));
  118. } else {
  119. $(this).val('');
  120. }
  121. });
  122. clone.find('input[type=checkbox]').each(function() {
  123. $(this).parent().after($(this));
  124. $(this).prev().remove();
  125. $(this).attr('checked', false);
  126. });
  127. clone.find('.switch').bootstrapToggle();
  128. clone.find('.wifi_secure').change(wifiSecureBtn);
  129. clone.find('.nav-tabs a').click(tabsClick);
  130. clone.find('.dropdown-menu li').click(dropDownClick);
  131. clone.find('.wifi_passphrase').hide();
  132. clone.find('h3').each(function() {
  133. $(this).text($(this).data('label') + ' ' + (id + 1));
  134. });
  135. $('#ssids').append(clone);
  136. });
  137. });
  138. $(document).keydown(function(e) {
  139. if(e.keyCode == 27) {
  140. $('#wifiparty_close').click();
  141. }
  142. });