`;
sectionDiv.appendChild(taskRow);
});
container.appendChild(sectionDiv);
});
}
// --- Interaction Logic ---
window.tacToggleCompletion = function(id) {
const task = trustTasks.find(t => t.id === id);
if (task) {
task.completed = !task.completed;
tacRenderChecklist(); // Re-render to update line-through
}
};
window.tacEditTask = function(id) {
const task = trustTasks.find(t => t.id === id);
if (task) {
const newNote = prompt(`Edit Notes for: ${task.task}\n\nCurrent Note: ${task.notes || ''}`);
if (newNote !== null) {
task.notes = newNote.trim();
tacRenderChecklist();
}
}
};
// --- PDF Generation ---
window.tacDownloadPDF = function() {
const element = document.getElementById('tac-print-area');
const trustorName = document.getElementById('cfg-trustor').value || 'Trust';
const dateStr = new Date().toISOString().split('T')[0];
document.body.classList.add('tac-generating-pdf');
const opt = {
margin: [0.5, 0.5],
filename: `${trustorName.replace(/\s+/g, '_')}_Trust_Checklist_${dateStr}.pdf`,
image: { type: 'jpeg', quality: 0.98 },
html2canvas: { scale: 2, useCORS: true },
jsPDF: { unit: 'in', format: 'letter', orientation: 'portrait' }
};
html2pdf().set(opt).from(element).save().then(() => {
document.body.classList.remove('tac-generating-pdf');
});
};
// Utility: HTML Escape
function escapeHtml(text) {
if (!text) return '';
return text.replace(/[&<>"']/g, function(m) {
switch (m) {
case '&': return '&';
case '<': return '<';
case '>': return '>';
case '"': return '"';
case "'": return ''';
default: return m;
}
});
}
