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.

repo-template.js 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import {htmlEscape} from 'escape-goat';
  2. const {appSubUrl} = window.config;
  3. export function initRepoTemplateSearch() {
  4. const $repoTemplate = $('#repo_template');
  5. const checkTemplate = function () {
  6. const $templateUnits = $('#template_units');
  7. const $nonTemplate = $('#non_template');
  8. if ($repoTemplate.val() !== '' && $repoTemplate.val() !== '0') {
  9. $templateUnits.show();
  10. $nonTemplate.hide();
  11. } else {
  12. $templateUnits.hide();
  13. $nonTemplate.show();
  14. }
  15. };
  16. $repoTemplate.on('change', checkTemplate);
  17. checkTemplate();
  18. const changeOwner = function () {
  19. $('#repo_template_search')
  20. .dropdown({
  21. apiSettings: {
  22. url: `${appSubUrl}/api/v1/repos/search?q={query}&template=true&priority_owner_id=${$('#uid').val()}`,
  23. onResponse(response) {
  24. const filteredResponse = {success: true, results: []};
  25. filteredResponse.results.push({
  26. name: '',
  27. value: ''
  28. });
  29. // Parse the response from the api to work with our dropdown
  30. $.each(response.data, (_r, repo) => {
  31. filteredResponse.results.push({
  32. name: htmlEscape(repo.full_name),
  33. value: repo.id
  34. });
  35. });
  36. return filteredResponse;
  37. },
  38. cache: false,
  39. },
  40. fullTextSearch: true
  41. });
  42. };
  43. $('#uid').on('change', changeOwner);
  44. changeOwner();
  45. }