wp plugin
This commit is contained in:
188
igny8-wp-plugin/admin/assets/js/admin.js
Normal file
188
igny8-wp-plugin/admin/assets/js/admin.js
Normal 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);
|
||||
|
||||
Reference in New Issue
Block a user