|
|
|
@@ -524,7 +524,7 @@
|
|
|
|
|
<option value="card_only">Nur Ausweis erfassen</option>
|
|
|
|
|
<option value="quick_toggle">Schnellmodus: Ausweis + Mediencode</option>
|
|
|
|
|
</select>
|
|
|
|
|
<input type="text" id="activeStudentCard" placeholder="Aktiver Ausweis (gescannt)" readonly>
|
|
|
|
|
<input type="text" id="activeStudentCard" placeholder="Aktiver Ausweis (gescannt)" >
|
|
|
|
|
<input type="text" id="manualItemCode" placeholder="Manueller Mediencode (optional)" style="min-width:180px;">
|
|
|
|
|
<button id="resetCardBtn" class="button" type="button">Ausweis löschen</button>
|
|
|
|
|
<button id="toggleScannerBtn" class="button" type="button">Scanner starten</button>
|
|
|
|
@@ -800,7 +800,7 @@
|
|
|
|
|
return `
|
|
|
|
|
<tr>
|
|
|
|
|
<td class="table-title">${escapeHtml(item.Name || 'Untitled')}</td>
|
|
|
|
|
<td>${escapeHtml(item.ISBN || item.Code_4 || item.Code4 || '-')}</td>
|
|
|
|
|
<td>${escapeHtml(item.Code_4 || item.Code4 || '-')}</td>
|
|
|
|
|
<td>${getItemTypeLabel(item.ItemType || 'book')}</td>
|
|
|
|
|
<td style="font-weight:600; text-align:center;">${item.Quantity || item.GroupedDisplayCount || 1}</td>
|
|
|
|
|
<td>
|
|
|
|
@@ -1027,20 +1027,55 @@
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function processQuickToggleScan(scannedCode) {
|
|
|
|
|
// 1. Prüfen, ob "Nur Rückgabe"-Modus aktiv ist
|
|
|
|
|
const returnOnly = (document.getElementById('returnOnlyToggle') || {}).checked;
|
|
|
|
|
if (returnOnly) {
|
|
|
|
|
await returnByCode(scannedCode);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 2. Wenn kein Ausweis gesetzt ist, wird der Code als Ausweis interpretiert
|
|
|
|
|
if (!activeStudentCardId) {
|
|
|
|
|
// If return-only mode is active, always attempt to return by code
|
|
|
|
|
const returnOnly = (document.getElementById('returnOnlyToggle') || {}).checked;
|
|
|
|
|
if (returnOnly) {
|
|
|
|
|
await returnByCode(scannedCode);
|
|
|
|
|
setActiveStudentCard(scannedCode);
|
|
|
|
|
setScanStatus(`Ausweis gesetzt: ${activeStudentCardId}`, 'ok');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 3. Ausleihe/Rückgabe verarbeiten (wenn Ausweis vorhanden)
|
|
|
|
|
try {
|
|
|
|
|
setScanStatus('Verarbeite Mediencode...', 'warn');
|
|
|
|
|
const response = await fetch('/api/library_scan_action', {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: {'Content-Type': 'application/json'},
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
student_card_id: activeStudentCardId,
|
|
|
|
|
item_code: scannedCode
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const result = await response.json();
|
|
|
|
|
if (!response.ok || !result.ok) {
|
|
|
|
|
setScanStatus(result.message || 'Scan-Aktion fehlgeschlagen.', 'error');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!activeStudentCardId) {
|
|
|
|
|
setActiveStudentCard(scannedCode);
|
|
|
|
|
setScanStatus(`Ausweis gesetzt: ${activeStudentCardId}`, 'ok');
|
|
|
|
|
return;
|
|
|
|
|
if (result.action === 'borrowed') {
|
|
|
|
|
setScanStatus(`Ausgeliehen: ${result.item_name}`, 'ok');
|
|
|
|
|
showSmallConfirm(`Ausgeliehen: ${result.item_name}`, 'ok');
|
|
|
|
|
} else if (result.action === 'returned') {
|
|
|
|
|
setScanStatus(`Zurückgegeben: ${result.item_name}`, 'ok');
|
|
|
|
|
showSmallConfirm(`Zurückgegeben: ${result.item_name}`, 'ok');
|
|
|
|
|
} else {
|
|
|
|
|
setScanStatus(result.message || 'Aktion durchgeführt.', 'ok');
|
|
|
|
|
showSmallConfirm(result.message || 'Aktion durchgeführt.', 'ok');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
await loadLibraryItems();
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error('Quick scan action failed:', err);
|
|
|
|
|
setScanStatus('Fehler beim Verarbeiten des Scans.', 'error');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function returnByCode(code) {
|
|
|
|
|
if (!code) return;
|
|
|
|
@@ -1068,40 +1103,6 @@
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
try {
|
|
|
|
|
setScanStatus('Verarbeite Mediencode...', 'warn');
|
|
|
|
|
const response = await fetch('/api/library_scan_action', {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: {'Content-Type': 'application/json'},
|
|
|
|
|
body: JSON.stringify({
|
|
|
|
|
student_card_id: activeStudentCardId,
|
|
|
|
|
item_code: scannedCode
|
|
|
|
|
})
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const result = await response.json();
|
|
|
|
|
if (!response.ok || !result.ok) {
|
|
|
|
|
setScanStatus(result.message || 'Scan-Aktion fehlgeschlagen.', 'error');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (result.action === 'borrowed') {
|
|
|
|
|
setScanStatus(`Ausgeliehen: ${result.item_name}`, 'ok');
|
|
|
|
|
showSmallConfirm(`Ausgeliehen: ${result.item_name}`, 'ok');
|
|
|
|
|
} else if (result.action === 'returned') {
|
|
|
|
|
setScanStatus(`Zurückgegeben: ${result.item_name}`, 'ok');
|
|
|
|
|
showSmallConfirm(`Zurückgegeben: ${result.item_name}`, 'ok');
|
|
|
|
|
} else {
|
|
|
|
|
setScanStatus(result.message || 'Aktion durchgeführt.', 'ok');
|
|
|
|
|
showSmallConfirm(result.message || 'Aktion durchgeführt.', 'ok');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await loadLibraryItems();
|
|
|
|
|
} catch (err) {
|
|
|
|
|
console.error('Quick scan action failed:', err);
|
|
|
|
|
setScanStatus('Fehler beim Verarbeiten des Scans.', 'error');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function scanIntoEditCode() {
|
|
|
|
|
const scanReaderWrap = document.getElementById('scanReaderWrap');
|
|
|
|
@@ -1110,15 +1111,15 @@
|
|
|
|
|
if (!scanReaderWrap || !editCodeInput || !scanEditBtn) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (scannerRunning && scanReaderWrap.style.display !== 'none') {
|
|
|
|
|
stopScanner();
|
|
|
|
|
scanEditBtn.textContent = 'Barcode scannen';
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
scanEditBtn.textContent = 'Scanner schließen';
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
startScanner(function(decodedText) {
|
|
|
|
|
editCodeInput.value = decodedText;
|
|
|
|
|
if(typeof validateCodeField === "function") {
|
|
|
|
@@ -1137,16 +1138,16 @@
|
|
|
|
|
alert('Dieses Medium ist als defekt/zerstört markiert und kann nicht ausgeliehen werden.');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const defaultCardId = activeStudentCardId || '';
|
|
|
|
|
const cardId = (window.prompt('Bitte Schülerausweis-ID eingeben:', defaultCardId) || '').trim().toUpperCase();
|
|
|
|
|
if (!cardId) {
|
|
|
|
|
alert('Ausleihe abgebrochen: Für Bibliotheksmedien ist eine gültige Schülerausweis-ID erforderlich.');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
setActiveStudentCard(cardId);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const durationInput = (window.prompt('Ausleihdauer in Tagen (optional):') || '').trim();
|
|
|
|
|
const maxAvailable = Math.max(1, parseInt(selectedItem?.AvailableGroupedCount || selectedItem?.Quantity || 1, 10) || 1);
|
|
|
|
|
const countPrompt = (window.prompt(`Anzahl ausleihen? (Standard: 1, verfügbar: ${maxAvailable})`, '1') || '').trim();
|
|
|
|
@@ -1158,29 +1159,29 @@
|
|
|
|
|
alert(`Es sind nur ${maxAvailable} Exemplar(e) verfügbar.`);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const form = document.createElement('form');
|
|
|
|
|
form.method = 'POST';
|
|
|
|
|
form.action = `/ausleihen/${itemId}`;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const csrfField = document.createElement('input');
|
|
|
|
|
csrfField.type = 'hidden';
|
|
|
|
|
csrfField.name = 'csrf_token';
|
|
|
|
|
csrfField.value = '{{ csrf_token }}';
|
|
|
|
|
form.appendChild(csrfField);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const cardField = document.createElement('input');
|
|
|
|
|
cardField.type = 'hidden';
|
|
|
|
|
cardField.name = 'borrower_card_id';
|
|
|
|
|
cardField.value = cardId;
|
|
|
|
|
form.appendChild(cardField);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const returnTargetField = document.createElement('input');
|
|
|
|
|
returnTargetField.type = 'hidden';
|
|
|
|
|
returnTargetField.name = 'return_to';
|
|
|
|
|
returnTargetField.value = 'library';
|
|
|
|
|
form.appendChild(returnTargetField);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (durationInput) {
|
|
|
|
|
const durationField = document.createElement('input');
|
|
|
|
|
durationField.type = 'hidden';
|
|
|
|
@@ -1188,13 +1189,13 @@
|
|
|
|
|
durationField.value = durationInput;
|
|
|
|
|
form.appendChild(durationField);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const countField = document.createElement('input');
|
|
|
|
|
countField.type = 'hidden';
|
|
|
|
|
countField.name = 'exemplare_count';
|
|
|
|
|
countField.value = String(borrowCount || 1);
|
|
|
|
|
form.appendChild(countField);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
document.body.appendChild(form);
|
|
|
|
|
form.submit();
|
|
|
|
|
}
|
|
|
|
@@ -1221,13 +1222,13 @@
|
|
|
|
|
// auto remove after 3 seconds
|
|
|
|
|
setTimeout(() => { try { if (el && el.parentNode) el.parentNode.removeChild(el); } catch(e){} }, 3000);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function setActiveStudentCard(cardId) {
|
|
|
|
|
activeStudentCardId = (cardId || '').trim().toUpperCase();
|
|
|
|
|
const input = document.getElementById('activeStudentCard');
|
|
|
|
|
if (input) input.value = activeStudentCardId;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
function normalizeScannedCode(code) {
|
|
|
|
|
return (code || '').trim();
|
|
|
|
|
}
|
|
|
|
@@ -1292,7 +1293,7 @@
|
|
|
|
|
const resetBtn = document.getElementById('resetCardBtn');
|
|
|
|
|
const modeSelect = document.getElementById('scanModeSelect');
|
|
|
|
|
const keyboardToggle = document.getElementById('keyboardScannerToggle');
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (toggleBtn) {
|
|
|
|
|
toggleBtn.addEventListener('click', async () => {
|
|
|
|
|
if (scannerRunning) {
|
|
|
|
@@ -1302,14 +1303,14 @@
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (resetBtn) {
|
|
|
|
|
resetBtn.addEventListener('click', () => {
|
|
|
|
|
setActiveStudentCard('');
|
|
|
|
|
setScanStatus('Ausweis zurückgesetzt. Bitte neu scannen.', 'warn');
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (modeSelect) {
|
|
|
|
|
modeSelect.addEventListener('change', () => {
|
|
|
|
|
if (modeSelect.value === 'quick_toggle' && !activeStudentCardId) {
|
|
|
|
@@ -1335,8 +1336,8 @@
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Run when DOM structure is entirely ready
|
|
|
|
|
document.addEventListener('DOMContentLoaded', () => {
|
|
|
|
|
wireScannerUi(); // Setup scanner control buttons
|
|
|
|
|
document.addEventListener('DOMContentLoaded', async () => {
|
|
|
|
|
wireScannerUi(); // Setup scanner control buttons
|
|
|
|
|
loadLibraryItems(); // Fetch your database items right away!
|
|
|
|
|
|
|
|
|
|
// Safely connect standard Filters and Search inputs inside DOMContentLoaded
|
|
|
|
@@ -1365,7 +1366,7 @@
|
|
|
|
|
document.getElementById('filterISBN').value = '';
|
|
|
|
|
document.getElementById('filterType').value = '';
|
|
|
|
|
document.getElementById('filterStatus').value = '';
|
|
|
|
|
activeFilters = { isbn: '', type: '', status: '' };
|
|
|
|
|
activeFilters = {isbn: '', type: '', status: ''};
|
|
|
|
|
applyFiltersAndSearch(true);
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
@@ -1401,13 +1402,16 @@
|
|
|
|
|
|
|
|
|
|
const editForm = document.getElementById('editLibraryForm');
|
|
|
|
|
if (editForm) {
|
|
|
|
|
editForm.addEventListener('submit', async function(e) {
|
|
|
|
|
editForm.addEventListener('submit', async function (e) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
|
|
const itemId = document.getElementById('editLibraryItemId').value;
|
|
|
|
|
const currentItem = libraryItems.find(i => i._id === itemId);
|
|
|
|
|
if (!currentItem) return;
|
|
|
|
|
|
|
|
|
|
const codeInputs = Array.from(document.querySelectorAll('#editLibraryCodesContainer input[data-item-id]'));
|
|
|
|
|
|
|
|
|
|
// Daten aus dem Formular sammeln
|
|
|
|
|
const sharedPayload = {
|
|
|
|
|
name: document.getElementById('editLibraryName').value,
|
|
|
|
|
item_type: document.getElementById('editLibraryType').value,
|
|
|
|
@@ -1419,11 +1423,11 @@
|
|
|
|
|
reservierbar: currentItem.Reservierbar !== false,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const codeInputs = Array.from(document.querySelectorAll('#editLibraryCodesContainer input[data-item-id]'));
|
|
|
|
|
const codeByItemId = new Map(codeInputs.map(input => [input.dataset.itemId, (input.value || '').trim()]));
|
|
|
|
|
const groupMembers = editLibraryState.groupMembers.length > 0 ? editLibraryState.groupMembers : [currentItem];
|
|
|
|
|
const isGroupedEdit = Boolean(currentItem.SeriesGroupId) && groupMembers.length > 1;
|
|
|
|
|
|
|
|
|
|
// API-Aufruf
|
|
|
|
|
try {
|
|
|
|
|
if (isGroupedEdit) {
|
|
|
|
|
const payload = {
|
|
|
|
@@ -1495,7 +1499,6 @@
|
|
|
|
|
|
|
|
|
|
async function fetchLibraryGroupMembers(seriesGroupId) {
|
|
|
|
|
if (!seriesGroupId) return [];
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const response = await fetch(`/api/library_group/${encodeURIComponent(seriesGroupId)}`);
|
|
|
|
|
if (!response.ok) {
|
|
|
|
@@ -1554,15 +1557,15 @@
|
|
|
|
|
labelParts.push('aktuelles Medium');
|
|
|
|
|
}
|
|
|
|
|
return `
|
|
|
|
|
<div style="display:flex; flex-direction:column; gap:6px; margin-bottom:10px;">
|
|
|
|
|
<label for="editLibraryCode-${member._id}" style="font-weight:600; font-size:0.9em; color:var(--ui-text);">${escapeHtml(labelParts.join(' · '))}</label>
|
|
|
|
|
<input id="editLibraryCode-${member._id}" data-item-id="${escapeHtml(member._id)}" value="${escapeHtml(codeValue)}" placeholder="Mediencode" style="width:100%; padding:8px 10px; border:1px solid #d0d7e2; border-radius:6px;">
|
|
|
|
|
</div>
|
|
|
|
|
<div style="display:flex; flex-direction:column; gap:6px; margin-bottom:10px;">
|
|
|
|
|
<label for="editLibraryCode-${member._id}" style="font-weight:600; font-size:0.9em; color:var(--ui-text);">${escapeHtml(labelParts.join(' · '))}</label>
|
|
|
|
|
<input id="editLibraryCode-${member._id}" data-item-id="${escapeHtml(member._id)}" value="${escapeHtml(codeValue)}" placeholder="Mediencode" style="width:100%; padding:8px 10px; border:1px solid #d0d7e2; border-radius:6px;">
|
|
|
|
|
</div>
|
|
|
|
|
`;
|
|
|
|
|
}).join('');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
window.openEditLibraryItem = async function(itemId) {
|
|
|
|
|
window.openEditLibraryItem = async function (itemId) {
|
|
|
|
|
const item = libraryItems.find(i => i._id === itemId);
|
|
|
|
|
if (!item) return;
|
|
|
|
|
|
|
|
|
@@ -1570,7 +1573,7 @@
|
|
|
|
|
editLibraryState.seriesGroupId = item.SeriesGroupId || '';
|
|
|
|
|
editLibraryState.groupMembers = [];
|
|
|
|
|
|
|
|
|
|
// 1. Felder befüllen
|
|
|
|
|
// Felder befüllen
|
|
|
|
|
document.getElementById('editLibraryItemId').value = item._id;
|
|
|
|
|
document.getElementById('editLibraryName').value = item.Name;
|
|
|
|
|
document.getElementById('editLibraryType').value = item.ItemType;
|
|
|
|
|