Priority Time Planner

Priority Time Planner

Weekly Priority Plan

Add a New Task

Task List

Export Planner

Download your weekly planner as a PDF document.

${task.name}

${task.time}

`; // (hour - 8) * 7 days + dayIndex + 1 (for time label) + 8 (for headers) const gridIndex = (startHour - 8) * 8 + dayIndex + 1 + 8; const targetCell = plannerGridContainer.children[gridIndex]; if(targetCell) targetCell.appendChild(taskBlock); }); } function renderTaskList() { const table = ` ${tasks.map(task => ` `).join('')}
Task Priority Day Time Actions
${task.name} ${task.priority} ${task.day} ${task.time}
`; taskListContainer.innerHTML = table; } // --- LOGIC FUNCTIONS --- function populateSelects() { taskDaySelect.innerHTML = daysOfWeek.map(d => ``).join(''); } function clearForm() { taskForm.reset(); taskIdInput.value = ''; saveTaskBtn.textContent = 'Add Task'; } function handleFormSubmit(e) { e.preventDefault(); const id = taskIdInput.value ? parseInt(taskIdInput.value) : null; const taskData = { name: taskNameInput.value, priority: taskPrioritySelect.value, day: taskDaySelect.value, time: taskTimeInput.value, duration: parseInt(taskDurationInput.value), }; if (id) { const index = tasks.findIndex(t => t.id === id); tasks[index] = { ...tasks[index], ...taskData }; } else { const newId = tasks.length > 0 ? Math.max(...tasks.map(t => t.id)) + 1 : 1; tasks.push({ id: newId, ...taskData }); } clearForm(); renderAll(); } window.editTask = (id) => { const task = tasks.find(t => t.id === id); if (task) { taskIdInput.value = task.id; taskNameInput.value = task.name; taskPrioritySelect.value = task.priority; taskDaySelect.value = task.day; taskTimeInput.value = task.time; taskDurationInput.value = task.duration; saveTaskBtn.textContent = 'Update Task'; changeTab(null, 'manage-tasks'); } }; window.deleteTask = (id) => { if (confirm('Are you sure you want to delete this task?')) { tasks = tasks.filter(t => t.id !== id); renderAll(); } }; function downloadPDF() { const { jsPDF } = window.jspdf; const pdfContentEl = document.getElementById('pdf-content'); html2canvas(pdfContentEl, { scale: 2 }).then(canvas => { const imgData = canvas.toDataURL('image/png'); const pdf = new jsPDF({ orientation: 'landscape', unit: 'pt', format: 'a4' }); const pdfWidth = pdf.internal.pageSize.getWidth(); const imgProps = pdf.getImageProperties(imgData); const pdfHeight = (imgProps.height * pdfWidth) / imgProps.width; pdf.addImage(imgData, 'PNG', 20, 20, pdfWidth - 40, pdfHeight - 40); pdf.save('Priority_Time_Plan.pdf'); }); } function renderAll() { renderPlanner(); renderTaskList(); } // --- TAB NAVIGATION --- window.changeTab = function(evt, tabName) { document.querySelectorAll(".tab-content").forEach(tc => tc.classList.remove('active')); document.querySelectorAll(".tab-button").forEach(tb => tb.classList.remove('active')); document.getElementById(tabName).classList.add('active'); const button = evt ? evt.currentTarget : document.querySelector(`.tab-button[onclick*="'${tabName}'"]`); if(button) button.classList.add('active'); currentTab = tabName; updateNavButtons(); if (tabName === 'planner') renderPlanner(); } function updateNavButtons() { const currentIndex = tabs.indexOf(currentTab); prevBtn.disabled = currentIndex === 0; nextBtn.disabled = currentIndex === tabs.length - 1; prevBtn.classList.toggle('opacity-50', prevBtn.disabled); nextBtn.classList.toggle('opacity-50', nextBtn.disabled); } prevBtn.addEventListener('click', () => { const currentIndex = tabs.indexOf(currentTab); if (currentIndex > 0) changeTab(null, tabs[currentIndex - 1]); }); nextBtn.addEventListener('click', () => { const currentIndex = tabs.indexOf(currentTab); if (currentIndex < tabs.length - 1) changeTab(null, tabs[currentIndex + 1]); }); // --- INITIALIZATION --- populateSelects(); clearFormBtn.addEventListener('click', clearForm); taskForm.addEventListener('submit', handleFormSubmit); downloadPdfBtn.addEventListener('click', downloadPDF); renderAll(); updateNavButtons(); });
Scroll to Top