You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

48 lines
1.4 KiB

  1. const $service = $('#service_type');
  2. const $user = $('#auth_username');
  3. const $pass = $('#auth_password');
  4. const $token = $('#auth_token');
  5. const $mirror = $('#mirror');
  6. const $items = $('#migrate_items').find('input[type=checkbox]');
  7. export default function initMigration() {
  8. checkAuth();
  9. $user.on('keyup', () => {checkItems(false)});
  10. $pass.on('keyup', () => {checkItems(false)});
  11. $token.on('keyup', () => {checkItems(true)});
  12. $mirror.on('change', () => {checkItems(true)});
  13. const $cloneAddr = $('#clone_addr');
  14. $cloneAddr.on('change', () => {
  15. const $repoName = $('#repo_name');
  16. if ($cloneAddr.val().length > 0 && $repoName.val().length === 0) { // Only modify if repo_name input is blank
  17. $repoName.val($cloneAddr.val().match(/^(.*\/)?((.+?)(\.git)?)$/)[3]);
  18. }
  19. });
  20. }
  21. function checkAuth() {
  22. const serviceType = $service.val();
  23. checkItems(serviceType !== 1);
  24. }
  25. function checkItems(tokenAuth) {
  26. let enableItems;
  27. if (tokenAuth) {
  28. enableItems = $token.val() !== '';
  29. } else {
  30. enableItems = $user.val() !== '' || $pass.val() !== '';
  31. }
  32. if (enableItems && $service.val() > 1) {
  33. if ($mirror.is(':checked')) {
  34. $items.not('[name="wiki"]').attr('disabled', true);
  35. $items.filter('[name="wiki"]').attr('disabled', false);
  36. return;
  37. }
  38. $items.attr('disabled', false);
  39. } else {
  40. $items.attr('disabled', true);
  41. }
  42. }