PDF-Export: Autotable-Plugin zuverlaessig laden vor der Generierung
loadPdfLibraries() hat im "bereits ladend"-Zweig aufgeloest, sobald jsPDF vorhanden war — das Autotable-Plugin (zweites Script) war dann aber noch nicht angehaengt, sodass doc.autoTable undefined war und die Generierung mit "doc.autoTable is not a function" fehlschlug. Die Polling-Bedingung prueft jetzt auch jsPDF.API.autoTable, und generatePDF wartet zusaetzlich auf loadPdfLibraries(), bevor das Dokument gebaut wird. Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
+13
-2
@@ -212,11 +212,17 @@ function generatePDF(event) {
|
|||||||
url += params.join('&') + '&';
|
url += params.join('&') + '&';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// loadPdfLibraries() is awaited here too (not only when the modal opens) so
|
||||||
|
// the autotable plugin is guaranteed to be attached before we build the doc.
|
||||||
|
// Without this, opening the modal and submitting before the plugin script
|
||||||
|
// finished loading would reach generatePdfDocument() with doc.autoTable
|
||||||
|
// still undefined ("doc.autoTable is not a function").
|
||||||
Promise.all([
|
Promise.all([
|
||||||
|
loadPdfLibraries(),
|
||||||
fetch('/api/settings').then(res => res.json()),
|
fetch('/api/settings').then(res => res.json()),
|
||||||
fetch(url).then(res => res.json())
|
fetch(url).then(res => res.json())
|
||||||
])
|
])
|
||||||
.then(([settings, applications]) => {
|
.then(([_loaded, settings, applications]) => {
|
||||||
generatePdfDocument(settings, applications, month, year);
|
generatePdfDocument(settings, applications, month, year);
|
||||||
hideModal(pdfExportModal);
|
hideModal(pdfExportModal);
|
||||||
})
|
})
|
||||||
@@ -603,7 +609,12 @@ function loadPdfLibraries() {
|
|||||||
// Check if already loading
|
// Check if already loading
|
||||||
if (document.getElementById('jspdf-script')) {
|
if (document.getElementById('jspdf-script')) {
|
||||||
const checkLoaded = setInterval(() => {
|
const checkLoaded = setInterval(() => {
|
||||||
if (window.jspdf && window.jspdf.jsPDF) {
|
// Wait for the autotable plugin too, not just jsPDF: jsPDF loads
|
||||||
|
// first (script1), the plugin second (script2). Resolving the
|
||||||
|
// moment jsPDF exists leaves doc.autoTable undefined if script2
|
||||||
|
// has not run yet.
|
||||||
|
if (window.jspdf && window.jspdf.jsPDF
|
||||||
|
&& typeof window.jspdf.jsPDF.API.autoTable === 'function') {
|
||||||
clearInterval(checkLoaded);
|
clearInterval(checkLoaded);
|
||||||
pdfLibrariesLoaded = true;
|
pdfLibrariesLoaded = true;
|
||||||
resolve();
|
resolve();
|
||||||
|
|||||||
Reference in New Issue
Block a user