This commit is contained in:
alorig
2025-11-22 19:46:34 +05:00
parent cbb6198214
commit 8296685fbd
34 changed files with 12200 additions and 1 deletions

View File

@@ -0,0 +1,188 @@
/**
* Admin JavaScript
*
* @package Igny8Bridge
*/
(function($) {
'use strict';
$(document).ready(function() {
// Test connection button
$('#igny8-test-connection').on('click', function() {
var $button = $(this);
var $result = $('#igny8-test-result');
$button.prop('disabled', true).addClass('igny8-loading');
$result.html('<span class="igny8-loading">Testing...</span>');
$.ajax({
url: igny8Admin.ajaxUrl,
type: 'POST',
data: {
action: 'igny8_test_connection',
nonce: igny8Admin.nonce
},
success: function(response) {
if (response.success) {
$result.html('<span class="igny8-success">✓ ' + (response.data.message || 'Connection successful') + '</span>');
} else {
var errorMsg = response.data.message || 'Connection failed';
var httpStatus = response.data.http_status || '';
var fullMsg = errorMsg;
if (httpStatus) {
fullMsg += ' (HTTP ' + httpStatus + ')';
}
$result.html('<span class="igny8-error">✗ ' + fullMsg + '</span>');
// Log full error to console for debugging
console.error('IGNY8 Connection Test Failed:', response.data);
}
},
error: function(xhr, status, error) {
$result.html('<span class="igny8-error">✗ Request failed: ' + error + '</span>');
console.error('IGNY8 AJAX Error:', xhr, status, error);
},
complete: function() {
$button.prop('disabled', false).removeClass('igny8-loading');
}
});
});
// Sync posts to IGNY8
$('#igny8-sync-posts').on('click', function() {
igny8TriggerSync('igny8_sync_posts', 'Syncing posts to IGNY8...');
});
// Sync taxonomies
$('#igny8-sync-taxonomies').on('click', function() {
igny8TriggerSync('igny8_sync_taxonomies', 'Syncing taxonomies...');
});
// Sync from IGNY8
$('#igny8-sync-from-igny8').on('click', function() {
igny8TriggerSync('igny8_sync_from_igny8', 'Syncing from IGNY8...');
});
// Collect and send site data
$('#igny8-collect-site-data').on('click', function() {
igny8TriggerSync('igny8_collect_site_data', 'Collecting and sending site data...');
});
// Load sync statistics
igny8LoadStats();
// Handle row action links
$(document).on('click', '.igny8-action-link', function(e) {
e.preventDefault();
var $link = $(this);
var postId = $link.data('post-id');
var action = $link.data('action');
if (!postId) {
return;
}
if (!confirm('Are you sure you want to ' + (action === 'send' ? 'send' : 'update') + ' this post to IGNY8?')) {
return;
}
$link.text('Processing...').prop('disabled', true);
$.ajax({
url: igny8Admin.ajaxUrl,
type: 'POST',
data: {
action: 'igny8_send_to_igny8',
post_id: postId,
action_type: action,
nonce: igny8Admin.nonce
},
success: function(response) {
if (response.success) {
alert(response.data.message || 'Success!');
location.reload();
} else {
alert(response.data.message || 'Failed to send to IGNY8');
$link.text(action === 'send' ? 'Send to IGNY8' : 'Update in IGNY8').prop('disabled', false);
}
},
error: function() {
alert('Request failed');
$link.text(action === 'send' ? 'Send to IGNY8' : 'Update in IGNY8').prop('disabled', false);
}
});
});
});
/**
* Trigger sync operation
*/
function igny8TriggerSync(action, message) {
var $status = $('#igny8-sync-status');
var $button = $('#' + action.replace('igny8_', 'igny8-'));
$status.removeClass('igny8-sync-status-success igny8-sync-status-error')
.addClass('igny8-sync-status-loading')
.html('<span class="igny8-spinner"></span>' + message);
$button.prop('disabled', true).addClass('igny8-loading');
$.ajax({
url: igny8Admin.ajaxUrl,
type: 'POST',
data: {
action: action,
nonce: igny8Admin.nonce
},
success: function(response) {
if (response.success) {
$status.removeClass('igny8-sync-status-loading')
.addClass('igny8-sync-status-success')
.html('✓ ' + (response.data.message || 'Operation completed successfully'));
// Reload stats
igny8LoadStats();
} else {
$status.removeClass('igny8-sync-status-loading')
.addClass('igny8-sync-status-error')
.html('✗ ' + (response.data.message || 'Operation failed'));
}
},
error: function() {
$status.removeClass('igny8-sync-status-loading')
.addClass('igny8-sync-status-error')
.html('✗ Request failed');
},
complete: function() {
$button.prop('disabled', false).removeClass('igny8-loading');
}
});
}
/**
* Load sync statistics
*/
function igny8LoadStats() {
$.ajax({
url: igny8Admin.ajaxUrl,
type: 'POST',
data: {
action: 'igny8_get_stats',
nonce: igny8Admin.nonce
},
success: function(response) {
if (response.success && response.data) {
if (response.data.synced_posts !== undefined) {
$('#igny8-stat-posts').text(response.data.synced_posts);
}
if (response.data.last_sync) {
$('#igny8-stat-last-sync').text(response.data.last_sync);
}
}
}
});
}
})(jQuery);

