diff --git a/assets/admin/peptiderepo-model-picker.css b/assets/admin/peptiderepo-model-picker.css new file mode 100644 index 0000000..5a7584f --- /dev/null +++ b/assets/admin/peptiderepo-model-picker.css @@ -0,0 +1,6 @@ +/** + * Styling for model registry picker refresh functionality. + * + * Button animations and toast notifications are defined in admin.css. + * This file is reserved for model-picker-specific styles (future extensibility). + */ diff --git a/assets/admin/peptiderepo-model-picker.js b/assets/admin/peptiderepo-model-picker.js new file mode 100644 index 0000000..eb92ba8 --- /dev/null +++ b/assets/admin/peptiderepo-model-picker.js @@ -0,0 +1,58 @@ +/** + * Model registry refresh handler for PRAutoBlogger admin settings. + * + * Handles the "Refresh Model List" button click in the AI Models admin tab. + * Sends AJAX request to refresh the OpenRouter model registry cache and shows + * success/error toast notifications. + * + * @see admin/class-admin-page.php — Renders the refresh button + nonce. + * @see ajax/class-model-registry-refresh.php — Server-side handler. + */ +(function ($) { + 'use strict'; + + // Refresh model registry button. + $(document).on('click', '#prautoblogger-refresh-models', function (e) { + e.preventDefault(); + var $btn = $(this); + var nonce = $btn.data('nonce'); + var originalText = $btn.html(); + + $btn.prop('disabled', true).addClass('ab-btn-loading'); + + $.ajax({ + url: ajaxurl, + method: 'POST', + data: { + action: 'prautoblogger_refresh_models', + nonce: nonce + }, + timeout: 30000 + }) + .done(function (response) { + if (response.success && response.data && response.data.message) { + // Show success toast + var $notice = $('
') + .html(' ' + response.data.message) + .insertBefore('.ab-layout') + .delay(4000) + .fadeOut(function () { + $(this).remove(); + }); + } + }) + .fail(function () { + var $notice = $('') + .html(' ' + 'Failed to refresh model list. Please try again.') + .insertBefore('.ab-layout') + .delay(5000) + .fadeOut(function () { + $(this).remove(); + }); + }) + .always(function () { + $btn.prop('disabled', false).removeClass('ab-btn-loading').html(originalText); + }); + }); + +})(jQuery); diff --git a/assets/js/admin.js b/assets/js/admin.js index 4b32e8c..a81a325 100644 --- a/assets/js/admin.js +++ b/assets/js/admin.js @@ -446,49 +446,4 @@ }); }); - - // Refresh model registry button. - $(document).on('click', '#prautoblogger-refresh-models', function (e) { - e.preventDefault(); - var $btn = $(this); - var nonce = $btn.data('nonce'); - var originalText = $btn.html(); - - $btn.prop('disabled', true).addClass('ab-btn-loading'); - - $.ajax({ - url: ajaxurl, - method: 'POST', - data: { - action: 'prautoblogger_refresh_models', - nonce: nonce - }, - timeout: 30000 - }) - .done(function (response) { - if (response.success && response.data && response.data.message) { - // Show success toast - var $notice = $('
') - .html(' ' + response.data.message) - .insertBefore('.ab-layout') - .delay(4000) - .fadeOut(function () { - $(this).remove(); - }); - } - }) - .fail(function () { - var $notice = $('') - .html(' ' + 'Failed to refresh model list. Please try again.') - .insertBefore('.ab-layout') - .delay(5000) - .fadeOut(function () { - $(this).remove(); - }); - }) - .always(function () { - $btn.prop('disabled', false).removeClass('ab-btn-loading').html(originalText); - }); - }); - })(jQuery); diff --git a/includes/admin/class-admin-page.php b/includes/admin/class-admin-page.php index b29ed8e..59e90dc 100755 --- a/includes/admin/class-admin-page.php +++ b/includes/admin/class-admin-page.php @@ -75,6 +75,8 @@ class PRAutoBlogger_Admin_Page { wp_enqueue_style( 'prautoblogger-model-picker', PRAUTOBLOGGER_PLUGIN_URL . 'assets/css/model-picker.css', array( 'prautoblogger-admin' ), PRAUTOBLOGGER_VERSION ); wp_enqueue_script( 'prautoblogger-admin', PRAUTOBLOGGER_PLUGIN_URL . 'assets/js/admin.js', array( 'jquery' ), PRAUTOBLOGGER_VERSION, true ); wp_enqueue_script( 'prautoblogger-model-picker', PRAUTOBLOGGER_PLUGIN_URL . 'assets/js/model-picker.js', array( 'jquery', 'prautoblogger-admin' ), PRAUTOBLOGGER_VERSION, true ); + wp_enqueue_script( 'peptiderepo-model-picker', PRAUTOBLOGGER_PLUGIN_URL . 'assets/admin/peptiderepo-model-picker.js', array( 'jquery' ), PRAUTOBLOGGER_VERSION, true ); + wp_enqueue_style( 'peptiderepo-model-picker', PRAUTOBLOGGER_PLUGIN_URL . 'assets/admin/peptiderepo-model-picker.css', array(), PRAUTOBLOGGER_VERSION ); wp_localize_script( 'prautoblogger-admin',