refactor(assets): extract model-picker refresh handler to generic-handle file (Phase 2 lift)
This commit is contained in:
6
assets/admin/peptiderepo-model-picker.css
Normal file
6
assets/admin/peptiderepo-model-picker.css
Normal file
@@ -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).
|
||||||
|
*/
|
||||||
58
assets/admin/peptiderepo-model-picker.js
Normal file
58
assets/admin/peptiderepo-model-picker.js
Normal file
@@ -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 = $('<div class="ab-save-notice" role="status"></div>')
|
||||||
|
.html('<span class="dashicons dashicons-yes"></span> ' + response.data.message)
|
||||||
|
.insertBefore('.ab-layout')
|
||||||
|
.delay(4000)
|
||||||
|
.fadeOut(function () {
|
||||||
|
$(this).remove();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.fail(function () {
|
||||||
|
var $notice = $('<div class="ab-save-notice notice-error" role="alert"></div>')
|
||||||
|
.html('<span class="dashicons dashicons-warning"></span> ' + '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);
|
||||||
@@ -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 = $('<div class="ab-save-notice" role="status"></div>')
|
|
||||||
.html('<span class="dashicons dashicons-yes"></span> ' + response.data.message)
|
|
||||||
.insertBefore('.ab-layout')
|
|
||||||
.delay(4000)
|
|
||||||
.fadeOut(function () {
|
|
||||||
$(this).remove();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.fail(function () {
|
|
||||||
var $notice = $('<div class="ab-save-notice notice-error" role="alert"></div>')
|
|
||||||
.html('<span class="dashicons dashicons-warning"></span> ' + '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);
|
})(jQuery);
|
||||||
|
|||||||
@@ -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_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-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( '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(
|
wp_localize_script(
|
||||||
'prautoblogger-admin',
|
'prautoblogger-admin',
|
||||||
|
|||||||
Reference in New Issue
Block a user