`;
});
goalsContainer.innerHTML = `
Goals & Action Plan
${goalsHTML.length > 0 ? goalsHTML : 'No goals or action plans have been created.
'}`; } } // --- DATA GATHERING --- function getAssessmentData() { const data = []; if (!assessmentForm) return data; const formData = new FormData(assessmentForm); for (const comp of leadershipCompetencies) { const score = formData.get(comp.id); if (score) { data.push({ id: comp.id, name: comp.name, score: parseInt(score) }); } } return data; } function getGoalsData() { const goals = []; if (!goalsContainer) return goals; const goalTextareas = goalsContainer.querySelectorAll('textarea'); goalTextareas.forEach(textarea => { goals.push({ id: textarea.dataset.competencyId, name: textarea.dataset.competencyName, text: textarea.value }); }); return goals; } function getActionPlanData() { const plans = []; if (!actionPlanContainer) return plans; const uniqueGoalIds = [...new Set(Array.from(actionPlanContainer.querySelectorAll('.action-input')).map(el => el.dataset.goalId))]; uniqueGoalIds.forEach(id => { const stepsEl = document.getElementById(`action-steps-${id}`); const resourcesEl = document.getElementById(`action-resources-${id}`); const timelineEl = document.getElementById(`action-timeline-${id}`); if (stepsEl && resourcesEl && timelineEl) { plans.push({ id: id, steps: stepsEl.value, resources: resourcesEl.value, timeline: timelineEl.value }); } }); return plans; } // --- UI & NAVIGATION --- function switchTab(tabIndex) { // Validation before switching if (tabIndex > currentTab) { if (currentTab === 0 && !assessmentForm.checkValidity()) { alert('Please complete all assessment questions before proceeding.'); assessmentForm.reportValidity(); return; } } // Run population functions when moving to a new tab if (tabIndex === 1 && currentTab === 0) { populateGoalsTab(); } if (tabIndex === 2 && currentTab === 1) { populateActionPlanTab(); } if (tabIndex === 3 && currentTab === 2) { populateDashboard(); } currentTab = tabIndex; tabButtons.forEach((button, index) => { button.classList.toggle('active', index === currentTab); }); tabContents.forEach((content, index) => { content.classList.toggle('active', index === currentTab); }); updateNavButtons(); } function updateNavButtons() { if (prevBtn) { prevBtn.classList.toggle('invisible', currentTab === 0); } if (nextBtn) { nextBtn.textContent = (currentTab === tabs.length - 2) ? 'Finish' : 'Next'; nextBtn.classList.toggle('invisible', currentTab === tabs.length - 1); } } // --- EVENT LISTENERS --- function addEventListeners() { tabButtons.forEach((button, index) => { button.addEventListener('click', () => { // Allow jumping back, but not forward past uncompleted steps if (index < currentTab) { switchTab(index); } }); }); if (nextBtn) { nextBtn.addEventListener('click', () => { if (currentTab < tabs.length - 1) { switchTab(currentTab + 1); } }); } if (prevBtn) { prevBtn.addEventListener('click', () => { if (currentTab > 0) { switchTab(currentTab - 1); } }); } if (downloadPdfBtn) { downloadPdfBtn.addEventListener('click', generatePdf); } } // --- PDF GENERATION --- function generatePdf() { const { jsPDF } = window.jspdf; const pdfContent = document.getElementById('pdf-content'); if (!pdfContent) { console.error("PDF content area not found."); return; } const toolTitle = "Leadership Development Plan"; html2canvas(pdfContent, { scale: 2, // Higher scale for better quality useCORS: true, logging: false }).then(canvas => { const imgData = canvas.toDataURL('image/png'); const pdf = new jsPDF({ orientation: 'p', unit: 'mm', format: 'a4' }); const pdfWidth = pdf.internal.pageSize.getWidth(); const pdfHeight = pdf.internal.pageSize.getHeight(); const canvasWidth = canvas.width; const canvasHeight = canvas.height; const ratio = canvasWidth / canvasHeight; const imgWidth = pdfWidth - 20; // with 10mm margin on each side const imgHeight = imgWidth / ratio; let heightLeft = imgHeight; let position = 15; // Top margin pdf.setFont('Inter', 'bold'); pdf.setFontSize(20); pdf.text(toolTitle, pdfWidth / 2, 10, { align: 'center' }); pdf.addImage(imgData, 'PNG', 10, position, imgWidth, imgHeight); heightLeft -= (pdfHeight - position - 10); // 10mm bottom margin while (heightLeft > 0) { position = -heightLeft - 10; pdf.addPage(); pdf.addImage(imgData, 'PNG', 10, position, imgWidth, imgHeight); heightLeft -= pdfHeight; } pdf.save('Leadership-Development-Plan.pdf'); }).catch(error => { console.error("Error generating PDF:", error); alert("Sorry, there was an error generating the PDF. Please try again."); }); } // --- START THE APP --- initialize(); });