You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

install.js 2.6KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. import $ from 'jquery';
  2. import {hideElem, showElem} from '../utils/dom.js';
  3. export function initInstall() {
  4. if ($('.page-content.install').length === 0) {
  5. return;
  6. }
  7. const defaultDbUser = 'gitea';
  8. const defaultDbName = 'gitea';
  9. const defaultDbHosts = {
  10. mysql: '127.0.0.1:3306',
  11. postgres: '127.0.0.1:5432',
  12. mssql: '127.0.0.1:1433'
  13. };
  14. const $dbHost = $('#db_host');
  15. const $dbUser = $('#db_user');
  16. const $dbName = $('#db_name');
  17. // Database type change detection.
  18. $('#db_type').on('change', function () {
  19. const dbType = $(this).val();
  20. hideElem($('div[data-db-setting-for]'));
  21. showElem($(`div[data-db-setting-for=${dbType}]`));
  22. if (dbType !== 'sqlite3') {
  23. // for most remote database servers
  24. showElem($(`div[data-db-setting-for=common-host]`));
  25. const lastDbHost = $dbHost.val();
  26. const isDbHostDefault = !lastDbHost || Object.values(defaultDbHosts).includes(lastDbHost);
  27. if (isDbHostDefault) {
  28. $dbHost.val(defaultDbHosts[dbType] ?? '');
  29. }
  30. if (!$dbUser.val() && !$dbName.val()) {
  31. $dbUser.val(defaultDbUser);
  32. $dbName.val(defaultDbName);
  33. }
  34. } // else: for SQLite3, the default path is always prepared by backend code (setting)
  35. }).trigger('change');
  36. // TODO: better handling of exclusive relations.
  37. $('#offline-mode input').on('change', function () {
  38. if ($(this).is(':checked')) {
  39. $('#disable-gravatar').checkbox('check');
  40. $('#federated-avatar-lookup').checkbox('uncheck');
  41. }
  42. });
  43. $('#disable-gravatar input').on('change', function () {
  44. if ($(this).is(':checked')) {
  45. $('#federated-avatar-lookup').checkbox('uncheck');
  46. } else {
  47. $('#offline-mode').checkbox('uncheck');
  48. }
  49. });
  50. $('#federated-avatar-lookup input').on('change', function () {
  51. if ($(this).is(':checked')) {
  52. $('#disable-gravatar').checkbox('uncheck');
  53. $('#offline-mode').checkbox('uncheck');
  54. }
  55. });
  56. $('#enable-openid-signin input').on('change', function () {
  57. if ($(this).is(':checked')) {
  58. if (!$('#disable-registration input').is(':checked')) {
  59. $('#enable-openid-signup').checkbox('check');
  60. }
  61. } else {
  62. $('#enable-openid-signup').checkbox('uncheck');
  63. }
  64. });
  65. $('#disable-registration input').on('change', function () {
  66. if ($(this).is(':checked')) {
  67. $('#enable-captcha').checkbox('uncheck');
  68. $('#enable-openid-signup').checkbox('uncheck');
  69. } else {
  70. $('#enable-openid-signup').checkbox('check');
  71. }
  72. });
  73. $('#enable-captcha input').on('change', function () {
  74. if ($(this).is(':checked')) {
  75. $('#disable-registration').checkbox('uncheck');
  76. }
  77. });
  78. }