add_db.js 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. //
  2. //
  3. // Updates database username dynamically, showing its prefix
  4. App.Actions.DB.update_db_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.DB_USER_PREFIX) == 0) {
  10. hint = hint.slice(GLOBAL.DB_USER_PREFIX.length, hint.length);
  11. }
  12. $(elm).parent().find('.hint').text(GLOBAL.DB_USER_PREFIX + hint);
  13. }
  14. //
  15. //
  16. // Updates database name dynamically, showing its prefix
  17. App.Actions.DB.update_db_databasename_hint = function(elm, hint) {
  18. if (hint.trim() == '') {
  19. $(elm).parent().find('.hint').html('');
  20. }
  21. // remove prefix from value in order to eliminate duplicates
  22. if (hint.indexOf(GLOBAL.DB_DBNAME_PREFIX) == 0) {
  23. hint = hint.slice(GLOBAL.DB_DBNAME_PREFIX.length, hint.length);
  24. }
  25. $(elm).parent().find('.hint').text(GLOBAL.DB_DBNAME_PREFIX + hint);
  26. }
  27. //
  28. // listener that triggers database user hint updating
  29. App.Listeners.DB.keypress_db_username = function() {
  30. var ref = $('input[name="v_dbuser"]');
  31. var current_val = ref.val();
  32. if (current_val.trim() != '') {
  33. App.Actions.DB.update_db_username_hint(ref, current_val);
  34. }
  35. ref.bind('keypress input', function(evt) {
  36. clearTimeout(window.frp_usr_tmt);
  37. window.frp_usr_tmt = setTimeout(function() {
  38. var elm = $(evt.target);
  39. App.Actions.DB.update_db_username_hint(elm, $(elm).val());
  40. }, 100);
  41. });
  42. }
  43. //
  44. // listener that triggers database name hint updating
  45. App.Listeners.DB.keypress_db_databasename = function() {
  46. var ref = $('input[name="v_database"]');
  47. var current_val = ref.val();
  48. if (current_val.trim() != '') {
  49. App.Actions.DB.update_db_databasename_hint(ref, current_val);
  50. }
  51. ref.bind('keypress input', function(evt) {
  52. clearTimeout(window.frp_dbn_tmt);
  53. window.frp_dbn_tmt = setTimeout(function() {
  54. var elm = $(evt.target);
  55. App.Actions.DB.update_db_databasename_hint(elm, $(elm).val());
  56. }, 100);
  57. });
  58. }
  59. //
  60. // Page entry point
  61. // Trigger listeners
  62. App.Listeners.DB.keypress_db_username();
  63. App.Listeners.DB.keypress_db_databasename();
  64. randomString = function() {
  65. var chars = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXTZabcdefghiklmnopqrstuvwxyz';
  66. var string_length = 10;
  67. var randomstring = '';
  68. for (var i = 0; i < string_length; i++) {
  69. var rnum = Math.floor(Math.random() * chars.length);
  70. randomstring += chars.substr(rnum, 1);
  71. }
  72. document.v_add_db.v_password.value = randomstring;
  73. }