install.js 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. // @license magnet:?xt=urn:btih:0b31508aeb0634b347b8270c7bee4d411b5d4109&dn=agpl-3.0.txt AGPL-3.0
  2. 'use strict';
  3. (function parseJsonVars() {
  4. const jsonVars = document.getElementById('jsonVars');
  5. const json = JSON.parse(jsonVars.innerHTML);
  6. jsonVars.outerHTML = '';
  7. window.context = { 'i18n': json.i18n };
  8. }());
  9. const auth_type = document.getElementById('auth_type');
  10. function auth_type_change() {
  11. if (auth_type) {
  12. const auth_value = auth_type.value;
  13. const password_input = document.getElementById('passwordPlain');
  14. if (auth_value === 'form') {
  15. password_input.required = true;
  16. } else {
  17. password_input.required = false;
  18. }
  19. }
  20. }
  21. if (auth_type) {
  22. auth_type_change();
  23. auth_type.addEventListener('change', auth_type_change);
  24. }
  25. function mySqlShowHide() {
  26. const mysql = document.getElementById('mysql');
  27. if (mysql) {
  28. if (document.getElementById('type').value === 'sqlite') {
  29. document.getElementById('host').value = '';
  30. document.getElementById('user').value = '';
  31. document.getElementById('pass').value = '';
  32. document.getElementById('base').value = '';
  33. document.getElementById('prefix').value = '';
  34. mysql.style.display = 'none';
  35. } else {
  36. mysql.style.display = 'block';
  37. }
  38. }
  39. }
  40. const db_type = document.getElementById('type');
  41. if (db_type) {
  42. mySqlShowHide();
  43. db_type.addEventListener('change', mySqlShowHide);
  44. }
  45. function ask_confirmation(ev) {
  46. const str_confirmation = ev.target.getAttribute('data-str-confirm');
  47. if (!confirm(str_confirmation)) {
  48. ev.preventDefault();
  49. }
  50. }
  51. const confirms = document.getElementsByClassName('confirm');
  52. for (let i = 0; i < confirms.length; i++) {
  53. confirms[i].addEventListener('click', ask_confirmation);
  54. }
  55. // @license-end