4
0

install.js 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. // @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-3.0
  2. 'use strict';
  3. let timeoutHide;
  4. function showPW_this() {
  5. const id_passwordField = this.getAttribute('data-toggle');
  6. if (this.classList.contains('active')) {
  7. hidePW(id_passwordField);
  8. } else {
  9. showPW(id_passwordField);
  10. }
  11. return false;
  12. }
  13. function showPW(id_passwordField) {
  14. const passwordField = document.getElementById(id_passwordField);
  15. passwordField.setAttribute('type', 'text');
  16. passwordField.nextElementSibling.classList.add('active');
  17. clearTimeout(timeoutHide);
  18. timeoutHide = setTimeout(function () { hidePW(id_passwordField); }, 5000);
  19. return false;
  20. }
  21. function hidePW(id_passwordField) {
  22. clearTimeout(timeoutHide);
  23. const passwordField = document.getElementById(id_passwordField);
  24. passwordField.setAttribute('type', 'password');
  25. passwordField.nextElementSibling.classList.remove('active');
  26. return false;
  27. }
  28. function init_password_observers(parent) {
  29. parent.querySelectorAll('.toggle-password').forEach(function (btn) {
  30. btn.addEventListener('click', showPW_this);
  31. });
  32. }
  33. init_password_observers(document.body);
  34. const auth_type = document.getElementById('auth_type');
  35. function auth_type_change() {
  36. if (auth_type) {
  37. const auth_value = auth_type.value;
  38. const password_input = document.getElementById('passwordPlain');
  39. if (auth_value === 'form') {
  40. password_input.required = true;
  41. } else {
  42. password_input.required = false;
  43. }
  44. }
  45. }
  46. if (auth_type) {
  47. auth_type_change();
  48. auth_type.addEventListener('change', auth_type_change);
  49. }
  50. function mySqlShowHide() {
  51. const mysql = document.getElementById('mysql');
  52. if (mysql) {
  53. if (document.getElementById('type').value === 'sqlite') {
  54. document.getElementById('host').value = '';
  55. document.getElementById('user').value = '';
  56. document.getElementById('pass').value = '';
  57. document.getElementById('base').value = '';
  58. document.getElementById('prefix').value = '';
  59. mysql.style.display = 'none';
  60. } else {
  61. mysql.style.display = 'block';
  62. }
  63. }
  64. }
  65. const bd_type = document.getElementById('type');
  66. if (bd_type) {
  67. mySqlShowHide();
  68. bd_type.addEventListener('change', mySqlShowHide);
  69. }
  70. function ask_confirmation(ev) {
  71. const str_confirmation = ev.target.getAttribute('data-str-confirm');
  72. if (!confirm(str_confirmation)) {
  73. ev.preventDefault();
  74. }
  75. }
  76. const confirms = document.getElementsByClassName('confirm');
  77. for (let i = 0; i < confirms.length; i++) {
  78. confirms[i].addEventListener('click', ask_confirmation);
  79. }
  80. // @license-end