48 lines
1.8 KiB
JavaScript
48 lines
1.8 KiB
JavaScript
/* global breAdmin */
|
|
jQuery( function ( $ ) {
|
|
function updateProviderRows() {
|
|
var active = $( '#bre-provider' ).val();
|
|
$( '.bre-provider-row' ).removeClass( 'active' );
|
|
$( '.bre-provider-row[data-provider="' + active + '"]' ).addClass( 'active' );
|
|
}
|
|
updateProviderRows();
|
|
$( '#bre-provider' ).on( 'change', updateProviderRows );
|
|
|
|
$( document ).on( 'click', '.bre-test-btn', function () {
|
|
var btn = $( this );
|
|
var providerId = btn.data( 'provider' );
|
|
var resultEl = $( '#test-result-' + providerId );
|
|
|
|
resultEl.removeClass( 'success error' ).text( 'Teste\u2026' );
|
|
btn.prop( 'disabled', true );
|
|
|
|
$.post( breAdmin.ajaxUrl, {
|
|
action: 'bre_test_connection',
|
|
nonce: breAdmin.nonce,
|
|
provider: providerId,
|
|
// api_key removed — server reads stored encrypted key
|
|
} ).done( function ( res ) {
|
|
if ( res.success ) {
|
|
resultEl.addClass( 'success' ).text( '\u2713 ' + res.data );
|
|
} else {
|
|
resultEl.addClass( 'error' ).text( '\u2717 ' + res.data );
|
|
}
|
|
} ).fail( function () {
|
|
resultEl.addClass( 'error' ).text( '\u2717 Netzwerkfehler' );
|
|
} ).always( function () {
|
|
btn.prop( 'disabled', false );
|
|
} );
|
|
} );
|
|
|
|
$( '#bre-reset-prompt' ).on( 'click', function () {
|
|
if ( ! confirm( 'Prompt wirklich zur\u00fccksetzen?' ) ) return;
|
|
$.post( breAdmin.ajaxUrl, {
|
|
action: 'bre_get_default_prompt',
|
|
nonce: breAdmin.nonce,
|
|
} ).done( function ( res ) {
|
|
if ( res.success ) {
|
|
$( 'textarea[name*="prompt"]' ).val( res.data );
|
|
}
|
|
} );
|
|
} );
|
|
} );
|