Remove jQuery from the repo migration form (#29229)
- Switched to plain JavaScript - Tested the repo migration form functionality and it works as before # Demo using JavaScript without jQuery ![action](https://github.com/go-gitea/gitea/assets/20454870/3496ec05-48a7-449e-8cdd-f8372ba0d589) --------- Signed-off-by: Yarden Shoham <git@yardenshoham.com> Co-authored-by: silverwind <me@silverwind.io>
This commit is contained in:
parent
35d5e4aea4
commit
100031f5f1
|
@ -1,38 +1,42 @@
|
||||||
import $ from 'jquery';
|
|
||||||
import {hideElem, showElem, toggleElem} from '../utils/dom.js';
|
import {hideElem, showElem, toggleElem} from '../utils/dom.js';
|
||||||
|
|
||||||
const $service = $('#service_type');
|
const service = document.getElementById('service_type');
|
||||||
const $user = $('#auth_username');
|
const user = document.getElementById('auth_username');
|
||||||
const $pass = $('#auth_password');
|
const pass = document.getElementById('auth_password');
|
||||||
const $token = $('#auth_token');
|
const token = document.getElementById('auth_token');
|
||||||
const $mirror = $('#mirror');
|
const mirror = document.getElementById('mirror');
|
||||||
const $lfs = $('#lfs');
|
const lfs = document.getElementById('lfs');
|
||||||
const $lfsSettings = $('#lfs_settings');
|
const lfsSettings = document.getElementById('lfs_settings');
|
||||||
const $lfsEndpoint = $('#lfs_endpoint');
|
const lfsEndpoint = document.getElementById('lfs_endpoint');
|
||||||
const $items = $('#migrate_items').find('input[type=checkbox]');
|
const items = document.querySelectorAll('#migrate_items input[type=checkbox]');
|
||||||
|
|
||||||
export function initRepoMigration() {
|
export function initRepoMigration() {
|
||||||
checkAuth();
|
checkAuth();
|
||||||
setLFSSettingsVisibility();
|
setLFSSettingsVisibility();
|
||||||
|
|
||||||
$user.on('input', () => {checkItems(false)});
|
user?.addEventListener('input', () => {checkItems(false)});
|
||||||
$pass.on('input', () => {checkItems(false)});
|
pass?.addEventListener('input', () => {checkItems(false)});
|
||||||
$token.on('input', () => {checkItems(true)});
|
token?.addEventListener('input', () => {checkItems(true)});
|
||||||
$mirror.on('change', () => {checkItems(true)});
|
mirror?.addEventListener('change', () => {checkItems(true)});
|
||||||
$('#lfs_settings_show').on('click', () => { showElem($lfsEndpoint); return false });
|
document.getElementById('lfs_settings_show')?.addEventListener('click', (e) => {
|
||||||
$lfs.on('change', setLFSSettingsVisibility);
|
e.preventDefault();
|
||||||
|
e.stopPropagation();
|
||||||
|
showElem(lfsEndpoint);
|
||||||
|
});
|
||||||
|
lfs?.addEventListener('change', setLFSSettingsVisibility);
|
||||||
|
|
||||||
const $cloneAddr = $('#clone_addr');
|
const cloneAddr = document.getElementById('clone_addr');
|
||||||
$cloneAddr.on('change', () => {
|
cloneAddr?.addEventListener('change', () => {
|
||||||
const $repoName = $('#repo_name');
|
const repoName = document.getElementById('repo_name');
|
||||||
if ($cloneAddr.val().length > 0 && $repoName.val().length === 0) { // Only modify if repo_name input is blank
|
if (cloneAddr.value && !repoName?.value) { // Only modify if repo_name input is blank
|
||||||
$repoName.val($cloneAddr.val().match(/^(.*\/)?((.+?)(\.git)?)$/)[3]);
|
repoName.value = cloneAddr.value.match(/^(.*\/)?((.+?)(\.git)?)$/)[3];
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function checkAuth() {
|
function checkAuth() {
|
||||||
const serviceType = $service.val();
|
if (!service) return;
|
||||||
|
const serviceType = Number(service.value);
|
||||||
|
|
||||||
checkItems(serviceType !== 1);
|
checkItems(serviceType !== 1);
|
||||||
}
|
}
|
||||||
|
@ -40,24 +44,26 @@ function checkAuth() {
|
||||||
function checkItems(tokenAuth) {
|
function checkItems(tokenAuth) {
|
||||||
let enableItems;
|
let enableItems;
|
||||||
if (tokenAuth) {
|
if (tokenAuth) {
|
||||||
enableItems = $token.val() !== '';
|
enableItems = token?.value !== '';
|
||||||
} else {
|
} else {
|
||||||
enableItems = $user.val() !== '' || $pass.val() !== '';
|
enableItems = user?.value !== '' || pass?.value !== '';
|
||||||
}
|
}
|
||||||
if (enableItems && $service.val() > 1) {
|
if (enableItems && Number(service?.value) > 1) {
|
||||||
if ($mirror.is(':checked')) {
|
if (mirror?.checked) {
|
||||||
$items.not('[name="wiki"]').attr('disabled', true);
|
for (const item of items) {
|
||||||
$items.filter('[name="wiki"]').attr('disabled', false);
|
item.disabled = item.name !== 'wiki';
|
||||||
|
}
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
$items.attr('disabled', false);
|
for (const item of items) item.disabled = false;
|
||||||
} else {
|
} else {
|
||||||
$items.attr('disabled', true);
|
for (const item of items) item.disabled = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function setLFSSettingsVisibility() {
|
function setLFSSettingsVisibility() {
|
||||||
const visible = $lfs.is(':checked');
|
if (!lfs) return;
|
||||||
toggleElem($lfsSettings, visible);
|
const visible = lfs.checked;
|
||||||
hideElem($lfsEndpoint);
|
toggleElem(lfsSettings, visible);
|
||||||
|
hideElem(lfsEndpoint);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue