edit.web.js 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138
  1. App.Actions.WEB.update_ftp_username_hint = function(elm, hint) {
  2. if (hint.trim() == '') {
  3. $(elm).parent().find('.hint').html('');
  4. }
  5. hint = hint.replace(/[^\w\d]/gi, '');
  6. if (hint.indexOf(GLOBAL.FTP_USER_PREFIX) == 0) {
  7. hint = hint.slice(GLOBAL.FTP_USER_PREFIX.length, hint.length);
  8. }
  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).attr('name').replace('%INDEX%', index);
  65. $(elm).attr('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. //
  115. // Page entry point
  116. App.Listeners.WEB.keypress_ftp_username();
  117. App.Listeners.WEB.keypress_ftp_path();