custom.js 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. $(document).ready(function() {
  19. $('.btn-group').button();
  20. $('[data-toggle="tooltip"]').tooltip();
  21. $('.switch').bootstrapToggle();
  22. $('.fileinput').click(function() {
  23. if(!$(this).hasClass('btn-danger')) {
  24. var realinputid = '#' + $(this).attr('id').replace(/_chooser.*/, '');
  25. $(realinputid).click();
  26. }
  27. });
  28. $('.deletefile').click(function() {
  29. var chooserbtnid = '#' + $(this).attr('id').replace(/_deletebtn$/, '_chooserbtn');
  30. var choosertxtid = '#' + $(this).attr('id').replace(/_deletebtn$/, '_choosertxt');
  31. var fileinputid = '#' + $(this).attr('id').replace(/_deletebtn$/, '');
  32. var deleteinputid = '#' + $(this).attr('id').replace(/btn$/, '');
  33. $(deleteinputid).click();
  34. $(chooserbtnid).toggleClass('btn-danger');
  35. $(chooserbtnid).toggleClass('not-allowed');
  36. $(choosertxtid).toggleClass('btn-danger');
  37. $(choosertxtid).val($(choosertxtid).hasClass('btn-danger') ? 'Removal requested' : '');
  38. $(fileinputid).val('');
  39. if($(this).attr('id').search('_key') >= 0) {
  40. if($(choosertxtid).hasClass('btn-danger') != $('#crt_client_choosertxt').hasClass('btn-danger')) {
  41. $('#crt_client_deletebtn').click();
  42. }
  43. } else {
  44. if($(choosertxtid).hasClass('btn-danger') != $('#crt_client_key_choosertxt').hasClass('btn-danger')) {
  45. $('#crt_client_key_deletebtn').click();
  46. }
  47. }
  48. });
  49. $('input[type="file"]').change(function() {
  50. var choosertxtid = '#' + $(this).attr('id') + '_choosertxt';
  51. $(choosertxtid).val($(this).val().replace(/^.*[\/\\]/, ''));
  52. });
  53. $('#save').click(function() {
  54. $(this).prop('disabled', true);
  55. $('#save-loading').show();
  56. $('#form').submit();
  57. });
  58. $('#status .close').click(function() {
  59. $(this).parent().hide();
  60. });
  61. $('#statusbtn').click(function() {
  62. if($('#status-loading').is(':hidden')) {
  63. $('#status').hide();
  64. $('#status-loading').show();
  65. $.ajax({
  66. url: '?/status',
  67. }).done(function(data) {
  68. $('#status-loading').hide();
  69. $('#status-text').html('<ul>' + data + '</ul>');
  70. $('#status').show('slow');
  71. });
  72. }
  73. });
  74. $('#raw_openvpn_btn').click(function() {
  75. $('#raw_openvpn_btnpanel').hide();
  76. $('#raw_openvpn_panel').show('low');
  77. });
  78. $('#service_enabled').change(function() {
  79. if($('#service_enabled').parent().hasClass('off')) {
  80. $('.enabled').hide('slow');
  81. } else {
  82. $('.enabled').show('slow');
  83. }
  84. });
  85. });