edit_db.js 3.1 KB

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