View File

@@ -0,0 +1,200 @@
/**
* Post Editor JavaScript
*
* Handles AJAX interactions for Planner and Optimizer meta boxes
*
* @package Igny8Bridge
*/
(function($) {
'use strict';
$(document).ready(function() {
// Fetch Planner Brief
$('#igny8-fetch-brief').on('click', function() {
var $button = $(this);
var $message = $('#igny8-planner-brief-message');
var postId = $button.data('post-id');
var taskId = $button.data('task-id');
$button.prop('disabled', true).text('Fetching...');
$message.hide().removeClass('notice-success notice-error');
$.ajax({
url: igny8PostEditor.ajaxUrl,
type: 'POST',
data: {
action: 'igny8_fetch_planner_brief',
nonce: igny8PostEditor.nonce,
post_id: postId,
task_id: taskId
},
success: function(response) {
if (response.success) {
$message.addClass('notice notice-success inline')
.html('<p>' + response.data.message + '</p>')
.show();
// Reload page to show updated brief
setTimeout(function() {
location.reload();
}, 1000);
} else {
$message.addClass('notice notice-error inline')
.html('<p>' + (response.data.message || 'Failed to fetch brief') + '</p>')
.show();
$button.prop('disabled', false).text('Fetch Brief');
}
},
error: function() {
$message.addClass('notice notice-error inline')
.html('<p>Request failed</p>')
.show();
$button.prop('disabled', false).text('Fetch Brief');
}
});
});
// Refresh Planner Task
$('#igny8-refresh-task').on('click', function() {
var $button = $(this);
var $message = $('#igny8-planner-brief-message');
var postId = $button.data('post-id');
var taskId = $button.data('task-id');
if (!confirm('Are you sure you want to request a refresh of this task from IGNY8 Planner?')) {
return;
}
$button.prop('disabled', true).text('Requesting...');
$message.hide().removeClass('notice-success notice-error');
$.ajax({
url: igny8PostEditor.ajaxUrl,
type: 'POST',
data: {
action: 'igny8_refresh_planner_task',
nonce: igny8PostEditor.nonce,
post_id: postId,
task_id: taskId
},
success: function(response) {
if (response.success) {
$message.addClass('notice notice-success inline')
.html('<p>' + response.data.message + '</p>')
.show();
} else {
$message.addClass('notice notice-error inline')
.html('<p>' + (response.data.message || 'Failed to request refresh') + '</p>')
.show();
}
$button.prop('disabled', false).text('Request Refresh');
},
error: function() {
$message.addClass('notice notice-error inline')
.html('<p>Request failed</p>')
.show();
$button.prop('disabled', false).text('Request Refresh');
}
});
});
// Create Optimizer Job
$('#igny8-create-optimizer-job').on('click', function() {
var $button = $(this);
var $message = $('#igny8-optimizer-message');
var postId = $button.data('post-id');
var taskId = $button.data('task-id');
if (!confirm('Create a new optimizer job for this post?')) {
return;
}
$button.prop('disabled', true).text('Creating...');
$message.hide().removeClass('notice-success notice-error');
$.ajax({
url: igny8PostEditor.ajaxUrl,
type: 'POST',
data: {
action: 'igny8_create_optimizer_job',
nonce: igny8PostEditor.nonce,
post_id: postId,
task_id: taskId,
job_type: 'audit',
priority: 'normal'
},
success: function(response) {
if (response.success) {
$message.addClass('notice notice-success inline')
.html('<p>' + response.data.message + '</p>')
.show();
// Reload page to show updated status
setTimeout(function() {
location.reload();
}, 1000);
} else {
$message.addClass('notice notice-error inline')
.html('<p>' + (response.data.message || 'Failed to create job') + '</p>')
.show();
$button.prop('disabled', false).text('Request Optimization');
}
},
error: function() {
$message.addClass('notice notice-error inline')
.html('<p>Request failed</p>')
.show();
$button.prop('disabled', false).text('Request Optimization');
}
});
});
// Check Optimizer Status
$('#igny8-check-optimizer-status').on('click', function() {
var $button = $(this);
var $message = $('#igny8-optimizer-message');
var postId = $button.data('post-id');
var jobId = $button.data('job-id');
$button.prop('disabled', true).text('Checking...');
$message.hide().removeClass('notice-success notice-error');
$.ajax({
url: igny8PostEditor.ajaxUrl,
type: 'POST',
data: {
action: 'igny8_get_optimizer_status',
nonce: igny8PostEditor.nonce,
post_id: postId,
job_id: jobId
},
success: function(response) {
if (response.success) {
$message.addClass('notice notice-success inline')
.html('<p>Status: <strong>' + response.data.status + '</strong></p>')
.show();
// Reload page to show updated status
setTimeout(function() {
location.reload();
}, 1000);
} else {
$message.addClass('notice notice-error inline')
.html('<p>' + (response.data.message || 'Failed to get status') + '</p>')
.show();
}
$button.prop('disabled', false).text('Check Status');
},
error: function() {
$message.addClass('notice notice-error inline')
.html('<p>Request failed</p>')
.show();
$button.prop('disabled', false).text('Check Status');
}
});
});
});
})(jQuery);