@@ -58,6 +58,36 @@ function initRepoNewTemplateSearch(form: HTMLFormElement) {
5858 onChangeOwner ( ) ;
5959}
6060
61+ function initRepoGroupSelector ( form : HTMLFormElement ) {
62+ const inputRepoOwnerUid = form . querySelector < HTMLInputElement > ( '#uid' ) ;
63+ const elGroupDropdown = form . querySelector < HTMLInputElement > ( '#group_selector' ) ;
64+ const $dropdown = fomanticQuery ( elGroupDropdown ) ;
65+ const onChangeRepoOwner = function ( ) {
66+ $dropdown . dropdown ( 'setting' , {
67+ apiSettings : {
68+ url : `${ appSubUrl } /group/search?uid=${ inputRepoOwnerUid . value } &recurse=true` ,
69+ onResponse ( response ) {
70+ 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+ for ( const sg of subgroups ) {
75+ forEachFn ( sg , depth + 1 ) ;
76+ }
77+ } ;
78+ for ( const g of response . data . subgroups ) {
79+ forEachFn ( g , 0 ) ;
80+ }
81+ return { results} ;
82+ } ,
83+ cache : false ,
84+ } ,
85+ } ) ;
86+ } ;
87+ inputRepoOwnerUid . addEventListener ( 'change' , onChangeRepoOwner ) ;
88+ onChangeRepoOwner ( ) ;
89+ }
90+
6191export function initRepoNew ( ) {
6292 const pageContent = document . querySelector ( '.page-content.repository.new-repo' ) ;
6393 if ( ! pageContent ) return ;
@@ -96,4 +126,5 @@ export function initRepoNew() {
96126 updateUiRepoName ( ) ;
97127
98128 initRepoNewTemplateSearch ( form ) ;
129+ initRepoGroupSelector ( form ) ;
99130}
0 commit comments