first commit
This commit is contained in:
@@ -0,0 +1,88 @@
|
||||
/**
|
||||
* Yacht Booking Admin JavaScript
|
||||
*
|
||||
* @package YachtBooking
|
||||
*/
|
||||
|
||||
;(function($) {
|
||||
'use strict';
|
||||
|
||||
/**
|
||||
* Admin functionality
|
||||
*/
|
||||
const YachtBookingAdmin = {
|
||||
init: function() {
|
||||
this.bindEvents();
|
||||
},
|
||||
|
||||
bindEvents: function() {
|
||||
// Manual sync button
|
||||
$(document).on('click', '#yacht-booking-manual-sync', this.handleManualSync.bind(this));
|
||||
},
|
||||
|
||||
handleManualSync: function(e) {
|
||||
e.preventDefault();
|
||||
|
||||
const $button = $(e.currentTarget);
|
||||
const $status = $('#yacht-booking-sync-status');
|
||||
const $result = $('#yacht-booking-sync-result');
|
||||
const nonce = $button.data('nonce');
|
||||
const originalText = $button.text();
|
||||
|
||||
// Disable button and show loading
|
||||
$button.prop('disabled', true).text('Synchronizowanie...');
|
||||
$status.html('<span class="spinner is-active" style="float: none; margin: 0;"></span>');
|
||||
$result.empty();
|
||||
|
||||
// AJAX call
|
||||
$.ajax({
|
||||
url: ajaxurl,
|
||||
type: 'POST',
|
||||
data: {
|
||||
action: 'yacht_booking_manual_sync',
|
||||
nonce: nonce
|
||||
},
|
||||
success: function(response) {
|
||||
if (response.success) {
|
||||
$result.html(
|
||||
'<div class="notice notice-success inline"><p>' +
|
||||
response.data.message +
|
||||
'</p></div>'
|
||||
);
|
||||
} else {
|
||||
$result.html(
|
||||
'<div class="notice notice-error inline"><p>' +
|
||||
response.data.message +
|
||||
'</p></div>'
|
||||
);
|
||||
}
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
$result.html(
|
||||
'<div class="notice notice-error inline"><p>' +
|
||||
'Błąd połączenia: ' + error +
|
||||
'</p></div>'
|
||||
);
|
||||
},
|
||||
complete: function() {
|
||||
// Re-enable button
|
||||
$button.prop('disabled', false).text(originalText);
|
||||
$status.empty();
|
||||
|
||||
// Auto-hide success message after 5 seconds
|
||||
setTimeout(function() {
|
||||
$result.find('.notice-success').fadeOut();
|
||||
}, 5000);
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
* Document ready
|
||||
*/
|
||||
$(document).ready(function() {
|
||||
YachtBookingAdmin.init();
|
||||
});
|
||||
|
||||
})(jQuery);
|
||||
Reference in New Issue
Block a user