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.

migration.js 1.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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 $lfs = $('#lfs');
  7. const $lfsSettings = $('#lfs_settings');
  8. const $lfsEndpoint = $('#lfs_endpoint');
  9. const $items = $('#migrate_items').find('input[type=checkbox]');
  10. export default function initMigration() {
  11. checkAuth();
  12. setLFSSettingsVisibility();
  13. $user.on('keyup', () => {checkItems(false)});
  14. $pass.on('keyup', () => {checkItems(false)});
  15. $token.on('keyup', () => {checkItems(true)});
  16. $mirror.on('change', () => {checkItems(true)});
  17. $('#lfs_settings_show').on('click', () => { $lfsEndpoint.show(); return false });
  18. $lfs.on('change', setLFSSettingsVisibility);
  19. const $cloneAddr = $('#clone_addr');
  20. $cloneAddr.on('change', () => {
  21. const $repoName = $('#repo_name');
  22. if ($cloneAddr.val().length > 0 && $repoName.val().length === 0) { // Only modify if repo_name input is blank
  23. $repoName.val($cloneAddr.val().match(/^(.*\/)?((.+?)(\.git)?)$/)[3]);
  24. }
  25. });
  26. }
  27. function checkAuth() {
  28. const serviceType = $service.val();
  29. checkItems(serviceType !== 1);
  30. }
  31. function checkItems(tokenAuth) {
  32. let enableItems;
  33. if (tokenAuth) {
  34. enableItems = $token.val() !== '';
  35. } else {
  36. enableItems = $user.val() !== '' || $pass.val() !== '';
  37. }
  38. if (enableItems && $service.val() > 1) {
  39. if ($mirror.is(':checked')) {
  40. $items.not('[name="wiki"]').attr('disabled', true);
  41. $items.filter('[name="wiki"]').attr('disabled', false);
  42. return;
  43. }
  44. $items.attr('disabled', false);
  45. } else {
  46. $items.attr('disabled', true);
  47. }
  48. }
  49. function setLFSSettingsVisibility() {
  50. const visible = $lfs.is(':checked');
  51. $lfsSettings.toggle(visible);
  52. $lfsEndpoint.hide();
  53. }