Skip to content

Commit

Permalink
Merge pull request #697 from 10up/fix/696
Browse files Browse the repository at this point in the history
Fixed IBM Waston NLU Credentials toggle link in the ClassifAI setup.
  • Loading branch information
dkotter authored Feb 6, 2024
2 parents 381a5ee + ec4e1c3 commit c711d06
Showing 1 changed file with 22 additions and 11 deletions.
33 changes: 22 additions & 11 deletions src/js/admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ document.addEventListener( 'DOMContentLoaded', function () {
( () => {
const $toggler = document.getElementById( 'classifai-waston-cred-toggle' );
const $userField = document.getElementById( 'username' );
const isSetupPage = document.querySelector( '.classifai-setup-form' )
? true
: false;

if ( $toggler === null || $userField === null ) {
return;
Expand All @@ -42,30 +45,38 @@ document.addEventListener( 'DOMContentLoaded', function () {
let $passwordFieldTitle = null;
if ( $userField.closest( 'tr' ) ) {
$userFieldWrapper = $userField.closest( 'tr' );
} else if ( $userField.closest( '.classifai-setup-form-field' ) ) {
$userFieldWrapper = $userField.closest( '.classifai-setup-form-field' );
if ( isSetupPage ) {
$userFieldWrapper = $userField.closest( 'td' );
}
}

if ( document.getElementById( 'password' ).closest( 'tr' ) ) {
[ $passwordFieldTitle ] = document
.getElementById( 'password' )
.closest( 'tr' )
.getElementsByTagName( 'label' );
} else if (
document
.getElementById( 'password' )
.closest( '.classifai-setup-form-field' )
) {
[ $passwordFieldTitle ] = document
.getElementById( 'password' )
.closest( '.classifai-setup-form-field' )
.getElementsByTagName( 'label' );

if ( isSetupPage ) {
$passwordFieldTitle = document.querySelector(
'label[for="password"]'
);
}
}

$toggler.addEventListener( 'click', ( e ) => {
e.preventDefault();
$userFieldWrapper.classList.toggle( 'hide-username' );

if (
isSetupPage &&
document.querySelector( 'label[for="username"]' )
) {
document
.querySelector( 'label[for="username"]' )
.closest( 'th' )
.classList.toggle( 'hide-username' );
}

if ( $userFieldWrapper.classList.contains( 'hide-username' ) ) {
$toggler.innerText = ClassifAI.use_password;
$passwordFieldTitle.innerText = ClassifAI.api_key;
Expand Down

0 comments on commit c711d06

Please sign in to comment.