`;
pmd_populateConfigFields();
}
window.pmd_populateConfigFields = function() {
const selectedKey = document.getElementById('pmd-config-select').value;
const data = pmd_data[selectedKey];
const fieldsContainer = document.getElementById('pmd-config-fields');
let comparisonHtml = Object.keys(data.comparison).map(key => `
`).join('');
let visualHtml = '';
if (data.visual.type === 'waterfall') {
visualHtml = data.visual.stages.map((stage, i) => `
`).join('') + ``;
} else if (data.visual.type === 'agile') {
visualHtml = `` +
data.visual.steps.map(step => `
`).join('') + ``;
} else if (data.visual.type === 'kanban') {
visualHtml = data.visual.columns.map((col, i) => `
`).join('');
}
fieldsContainer.innerHTML = `
`;
}
window.pmd_addConfigInput = function(containerId, className) {
const container = document.getElementById(containerId);
const div = document.createElement('div');
div.className = 'pmd-dynamic-input-group';
div.innerHTML = ``;
container.insertBefore(div, container.lastElementChild);
}
window.pmd_saveConfigChanges = function() {
const selectedKey = document.getElementById('pmd-config-select').value;
const data = pmd_data[selectedKey];
data.title = document.getElementById('pmd-config-title').value;
data.description = document.getElementById('pmd-config-desc').value;
data.pros = document.getElementById('pmd-config-pros').value.split('\n').filter(Boolean);
data.cons = document.getElementById('pmd-config-cons').value.split('\n').filter(Boolean);
Object.keys(data.comparison).forEach(key => {
data.comparison[key] = document.getElementById(`pmd-config-comp-${key}`).value;
});
if (data.visual.type === 'waterfall') {
data.visual.stages = Array.from(document.querySelectorAll('.pmd-config-visual-stage')).map(el => el.value);
} else if (data.visual.type === 'agile') {
data.visual.centerText = document.getElementById('pmd-config-visual-center').value;
data.visual.steps = Array.from(document.querySelectorAll('.pmd-config-visual-step')).map(el => el.value);
} else if (data.visual.type === 'kanban') {
data.visual.columns = Array.from(document.querySelectorAll('[id^=pmd-config-kanban-col]')).map(fs => ({
title: fs.querySelector('.pmd-config-visual-k-title').value,
cards: fs.querySelector('.pmd-config-visual-k-cards').value.split('\n').filter(Boolean)
}));
}
pmd_rerenderAll();
alert(data.title + ' content updated successfully!');
}
window.pmd_openTab = function(evt, tabId) {
document.querySelectorAll("#pmd-container .pmd-tab-content").forEach(c => c.classList.remove('active'));
document.querySelectorAll("#pmd-container .pmd-tab-link").forEach(l => l.classList.remove('active'));
document.getElementById(tabId).classList.add('active');
evt.currentTarget.classList.add('active');
};
window.pmd_navigateTabs = function(direction) {
const activeTab = document.querySelector('#pmd-container .pmd-tab-link.active');
const activeIndex = pmd_tabOrder.indexOf(activeTab.dataset.tab.replace('pmd-', ''));
let nextIndex = (direction === 'next') ? (activeIndex + 1) % pmd_tabOrder.length : (activeIndex - 1 + pmd_tabOrder.length) % pmd_tabOrder.length;
document.querySelector(`.pmd-tab-link[data-tab="pmd-${pmd_tabOrder[nextIndex]}"]`).click();
};
window.pmd_downloadPDF = function() {
const { jsPDF } = window.jspdf;
const activeTabContent = document.querySelector('.pmd-tab-content.active');
if (!activeTabContent || activeTabContent.id === 'pmd-config') {
alert("PDF download is not available for the configuration tab.");
return;
}
const activeTabLink = document.querySelector('.pmd-tab-link.active');
const title = activeTabLink.textContent + " - Methodology Report";
html2canvas(activeTabContent, { scale: 2, useCORS: true }).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 imgProps = pdf.getImageProperties(imgData);
const imgHeight = (imgProps.height * (pdfWidth - 20)) / imgProps.width;
pdf.setFontSize(18);
pdf.text(title, pdfWidth / 2, 15, { align: 'center' });
pdf.addImage(imgData, 'PNG', 10, 25, pdfWidth - 20, imgHeight);
pdf.save(`${activeTabLink.textContent.replace(/\s+/g, '-')}-Report.pdf`);
});
};
pmd_init();
});
