add_db.js 2.9 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).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.trim() != '') {
  41. App.Actions.DB.update_db_databasename_hint(ref, current_val);
  42. }
  43. ref.bind('keypress input', function(evt) {
  44. clearTimeout(window.frp_dbn_tmt);
  45. window.frp_dbn_tmt = setTimeout(function() {
  46. var elm = $(evt.target);
  47. App.Actions.DB.update_db_databasename_hint(elm, $(elm).val());
  48. }, 100);
  49. });
  50. }
  51. App.Actions.DB.update_v_password = function (){
  52. var password = $('input[name="v_password"]').val();
  53. var min_small = new RegExp(/^(?=.*[a-z]).+$/);
  54. var min_cap = new RegExp(/^(?=.*[A-Z]).+$/);
  55. var min_num = new RegExp(/^(?=.*\d).+$/);
  56. var min_length = 8;
  57. var score = 0;
  58. if(password.length >= min_length) { score = score + 1; }
  59. if(min_small.test(password)) { score = score + 1;}
  60. if(min_cap.test(password)) { score = score + 1;}
  61. if(min_num.test(password)) { score = score+ 1; }
  62. $('#meter').val(score);
  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. var elm = $(evt.target);
  70. App.Actions.DB.update_v_password(elm, $(elm).val());
  71. }, 100);
  72. });
  73. }
  74. App.Listeners.DB.keypress_v_password();
  75. //
  76. // Page entry point
  77. // Trigger listeners
  78. App.Listeners.DB.keypress_db_username();
  79. App.Listeners.DB.keypress_db_databasename();
  80. randomString = function(min_length = 16) {
  81. $('input[name=v_password]').val(randomString2(min_length));
  82. App.Actions.DB.update_v_password();
  83. }