Implement library item return by code API and enhance UI for manual returns
Release Inventarsystem / release-docker (push) Successful in 2m14s
Release Inventarsystem / release-docker (push) Successful in 2m14s
This commit is contained in:
@@ -355,6 +355,28 @@
|
||||
color: #6b7280;
|
||||
}
|
||||
|
||||
/* Small confirmation popup (toast) */
|
||||
.small-popup {
|
||||
position: fixed;
|
||||
bottom: 24px;
|
||||
left: 50%;
|
||||
transform: translateX(-50%);
|
||||
background: rgba(17, 24, 39, 0.96);
|
||||
color: #fff;
|
||||
padding: 12px 16px;
|
||||
border-radius: 8px;
|
||||
box-shadow: 0 6px 24px rgba(2,6,23,0.6);
|
||||
z-index: 2000;
|
||||
display: flex;
|
||||
gap: 10px;
|
||||
align-items: center;
|
||||
max-width: 90%;
|
||||
font-size: 0.95em;
|
||||
}
|
||||
.small-popup.ok { background: rgba(16,185,129,0.95); color: #032; }
|
||||
.small-popup.error { background: rgba(239,68,68,0.95); color: #210; }
|
||||
.small-popup .close-x { margin-left: 8px; cursor: pointer; font-weight: 700; }
|
||||
|
||||
/* Modal styles */
|
||||
.modal {
|
||||
display: none;
|
||||
@@ -503,12 +525,18 @@
|
||||
<option value="quick_toggle">Schnellmodus: Ausweis + Mediencode</option>
|
||||
</select>
|
||||
<input type="text" id="activeStudentCard" placeholder="Aktiver Ausweis (gescannt)" readonly>
|
||||
<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>
|
||||
<label style="display:flex; align-items:center; gap:8px; margin-left:6px;">
|
||||
<input type="checkbox" id="keyboardScannerToggle">
|
||||
<span style="font-size:0.9em;">Physischer Scanner</span>
|
||||
</label>
|
||||
<label style="display:flex; align-items:center; gap:8px; margin-left:6px;">
|
||||
<input type="checkbox" id="returnOnlyToggle">
|
||||
<span style="font-size:0.9em;">Nur Rückgabe (nur Mediencode)</span>
|
||||
</label>
|
||||
<button id="manualReturnBtn" class="button" type="button" style="margin-left:6px; background:#10b981;color:white;">Rückgabe per Code</button>
|
||||
</div>
|
||||
<div id="scanStatus" class="library-scan-status">
|
||||
Hinweis: Im Schnellmodus zuerst den Schülerausweis scannen, danach den Buch-/Mediencode.
|
||||
@@ -914,6 +942,13 @@
|
||||
const currentCallback = activeScannerCallback;
|
||||
stopScanner();
|
||||
|
||||
const returnOnly = (document.getElementById('returnOnlyToggle') || {}).checked;
|
||||
if (returnOnly) {
|
||||
// direct return flow
|
||||
returnByCode(barcode);
|
||||
return;
|
||||
}
|
||||
|
||||
if (typeof currentCallback === "function") {
|
||||
currentCallback(barcode);
|
||||
} else {
|
||||
@@ -940,6 +975,13 @@
|
||||
keyboardScanBuffer = '';
|
||||
keyboardLastKeyAt = 0;
|
||||
if (!code) return;
|
||||
// If return-only mode is active, attempt direct return
|
||||
const returnOnly = (document.getElementById('returnOnlyToggle') || {}).checked;
|
||||
if (returnOnly) {
|
||||
returnByCode(code);
|
||||
return;
|
||||
}
|
||||
|
||||
// Process exactly like a camera scan
|
||||
handleScanSuccess(code);
|
||||
return;
|
||||
@@ -981,11 +1023,46 @@
|
||||
|
||||
async function processQuickToggleScan(scannedCode) {
|
||||
if (!activeStudentCardId) {
|
||||
setActiveStudentCard(scannedCode);
|
||||
setScanStatus(`Ausweis gesetzt: ${activeStudentCardId}`, 'ok');
|
||||
return;
|
||||
}
|
||||
// If return-only mode is active, always attempt to return by code
|
||||
const returnOnly = (document.getElementById('returnOnlyToggle') || {}).checked;
|
||||
if (returnOnly) {
|
||||
await returnByCode(scannedCode);
|
||||
return;
|
||||
}
|
||||
|
||||
if (!activeStudentCardId) {
|
||||
setActiveStudentCard(scannedCode);
|
||||
setScanStatus(`Ausweis gesetzt: ${activeStudentCardId}`, 'ok');
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
async function returnByCode(code) {
|
||||
if (!code) return;
|
||||
setScanStatus('Verarbeite Rückgabe...', 'warn');
|
||||
try {
|
||||
const resp = await fetch('/api/library_return_by_code', {
|
||||
method: 'POST',
|
||||
headers: {'Content-Type': 'application/json'},
|
||||
body: JSON.stringify({ item_code: code })
|
||||
});
|
||||
const result = await resp.json();
|
||||
if (!resp.ok || !result.ok) {
|
||||
setScanStatus(result.message || 'Rückgabe fehlgeschlagen.', 'error');
|
||||
showSmallConfirm(result.message || 'Rückgabe fehlgeschlagen.', 'error');
|
||||
return false;
|
||||
}
|
||||
setScanStatus(result.message || `Zurückgegeben: ${result.item_name || ''}`, 'ok');
|
||||
showSmallConfirm(result.message || `Zurückgegeben: ${result.item_name || ''}`, 'ok');
|
||||
await loadLibraryItems();
|
||||
return true;
|
||||
} catch (err) {
|
||||
console.error('Return by code failed:', err);
|
||||
setScanStatus('Fehler bei Rückgabe.', 'error');
|
||||
showSmallConfirm('Fehler bei Rückgabe.', 'error');
|
||||
return false;
|
||||
}
|
||||
}
|
||||
try {
|
||||
setScanStatus('Verarbeite Mediencode...', 'warn');
|
||||
const response = await fetch('/api/library_scan_action', {
|
||||
@@ -1005,10 +1082,13 @@
|
||||
|
||||
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();
|
||||
@@ -1121,6 +1201,21 @@
|
||||
el.classList.remove('ok', 'warn', 'error');
|
||||
if (kind) el.classList.add(kind);
|
||||
}
|
||||
|
||||
function showSmallConfirm(message, kind='ok') {
|
||||
// Append the small helper text in German
|
||||
const helper = 'Sie können fortfahren. Dies ist nur eine kleine Benachrichtigung.';
|
||||
const el = document.createElement('div');
|
||||
el.className = `small-popup ${kind === 'error' ? 'error' : 'ok'}`;
|
||||
el.innerHTML = `<div>${escapeHtml(String(message || ''))}</div><div style="opacity:0.9; margin-left:8px; font-size:0.85em;">${helper}</div><div class="close-x">×</div>`;
|
||||
document.body.appendChild(el);
|
||||
// close handler
|
||||
el.querySelector('.close-x').addEventListener('click', () => {
|
||||
if (el && el.parentNode) el.parentNode.removeChild(el);
|
||||
});
|
||||
// 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();
|
||||
@@ -1286,6 +1381,19 @@
|
||||
});
|
||||
}
|
||||
|
||||
const manualReturnBtn = document.getElementById('manualReturnBtn');
|
||||
const manualItemCode = document.getElementById('manualItemCode');
|
||||
if (manualReturnBtn && manualItemCode) {
|
||||
manualReturnBtn.addEventListener('click', async () => {
|
||||
const code = (manualItemCode.value || '').trim();
|
||||
if (!code) {
|
||||
alert('Bitte einen Mediencode eingeben.');
|
||||
return;
|
||||
}
|
||||
await returnByCode(code);
|
||||
});
|
||||
}
|
||||
|
||||
// Edit Modal Form processing
|
||||
const editForm = document.getElementById('editLibraryForm');
|
||||
if (editForm) {
|
||||
|
||||
@@ -23,16 +23,6 @@
|
||||
</a>
|
||||
</div>
|
||||
|
||||
<form method="POST" action="{{ url_for('admin_anonymize_names') }}" class="mb-3">
|
||||
<button
|
||||
type="submit"
|
||||
class="btn btn-outline-danger"
|
||||
onclick="return confirm('Sollen alle gespeicherten Klarnamen dauerhaft in Synonym-Kuerzel umgewandelt werden?')"
|
||||
>
|
||||
Gespeicherte Namen anonymisieren
|
||||
</button>
|
||||
</form>
|
||||
|
||||
<div class="filter-bar mb-3">
|
||||
<div class="row g-2 align-items-end">
|
||||
<div class="col-md-3">
|
||||
|
||||
Reference in New Issue
Block a user