diff --git a/Web/templates/upload_admin.html b/Web/templates/upload_admin.html index 3c33787..d41f4a6 100755 --- a/Web/templates/upload_admin.html +++ b/Web/templates/upload_admin.html @@ -1523,78 +1523,8 @@ document.getElementById('new-location-input').value = ''; } - // Function to fetch book information from ISBN - function fetchBookInfo(formType) { - if (!libraryModuleEnabled) { - alert('Bibliotheks-Modul ist deaktiviert.'); - return; - } - const isbnField = document.getElementById('isbn'); - const infoContainer = document.getElementById('book-info-container'); - - if (!isbnField || !infoContainer) { - alert('Fehler: Erforderliche Formularelemente nicht gefunden.'); - return; - } - - const isbn = normalizeIsbnClient(isbnField.value); - - if (!isbn) { - infoContainer.innerHTML = '
Bitte geben Sie eine ISBN oder einen Barcode ein.
'; - return; - } - - // Show loading indicator - infoContainer.innerHTML = '
Informationen werden abgerufen...
'; - - // Make API request to fetch book data - fetch(`/fetch_book_info/${isbn}`) - .then(response => { - if (!response.ok) { - if (response.status === 404) { - throw new Error('Buch nicht gefunden. Überprüfen Sie die ISBN.'); - } else { - throw new Error('Fehler beim Abrufen der Buchinformationen'); - } - } - return response.json(); - }) - .then(data => { - if (data.error) { - infoContainer.innerHTML = `
${data.error}
`; - return; - } - - // Store book data globally for import functionality - currentBookData = data; - - // Display book information with import button - infoContainer.innerHTML = ` -
-

${data.title}

- ${data.authors ? `

Autor(en): ${data.authors}

` : ''} - ${data.publisher ? `

Verlag: ${data.publisher}

` : ''} - ${data.publishedDate ? `

Erscheinungsdatum: ${data.publishedDate}

` : ''} - ${data.pageCount ? `

Seitenanzahl: ${data.pageCount}

` : ''} - ${data.price ? `

Preis: ${data.price}

` : ''} - ${data.thumbnail ? `Buchcover` : ''} - ${data.description ? ` -
-
Beschreibung:
-

${data.description}

-
- ` : ''} - -
- `; - }) - .catch(error => { - infoContainer.innerHTML = `
${error.message}
`; - currentBookData = null; - }); - } + let currentFetchedIsbn = null; + let currentBookData = null; // Function to import book information into form function importBookInfo(formType) { @@ -1602,23 +1532,23 @@ alert('Keine Buchdaten verfügbar zum Import.'); return; } - + // Get form fields const nameField = document.getElementById('name'); const descriptionField = document.getElementById('beschreibung'); - const priceField = document.getElementById('anschaffungskosten'); // <-- NEU - + const priceField = document.getElementById('anschaffungskosten'); + if (!nameField || !descriptionField) { alert('Fehler: Formularfelder nicht gefunden.'); return; } - + // Generate book title let bookTitle = currentBookData.title || ''; if (currentBookData.authors && currentBookData.authors !== 'Unknown Author') { bookTitle += ` - ${currentBookData.authors}`; } - + // Generate description let description = ''; if (currentBookData.description && currentBookData.description !== 'No description available') { @@ -1639,11 +1569,11 @@ description += `\nSeiten: ${currentBookData.pageCount}`; } } - + // Import the data into form fields nameField.value = bookTitle; descriptionField.value = description; - + // Preis in das Formularfeld eintragen if (priceField && currentBookData.price !== null && currentBookData.price !== undefined) { // Wandelt den Float (z.B. 12.25) in einen String mit Komma (12,25) um @@ -1651,18 +1581,31 @@ priceField.value = formattedPrice; } - // Download and import book cover image if available + // Download and import book cover image if available (mit Sicherheits-Check) if (currentBookData.thumbnail) { - downloadBookCover(currentBookData.thumbnail); + if (typeof downloadBookCover === 'function') { + try { + downloadBookCover(currentBookData.thumbnail); + } catch (e) { + console.warn("Cover konnte nicht heruntergeladen werden:", e); + } + } } - + // Show success message const infoContainer = document.getElementById('book-info-container'); + + // Alte Erfolgsmeldung entfernen, falls jemand mehrfach klickt + const oldMessage = infoContainer.querySelector('.import-success-message'); + if (oldMessage) { + oldMessage.remove(); + } + const successMessage = document.createElement('div'); successMessage.className = 'import-success-message'; successMessage.textContent = 'Buchdaten erfolgreich in das Formular übernommen!'; infoContainer.appendChild(successMessage); - + // Remove success message after 3 seconds setTimeout(() => { if (successMessage.parentNode) { @@ -1671,6 +1614,95 @@ }, 3000); } + // Function to fetch book information from ISBN + function fetchBookInfo(formType) { + if (typeof libraryModuleEnabled !== 'undefined' && !libraryModuleEnabled) { + alert('Bibliotheks-Modul ist deaktiviert.'); + return; + } + const isbnField = document.getElementById('isbn'); + const infoContainer = document.getElementById('book-info-container'); + + if (!isbnField || !infoContainer) { + alert('Fehler: Erforderliche Formularelemente nicht gefunden.'); + return; + } + + const isbn = typeof normalizeIsbnClient === 'function' + ? normalizeIsbnClient(isbnField.value) + : isbnField.value.trim(); + + if (!isbn) { + infoContainer.innerHTML = '
Bitte geben Sie eine ISBN oder einen Barcode ein.
'; + currentFetchedIsbn = null; + return; + } + + // --- DER FIX FÜR DAS DOPPELKLICK-PROBLEM --- + // Wenn das Buch bereits erfolgreich geladen wurde und auf dem Bildschirm steht, + // unterbrechen wir hier. Das schützt den Button vor dem Überschreiben. + if (currentFetchedIsbn === isbn && currentBookData !== null) { + return; + } + // ------------------------------------------- + + // Sperre für den aktuellen Suchbegriff setzen + currentFetchedIsbn = isbn; + + // Show loading indicator + infoContainer.innerHTML = '
Informationen werden abgerufen...
'; + + // Make API request to fetch book data + fetch(`/fetch_book_info/${isbn}`) + .then(response => { + if (!response.ok) { + if (response.status === 404) { + throw new Error('Buch nicht gefunden. Überprüfen Sie die ISBN.'); + } else { + throw new Error('Fehler beim Abrufen der Buchinformationen'); + } + } + return response.json(); + }) + .then(data => { + if (data.error) { + infoContainer.innerHTML = `
${data.error}
`; + currentFetchedIsbn = null; // Freigabe bei Fehler + return; + } + + // Store book data globally for import functionality + currentBookData = data; + + // Display book information with import button + infoContainer.innerHTML = ` +
+

${data.title}

+ ${data.authors ? `

Autor(en): ${data.authors}

` : ''} + ${data.publisher ? `

Verlag: ${data.publisher}

` : ''} + ${data.publishedDate ? `

Erscheinungsdatum: ${data.publishedDate}

` : ''} + ${data.pageCount ? `

Seitenanzahl: ${data.pageCount}

` : ''} + ${data.price ? `

Preis: ${data.price}

` : ''} + ${data.thumbnail ? `Buchcover` : ''} + ${data.description ? ` +
+
Beschreibung:
+

${data.description}

+
+ ` : ''} + +
+ `; + }) + .catch(error => { + infoContainer.innerHTML = `
${error.message}
`; + currentBookData = null; + currentFetchedIsbn = null; + }); + } + function downloadBookCover(imageUrl) { if (!imageUrl) { console.log('No image URL provided');