|
1 | 1 | import $ from 'jquery';
|
2 | 2 | import {checkAppUrl} from '../common-global.js';
|
3 |
| -import {hideElem, showElem, toggleElem} from '../../utils/dom.js'; |
| 3 | +import {hideElem, queryElems, showElem, toggleElem} from '../../utils/dom.js'; |
4 | 4 | import {POST} from '../../modules/fetch.js';
|
5 | 5 |
|
6 | 6 | const {appSubUrl} = window.config;
|
@@ -67,39 +67,44 @@ export function initAdminCommon() {
|
67 | 67 | input.removeAttribute('required');
|
68 | 68 | }
|
69 | 69 |
|
70 |
| - const provider = document.getElementById('oauth2_provider')?.value; |
| 70 | + const provider = document.getElementById('oauth2_provider').value; |
71 | 71 | switch (provider) {
|
72 | 72 | case 'openidConnect':
|
73 |
| - for (const input of document.querySelectorAll('.open_id_connect_auto_discovery_url input')) { |
74 |
| - input.setAttribute('required', 'required'); |
75 |
| - } |
| 73 | + document.querySelector('.open_id_connect_auto_discovery_url input').setAttribute('required', 'required'); |
76 | 74 | showElem('.open_id_connect_auto_discovery_url');
|
77 | 75 | break;
|
78 |
| - default: |
79 |
| - if (document.getElementById(`#${provider}_customURLSettings`)?.getAttribute('data-required')) { |
80 |
| - document.getElementById('oauth2_use_custom_url')?.setAttribute('checked', 'checked'); |
| 76 | + default: { |
| 77 | + const elProviderCustomUrlSettings = document.querySelector(`#${provider}_customURLSettings`); |
| 78 | + if (!elProviderCustomUrlSettings) break; // some providers do not have custom URL settings |
| 79 | + const couldChangeCustomURLs = elProviderCustomUrlSettings.getAttribute('data-available') === 'true'; |
| 80 | + const mustProvideCustomURLs = elProviderCustomUrlSettings.getAttribute('data-required') === 'true'; |
| 81 | + if (couldChangeCustomURLs) { |
| 82 | + showElem('.oauth2_use_custom_url'); // show the checkbox |
81 | 83 | }
|
82 |
| - if (document.getElementById(`#${provider}_customURLSettings`)?.getAttribute('data-available')) { |
83 |
| - showElem('.oauth2_use_custom_url'); |
| 84 | + if (mustProvideCustomURLs) { |
| 85 | + document.querySelector('#oauth2_use_custom_url').checked = true; // make the checkbox checked |
84 | 86 | }
|
| 87 | + break; |
| 88 | + } |
85 | 89 | }
|
86 | 90 | onOAuth2UseCustomURLChange(applyDefaultValues);
|
87 | 91 | }
|
88 | 92 |
|
89 | 93 | function onOAuth2UseCustomURLChange(applyDefaultValues) {
|
90 |
| - const provider = document.getElementById('oauth2_provider')?.value; |
| 94 | + const provider = document.getElementById('oauth2_provider').value; |
91 | 95 | hideElem('.oauth2_use_custom_url_field');
|
92 | 96 | for (const input of document.querySelectorAll('.oauth2_use_custom_url_field input[required]')) {
|
93 | 97 | input.removeAttribute('required');
|
94 | 98 | }
|
95 | 99 |
|
96 |
| - if (document.getElementById('oauth2_use_custom_url')?.checked) { |
| 100 | + const elProviderCustomUrlSettings = document.querySelector(`#${provider}_customURLSettings`); |
| 101 | + if (elProviderCustomUrlSettings && document.getElementById('oauth2_use_custom_url').checked) { |
97 | 102 | for (const custom of ['token_url', 'auth_url', 'profile_url', 'email_url', 'tenant']) {
|
98 | 103 | if (applyDefaultValues) {
|
99 | 104 | document.getElementById(`oauth2_${custom}`).value = document.getElementById(`${provider}_${custom}`).value;
|
100 | 105 | }
|
101 | 106 | const customInput = document.getElementById(`${provider}_${custom}`);
|
102 |
| - if (customInput && customInput.getAttribute('data-available')) { |
| 107 | + if (customInput && customInput.getAttribute('data-available') === 'true') { |
103 | 108 | for (const input of document.querySelectorAll(`.oauth2_${custom} input`)) {
|
104 | 109 | input.setAttribute('required', 'required');
|
105 | 110 | }
|
|
0 commit comments