edit_db.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  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.Actions.DB.update_password_meter = function () {
  65. var password = $('input[name="v_password"]').val();
  66. var min_small = new RegExp(/^(?=.*[a-z]).+$/);
  67. var min_cap = new RegExp(/^(?=.*[A-Z]).+$/);
  68. var min_num = new RegExp(/^(?=.*\d).+$/);
  69. var min_length = 8;
  70. var score = 0;
  71. if (password.length >= min_length) {
  72. score = score + 1;
  73. }
  74. if (min_small.test(password)) {
  75. score = score + 1;
  76. }
  77. if (min_cap.test(password)) {
  78. score = score + 1;
  79. }
  80. if (min_num.test(password)) {
  81. score = score + 1;
  82. }
  83. $('.js-password-meter').val(score);
  84. };
  85. App.Listeners.DB.keypress_v_password = function () {
  86. var ref = $('input[name="v_password"]');
  87. ref.bind('keypress input', function (evt) {
  88. clearTimeout(window.frp_usr_tmt);
  89. window.frp_usr_tmt = setTimeout(function () {
  90. var elm = $(evt.target);
  91. App.Actions.DB.update_password_meter(elm, $(elm).val());
  92. }, 100);
  93. });
  94. };
  95. App.Listeners.DB.keypress_v_password();
  96. //
  97. // Page entry point
  98. // Trigger listeners
  99. App.Listeners.DB.keypress_db_username();
  100. App.Listeners.DB.keypress_db_databasename();
  101. applyRandomPassword = function (min_length = 16) {
  102. $('input[name=v_password]').val(randomString(min_length));
  103. App.Actions.DB.update_password_meter();
  104. };