|
1 |
| -import $ from 'jquery'; |
2 |
| -import {hideElem, showElem} from '../utils/dom.ts'; |
| 1 | +import {queryElems, toggleElem} from '../utils/dom.ts'; |
| 2 | +import {fomanticQuery} from '../modules/fomantic/base.ts'; |
3 | 3 |
|
4 | 4 | const {appSubUrl} = window.config;
|
5 | 5 |
|
6 |
| -export function initOrgTeamSettings() { |
7 |
| - // Change team access mode |
8 |
| - $('.organization.new.team input[name=permission]').on('change', () => { |
9 |
| - const val = $('input[name=permission]:checked', '.organization.new.team').val(); |
10 |
| - if (val === 'admin') { |
11 |
| - hideElem('.organization.new.team .team-units'); |
12 |
| - } else { |
13 |
| - showElem('.organization.new.team .team-units'); |
14 |
| - } |
15 |
| - }); |
| 6 | +function initOrgTeamSettings() { |
| 7 | + // on the page "page-content organization new team" |
| 8 | + const pageContent = document.querySelector('.page-content.organization.new.team'); |
| 9 | + if (!pageContent) return; |
| 10 | + queryElems(pageContent, 'input[name=permission]', (el) => el.addEventListener('change', () => { |
| 11 | + // Change team access mode |
| 12 | + const val = pageContent.querySelector<HTMLInputElement>('input[name=permission]:checked')?.value; |
| 13 | + toggleElem(pageContent.querySelectorAll('.team-units'), val !== 'admin'); |
| 14 | + })); |
16 | 15 | }
|
17 | 16 |
|
18 |
| -export function initOrgTeamSearchRepoBox() { |
19 |
| - const $searchRepoBox = $('#search-repo-box'); |
| 17 | +function initOrgTeamSearchRepoBox() { |
| 18 | + // on the page "page-content organization teams" |
| 19 | + const $searchRepoBox = fomanticQuery('#search-repo-box'); |
20 | 20 | $searchRepoBox.search({
|
21 | 21 | minCharacters: 2,
|
22 | 22 | apiSettings: {
|
23 | 23 | url: `${appSubUrl}/repo/search?q={query}&uid=${$searchRepoBox.data('uid')}`,
|
24 | 24 | onResponse(response) {
|
25 | 25 | const items = [];
|
26 |
| - $.each(response.data, (_i, item) => { |
| 26 | + for (const item of response.data) { |
27 | 27 | items.push({
|
28 | 28 | title: item.repository.full_name.split('/')[1],
|
29 | 29 | description: item.repository.full_name,
|
30 | 30 | });
|
31 |
| - }); |
32 |
| - |
| 31 | + } |
33 | 32 | return {results: items};
|
34 | 33 | },
|
35 | 34 | },
|
36 | 35 | searchFields: ['full_name'],
|
37 | 36 | showNoResults: false,
|
38 | 37 | });
|
39 | 38 | }
|
| 39 | + |
| 40 | +export function initOrgTeam() { |
| 41 | + if (!document.querySelector('.page-content.organization')) return; |
| 42 | + initOrgTeamSettings(); |
| 43 | + initOrgTeamSearchRepoBox(); |
| 44 | +} |
0 commit comments