aboutsummaryrefslogtreecommitdiffstats
path: root/web_src/js/features/repo-migration.js
blob: ece01e53bd72f54c0c617b6b22bd19cfb1d450f9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import $ from 'jquery';

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 default 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', () => { $lfsEndpoint.show(); 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');
  $lfsSettings.toggle(visible);
  $lfsEndpoint.hide();
}