2025-12-23 07:48:45 +01:00
|
|
|
/**
|
|
|
|
|
* Admin JavaScript for Informatiq Smart Pricing
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
(function($) {
|
|
|
|
|
'use strict';
|
|
|
|
|
|
|
|
|
|
var InformatiqSP = {
|
|
|
|
|
/**
|
|
|
|
|
* Initialize
|
|
|
|
|
*/
|
|
|
|
|
init: function() {
|
|
|
|
|
this.bindEvents();
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Bind event handlers
|
|
|
|
|
*/
|
|
|
|
|
bindEvents: function() {
|
|
|
|
|
$('#informatiq-sp-manual-sync').on('click', this.handleManualSync);
|
|
|
|
|
$('#informatiq-sp-test-connection').on('click', this.handleTestConnection);
|
2026-01-21 08:52:57 +01:00
|
|
|
$('#informatiq-sp-revoke-auth').on('click', this.handleRevokeAuth);
|
2025-12-23 07:48:45 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Handle manual sync button click
|
|
|
|
|
*/
|
|
|
|
|
handleManualSync: function(e) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
|
|
var $button = $(this);
|
|
|
|
|
var $status = $('#informatiq-sp-sync-status');
|
|
|
|
|
|
|
|
|
|
// Confirm action
|
|
|
|
|
if (!confirm(informatiqSP.strings.confirmSync || 'Are you sure you want to run a manual price sync? This may take several minutes.')) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Disable button and show loading state
|
|
|
|
|
$button.prop('disabled', true).addClass('informatiq-sp-loading');
|
|
|
|
|
|
|
|
|
|
// Show status message
|
|
|
|
|
$status
|
|
|
|
|
.removeClass('notice-success notice-error')
|
|
|
|
|
.addClass('notice-info')
|
|
|
|
|
.html('<p>' + (informatiqSP.strings.syncInProgress || 'Sync in progress...') + '</p>')
|
|
|
|
|
.show();
|
|
|
|
|
|
|
|
|
|
// Make AJAX request
|
|
|
|
|
$.ajax({
|
|
|
|
|
url: informatiqSP.ajaxUrl,
|
|
|
|
|
type: 'POST',
|
|
|
|
|
data: {
|
|
|
|
|
action: 'informatiq_sp_manual_sync',
|
|
|
|
|
nonce: informatiqSP.nonce
|
|
|
|
|
},
|
|
|
|
|
success: function(response) {
|
|
|
|
|
if (response.success) {
|
|
|
|
|
$status
|
|
|
|
|
.removeClass('notice-info notice-error')
|
|
|
|
|
.addClass('notice-success')
|
|
|
|
|
.html('<p>' + response.data.message + '</p>');
|
|
|
|
|
|
|
|
|
|
// Reload page after 2 seconds to show updated logs
|
|
|
|
|
setTimeout(function() {
|
|
|
|
|
location.reload();
|
|
|
|
|
}, 2000);
|
|
|
|
|
} else {
|
|
|
|
|
$status
|
|
|
|
|
.removeClass('notice-info notice-success')
|
|
|
|
|
.addClass('notice-error')
|
|
|
|
|
.html('<p>Error: ' + (response.data.message || 'Unknown error') + '</p>');
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
error: function(jqXHR, textStatus, errorThrown) {
|
|
|
|
|
$status
|
|
|
|
|
.removeClass('notice-info notice-success')
|
|
|
|
|
.addClass('notice-error')
|
|
|
|
|
.html('<p>Error: ' + errorThrown + '</p>');
|
|
|
|
|
},
|
|
|
|
|
complete: function() {
|
|
|
|
|
$button.prop('disabled', false).removeClass('informatiq-sp-loading');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Handle test connection button click
|
|
|
|
|
*/
|
|
|
|
|
handleTestConnection: function(e) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
|
|
var $button = $(this);
|
|
|
|
|
var $status = $('#informatiq-sp-sync-status');
|
|
|
|
|
|
|
|
|
|
// Disable button and show loading state
|
|
|
|
|
$button.prop('disabled', true).addClass('informatiq-sp-loading');
|
|
|
|
|
|
|
|
|
|
// Show status message
|
|
|
|
|
$status
|
|
|
|
|
.removeClass('notice-success notice-error')
|
|
|
|
|
.addClass('notice-info')
|
|
|
|
|
.html('<p>' + (informatiqSP.strings.testInProgress || 'Testing connection...') + '</p>')
|
|
|
|
|
.show();
|
|
|
|
|
|
|
|
|
|
// Make AJAX request
|
|
|
|
|
$.ajax({
|
|
|
|
|
url: informatiqSP.ajaxUrl,
|
|
|
|
|
type: 'POST',
|
|
|
|
|
data: {
|
|
|
|
|
action: 'informatiq_sp_test_connection',
|
|
|
|
|
nonce: informatiqSP.nonce
|
|
|
|
|
},
|
|
|
|
|
success: function(response) {
|
|
|
|
|
if (response.success) {
|
|
|
|
|
$status
|
|
|
|
|
.removeClass('notice-info notice-error')
|
|
|
|
|
.addClass('notice-success')
|
|
|
|
|
.html('<p>' + response.data.message + '</p>');
|
|
|
|
|
} else {
|
|
|
|
|
$status
|
|
|
|
|
.removeClass('notice-info notice-success')
|
|
|
|
|
.addClass('notice-error')
|
|
|
|
|
.html('<p>Error: ' + (response.data.message || 'Unknown error') + '</p>');
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
error: function(jqXHR, textStatus, errorThrown) {
|
|
|
|
|
$status
|
|
|
|
|
.removeClass('notice-info notice-success')
|
|
|
|
|
.addClass('notice-error')
|
|
|
|
|
.html('<p>Error: ' + errorThrown + '</p>');
|
|
|
|
|
},
|
|
|
|
|
complete: function() {
|
|
|
|
|
$button.prop('disabled', false).removeClass('informatiq-sp-loading');
|
|
|
|
|
|
|
|
|
|
// Hide status message after 5 seconds
|
|
|
|
|
setTimeout(function() {
|
|
|
|
|
$status.fadeOut();
|
|
|
|
|
}, 5000);
|
|
|
|
|
}
|
|
|
|
|
});
|
2026-01-21 08:52:57 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Handle revoke authorization button click
|
|
|
|
|
*/
|
|
|
|
|
handleRevokeAuth: function(e) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
|
|
var $button = $(this);
|
|
|
|
|
|
|
|
|
|
// Confirm action
|
|
|
|
|
if (!confirm(informatiqSP.strings.revokeConfirm || 'Are you sure you want to revoke Google authorization?')) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Disable button and show loading state
|
|
|
|
|
$button.prop('disabled', true).text(informatiqSP.strings.revokeInProgress || 'Revoking...');
|
|
|
|
|
|
|
|
|
|
// Make AJAX request
|
|
|
|
|
$.ajax({
|
|
|
|
|
url: informatiqSP.ajaxUrl,
|
|
|
|
|
type: 'POST',
|
|
|
|
|
data: {
|
|
|
|
|
action: 'informatiq_sp_revoke_auth',
|
|
|
|
|
nonce: informatiqSP.nonce
|
|
|
|
|
},
|
|
|
|
|
success: function(response) {
|
|
|
|
|
if (response.success) {
|
|
|
|
|
// Reload page to show updated status
|
|
|
|
|
location.reload();
|
|
|
|
|
} else {
|
|
|
|
|
alert('Error: ' + (response.data.message || 'Unknown error'));
|
|
|
|
|
$button.prop('disabled', false).text('Revoke Authorization');
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
error: function(jqXHR, textStatus, errorThrown) {
|
|
|
|
|
alert('Error: ' + errorThrown);
|
|
|
|
|
$button.prop('disabled', false).text('Revoke Authorization');
|
|
|
|
|
}
|
|
|
|
|
});
|
2025-12-23 07:48:45 +01:00
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
// Initialize when document is ready
|
|
|
|
|
$(document).ready(function() {
|
|
|
|
|
InformatiqSP.init();
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
})(jQuery);
|