edit_web.js 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204
  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.randomPasswordGenerated = function(elm) {
  115. return App.Actions.WEB.passwordChanged(elm);
  116. }
  117. App.Actions.WEB.passwordChanged = function(elm) {
  118. var ref = $(elm).parents('.ftptable');
  119. if (ref.find('.vst-email-alert-on-psw').length == 0) {
  120. var inp_name = ref.find('.v-ftp-user-is-new').prop('name');
  121. inp_name = inp_name.replace('is_new', 'v_ftp_email');
  122. ref.find('tr:last').after('<tr>\
  123. <td class="vst-text step-left input-label">\
  124. Send FTP credentials to email\
  125. </td>\
  126. </tr>\
  127. <tr>\
  128. <td class="step-left">\
  129. <input type="text" value="" name="' + inp_name + '" class="vst-input vst-email-alert-on-psw">\
  130. </td>\
  131. </tr>');
  132. }
  133. }
  134. //
  135. // Page entry point
  136. App.Listeners.WEB.keypress_ftp_username();
  137. App.Listeners.WEB.keypress_ftp_path();
  138. $('.v-ftp-user-psw').on('keypress', function(evt) {
  139. var elm = $(evt.target);
  140. App.Actions.WEB.passwordChanged(elm);
  141. });
  142. function WEBrandom() {
  143. var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz';
  144. var string_length = 10;
  145. var webrandom = '';
  146. for (var i = 0; i < string_length; i++) {
  147. var rnum = Math.floor(Math.random() * chars.length);
  148. webrandom += chars.substr(rnum, 1);
  149. }
  150. document.v_edit_web.v_stats_password.value = webrandom;
  151. }
  152. function FTPrandom(elm) {
  153. var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz';
  154. var string_length = 10;
  155. var ftprandomstring = '';
  156. for (var i = 0; i < string_length; i++) {
  157. var rnum = Math.floor(Math.random() * chars.length);
  158. ftprandomstring += chars.substr(rnum, 1);
  159. }
  160. $(elm).parents('.ftptable').find('.v-ftp-user-psw').val(ftprandomstring);
  161. App.Actions.WEB.randomPasswordGenerated && App.Actions.WEB.randomPasswordGenerated(elm);
  162. }
  163. function elementHideShow(elementToHideOrShow){
  164. var el = document.getElementById(elementToHideOrShow);
  165. el.style.display = el.style.display === 'none' ? 'block' : 'none';
  166. }
  167. $('#vstobjects').bind('submit', function(evt) {
  168. $('input[disabled]').each(function(i, elm) {
  169. var copy_elm = $(elm).clone(true);
  170. $(copy_elm).attr('type', 'hidden');
  171. $(copy_elm).removeAttr('disabled');
  172. $(elm).after(copy_elm);
  173. });
  174. });