Template
1
0
Fork 0
mirror of https://codeberg.org/forgejo/forgejo synced 2024-11-30 13:56:09 +01:00
forgejo/web_src/js/features/repo-migration.js
wxiaoguang d32af84a10
Refactor hiding-methods, remove jQuery show/hide, remove .hide class, remove inline style=display:none (#22950)
Close #22847

This PR:

* introduce Gitea's own `showElem` and related functions
* remove jQuery show/hide
* remove .hide class
* remove inline style=display:none 

From now on:

do not use:
* "[hidden]" attribute: it's too weak, can not be applied to an element
with "display: flex"
* ".hidden" class: it has been polluted by Fomantic UI in many cases
* inline style="display: none": it's difficult to tweak
* jQuery's show/hide/toggle: it can not show/hide elements with
"display: xxx !important"

only use:
* this ".gt-hidden" class
* showElem/hideElem/toggleElem functions in "utils/dom.js"

cc: @silverwind , this is the all-in-one PR
2023-02-19 12:06:14 +08:00

64 lines
1.8 KiB
JavaScript

import $ from 'jquery';
import {hideElem, showElem, toggleElem} from '../utils/dom.js';
const $service = $('#service_type');
const $user = $('#auth_username');
const $pass = $('#auth_password');
const $token = $('#auth_token');
const $mirror = $('#mirror');
const $lfs = $('#lfs');
const $lfsSettings = $('#lfs_settings');
const $lfsEndpoint = $('#lfs_endpoint');
const $items = $('#migrate_items').find('input[type=checkbox]');
export function initRepoMigration() {
checkAuth();
setLFSSettingsVisibility();
$user.on('keyup', () => {checkItems(false)});
$pass.on('keyup', () => {checkItems(false)});
$token.on('keyup', () => {checkItems(true)});
$mirror.on('change', () => {checkItems(true)});
$('#lfs_settings_show').on('click', () => { showElem($lfsEndpoint); return false });
$lfs.on('change', setLFSSettingsVisibility);
const $cloneAddr = $('#clone_addr');
$cloneAddr.on('change', () => {
const $repoName = $('#repo_name');
if ($cloneAddr.val().length > 0 && $repoName.val().length === 0) { // Only modify if repo_name input is blank
$repoName.val($cloneAddr.val().match(/^(.*\/)?((.+?)(\.git)?)$/)[3]);
}
});
}
function checkAuth() {
const serviceType = $service.val();
checkItems(serviceType !== 1);
}
function checkItems(tokenAuth) {
let enableItems;
if (tokenAuth) {
enableItems = $token.val() !== '';
} else {
enableItems = $user.val() !== '' || $pass.val() !== '';
}
if (enableItems && $service.val() > 1) {
if ($mirror.is(':checked')) {
$items.not('[name="wiki"]').attr('disabled', true);
$items.filter('[name="wiki"]').attr('disabled', false);
return;
}
$items.attr('disabled', false);
} else {
$items.attr('disabled', true);
}
}
function setLFSSettingsVisibility() {
const visible = $lfs.is(':checked');
toggleElem($lfsSettings, visible);
hideElem($lfsEndpoint);
}