mirror of
https://codeberg.org/forgejo/forgejo.git
synced 2024-11-29 09:31:11 -05:00
Remove jQuery from the installation page (#29284)
- Switched to plain JavaScript - Tested the installation page functionality and it works as before # Demo using JavaScript without jQuery ![action](https://github.com/go-gitea/gitea/assets/20454870/286475b3-1919-4d99-b790-def10fa36e66) Signed-off-by: Yarden Shoham <git@yardenshoham.com> (cherry picked from commit 4e536edaead97d61a64508db0e93cf781a889472)
This commit is contained in:
parent
2c8f112c1c
commit
769db26c5a
1 changed files with 49 additions and 52 deletions
|
@ -1,19 +1,17 @@
|
||||||
import $ from 'jquery';
|
|
||||||
import {hideElem, showElem} from '../utils/dom.js';
|
import {hideElem, showElem} from '../utils/dom.js';
|
||||||
import {GET} from '../modules/fetch.js';
|
import {GET} from '../modules/fetch.js';
|
||||||
|
|
||||||
export function initInstall() {
|
export function initInstall() {
|
||||||
const $page = $('.page-content.install');
|
const page = document.querySelector('.page-content.install');
|
||||||
if ($page.length === 0) {
|
if (!page) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ($page.is('.post-install')) {
|
if (page.classList.contains('post-install')) {
|
||||||
initPostInstall();
|
initPostInstall();
|
||||||
} else {
|
} else {
|
||||||
initPreInstall();
|
initPreInstall();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function initPreInstall() {
|
function initPreInstall() {
|
||||||
const defaultDbUser = 'forgejo';
|
const defaultDbUser = 'forgejo';
|
||||||
const defaultDbName = 'forgejo';
|
const defaultDbName = 'forgejo';
|
||||||
|
@ -24,83 +22,82 @@ function initPreInstall() {
|
||||||
mssql: '127.0.0.1:1433'
|
mssql: '127.0.0.1:1433'
|
||||||
};
|
};
|
||||||
|
|
||||||
const $dbHost = $('#db_host');
|
const dbHost = document.getElementById('db_host');
|
||||||
const $dbUser = $('#db_user');
|
const dbUser = document.getElementById('db_user');
|
||||||
const $dbName = $('#db_name');
|
const dbName = document.getElementById('db_name');
|
||||||
|
|
||||||
// Database type change detection.
|
// Database type change detection.
|
||||||
$('#db_type').on('change', function () {
|
document.getElementById('db_type').addEventListener('change', function () {
|
||||||
const dbType = $(this).val();
|
const dbType = this.value;
|
||||||
hideElem($('div[data-db-setting-for]'));
|
hideElem('div[data-db-setting-for]');
|
||||||
showElem($(`div[data-db-setting-for=${dbType}]`));
|
showElem(`div[data-db-setting-for=${dbType}]`);
|
||||||
|
|
||||||
if (dbType !== 'sqlite3') {
|
if (dbType !== 'sqlite3') {
|
||||||
// for most remote database servers
|
// for most remote database servers
|
||||||
showElem($(`div[data-db-setting-for=common-host]`));
|
showElem('div[data-db-setting-for=common-host]');
|
||||||
const lastDbHost = $dbHost.val();
|
const lastDbHost = dbHost.value;
|
||||||
const isDbHostDefault = !lastDbHost || Object.values(defaultDbHosts).includes(lastDbHost);
|
const isDbHostDefault = !lastDbHost || Object.values(defaultDbHosts).includes(lastDbHost);
|
||||||
if (isDbHostDefault) {
|
if (isDbHostDefault) {
|
||||||
$dbHost.val(defaultDbHosts[dbType] ?? '');
|
dbHost.value = defaultDbHosts[dbType] ?? '';
|
||||||
}
|
}
|
||||||
if (!$dbUser.val() && !$dbName.val()) {
|
if (!dbUser.value && !dbName.value) {
|
||||||
$dbUser.val(defaultDbUser);
|
dbUser.value = defaultDbUser;
|
||||||
$dbName.val(defaultDbName);
|
dbName.value = defaultDbName;
|
||||||
}
|
}
|
||||||
} // else: for SQLite3, the default path is always prepared by backend code (setting)
|
} // else: for SQLite3, the default path is always prepared by backend code (setting)
|
||||||
}).trigger('change');
|
});
|
||||||
|
document.getElementById('db_type').dispatchEvent(new Event('change'));
|
||||||
|
|
||||||
const $appUrl = $('#app_url');
|
const appUrl = document.getElementById('app_url');
|
||||||
const configAppUrl = $appUrl.val();
|
if (appUrl.value.includes('://localhost')) {
|
||||||
if (configAppUrl.includes('://localhost')) {
|
appUrl.value = window.location.href;
|
||||||
$appUrl.val(window.location.href);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const $domain = $('#domain');
|
const domain = document.getElementById('domain');
|
||||||
const configDomain = $domain.val().trim();
|
if (domain.value.trim() === 'localhost') {
|
||||||
if (configDomain === 'localhost') {
|
domain.value = window.location.hostname;
|
||||||
$domain.val(window.location.hostname);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: better handling of exclusive relations.
|
// TODO: better handling of exclusive relations.
|
||||||
$('#offline-mode input').on('change', function () {
|
document.querySelector('#offline-mode input').addEventListener('change', function () {
|
||||||
if ($(this).is(':checked')) {
|
if (this.checked) {
|
||||||
$('#disable-gravatar').checkbox('check');
|
document.querySelector('#disable-gravatar input').checked = true;
|
||||||
$('#federated-avatar-lookup').checkbox('uncheck');
|
document.querySelector('#federated-avatar-lookup input').checked = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$('#disable-gravatar input').on('change', function () {
|
document.querySelector('#disable-gravatar input').addEventListener('change', function () {
|
||||||
if ($(this).is(':checked')) {
|
if (this.checked) {
|
||||||
$('#federated-avatar-lookup').checkbox('uncheck');
|
document.querySelector('#federated-avatar-lookup input').checked = false;
|
||||||
} else {
|
} else {
|
||||||
$('#offline-mode').checkbox('uncheck');
|
document.querySelector('#offline-mode input').checked = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$('#federated-avatar-lookup input').on('change', function () {
|
document.querySelector('#federated-avatar-lookup input').addEventListener('change', function () {
|
||||||
if ($(this).is(':checked')) {
|
if (this.checked) {
|
||||||
$('#disable-gravatar').checkbox('uncheck');
|
document.querySelector('#disable-gravatar input').checked = false;
|
||||||
$('#offline-mode').checkbox('uncheck');
|
document.querySelector('#offline-mode input').checked = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$('#enable-openid-signin input').on('change', function () {
|
document.querySelector('#enable-openid-signin input').addEventListener('change', function () {
|
||||||
if ($(this).is(':checked')) {
|
if (this.checked) {
|
||||||
if (!$('#disable-registration input').is(':checked')) {
|
if (!document.querySelector('#disable-registration input').checked) {
|
||||||
$('#enable-openid-signup').checkbox('check');
|
document.querySelector('#enable-openid-signup input').checked = true;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$('#enable-openid-signup').checkbox('uncheck');
|
document.querySelector('#enable-openid-signup input').checked = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$('#disable-registration input').on('change', function () {
|
document.querySelector('#disable-registration input').addEventListener('change', function () {
|
||||||
if ($(this).is(':checked')) {
|
if (this.checked) {
|
||||||
$('#enable-captcha').checkbox('uncheck');
|
document.querySelector('#enable-captcha input').checked = false;
|
||||||
$('#enable-openid-signup').checkbox('uncheck');
|
document.querySelector('#enable-openid-signup input').checked = false;
|
||||||
} else {
|
} else {
|
||||||
$('#enable-openid-signup').checkbox('check');
|
document.querySelector('#enable-openid-signup input').checked = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
$('#enable-captcha input').on('change', function () {
|
document.querySelector('#enable-captcha input').addEventListener('change', function () {
|
||||||
if ($(this).is(':checked')) {
|
if (this.checked) {
|
||||||
$('#disable-registration').checkbox('uncheck');
|
document.querySelector('#disable-registration input').checked = false;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue