`;
container.innerHTML = tableHTML;
}
window.editInfringement = (id) => {
const item = infringements.find(i => i.id === id);
if (item) {
editingIdField.value = id;
document.getElementById('infringingUrl').value = item.url;
document.getElementById('workType').value = item.workType;
document.getElementById('dateDiscovered').value = item.date;
document.getElementById('actionTaken').value = item.action;
document.getElementById('status').value = item.status;
document.getElementById('notes').value = item.notes;
formSubmitBtn.textContent = 'Update Infringement';
showTab(1);
}
};
window.deleteInfringement = (id) => {
if(confirm('Are you sure you want to delete this entry?')) {
infringements = infringements.filter(i => i.id !== id);
renderInfringementLog();
}
};
form.addEventListener('submit', (e) => {
e.preventDefault();
const editingId = parseInt(editingIdField.value);
const infringementData = {
url: document.getElementById('infringingUrl').value,
workType: document.getElementById('workType').value,
date: document.getElementById('dateDiscovered').value,
action: document.getElementById('actionTaken').value,
status: document.getElementById('status').value,
notes: document.getElementById('notes').value
};
if (editingId) {
const index = infringements.findIndex(i => i.id === editingId);
infringements[index] = { id: editingId, ...infringementData };
} else {
infringementData.id = infringements.length > 0 ? Math.max(...infringements.map(i => i.id)) + 1 : 1;
infringements.push(infringementData);
}
form.reset();
editingIdField.value = '';
formSubmitBtn.textContent = 'Add Infringement';
renderInfringementLog();
showTab(0);
});
async function downloadPdf() {
const pdfLoader = document.getElementById('pdf-loader');
const downloadBtn = document.getElementById('downloadPdfBtn');
renderReport(); // Make sure the report content is up-to-date
const content = document.getElementById('pdf-content');
if(!content) return;
pdfLoader.classList.remove('hidden');
downloadBtn.disabled = true;
try {
const { jsPDF } = window.jspdf;
const pdf = new jsPDF({ orientation: 'landscape', unit: 'pt', format: 'letter' });
const canvas = await html2canvas(content, { scale: 2 });
const imgData = canvas.toDataURL('image/png');
const pdfWidth = pdf.internal.pageSize.getWidth();
const pdfHeight = pdf.internal.pageSize.getHeight();
const margin = 40;
const imgWidth = pdfWidth - (margin * 2);
const imgHeight = (canvas.height * imgWidth) / canvas.width;
let position = margin;
pdf.addImage(imgData, 'PNG', margin, position, imgWidth, imgHeight);
let heightLeft = imgHeight - (pdfHeight - margin*2);
while (heightLeft > 0) {
position -= (pdfHeight - margin*2);
pdf.addPage();
pdf.addImage(imgData, 'PNG', margin, position, imgWidth, imgHeight);
heightLeft -= (pdfHeight - margin*2);
}
pdf.save('Copyright-Infringement-Report.pdf');
} catch (error) {
console.error("Error generating PDF:", error);
alert("There was an error generating the PDF. Please try again.");
} finally {
pdfLoader.classList.add('hidden');
downloadBtn.disabled = false;
}
}
document.getElementById('downloadPdfBtn').addEventListener('click', downloadPdf);
// Initial setup
document.getElementById('dateDiscovered').value = new Date().toISOString().split('T')[0];
showTab(currentTab);
renderInfringementLog();
lucide.createIcons();
});
