2022-01-28 14:00:11 -07:00
|
|
|
import $ from 'jquery';
|
2023-02-18 21:06:14 -07:00
|
|
|
import {hideElem, showElem, toggleElem} from '../utils/dom.js';
|
2022-01-28 14:00:11 -07:00
|
|
|
|
2020-08-27 19:36:37 -06:00
|
|
|
const $service = $('#service_type');
|
|
|
|
const $user = $('#auth_username');
|
|
|
|
const $pass = $('#auth_password');
|
|
|
|
const $token = $('#auth_token');
|
2020-09-21 16:42:22 -06:00
|
|
|
const $mirror = $('#mirror');
|
2021-04-08 16:25:57 -06:00
|
|
|
const $lfs = $('#lfs');
|
|
|
|
const $lfsSettings = $('#lfs_settings');
|
|
|
|
const $lfsEndpoint = $('#lfs_endpoint');
|
2020-09-21 16:42:22 -06:00
|
|
|
const $items = $('#migrate_items').find('input[type=checkbox]');
|
2020-08-27 19:36:37 -06:00
|
|
|
|
2022-12-23 09:03:11 -07:00
|
|
|
export function initRepoMigration() {
|
2020-08-27 19:36:37 -06:00
|
|
|
checkAuth();
|
2021-04-08 16:25:57 -06:00
|
|
|
setLFSSettingsVisibility();
|
2020-08-27 19:36:37 -06:00
|
|
|
|
2023-08-20 08:36:07 -06:00
|
|
|
$user.on('input', () => {checkItems(false)});
|
|
|
|
$pass.on('input', () => {checkItems(false)});
|
|
|
|
$token.on('input', () => {checkItems(true)});
|
2020-09-21 16:42:22 -06:00
|
|
|
$mirror.on('change', () => {checkItems(true)});
|
2023-02-18 21:06:14 -07:00
|
|
|
$('#lfs_settings_show').on('click', () => { showElem($lfsEndpoint); return false });
|
2021-04-08 16:25:57 -06:00
|
|
|
$lfs.on('change', setLFSSettingsVisibility);
|
2020-08-27 19:36:37 -06:00
|
|
|
|
|
|
|
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();
|
|
|
|
|
2020-09-09 12:29:10 -06:00
|
|
|
checkItems(serviceType !== 1);
|
2020-08-27 19:36:37 -06:00
|
|
|
}
|
|
|
|
|
|
|
|
function checkItems(tokenAuth) {
|
|
|
|
let enableItems;
|
|
|
|
if (tokenAuth) {
|
|
|
|
enableItems = $token.val() !== '';
|
|
|
|
} else {
|
|
|
|
enableItems = $user.val() !== '' || $pass.val() !== '';
|
|
|
|
}
|
|
|
|
if (enableItems && $service.val() > 1) {
|
2020-09-21 16:42:22 -06:00
|
|
|
if ($mirror.is(':checked')) {
|
|
|
|
$items.not('[name="wiki"]').attr('disabled', true);
|
|
|
|
$items.filter('[name="wiki"]').attr('disabled', false);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$items.attr('disabled', false);
|
2020-08-27 19:36:37 -06:00
|
|
|
} else {
|
2020-09-21 16:42:22 -06:00
|
|
|
$items.attr('disabled', true);
|
2020-08-27 19:36:37 -06:00
|
|
|
}
|
|
|
|
}
|
2021-04-08 16:25:57 -06:00
|
|
|
|
|
|
|
function setLFSSettingsVisibility() {
|
|
|
|
const visible = $lfs.is(':checked');
|
2023-02-18 21:06:14 -07:00
|
|
|
toggleElem($lfsSettings, visible);
|
|
|
|
hideElem($lfsEndpoint);
|
2021-04-08 16:25:57 -06:00
|
|
|
}
|