custom.js 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. function ready() {
  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. $('#form').on("submit", function(event) {
  63. event.preventDefault()
  64. $('#save').prop('disabled', true);
  65. $('#save-loading').show();
  66. $.ajax({
  67. url: this.action,
  68. type: this.method,
  69. contentType: false,
  70. processData: false,
  71. cache: false,
  72. data: new FormData(this),
  73. headers: {
  74. 'X-Requested-With': 'jQuery',
  75. },
  76. dataType: "html",
  77. success: function(data){
  78. document.body.innerHTML = new DOMParser().parseFromString(data, "text/html").body.innerHTML
  79. ready()
  80. },
  81. error: function() {
  82. $('#save').prop('disabled', false);
  83. $('#save-loading').hide();
  84. },
  85. });
  86. })
  87. $('#status .close').click(function() {
  88. $(this).parent().hide();
  89. });
  90. $('#statusbtn').click(function() {
  91. if($('#status-loading').is(':hidden')) {
  92. $('#status').hide();
  93. $('#status-loading').show();
  94. $.ajax({
  95. url: '?/status',
  96. }).done(function(data) {
  97. $('#status-loading').hide();
  98. $('#status-text').html('<ul>' + data + '</ul>');
  99. $('#status').show('slow');
  100. });
  101. }
  102. });
  103. $('#raw_openvpn_btn').click(function() {
  104. $('#raw_openvpn_btnpanel').hide();
  105. $('#raw_openvpn_panel').show('low');
  106. });
  107. $('#service_enabled').change(function() {
  108. if($('#service_enabled').parent().hasClass('off')) {
  109. $('.enabled').hide('slow');
  110. } else {
  111. $('.enabled').show('slow');
  112. }
  113. });
  114. }
  115. $(document).ready(ready)