@@ -6,7 +6,7 @@ import {POST} from '../../modules/fetch.js';
66const { appSubUrl} = window . config ;
77
88function onSecurityProtocolChange ( ) {
9- if ( Number ( document . getElementById ( ' security_protocol') ?. value ) > 0 ) {
9+ if ( Number ( document . querySelector ( '# security_protocol') ?. value ) > 0 ) {
1010 showElem ( '.has-tls' ) ;
1111 } else {
1212 hideElem ( '.has-tls' ) ;
@@ -21,34 +21,34 @@ export function initAdminCommon() {
2121
2222 // New user
2323 if ( $ ( '.admin.new.user' ) . length > 0 || $ ( '.admin.edit.user' ) . length > 0 ) {
24- document . getElementById ( ' login_type') ?. addEventListener ( 'change' , function ( ) {
24+ document . querySelector ( '# login_type') ?. addEventListener ( 'change' , function ( ) {
2525 if ( this . value ?. substring ( 0 , 1 ) === '0' ) {
26- document . getElementById ( ' user_name') ?. removeAttribute ( 'disabled' ) ;
27- document . getElementById ( ' login_name') ?. removeAttribute ( 'required' ) ;
26+ document . querySelector ( '# user_name') ?. removeAttribute ( 'disabled' ) ;
27+ document . querySelector ( '# login_name') ?. removeAttribute ( 'required' ) ;
2828 hideElem ( '.non-local' ) ;
2929 showElem ( '.local' ) ;
30- document . getElementById ( ' user_name') ?. focus ( ) ;
30+ document . querySelector ( '# user_name') ?. focus ( ) ;
3131
3232 if ( this . getAttribute ( 'data-password' ) === 'required' ) {
33- document . getElementById ( ' password') ?. setAttribute ( 'required' , 'required' ) ;
33+ document . querySelector ( '# password') ?. setAttribute ( 'required' , 'required' ) ;
3434 }
3535 } else {
3636 if ( document . querySelector ( '.admin.edit.user' ) ) {
37- document . getElementById ( ' user_name') ?. setAttribute ( 'disabled' , 'disabled' ) ;
37+ document . querySelector ( '# user_name') ?. setAttribute ( 'disabled' , 'disabled' ) ;
3838 }
39- document . getElementById ( ' login_name') ?. setAttribute ( 'required' , 'required' ) ;
39+ document . querySelector ( '# login_name') ?. setAttribute ( 'required' , 'required' ) ;
4040 showElem ( '.non-local' ) ;
4141 hideElem ( '.local' ) ;
42- document . getElementById ( ' login_name') ?. focus ( ) ;
42+ document . querySelector ( '# login_name') ?. focus ( ) ;
4343
44- document . getElementById ( ' password') ?. removeAttribute ( 'required' ) ;
44+ document . querySelector ( '# password') ?. removeAttribute ( 'required' ) ;
4545 }
4646 } ) ;
4747 }
4848
4949 function onUsePagedSearchChange ( ) {
5050 const searchPageSizeElements = document . querySelectorAll ( '.search-page-size' ) ;
51- if ( document . getElementById ( ' use_paged_search') . checked ) {
51+ if ( document . querySelector ( '# use_paged_search') . checked ) {
5252 showElem ( '.search-page-size' ) ;
5353 for ( const el of searchPageSizeElements ) {
5454 el . querySelector ( 'input' ) ?. setAttribute ( 'required' , 'required' ) ;
@@ -67,7 +67,7 @@ export function initAdminCommon() {
6767 input . removeAttribute ( 'required' ) ;
6868 }
6969
70- const provider = document . getElementById ( ' oauth2_provider') . value ;
70+ const provider = document . querySelector ( '# oauth2_provider') . value ;
7171 switch ( provider ) {
7272 case 'openidConnect' :
7373 document . querySelector ( '.open_id_connect_auto_discovery_url input' ) . setAttribute ( 'required' , 'required' ) ;
@@ -91,19 +91,19 @@ export function initAdminCommon() {
9191 }
9292
9393 function onOAuth2UseCustomURLChange ( applyDefaultValues ) {
94- const provider = document . getElementById ( ' oauth2_provider') . value ;
94+ const provider = document . querySelector ( '# oauth2_provider') . value ;
9595 hideElem ( '.oauth2_use_custom_url_field' ) ;
9696 for ( const input of document . querySelectorAll ( '.oauth2_use_custom_url_field input[required]' ) ) {
9797 input . removeAttribute ( 'required' ) ;
9898 }
9999
100100 const elProviderCustomUrlSettings = document . querySelector ( `#${ provider } _customURLSettings` ) ;
101- if ( elProviderCustomUrlSettings && document . getElementById ( ' oauth2_use_custom_url') . checked ) {
101+ if ( elProviderCustomUrlSettings && document . querySelector ( '# oauth2_use_custom_url') . checked ) {
102102 for ( const custom of [ 'token_url' , 'auth_url' , 'profile_url' , 'email_url' , 'tenant' ] ) {
103103 if ( applyDefaultValues ) {
104- document . getElementById ( ` oauth2_${ custom } `) . value = document . getElementById ( ` ${ provider } _${ custom } `) . value ;
104+ document . querySelector ( `# oauth2_${ custom } `) . value = document . querySelector ( `# ${ provider } _${ custom } `) . value ;
105105 }
106- const customInput = document . getElementById ( ` ${ provider } _${ custom } `) ;
106+ const customInput = document . querySelector ( `# ${ provider } _${ custom } `) ;
107107 if ( customInput && customInput . getAttribute ( 'data-available' ) === 'true' ) {
108108 for ( const input of document . querySelectorAll ( `.oauth2_${ custom } input` ) ) {
109109 input . setAttribute ( 'required' , 'required' ) ;
@@ -115,12 +115,12 @@ export function initAdminCommon() {
115115 }
116116
117117 function onEnableLdapGroupsChange ( ) {
118- toggleElem ( document . getElementById ( ' ldap-group-options') , $ ( '.js-ldap-group-toggle' ) [ 0 ] . checked ) ;
118+ toggleElem ( document . querySelector ( '# ldap-group-options') , $ ( '.js-ldap-group-toggle' ) [ 0 ] . checked ) ;
119119 }
120120
121121 // New authentication
122122 if ( document . querySelector ( '.admin.new.authentication' ) ) {
123- document . getElementById ( ' auth_type') ?. addEventListener ( 'change' , function ( ) {
123+ document . querySelector ( '# auth_type') ?. addEventListener ( 'change' , function ( ) {
124124 hideElem ( '.ldap, .dldap, .smtp, .pam, .oauth2, .has-tls, .search-page-size, .sspi' ) ;
125125
126126 for ( const input of document . querySelectorAll ( '.ldap input[required], .binddnrequired input[required], .dldap input[required], .smtp input[required], .pam input[required], .oauth2 input[required], .has-tls input[required], .sspi input[required]' ) ) {
@@ -180,39 +180,39 @@ export function initAdminCommon() {
180180 }
181181 } ) ;
182182 $ ( '#auth_type' ) . trigger ( 'change' ) ;
183- document . getElementById ( ' security_protocol') ?. addEventListener ( 'change' , onSecurityProtocolChange ) ;
184- document . getElementById ( ' use_paged_search') ?. addEventListener ( 'change' , onUsePagedSearchChange ) ;
185- document . getElementById ( ' oauth2_provider') ?. addEventListener ( 'change' , ( ) => onOAuth2Change ( true ) ) ;
186- document . getElementById ( ' oauth2_use_custom_url') ?. addEventListener ( 'change' , ( ) => onOAuth2UseCustomURLChange ( true ) ) ;
183+ document . querySelector ( '# security_protocol') ?. addEventListener ( 'change' , onSecurityProtocolChange ) ;
184+ document . querySelector ( '# use_paged_search') ?. addEventListener ( 'change' , onUsePagedSearchChange ) ;
185+ document . querySelector ( '# oauth2_provider') ?. addEventListener ( 'change' , ( ) => onOAuth2Change ( true ) ) ;
186+ document . querySelector ( '# oauth2_use_custom_url') ?. addEventListener ( 'change' , ( ) => onOAuth2UseCustomURLChange ( true ) ) ;
187187 $ ( '.js-ldap-group-toggle' ) . on ( 'change' , onEnableLdapGroupsChange ) ;
188188 }
189189 // Edit authentication
190190 if ( document . querySelector ( '.admin.edit.authentication' ) ) {
191- const authType = document . getElementById ( ' auth_type') ?. value ;
191+ const authType = document . querySelector ( '# auth_type') ?. value ;
192192 if ( authType === '2' || authType === '5' ) {
193- document . getElementById ( ' security_protocol') ?. addEventListener ( 'change' , onSecurityProtocolChange ) ;
193+ document . querySelector ( '# security_protocol') ?. addEventListener ( 'change' , onSecurityProtocolChange ) ;
194194 $ ( '.js-ldap-group-toggle' ) . on ( 'change' , onEnableLdapGroupsChange ) ;
195195 onEnableLdapGroupsChange ( ) ;
196196 if ( authType === '2' ) {
197- document . getElementById ( ' use_paged_search') ?. addEventListener ( 'change' , onUsePagedSearchChange ) ;
197+ document . querySelector ( '# use_paged_search') ?. addEventListener ( 'change' , onUsePagedSearchChange ) ;
198198 }
199199 } else if ( authType === '6' ) {
200- document . getElementById ( ' oauth2_provider') ?. addEventListener ( 'change' , ( ) => onOAuth2Change ( true ) ) ;
201- document . getElementById ( ' oauth2_use_custom_url') ?. addEventListener ( 'change' , ( ) => onOAuth2UseCustomURLChange ( false ) ) ;
200+ document . querySelector ( '# oauth2_provider') ?. addEventListener ( 'change' , ( ) => onOAuth2Change ( true ) ) ;
201+ document . querySelector ( '# oauth2_use_custom_url') ?. addEventListener ( 'change' , ( ) => onOAuth2UseCustomURLChange ( false ) ) ;
202202 onOAuth2Change ( false ) ;
203203 }
204204 }
205205
206206 if ( document . querySelector ( '.admin.authentication' ) ) {
207207 $ ( '#auth_name' ) . on ( 'input' , function ( ) {
208208 // appSubUrl is either empty or is a path that starts with `/` and doesn't have a trailing slash.
209- document . getElementById ( ' oauth2-callback-url') . textContent = `${ window . location . origin } ${ appSubUrl } /user/oauth2/${ encodeURIComponent ( this . value ) } /callback` ;
209+ document . querySelector ( '# oauth2-callback-url') . textContent = `${ window . location . origin } ${ appSubUrl } /user/oauth2/${ encodeURIComponent ( this . value ) } /callback` ;
210210 } ) . trigger ( 'input' ) ;
211211 }
212212
213213 // Notice
214214 if ( document . querySelector ( '.admin.notice' ) ) {
215- const detailModal = document . getElementById ( ' detail-modal') ;
215+ const detailModal = document . querySelector ( '# detail-modal') ;
216216
217217 // Attach view detail modals
218218 $ ( '.view-detail' ) . on ( 'click' , function ( ) {
@@ -244,7 +244,7 @@ export function initAdminCommon() {
244244 break ;
245245 }
246246 } ) ;
247- document . getElementById ( ' delete-selection') ?. addEventListener ( 'click' , async function ( e ) {
247+ document . querySelector ( '# delete-selection') ?. addEventListener ( 'click' , async function ( e ) {
248248 e . preventDefault ( ) ;
249249 this . classList . add ( 'is-loading' , 'disabled' ) ;
250250 const data = new FormData ( ) ;
0 commit comments