add.web.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158
  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. App.Listeners.WEB.keypress_domain_name = function() {
  30. $('#v_domain').bind('keypress input', function(evt) {
  31. clearTimeout(window.frp_usr_tmt);
  32. window.frp_usr_tmt = setTimeout(function() {
  33. //var elm = $(evt.target);
  34. //App.Actions.WEB.update_ftp_username_hint(elm, $(elm).val());
  35. var domain = $('.ftp-path-prefix').text(GLOBAL.FTP_USER_PREPATH + '/' + $('#v_domain').val());
  36. }, 100);
  37. });
  38. }
  39. //
  40. //
  41. App.Actions.WEB.update_ftp_path_hint = function(elm, hint) {
  42. if (hint.trim() == '') {
  43. $(elm).parent().find('.v-ftp-path-hint').html('');
  44. }
  45. if (hint[0] != '/') {
  46. hint = '/' + hint;
  47. }
  48. hint = hint.replace(/\/(\/+)/g, '/');
  49. $(elm).parent().find('.v-ftp-path-hint').text(hint);
  50. }
  51. App.Listeners.WEB.keypress_ftp_path = function() {
  52. var ftp_path_inputs = $('.v-ftp-path');
  53. $.each(ftp_path_inputs, function(i, ref) {
  54. var ref = $(ref);
  55. var current_val = ref.val();
  56. if (current_val.trim() != '') {
  57. App.Actions.WEB.update_ftp_path_hint(ref, current_val);
  58. }
  59. ref.bind('keypress input', function(evt) {
  60. clearTimeout(window.frp_usr_tmt);
  61. window.frp_usr_tmt = setTimeout(function() {
  62. var elm = $(evt.target);
  63. App.Actions.WEB.update_ftp_path_hint(elm, $(elm).val());
  64. }, 100);
  65. });
  66. });
  67. }
  68. //
  69. //
  70. App.Actions.WEB.add_ftp_user_form = function() {
  71. var ref = $('#templates').find('.ftptable').clone(true);
  72. var index = $('.data-col2 .ftptable').length + 1;
  73. ref.find('input').each(function(i, elm) {
  74. var attr_value = $(elm).attr('name').replace('%INDEX%', index);
  75. $(elm).attr('name', attr_value);
  76. });
  77. ref.find('.ftp-user-number').text(index);
  78. $('.data-col2 .ftptable:last').after(ref);
  79. var index = 1;
  80. $('.data-col2 .ftp-user-number:visible').each(function(i, o) {
  81. $(o).text(index);
  82. index += 1;
  83. });
  84. }
  85. App.Actions.WEB.remove_ftp_user = function(elm) {
  86. var ref = $(elm).parents('.ftptable');
  87. ref.remove();
  88. var index = 1;
  89. $('.data-col2 .ftp-user-number:visible').each(function(i, o) {
  90. $(o).text(index);
  91. index += 1;
  92. });
  93. if ($('.ftptable-nrm:visible').length == 0) {
  94. $('.v-add-new-user').hide();
  95. $('input[name="v_ftp"]').attr('checked', false);
  96. }
  97. }
  98. App.Actions.WEB.toggle_additional_ftp_accounts = function(elm) {
  99. if ($(elm).attr('checked')) {
  100. $('.ftptable-nrm, .v-add-new-user, .add-new-ftp-user-button').show();
  101. $('.ftptable-nrm').each(function(i, elm) {
  102. var login = $(elm).find('.v-ftp-user');
  103. if (login.val().trim() != '') {
  104. $(elm).find('.v-ftp-user-deleted').val(0);
  105. }
  106. });
  107. }
  108. else {
  109. $('.ftptable-nrm, .v-add-new-user, .add-new-ftp-user-button').hide();
  110. $('.ftptable-nrm').each(function(i, elm) {
  111. var login = $(elm).find('.v-ftp-user');
  112. if (login.val().trim() != '') {
  113. $(elm).find('.v-ftp-user-deleted').val(1);
  114. }
  115. });
  116. }
  117. if ($('.ftptable-nrm:visible').length == 0) {
  118. var ref = $('#templates').find('.ftptable').clone(true);
  119. var index = $('.data-col2 .ftptable').length + 1;
  120. ref.find('input').each(function(i, elm) {
  121. var attr_value = $(elm).attr('name').replace('%INDEX%', index);
  122. $(elm).attr('name', attr_value);
  123. });
  124. ref.find('.ftp-user-number').text(index);
  125. $('.v-add-new-user').parent('tr').prev().find('td').html(ref);
  126. }
  127. }
  128. //
  129. // Page entry point
  130. App.Listeners.WEB.keypress_ftp_username();
  131. App.Listeners.WEB.keypress_ftp_path();
  132. App.Listeners.WEB.keypress_domain_name();