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.5KB

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