2025-01-06 17:38:42 +08:00
|
|
|
import {queryElems, toggleElem} from '../utils/dom.ts';
|
|
|
|
import {fomanticQuery} from '../modules/fomantic/base.ts';
|
2022-01-28 13:00:11 -08:00
|
|
|
|
2021-10-21 15:37:43 +08:00
|
|
|
const {appSubUrl} = window.config;
|
2021-10-17 01:28:04 +08:00
|
|
|
|
2025-01-06 17:38:42 +08:00
|
|
|
function initOrgTeamSettings() {
|
|
|
|
// on the page "page-content organization new team"
|
|
|
|
const pageContent = document.querySelector('.page-content.organization.new.team');
|
|
|
|
if (!pageContent) return;
|
|
|
|
queryElems(pageContent, 'input[name=permission]', (el) => el.addEventListener('change', () => {
|
|
|
|
// Change team access mode
|
|
|
|
const val = pageContent.querySelector<HTMLInputElement>('input[name=permission]:checked')?.value;
|
|
|
|
toggleElem(pageContent.querySelectorAll('.team-units'), val !== 'admin');
|
|
|
|
}));
|
2021-10-17 01:28:04 +08:00
|
|
|
}
|
|
|
|
|
2025-01-06 17:38:42 +08:00
|
|
|
function initOrgTeamSearchRepoBox() {
|
|
|
|
// on the page "page-content organization teams"
|
|
|
|
const $searchRepoBox = fomanticQuery('#search-repo-box');
|
2021-10-17 01:28:04 +08:00
|
|
|
$searchRepoBox.search({
|
|
|
|
minCharacters: 2,
|
|
|
|
apiSettings: {
|
2022-04-08 02:59:56 +08:00
|
|
|
url: `${appSubUrl}/repo/search?q={query}&uid=${$searchRepoBox.data('uid')}`,
|
2021-10-17 01:28:04 +08:00
|
|
|
onResponse(response) {
|
|
|
|
const items = [];
|
2025-01-06 17:38:42 +08:00
|
|
|
for (const item of response.data) {
|
2021-10-17 01:28:04 +08:00
|
|
|
items.push({
|
2023-05-14 00:59:01 +03:00
|
|
|
title: item.repository.full_name.split('/')[1],
|
2024-03-22 15:06:53 +01:00
|
|
|
description: item.repository.full_name,
|
2021-10-17 01:28:04 +08:00
|
|
|
});
|
2025-01-06 17:38:42 +08:00
|
|
|
}
|
2021-10-17 01:28:04 +08:00
|
|
|
return {results: items};
|
2024-03-22 15:06:53 +01:00
|
|
|
},
|
2021-10-17 01:28:04 +08:00
|
|
|
},
|
|
|
|
searchFields: ['full_name'],
|
2024-03-22 15:06:53 +01:00
|
|
|
showNoResults: false,
|
2021-10-17 01:28:04 +08:00
|
|
|
});
|
|
|
|
}
|
2025-01-06 17:38:42 +08:00
|
|
|
|
|
|
|
export function initOrgTeam() {
|
|
|
|
if (!document.querySelector('.page-content.organization')) return;
|
|
|
|
initOrgTeamSettings();
|
|
|
|
initOrgTeamSearchRepoBox();
|
|
|
|
}
|