2022-01-29 05:00:11 +08:00
|
|
|
import $ from 'jquery';
|
2021-10-17 01:28:04 +08:00
|
|
|
import {htmlEscape} from 'escape-goat';
|
2023-02-19 12:06:14 +08:00
|
|
|
import {hideElem, showElem} from '../utils/dom.js';
|
2021-10-17 01:28:04 +08:00
|
|
|
|
2021-10-21 15:37:43 +08:00
|
|
|
const {appSubUrl} = window.config;
|
2021-10-17 01:28:04 +08:00
|
|
|
|
|
|
|
export function initRepoTemplateSearch() {
|
|
|
|
const $repoTemplate = $('#repo_template');
|
|
|
|
const checkTemplate = function () {
|
|
|
|
const $templateUnits = $('#template_units');
|
|
|
|
const $nonTemplate = $('#non_template');
|
|
|
|
if ($repoTemplate.val() !== '' && $repoTemplate.val() !== '0') {
|
2023-02-19 12:06:14 +08:00
|
|
|
showElem($templateUnits);
|
|
|
|
hideElem($nonTemplate);
|
2021-10-17 01:28:04 +08:00
|
|
|
} else {
|
2023-02-19 12:06:14 +08:00
|
|
|
hideElem($templateUnits);
|
|
|
|
showElem($nonTemplate);
|
2021-10-17 01:28:04 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
$repoTemplate.on('change', checkTemplate);
|
|
|
|
checkTemplate();
|
|
|
|
|
|
|
|
const changeOwner = function () {
|
|
|
|
$('#repo_template_search')
|
|
|
|
.dropdown({
|
|
|
|
apiSettings: {
|
2022-04-08 02:59:56 +08:00
|
|
|
url: `${appSubUrl}/repo/search?q={query}&template=true&priority_owner_id=${$('#uid').val()}`,
|
2021-10-17 01:28:04 +08:00
|
|
|
onResponse(response) {
|
|
|
|
const filteredResponse = {success: true, results: []};
|
|
|
|
filteredResponse.results.push({
|
|
|
|
name: '',
|
|
|
|
value: ''
|
|
|
|
});
|
|
|
|
// Parse the response from the api to work with our dropdown
|
|
|
|
$.each(response.data, (_r, repo) => {
|
|
|
|
filteredResponse.results.push({
|
2023-05-14 05:59:01 +08:00
|
|
|
name: htmlEscape(repo.repository.full_name),
|
|
|
|
value: repo.repository.id
|
2021-10-17 01:28:04 +08:00
|
|
|
});
|
|
|
|
});
|
|
|
|
return filteredResponse;
|
|
|
|
},
|
|
|
|
cache: false,
|
|
|
|
},
|
|
|
|
|
|
|
|
fullTextSearch: true
|
|
|
|
});
|
|
|
|
};
|
|
|
|
$('#uid').on('change', changeOwner);
|
|
|
|
changeOwner();
|
|
|
|
}
|