// Swiss Football Admin JavaScript jQuery(document).ready(function($) { 'use strict'; // Refresh teams functionality $('#refresh-teams').on('click', function() { var $button = $(this); var $status = $('#refresh-status'); $button.prop('disabled', true).text('Refreshing...'); $status.text('').removeClass('success error'); fetch(swi_foot_ajax.rest_url.replace(/\/$/, '') + '/admin/refresh-teams', { method: 'POST', credentials: 'same-origin', headers: { 'Content-Type': 'application/json', 'X-WP-Nonce': swi_foot_ajax.rest_nonce } }).then(function(resp) { return resp.json(); }).then(function(response) { if (response && response.success) { $status.text('Teams refreshed successfully!').addClass('success'); setTimeout(function() { location.reload(); }, 1500); } else { $status.text('Error: ' + (response.error || 'Unknown')).addClass('error'); } }).catch(function() { $status.text('Network error occurred.').addClass('error'); }).finally(function() { $button.prop('disabled', false).text('Refresh Teams List'); }); }); // Clear cache functionality $('#clear-cache').on('click', function() { var $button = $(this); var $status = $('#cache-status'); if (!confirm('Are you sure you want to clear the match data cache?')) { return; } $button.prop('disabled', true); $status.text('Clearing cache...').removeClass('success error'); fetch(swi_foot_ajax.rest_url.replace(/\/$/, '') + '/admin/clear-cache', { method: 'POST', credentials: 'same-origin', headers: { 'Content-Type': 'application/json', 'X-WP-Nonce': swi_foot_ajax.rest_nonce } }).then(function(resp) { return resp.json(); }).then(function(response) { if (response && response.success) { $status.text('Cache cleared successfully!').addClass('success'); setTimeout(function() { location.reload(); }, 1000); } else { $status.text('Error clearing cache.').addClass('error'); } }).catch(function() { $status.text('Error clearing cache.').addClass('error'); }).finally(function() { $button.prop('disabled', false); }); }); // Test API connection $('#test-connection').on('click', function() { var $button = $(this); var $status = $('#connection-status'); $button.prop('disabled', true).text('Testing...'); $status.text('').removeClass('success error'); fetch(swi_foot_ajax.rest_url.replace(/\/$/, '') + '/admin/test-connection', { method: 'POST', credentials: 'same-origin', headers: { 'Content-Type': 'application/json', 'X-WP-Nonce': swi_foot_ajax.rest_nonce } }).then(function(resp) { return resp.json(); }).then(function(response) { if (response && response.success) { $status.text('Connection successful!').addClass('success'); } else { $status.text('Connection failed: ' + (response.error || 'Unknown')).addClass('error'); } }).catch(function() { $status.text('Network error occurred.').addClass('error'); }).finally(function() { $button.prop('disabled', false).text('Test API Connection'); }); }); // Auto-save settings notice $('form').on('submit', function() { $('

Settings saved! The plugin will automatically refresh API tokens as needed.

') .insertAfter('.wrap h1'); }); });