edit_web.js 7.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. App.Actions.WEB.update_ftp_username_hint = function(elm, hint) {
  2. if (hint.trim() == '') {
  3. $(elm).parent().find('.hint').html('');
  4. }
  5. if (hint.indexOf(GLOBAL.FTP_USER_PREFIX) == 0) {
  6. hint = hint.slice(GLOBAL.FTP_USER_PREFIX.length, hint.length);
  7. }
  8. hint = hint.replace(/[^\w\d]/gi, '');
  9. $(elm).parent().find('.v-ftp-user').val(hint);
  10. $(elm).parent().find('.hint').text(GLOBAL.FTP_USER_PREFIX + hint);
  11. }
  12. App.Listeners.WEB.keypress_ftp_username = function() {
  13. var ftp_user_inputs = $('.v-ftp-user');
  14. $.each(ftp_user_inputs, function(i, ref) {
  15. var ref = $(ref);
  16. var current_val = ref.val();
  17. if (current_val.trim() != '') {
  18. App.Actions.WEB.update_ftp_username_hint(ref, current_val);
  19. }
  20. ref.bind('keypress input', function(evt) {
  21. clearTimeout(window.frp_usr_tmt);
  22. window.frp_usr_tmt = setTimeout(function() {
  23. var elm = $(evt.target);
  24. App.Actions.WEB.update_ftp_username_hint(elm, $(elm).val());
  25. }, 100);
  26. });
  27. });
  28. }
  29. //
  30. //
  31. App.Actions.WEB.update_ftp_path_hint = function(elm, hint) {
  32. if (hint.trim() == '') {
  33. $(elm).parent().find('.v-ftp-path-hint').html('');
  34. }
  35. if (hint[0] != '/') {
  36. hint = '/' + hint;
  37. }
  38. hint = hint.replace(/\/(\/+)/g, '/');
  39. $(elm).parent().find('.v-ftp-path-hint').text(hint);
  40. }
  41. App.Listeners.WEB.keypress_ftp_path = function() {
  42. var ftp_path_inputs = $('.v-ftp-path');
  43. $.each(ftp_path_inputs, function(i, ref) {
  44. var ref = $(ref);
  45. var current_val = ref.val();
  46. if (current_val.trim() != '') {
  47. App.Actions.WEB.update_ftp_path_hint(ref, current_val);
  48. }
  49. ref.bind('keypress input', function(evt) {
  50. clearTimeout(window.frp_usr_tmt);
  51. window.frp_usr_tmt = setTimeout(function() {
  52. var elm = $(evt.target);
  53. App.Actions.WEB.update_ftp_path_hint(elm, $(elm).val());
  54. }, 100);
  55. });
  56. });
  57. }
  58. //
  59. //
  60. App.Actions.WEB.add_ftp_user_form = function() {
  61. var ref = $('#templates').find('.ftptable').clone(true);
  62. var index = $('.data-col2 .ftptable').length + 1;
  63. ref.find('input').each(function(i, elm) {
  64. var attr_value = $(elm).prop('name').replace('%INDEX%', index);
  65. $(elm).prop('name', attr_value);
  66. });
  67. ref.find('.ftp-user-number').text(index);
  68. $('.data-col2 .ftptable:last').after(ref);
  69. var index = 1;
  70. $('.data-col2 .ftp-user-number:visible').each(function(i, o) {
  71. $(o).text(index);
  72. index += 1;
  73. });
  74. }
  75. App.Actions.WEB.remove_ftp_user = function(elm) {
  76. var ref = $(elm).parents('.ftptable');
  77. ref.find('.v-ftp-user-deleted').val('1');
  78. if (ref.find('.v-ftp-user-is-new').val() == 1) {
  79. ref.remove();
  80. return true;
  81. }
  82. ref.removeClass('ftptable-nrm');
  83. ref.hide();
  84. var index = 1;
  85. $('.data-col2 .ftp-user-number:visible').each(function(i, o) {
  86. $(o).text(index);
  87. index += 1;
  88. });
  89. if ($('.ftptable-nrm:visible').length == 0) {
  90. $('.add-new-ftp-user-button').hide();
  91. $('input[name="v_ftp"]').attr('checked', false);
  92. }
  93. }
  94. App.Actions.WEB.toggle_additional_ftp_accounts = function(elm) {
  95. if ($(elm).attr('checked')) {
  96. $('.ftptable-nrm, .v-add-new-user, .add-new-ftp-user-button').show();
  97. $('.ftptable-nrm').each(function(i, elm) {
  98. var login = $(elm).find('.v-ftp-user');
  99. if (login.val().trim() != '') {
  100. $(elm).find('.v-ftp-user-deleted').val(0);
  101. }
  102. });
  103. }
  104. else {
  105. $('.ftptable-nrm, .v-add-new-user, .add-new-ftp-user-button').hide();
  106. $('.ftptable-nrm').each(function(i, elm) {
  107. var login = $(elm).find('.v-ftp-user');
  108. if (login.val().trim() != '') {
  109. $(elm).find('.v-ftp-user-deleted').val(1);
  110. }
  111. });
  112. }
  113. }
  114. App.Actions.WEB.toggle_letsencrypt = function(elm) {
  115. if ($(elm).attr('checked')) {
  116. $('#ssltable textarea[name=v_ssl_crt],#ssltable textarea[name=v_ssl_key], #ssltable textarea[name=v_ssl_ca]').attr('disabled', 'disabled');
  117. $('#generate-csr').hide();
  118. if(!$('.lets-encrypt-note').hasClass('enabled')){
  119. $('.lets-encrypt-note').show();
  120. }
  121. }
  122. else {
  123. $('#ssltable textarea[name=v_ssl_crt],#ssltable textarea[name=v_ssl_key], #ssltable textarea[name=v_ssl_ca]').removeAttr('disabled');
  124. $('#generate-csr').show();
  125. $('.lets-encrypt-note').hide();
  126. }
  127. }
  128. App.Actions.WEB.randomPasswordGenerated = function(elm) {
  129. return App.Actions.WEB.passwordChanged(elm);
  130. }
  131. App.Actions.WEB.passwordChanged = function(elm) {
  132. var ref = $(elm).parents('.ftptable');
  133. if (ref.find('.vst-email-alert-on-psw').length == 0) {
  134. var inp_name = ref.find('.v-ftp-user-is-new').prop('name');
  135. inp_name = inp_name.replace('is_new', 'v_ftp_email');
  136. ref.find('tr:last').after('<tr>\
  137. <td class="vst-text step-left input-label">\
  138. Send FTP credentials to email\
  139. </td>\
  140. </tr>\
  141. <tr>\
  142. <td class="step-left">\
  143. <input type="text" value="" name="' + inp_name + '" class="vst-input vst-email-alert-on-psw">\
  144. </td>\
  145. </tr>');
  146. }
  147. }
  148. //
  149. // Page entry point
  150. App.Listeners.WEB.keypress_ftp_username();
  151. App.Listeners.WEB.keypress_ftp_path();
  152. $(function() {
  153. $('.v-ftp-user-psw').on('keypress', function (evt) {
  154. var elm = $(evt.target);
  155. App.Actions.WEB.passwordChanged(elm);
  156. });
  157. App.Actions.WEB.toggle_letsencrypt($('input[name=v_letsencrypt]'));
  158. $('select[name="v_stats"]').change(function(evt){
  159. var select = $(evt.target);
  160. if(select.val() == 'none'){
  161. $('.stats-auth').hide();
  162. } else {
  163. $('.stats-auth').show();
  164. }
  165. });
  166. });
  167. function WEBrandom() {
  168. var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz';
  169. var string_length = 10;
  170. var webrandom = '';
  171. for (var i = 0; i < string_length; i++) {
  172. var rnum = Math.floor(Math.random() * chars.length);
  173. webrandom += chars.substr(rnum, 1);
  174. }
  175. document.v_edit_web.v_stats_password.value = webrandom;
  176. }
  177. function FTPrandom(elm) {
  178. var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz';
  179. var string_length = 10;
  180. var ftprandomstring = '';
  181. for (var i = 0; i < string_length; i++) {
  182. var rnum = Math.floor(Math.random() * chars.length);
  183. ftprandomstring += chars.substr(rnum, 1);
  184. }
  185. $(elm).parents('.ftptable').find('.v-ftp-user-psw').val(ftprandomstring);
  186. App.Actions.WEB.randomPasswordGenerated && App.Actions.WEB.randomPasswordGenerated(elm);
  187. }
  188. function elementHideShow(elementToHideOrShow){
  189. var el = document.getElementById(elementToHideOrShow);
  190. el.style.display = el.style.display === 'none' ? 'block' : 'none';
  191. }
  192. $('#vstobjects').bind('submit', function(evt) {
  193. $('input[disabled]').each(function(i, elm) {
  194. var copy_elm = $(elm).clone(true);
  195. $(copy_elm).attr('type', 'hidden');
  196. $(copy_elm).removeAttr('disabled');
  197. $(elm).after(copy_elm);
  198. });
  199. });