/** * 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(''); $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( '

' + response.data.message + '

' ); } else { $result.html( '

' + response.data.message + '

' ); } }, error: function(xhr, status, error) { $result.html( '

' + 'Błąd połączenia: ' + error + '

' ); }, 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);