Cultural Festival Explorer

Cultural Festival Explorer

Current Festivals

Festival Name Country Typical Date Action

No festivals added. Go to the Configuration tab to add one.

'; return; } festivalData.forEach(festival => { const card = document.createElement('div'); card.className = 'festival-card'; card.innerHTML = ` ${festival.name}

${festival.name}

Country/Origin: ${festival.country}

Typical Date: ${festival.date}

${festival.desc}

`; cardGrid.appendChild(card); }); } function renderConfigTable() { configTableBody.innerHTML = ''; festivalData.forEach(festival => { const row = document.createElement('tr'); row.innerHTML = ` ${festival.name} ${festival.country} ${festival.date} `; configTableBody.appendChild(row); }); // Add delete listeners configTableBody.querySelectorAll('.festival-delete-btn').forEach(btn => { btn.addEventListener('click', (e) => { deleteFestival(e.target.dataset.id); }); }); } function handleAddFestival(e) { e.preventDefault(); const newFestival = { id: `festival_${Date.now()}`, name: document.getElementById('festival-name').value, country: document.getElementById('festival-country').value, date: document.getElementById('festival-date').value, desc: document.getElementById('festival-desc').value, img: document.getElementById('festival-image').value }; festivalData.push(newFestival); renderFestivalCards(); renderConfigTable(); configForm.reset(); // Optionally, switch back to dashboard // switchTab(0); } function deleteFestival(id) { if (confirm('Are you sure you want to delete this festival?')) { festivalData = festivalData.filter(f => f.id !== id); renderFestivalCards(); renderConfigTable(); } } function downloadPDF() { const { jsPDF } = window.jspdf; const doc = new jsPDF(); doc.setFontSize(18); doc.text("Cultural Festival Guide", 14, 22); const tableHead = [['Festival', 'Country/Origin', 'Typical Date', 'Description']]; const tableBody = festivalData.map(f => [f.name, f.country, f.date, f.desc]); doc.autoTable({ startY: 30, head: tableHead, body: tableBody, styles: { cellPadding: 3, fontSize: 10 }, headStyles: { fillColor: [0, 123, 255] // --primary-color }, columnStyles: { 3: { cellWidth: 80 } // Make description column wider } }); doc.save('cultural-festival-guide.pdf'); } // --- Tab Navigation --- function switchTab(tabIndex) { tabs.forEach((tab, index) => { tab.classList.toggle('active', index === tabIndex); contents[index].classList.toggle('active', index === tabIndex); }); currentTab = tabIndex; updateNavButtons(); } function updateNavButtons() { prevBtn.disabled = currentTab === 0; nextBtn.disabled = currentTab === tabs.length - 1; } tabs.forEach((tab, index) => { tab.addEventListener('click', () => switchTab(index)); }); nextBtn.addEventListener('click', () => { if (currentTab < tabs.length - 1) switchTab(currentTab + 1); }); prevBtn.addEventListener('click', () => { if (currentTab > 0) switchTab(currentTab - 1); }); // --- Event Listeners --- configForm.addEventListener('submit', handleAddFestival); pdfDownloadBtn.addEventListener('click', downloadPDF); // --- Initial Setup --- renderFestivalCards(); renderConfigTable(); updateNavButtons(); });