add.web.js 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. //
  2. //
  3. // Updates ftp username dynamically, showing its prefix
  4. App.Actions.WEB.update_ftp_username_hint = function(elm, hint) {
  5. if (hint.trim() == '') {
  6. $(elm).parent().find('.hint').html('');
  7. }
  8. // remove prefix from value in order to eliminate duplicates
  9. if (hint.indexOf(GLOBAL.FTP_USER_PREFIX) == 0) {
  10. hint = hint.slice(GLOBAL.FTP_USER_PREFIX.length, hint.length);
  11. }
  12. $(elm).parent().find('.hint').text(GLOBAL.FTP_USER_PREFIX + hint);
  13. }
  14. //
  15. // listener that triggers ftp user hint updating
  16. App.Listeners.WEB.keypress_ftp_username = function() {
  17. var ref = $('input[name="v_ftp_user"]');
  18. var current_val = ref.val();
  19. if (current_val.trim() != '') {
  20. App.Actions.DB.update_ftp_username_hint(ref, current_val);
  21. }
  22. ref.bind('keypress input', function(evt) {
  23. clearTimeout(window.frp_usr_tmt);
  24. window.frp_usr_tmt = setTimeout(function() {
  25. var elm = $(evt.target);
  26. App.Actions.WEB.update_ftp_username_hint(elm, $(elm).val());
  27. }, 100);
  28. });
  29. }
  30. //
  31. // Page entry point
  32. // Trigger listeners
  33. App.Listeners.WEB.keypress_ftp_username();