custom.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. /* VPN Client app for YunoHost
  2. * Copyright (C) 2015 Julien Vaubourg <julien@vaubourg.com>
  3. * Contribute at https://github.com/jvaubourg/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. $('.fileinput').click(function() {
  22. if(!$(this).hasClass('btn-danger')) {
  23. var realinputid = '#' + $(this).attr('id').replace(/_chooser.*/, '');
  24. $(realinputid).click();
  25. }
  26. });
  27. $('.deletefile').click(function() {
  28. var chooserbtnid = '#' + $(this).attr('id').replace(/_deletebtn$/, '_chooserbtn');
  29. var choosertxtid = '#' + $(this).attr('id').replace(/_deletebtn$/, '_choosertxt');
  30. var fileinputid = '#' + $(this).attr('id').replace(/_deletebtn$/, '');
  31. var deleteinputid = '#' + $(this).attr('id').replace(/btn$/, '');
  32. $(deleteinputid).click();
  33. $(chooserbtnid).toggleClass('btn-danger');
  34. $(chooserbtnid).toggleClass('not-allowed');
  35. $(choosertxtid).toggleClass('btn-danger');
  36. $(choosertxtid).val($(choosertxtid).hasClass('btn-danger') ? 'Removal requested' : '');
  37. $(fileinputid).val('');
  38. if($(this).attr('id').search('_key') >= 0) {
  39. if($(choosertxtid).hasClass('btn-danger') != $('#crt_client_choosertxt').hasClass('btn-danger')) {
  40. $('#crt_client_deletebtn').click();
  41. }
  42. } else {
  43. if($(choosertxtid).hasClass('btn-danger') != $('#crt_client_key_choosertxt').hasClass('btn-danger')) {
  44. $('#crt_client_key_deletebtn').click();
  45. }
  46. }
  47. });
  48. $('input[type="file"]').change(function() {
  49. var choosertxtid = '#' + $(this).attr('id') + '_choosertxt';
  50. $(choosertxtid).val($(this).val().replace(/^.*[\/\\]/, ''));
  51. });
  52. $('#save').click(function() {
  53. $(this).prop('disabled', true);
  54. $('#save-loading').show();
  55. $('#form').submit();
  56. });
  57. $('#status .close').click(function() {
  58. $(this).parent().hide();
  59. });
  60. $('#statusbtn').click(function() {
  61. if($('#status-loading').is(':hidden')) {
  62. $('#status').hide();
  63. $('#status-loading').show();
  64. $.ajax({
  65. url: '?/status',
  66. }).done(function(data) {
  67. $('#status-loading').hide();
  68. $('#status-text').html('<ul>' + data + '</ul>');
  69. $('#status').show('slow');
  70. });
  71. }
  72. });
  73. $('#raw_openvpn_btn').click(function() {
  74. $('#raw_openvpn_btnpanel').hide();
  75. $('#raw_openvpn_panel').show('low');
  76. });
  77. });