Case Timeline
${timelineHTML || '- No timeline events.
'}
`;
document.getElementById('download-pdf-btn').addEventListener('click', downloadCaseSummary);
}
// --- EVENT HANDLERS ---
function updateNavButtons() {
const tabOrder = ['dashboard', 'cases', 'config'];
const currentIndex = tabOrder.indexOf(state.currentTab);
navButtons.prev.disabled = currentIndex === 0;
navButtons.next.disabled = currentIndex === tabOrder.length - 1;
}
function switchTab(tabName) {
state.currentTab = tabName;
Object.values(tabs).forEach(t => t.classList.remove('active'));
Object.values(contents).forEach(c => c.classList.add('hidden'));
tabs[tabName].classList.add('active');
contents[tabName].classList.remove('hidden');
updateNavButtons();
}
caseSelector.addEventListener('change', (e) => {
state.selectedCaseId = parseInt(e.target.value);
renderCaseDetails();
});
addCaseForm.addEventListener('submit', (e) => {
e.preventDefault();
const newCase = {
id: Date.now(),
name: document.getElementById('case-name').value,
client: document.getElementById('client-name').value,
type: document.getElementById('case-type').value,
status: document.getElementById('case-status').value,
documents: [], deadlines: [], messages: [], timeline: [{id: Date.now(), date: new Date().toISOString().split('T')[0], event: 'Case Created'}]
};
state.cases.push(newCase);
addCaseForm.reset();
renderAll();
alert('Case added successfully!');
});
function downloadCaseSummary() {
const caseData = state.cases.find(c => c.id === state.selectedCaseId);
if (!caseData) return;
const { jsPDF } = window.jspdf;
const doc = new jsPDF();
doc.setFontSize(18);
doc.text(`Case Summary: ${caseData.name}`, 14, 22);
doc.setFontSize(12);
doc.text(`Client: ${caseData.client}`, 14, 30);
doc.text(`Status: ${caseData.status}`, 14, 38);
let lastY = 45;
const addSection = (title, data, formatter) => {
if (data.length > 0) {
doc.setFontSize(14);
doc.text(title, 14, lastY + 10);
doc.autoTable({ startY: lastY + 15, head: [formatter.head], body: data.map(formatter.body) });
lastY = doc.lastAutoTable.finalY;
}
};
addSection('Deadlines', caseData.deadlines, { head: ['Date', 'Description'], body: d => [d.date, d.desc] });
addSection('Documents', caseData.documents, { head: ['File Name'], body: d => [d.name] });
addSection('Timeline', caseData.timeline, { head: ['Date', 'Event'], body: t => [t.date, t.event] });
doc.save(`${caseData.name.replace(/\s/g, '_')}_Summary.pdf`);
}
navButtons.next.addEventListener('click', () => {
const tabOrder = ['dashboard', 'cases', 'config'];
const currentIndex = tabOrder.indexOf(state.currentTab);
if (currentIndex < tabOrder.length - 1) switchTab(tabOrder[currentIndex + 1]);
});
navButtons.prev.addEventListener('click', () => {
const tabOrder = ['dashboard', 'cases', 'config'];
const currentIndex = tabOrder.indexOf(state.currentTab);
if (currentIndex > 0) switchTab(tabOrder[currentIndex - 1]);
});
// --- INITIALIZATION ---
function init() {
loadInitialData();
renderAll();
updateNavButtons();
}
init();
});