/** * Admin status auto-update functionality */ (function($) { 'use strict'; // Status update interval ID let statusInterval = null; const refreshInterval = 3000; // 3 seconds /** * Updates the status cards with fresh data */ function updateStatus() { $.ajax({ url: mxchat_status_data.ajax_url, type: 'POST', data: { action: 'mxchat_get_status_updates', nonce: mxchat_status_data.nonce }, success: function(response) { // Update sitemap status if it exists if (response.sitemap_status) { // Update progress bar $('.mxchat-status-card:contains("Sitemap Processing") .mxchat-progress-fill') .css('width', response.sitemap_status.percentage + '%'); // Update status text $('.mxchat-status-card:contains("Sitemap Processing") .mxchat-status-details p:first') .text('Progress: ' + response.sitemap_status.processed_urls + ' of ' + response.sitemap_status.total_urls + ' URLs (' + response.sitemap_status.percentage + '%)'); // If complete, refresh the page to clean up if (response.sitemap_status.status === 'complete') { location.reload(); } } else { // If no more sitemap status, remove the card with animation $('.mxchat-status-card:contains("Sitemap Processing")').fadeOut(300); } // Update PDF status if it exists if (response.pdf_status) { // Update progress bar $('.mxchat-status-card:contains("PDF Processing") .mxchat-progress-fill') .css('width', response.pdf_status.percentage + '%'); // Update status text $('.mxchat-status-card:contains("PDF Processing") .mxchat-status-details p:first') .text('Progress: ' + response.pdf_status.processed_pages + ' of ' + response.pdf_status.total_pages + ' pages (' + response.pdf_status.percentage + '%)'); // If complete, refresh the page to clean up if (response.pdf_status.status === 'complete') { location.reload(); } } else { // If no more PDF status, remove the card with animation $('.mxchat-status-card:contains("PDF Processing")').fadeOut(300); } // If nothing is processing anymore, stop checking if (!response.is_processing) { clearInterval(statusInterval); // Maybe reload the page to refresh the table with new data location.reload(); } } }); } // Initialize when the document is ready $(document).ready(function() { // Change the text in the status headers $('.mxchat-status-header h4:contains("Refresh for update")').each(function() { $(this).text($(this).text().replace('(Refresh for update)', '(Auto-updating)')); }); // Start auto-updating if we have status cards if ($('.mxchat-status-card').length > 0) { updateStatus(); // Run once immediately statusInterval = setInterval(updateStatus, refreshInterval); } // Monitor for form submissions to start the updates $('#mxchat-sitemap-form').on('submit', function() { // We'll start the updating when the page reloads and shows a status card }); }); })(jQuery);