Digital Notebook for Life Planning
Your Goals
Settings saved!
No goals set yet.
'; } goals.forEach(goal => { const goalEl = document.createElement('div'); goalEl.className = 'p-3 bg-white border rounded-lg flex justify-between items-center'; goalEl.innerHTML = `${goal.title}
${goal.category} - Target: ${new Date(goal.date).toLocaleDateString()}
Your vision board is empty. Add an image to get started!
'; } visionItems.forEach(item => { const itemEl = document.createElement('div'); itemEl.className = 'vision-item relative group bg-gray-200 rounded-lg overflow-hidden shadow'; itemEl.innerHTML = `${item.caption}
`;
visionBoard.appendChild(itemEl);
});
};
const renderNotes = () => {
noteList.innerHTML = '';
if (notes.length === 0) {
noteList.innerHTML = 'You have no notes.
'; } [...notes].reverse().forEach(note => { const noteEl = document.createElement('div'); noteEl.className = 'bg-white p-4 rounded-lg border'; noteEl.innerHTML = `${note.title}
${note.text}
`; noteList.appendChild(noteEl); }); }; // --- Global Delete Functions --- window.deleteGoal = (id) => { goals = goals.filter(g => g.id !== id); saveData(); renderGoals(); }; window.deleteVisionItem = (id) => { visionItems = visionItems.filter(v => v.id !== id); saveData(); renderVisionBoard(); }; window.deleteNote = (id) => { notes = notes.filter(n => n.id !== id); saveData(); renderNotes(); }; // --- Event Listeners --- Object.keys(tabs).forEach(key => { tabs[key].addEventListener('click', () => switchTab(key)); }); goalForm.addEventListener('submit', (e) => { e.preventDefault(); goals.push({ id: Date.now(), title: document.getElementById('goal-title').value, category: document.getElementById('goal-category').value, date: document.getElementById('goal-date').value, }); goalForm.reset(); saveData(); renderGoals(); }); visionForm.addEventListener('submit', (e) => { e.preventDefault(); visionItems.push({ id: Date.now(), url: document.getElementById('vision-image-url').value, caption: document.getElementById('vision-caption').value, }); visionForm.reset(); saveData(); renderVisionBoard(); }); noteForm.addEventListener('submit', (e) => { e.preventDefault(); notes.push({ id: Date.now(), title: document.getElementById('note-title').value, text: document.getElementById('note-text').value, }); noteForm.reset(); saveData(); renderNotes(); }); saveSettingsBtn.addEventListener('click', () => { username = usernameInput.value.trim() || 'User'; saveData(); settingsSavedMsg.classList.remove('hidden'); setTimeout(() => settingsSavedMsg.classList.add('hidden'), 2000); }); pdfDownloadBtn.addEventListener('click', () => { const { jsPDF } = window.jspdf; const doc = new jsPDF(); let yPos = 40; doc.setFontSize(20); doc.text(`${username}'s Life Planning Notebook`, 105, 20, null, null, 'center'); doc.setFontSize(12); doc.text(new Date().toLocaleDateString(), 105, 28, null, null, 'center'); // Goals Section doc.setFontSize(16); doc.text("Goals", 14, yPos); doc.autoTable({ startY: yPos + 5, head: [['Title', 'Category', 'Target Date']], body: goals.map(g => [g.title, g.category, new Date(g.date).toLocaleDateString()]), }); yPos = doc.autoTable.previous.finalY + 15; // Notes Section doc.setFontSize(16); doc.text("Notes", 14, yPos); yPos += 10; notes.forEach(note => { if (yPos > 260) { doc.addPage(); yPos = 20; } doc.setFontSize(12); doc.setFont(undefined, 'bold'); doc.text(note.title, 14, yPos); yPos += 7; doc.setFont(undefined, 'normal'); const noteText = doc.splitTextToSize(note.text, 180); doc.text(noteText, 14, yPos); yPos += (noteText.length * 5) + 5; }); doc.save(`${username}_Life_Notebook.pdf`); }); // --- Initial Load --- loadData(); });