179 lines
6.3 KiB
JavaScript
179 lines
6.3 KiB
JavaScript
/**
|
|
* 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">✓ Connection successful</span>');
|
|
} else {
|
|
$result.html('<span class="igny8-error">✗ ' + (response.data.message || 'Connection failed') + '</span>');
|
|
}
|
|
},
|
|
error: function() {
|
|
$result.html('<span class="igny8-error">✗ Request failed</span>');
|
|
},
|
|
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);
|
|
|