// =================================== // Order Dashboard - Main JavaScript // =================================== // Global state let allData = []; let filteredData = []; let currentSort = { column: null, direction: null }; let filters = {}; let columnTextFilters = {}; let hideOkFilter = false; let apiCredentials = null; // API Configuration const API_URL = 'https://n8n.finorbrands.com/webhook/61f89d5c-8474-4045-b52c-50ee608435c0'; // Initialize document.addEventListener('DOMContentLoaded', () => { updateAuthUI(); loadData(); setupClickOutside(); }); // =================================== // Authentication // =================================== function updateAuthUI() { const btnText = document.getElementById('authBtnText'); if (!btnText) return; const storedUsername = localStorage.getItem('api_username'); if (storedUsername) { btnText.textContent = `Logged in as ${storedUsername}`; } else { btnText.textContent = 'Enter Credentials'; } } function toggleAuth() { const storedUsername = localStorage.getItem('api_username'); if (storedUsername) { localStorage.removeItem('api_username'); localStorage.removeItem('api_password'); apiCredentials = null; updateAuthUI(); loadData(); } else { showCredentialPrompt(); } } // =================================== // Data Loading // =================================== async function loadData() { const tableBody = document.getElementById('tableBody'); if (!tableBody) return; tableBody.innerHTML = `
No orders found matching your filters