code.gitea.io/gitea@v1.21.7/web_src/js/features/install.js (about) 1 import $ from 'jquery'; 2 import {hideElem, showElem} from '../utils/dom.js'; 3 import {GET} from '../modules/fetch.js'; 4 5 export function initInstall() { 6 const $page = $('.page-content.install'); 7 if ($page.length === 0) { 8 return; 9 } 10 if ($page.is('.post-install')) { 11 initPostInstall(); 12 } else { 13 initPreInstall(); 14 } 15 } 16 17 function initPreInstall() { 18 const defaultDbUser = 'gitea'; 19 const defaultDbName = 'gitea'; 20 21 const defaultDbHosts = { 22 mysql: '127.0.0.1:3306', 23 postgres: '127.0.0.1:5432', 24 mssql: '127.0.0.1:1433' 25 }; 26 27 const $dbHost = $('#db_host'); 28 const $dbUser = $('#db_user'); 29 const $dbName = $('#db_name'); 30 31 // Database type change detection. 32 $('#db_type').on('change', function () { 33 const dbType = $(this).val(); 34 hideElem($('div[data-db-setting-for]')); 35 showElem($(`div[data-db-setting-for=${dbType}]`)); 36 37 if (dbType !== 'sqlite3') { 38 // for most remote database servers 39 showElem($(`div[data-db-setting-for=common-host]`)); 40 const lastDbHost = $dbHost.val(); 41 const isDbHostDefault = !lastDbHost || Object.values(defaultDbHosts).includes(lastDbHost); 42 if (isDbHostDefault) { 43 $dbHost.val(defaultDbHosts[dbType] ?? ''); 44 } 45 if (!$dbUser.val() && !$dbName.val()) { 46 $dbUser.val(defaultDbUser); 47 $dbName.val(defaultDbName); 48 } 49 } // else: for SQLite3, the default path is always prepared by backend code (setting) 50 }).trigger('change'); 51 52 const $appUrl = $('#app_url'); 53 const configAppUrl = $appUrl.val(); 54 if (configAppUrl.includes('://localhost')) { 55 $appUrl.val(window.location.href); 56 } 57 58 const $domain = $('#domain'); 59 const configDomain = $domain.val().trim(); 60 if (configDomain === 'localhost') { 61 $domain.val(window.location.hostname); 62 } 63 64 // TODO: better handling of exclusive relations. 65 $('#offline-mode input').on('change', function () { 66 if ($(this).is(':checked')) { 67 $('#disable-gravatar').checkbox('check'); 68 $('#federated-avatar-lookup').checkbox('uncheck'); 69 } 70 }); 71 $('#disable-gravatar input').on('change', function () { 72 if ($(this).is(':checked')) { 73 $('#federated-avatar-lookup').checkbox('uncheck'); 74 } else { 75 $('#offline-mode').checkbox('uncheck'); 76 } 77 }); 78 $('#federated-avatar-lookup input').on('change', function () { 79 if ($(this).is(':checked')) { 80 $('#disable-gravatar').checkbox('uncheck'); 81 $('#offline-mode').checkbox('uncheck'); 82 } 83 }); 84 $('#enable-openid-signin input').on('change', function () { 85 if ($(this).is(':checked')) { 86 if (!$('#disable-registration input').is(':checked')) { 87 $('#enable-openid-signup').checkbox('check'); 88 } 89 } else { 90 $('#enable-openid-signup').checkbox('uncheck'); 91 } 92 }); 93 $('#disable-registration input').on('change', function () { 94 if ($(this).is(':checked')) { 95 $('#enable-captcha').checkbox('uncheck'); 96 $('#enable-openid-signup').checkbox('uncheck'); 97 } else { 98 $('#enable-openid-signup').checkbox('check'); 99 } 100 }); 101 $('#enable-captcha input').on('change', function () { 102 if ($(this).is(':checked')) { 103 $('#disable-registration').checkbox('uncheck'); 104 } 105 }); 106 } 107 108 function initPostInstall() { 109 const el = document.getElementById('goto-user-login'); 110 if (!el) return; 111 112 const targetUrl = el.getAttribute('href'); 113 let tid = setInterval(async () => { 114 try { 115 const resp = await GET(targetUrl); 116 if (tid && resp.status === 200) { 117 clearInterval(tid); 118 tid = null; 119 window.location.href = targetUrl; 120 } 121 } catch {} 122 }, 1000); 123 }