changes to the info importing for the library item
Release Inventarsystem / release-docker (push) Successful in 2m27s
Release Inventarsystem / release-docker (push) Successful in 2m27s
This commit is contained in:
+107
-75
@@ -1523,78 +1523,8 @@
|
|||||||
document.getElementById('new-location-input').value = '';
|
document.getElementById('new-location-input').value = '';
|
||||||
}
|
}
|
||||||
|
|
||||||
// Function to fetch book information from ISBN
|
let currentFetchedIsbn = null;
|
||||||
function fetchBookInfo(formType) {
|
let currentBookData = null;
|
||||||
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 = '<div class="error-message">Bitte geben Sie eine ISBN oder einen Barcode ein.</div>';
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Show loading indicator
|
|
||||||
infoContainer.innerHTML = '<div class="loading-spinner">Informationen werden abgerufen...</div>';
|
|
||||||
|
|
||||||
// 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 = `<div class="error-message">${data.error}</div>`;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Store book data globally for import functionality
|
|
||||||
currentBookData = data;
|
|
||||||
|
|
||||||
// Display book information with import button
|
|
||||||
infoContainer.innerHTML = `
|
|
||||||
<div class="book-info">
|
|
||||||
<h4>${data.title}</h4>
|
|
||||||
${data.authors ? `<p><strong>Autor(en):</strong> ${data.authors}</p>` : ''}
|
|
||||||
${data.publisher ? `<p><strong>Verlag:</strong> ${data.publisher}</p>` : ''}
|
|
||||||
${data.publishedDate ? `<p><strong>Erscheinungsdatum:</strong> ${data.publishedDate}</p>` : ''}
|
|
||||||
${data.pageCount ? `<p><strong>Seitenanzahl:</strong> ${data.pageCount}</p>` : ''}
|
|
||||||
${data.price ? `<p><strong>Preis:</strong> ${data.price}</p>` : ''}
|
|
||||||
${data.thumbnail ? `<img src="${data.thumbnail}" alt="Buchcover" class="book-thumbnail">` : ''}
|
|
||||||
${data.description ? `
|
|
||||||
<div class="book-description">
|
|
||||||
<h5>Beschreibung:</h5>
|
|
||||||
<p>${data.description}</p>
|
|
||||||
</div>
|
|
||||||
` : ''}
|
|
||||||
<button type="button" class="import-book-button" onclick="importBookInfo('${formType}')">
|
|
||||||
Buchdaten in Formular übernehmen
|
|
||||||
</button>
|
|
||||||
</div>
|
|
||||||
`;
|
|
||||||
})
|
|
||||||
.catch(error => {
|
|
||||||
infoContainer.innerHTML = `<div class="error-message">${error.message}</div>`;
|
|
||||||
currentBookData = null;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
// Function to import book information into form
|
// Function to import book information into form
|
||||||
function importBookInfo(formType) {
|
function importBookInfo(formType) {
|
||||||
@@ -1606,7 +1536,7 @@
|
|||||||
// Get form fields
|
// Get form fields
|
||||||
const nameField = document.getElementById('name');
|
const nameField = document.getElementById('name');
|
||||||
const descriptionField = document.getElementById('beschreibung');
|
const descriptionField = document.getElementById('beschreibung');
|
||||||
const priceField = document.getElementById('anschaffungskosten'); // <-- NEU
|
const priceField = document.getElementById('anschaffungskosten');
|
||||||
|
|
||||||
if (!nameField || !descriptionField) {
|
if (!nameField || !descriptionField) {
|
||||||
alert('Fehler: Formularfelder nicht gefunden.');
|
alert('Fehler: Formularfelder nicht gefunden.');
|
||||||
@@ -1651,13 +1581,26 @@
|
|||||||
priceField.value = formattedPrice;
|
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) {
|
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
|
// Show success message
|
||||||
const infoContainer = document.getElementById('book-info-container');
|
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');
|
const successMessage = document.createElement('div');
|
||||||
successMessage.className = 'import-success-message';
|
successMessage.className = 'import-success-message';
|
||||||
successMessage.textContent = 'Buchdaten erfolgreich in das Formular übernommen!';
|
successMessage.textContent = 'Buchdaten erfolgreich in das Formular übernommen!';
|
||||||
@@ -1671,6 +1614,95 @@
|
|||||||
}, 3000);
|
}, 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 = '<div class="error-message">Bitte geben Sie eine ISBN oder einen Barcode ein.</div>';
|
||||||
|
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 = '<div class="loading-spinner">Informationen werden abgerufen...</div>';
|
||||||
|
|
||||||
|
// 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 = `<div class="error-message">${data.error}</div>`;
|
||||||
|
currentFetchedIsbn = null; // Freigabe bei Fehler
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Store book data globally for import functionality
|
||||||
|
currentBookData = data;
|
||||||
|
|
||||||
|
// Display book information with import button
|
||||||
|
infoContainer.innerHTML = `
|
||||||
|
<div class="book-info">
|
||||||
|
<h4>${data.title}</h4>
|
||||||
|
${data.authors ? `<p><strong>Autor(en):</strong> ${data.authors}</p>` : ''}
|
||||||
|
${data.publisher ? `<p><strong>Verlag:</strong> ${data.publisher}</p>` : ''}
|
||||||
|
${data.publishedDate ? `<p><strong>Erscheinungsdatum:</strong> ${data.publishedDate}</p>` : ''}
|
||||||
|
${data.pageCount ? `<p><strong>Seitenanzahl:</strong> ${data.pageCount}</p>` : ''}
|
||||||
|
${data.price ? `<p><strong>Preis:</strong> ${data.price}</p>` : ''}
|
||||||
|
${data.thumbnail ? `<img src="${data.thumbnail}" alt="Buchcover" class="book-thumbnail">` : ''}
|
||||||
|
${data.description ? `
|
||||||
|
<div class="book-description">
|
||||||
|
<h5>Beschreibung:</h5>
|
||||||
|
<p>${data.description}</p>
|
||||||
|
</div>
|
||||||
|
` : ''}
|
||||||
|
<button type="button" class="import-book-button" onclick="importBookInfo('${formType}')">
|
||||||
|
Buchdaten in Formular übernehmen
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
`;
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
infoContainer.innerHTML = `<div class="error-message">${error.message}</div>`;
|
||||||
|
currentBookData = null;
|
||||||
|
currentFetchedIsbn = null;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function downloadBookCover(imageUrl) {
|
function downloadBookCover(imageUrl) {
|
||||||
if (!imageUrl) {
|
if (!imageUrl) {
|
||||||
console.log('No image URL provided');
|
console.log('No image URL provided');
|
||||||
|
|||||||
Reference in New Issue
Block a user