edit_db.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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').text('');
  7. }
  8. $(elm)
  9. .parent()
  10. .find('.hint')
  11. .text(Alpine.store('globals').DB_USER_PREFIX + hint);
  12. };
  13. //
  14. //
  15. // Updates database name dynamically, showing its prefix
  16. App.Actions.DB.update_db_databasename_hint = function (elm, hint) {
  17. if (hint.trim() == '') {
  18. $(elm).parent().find('.hint').text('');
  19. }
  20. $(elm)
  21. .parent()
  22. .find('.hint')
  23. .text(Alpine.store('globals').DB_DBNAME_PREFIX + hint);
  24. };
  25. //
  26. // listener that triggers database user hint updating
  27. App.Listeners.DB.keypress_db_username = function () {
  28. var ref = $('input[name="v_dbuser"]');
  29. var current_val = ref.val();
  30. if (current_val.trim() != '') {
  31. App.Actions.DB.update_db_username_hint(ref, current_val);
  32. }
  33. ref.bind('keypress input', function (evt) {
  34. clearTimeout(window.frp_usr_tmt);
  35. window.frp_usr_tmt = setTimeout(function () {
  36. var elm = $(evt.target);
  37. App.Actions.DB.update_db_username_hint(elm, $(elm).val());
  38. }, 100);
  39. });
  40. };
  41. //
  42. // listener that triggers database name hint updating
  43. App.Listeners.DB.keypress_db_databasename = function () {
  44. var ref = $('input[name="v_database"]');
  45. var current_val = ref.val();
  46. if (current_val.indexOf(Alpine.store('globals').DB_DBNAME_PREFIX) == 0) {
  47. current_val = current_val.slice(
  48. Alpine.store('globals').DB_DBNAME_PREFIX.length,
  49. current_val.length
  50. );
  51. ref.val(current_val);
  52. }
  53. if (current_val.trim() != '') {
  54. App.Actions.DB.update_db_username_hint(ref, current_val);
  55. }
  56. ref.bind('keypress input', function (evt) {
  57. clearTimeout(window.frp_dbn_tmt);
  58. window.frp_dbn_tmt = setTimeout(function () {
  59. var elm = $(evt.target);
  60. App.Actions.DB.update_db_databasename_hint(elm, $(elm).val());
  61. }, 100);
  62. });
  63. };
  64. App.Listeners.DB.keypress_v_password = function () {
  65. var ref = $('input[name="v_password"]');
  66. ref.bind('keypress input', function (evt) {
  67. clearTimeout(window.frp_usr_tmt);
  68. window.frp_usr_tmt = setTimeout(function () {
  69. VE.helpers.recalculatePasswordStrength(evt.target);
  70. }, 100);
  71. });
  72. };
  73. App.Listeners.DB.keypress_v_password();
  74. //
  75. // Page entry point
  76. // Trigger listeners
  77. App.Listeners.DB.keypress_db_username();
  78. App.Listeners.DB.keypress_db_databasename();
  79. applyRandomPassword = function (min_length = 16) {
  80. const passwordInput = document.querySelector('input[name=v_password]');
  81. if (passwordInput) {
  82. passwordInput.value = randomString(min_length);
  83. VE.helpers.recalculatePasswordStrength(passwordInput);
  84. }
  85. };