|
1 | 1 | import {hideElem, querySingleVisibleElem, showElem, toggleElem} from '../utils/dom.ts'; |
2 | | -import {htmlEscape} from '../utils/html.ts'; |
| 2 | +import {html, htmlEscape} from '../utils/html.ts'; |
3 | 3 | import {fomanticQuery} from '../modules/fomantic/base.ts'; |
4 | 4 | import {sanitizeRepoName} from './repo-common.ts'; |
5 | 5 |
|
6 | 6 | const {appSubUrl} = window.config; |
7 | | - |
| 7 | +const $ = window.$; |
8 | 8 | function initRepoNewTemplateSearch(form: HTMLFormElement) { |
9 | 9 | const elSubmitButton = querySingleVisibleElem<HTMLInputElement>(form, '.ui.primary.button'); |
10 | 10 | const elCreateRepoErrorMessage = form.querySelector('#create-repo-error-message'); |
@@ -59,18 +59,25 @@ function initRepoNewTemplateSearch(form: HTMLFormElement) { |
59 | 59 | } |
60 | 60 |
|
61 | 61 | function initRepoGroupSelector(form: HTMLFormElement) { |
62 | | - const inputRepoOwnerUid = form.querySelector<HTMLInputElement>('#uid'); |
| 62 | + const inputRepoOwnerUid = form.querySelector<HTMLInputElement>('input[name="uid"]'); |
63 | 63 | const elGroupDropdown = form.querySelector<HTMLInputElement>('#group_selector'); |
64 | 64 | const $dropdown = fomanticQuery(elGroupDropdown); |
65 | 65 | const onChangeRepoOwner = function () { |
66 | | - $dropdown.dropdown('setting', { |
| 66 | + $dropdown.dropdown({ |
| 67 | + keepSearchTerm: true, |
| 68 | + fireOnInit: true, |
| 69 | + saveRemoteData: false, |
67 | 70 | apiSettings: { |
68 | 71 | url: `${appSubUrl}/group/search?uid=${inputRepoOwnerUid.value}&recurse=true`, |
69 | | - onResponse(response) { |
| 72 | + onResponse(response: {data: any}) { |
70 | 73 | const results = []; |
71 | | - results.push({name: '', value: ''}); // empty item means not using template |
72 | | - const forEachFn = function({group, subgroups}, depth: number) { |
73 | | - results.push({name: group.name, value: String(group.id)}); |
| 74 | + results.push({name: '', value: '0'}); |
| 75 | + const forEachFn = function ({group, subgroups}: {group: any, subgroups: any[]}, depth: number) { |
| 76 | + results.push({ |
| 77 | + // eslint-disable-next-line github/unescaped-html-literal |
| 78 | + name: `<span style="margin-left: ${depth + 1}rem">${html`${group.name}`}</span>`, |
| 79 | + value: String(group.id), |
| 80 | + }); |
74 | 81 | for (const sg of subgroups) { |
75 | 82 | forEachFn(sg, depth + 1); |
76 | 83 | } |
|
0 commit comments