custom.js 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113
  1. /* VPN Client app for YunoHost
  2. * Copyright (C) 2015 Julien Vaubourg <julien@vaubourg.com>
  3. * Contribute at https://github.com/labriqueinternet/vpnclient_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 tabsClick() {
  19. var tab = $(this).parent().attr('data-tab');
  20. $('.nav').find('li.active').removeClass('active');
  21. $(this).parent().addClass('active');
  22. $('.tabs').hide();
  23. $('.tab' + tab).show();
  24. return false;
  25. }
  26. $(document).ready(function() {
  27. $('.btn-group').button();
  28. $('[data-toggle="tooltip"]').tooltip();
  29. $('.switch').bootstrapToggle();
  30. $('.nav-tabs a').click(tabsClick);
  31. $('.fileinput').click(function() {
  32. if(!$(this).hasClass('btn-danger')) {
  33. var realinputid = '#' + $(this).attr('id').replace(/_chooser.*/, '');
  34. $(realinputid).click();
  35. }
  36. });
  37. $('.deletefile').click(function() {
  38. var chooserbtnid = '#' + $(this).attr('id').replace(/_deletebtn$/, '_chooserbtn');
  39. var choosertxtid = '#' + $(this).attr('id').replace(/_deletebtn$/, '_choosertxt');
  40. var fileinputid = '#' + $(this).attr('id').replace(/_deletebtn$/, '');
  41. var deleteinputid = '#' + $(this).attr('id').replace(/btn$/, '');
  42. $(deleteinputid).click();
  43. $(chooserbtnid).toggleClass('btn-danger');
  44. $(chooserbtnid).toggleClass('not-allowed');
  45. $(choosertxtid).toggleClass('btn-danger');
  46. $(choosertxtid).val($(choosertxtid).hasClass('btn-danger') ? 'Removal requested' : '');
  47. $(fileinputid).val('');
  48. if($(this).attr('id').search('_key') >= 0) {
  49. if($(choosertxtid).hasClass('btn-danger') != $('#crt_client_choosertxt').hasClass('btn-danger')) {
  50. $('#crt_client_deletebtn').click();
  51. }
  52. } else if($(this).attr('id').search('_ta') < 0) {
  53. if($(choosertxtid).hasClass('btn-danger') != $('#crt_client_key_choosertxt').hasClass('btn-danger')) {
  54. $('#crt_client_key_deletebtn').click();
  55. }
  56. }
  57. });
  58. $('input[type="file"]').change(function() {
  59. var choosertxtid = '#' + $(this).attr('id') + '_choosertxt';
  60. $(choosertxtid).val($(this).val().replace(/^.*[\/\\]/, ''));
  61. });
  62. $('#save').click(function() {
  63. $(this).prop('disabled', true);
  64. $('#save-loading').show();
  65. $('#form').submit();
  66. });
  67. $('#status .close').click(function() {
  68. $(this).parent().hide();
  69. });
  70. $('#statusbtn').click(function() {
  71. if($('#status-loading').is(':hidden')) {
  72. $('#status').hide();
  73. $('#status-loading').show();
  74. $.ajax({
  75. url: '?/status',
  76. }).done(function(data) {
  77. $('#status-loading').hide();
  78. $('#status-text').html('<ul>' + data + '</ul>');
  79. $('#status').show('slow');
  80. });
  81. }
  82. });
  83. $('#raw_openvpn_btn').click(function() {
  84. $('#raw_openvpn_btnpanel').hide();
  85. $('#raw_openvpn_panel').show('low');
  86. });
  87. $('#service_enabled').change(function() {
  88. if($('#service_enabled').parent().hasClass('off')) {
  89. $('.enabled').hide('slow');
  90. } else {
  91. $('.enabled').show('slow');
  92. }
  93. });
  94. });