Compare commits
17 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 4917c22ae3 | |||
| a2f2dd5a9e | |||
| faf270ff93 | |||
| beeb562ac4 | |||
| 0199957545 | |||
| a518adb054 | |||
| 6a94d50d28 | |||
| c90cef6dcf | |||
| b5451a4ef0 | |||
| a4afef8283 | |||
| b2951eed6c | |||
| 9a37c047c1 | |||
| 7290fb4ed1 | |||
| ee9ef3df6f | |||
| 9f3799a77f | |||
| e9006f5a07 | |||
| a11bce17c5 |
+168
-3
@@ -46,7 +46,7 @@ import Web.modules.inventarsystem.pdf_export as pdf_export
|
|||||||
import Web.modules.inventarsystem.excel_export as excel_export
|
import Web.modules.inventarsystem.excel_export as excel_export
|
||||||
import datetime
|
import datetime
|
||||||
from apscheduler.schedulers.background import BackgroundScheduler
|
from apscheduler.schedulers.background import BackgroundScheduler
|
||||||
from bson.objectid import ObjectId
|
from bson.objectid import ObjectId, InvalidId
|
||||||
from urllib.parse import urlparse, urlunparse
|
from urllib.parse import urlparse, urlunparse
|
||||||
import requests
|
import requests
|
||||||
import csv
|
import csv
|
||||||
@@ -3788,6 +3788,7 @@ def api_item_detail(item_id):
|
|||||||
<h2>{html.escape(str(item.get('Name', 'Untitled')))}</h2>
|
<h2>{html.escape(str(item.get('Name', 'Untitled')))}</h2>
|
||||||
<p><strong>ISBN:</strong> {html.escape(str(item.get('ISBN', item.get('Code4', '-'))))}</p>
|
<p><strong>ISBN:</strong> {html.escape(str(item.get('ISBN', item.get('Code4', '-'))))}</p>
|
||||||
<p><strong>Anzahl:</strong> {html.escape(str(item.get('SeriesCount', '-')))}</p>
|
<p><strong>Anzahl:</strong> {html.escape(str(item.get('SeriesCount', '-')))}</p>
|
||||||
|
<p><strong>Code:</strong> {html.escape(str(item.get('Code_4', '-')))}</p>
|
||||||
<p><strong>Ort:</strong> {html.escape(str(item.get('Ort', '-')))}</p>
|
<p><strong>Ort:</strong> {html.escape(str(item.get('Ort', '-')))}</p>
|
||||||
<p><strong>Typ:</strong> {html.escape(str(item.get('ItemType', '-')))}</p>
|
<p><strong>Typ:</strong> {html.escape(str(item.get('ItemType', '-')))}</p>
|
||||||
<p><strong>Kategorie:</strong> {html.escape(str(item.get('library_category', '-')))}</p>
|
<p><strong>Kategorie:</strong> {html.escape(str(item.get('library_category', '-')))}</p>
|
||||||
@@ -5780,7 +5781,7 @@ def upload_item():
|
|||||||
app.logger.warning('Audit write failed for library_item_created')
|
app.logger.warning('Audit write failed for library_item_created')
|
||||||
|
|
||||||
flash(success_msg, 'success')
|
flash(success_msg, 'success')
|
||||||
return redirect(url_for(success_redirect_endpoint, highlight_item=str(item_id)))
|
return redirect(url_for(success_redirect_endpoint))
|
||||||
else:
|
else:
|
||||||
error_msg = 'Fehler beim Hinzufügen des Elements'
|
error_msg = 'Fehler beim Hinzufügen des Elements'
|
||||||
if is_mobile:
|
if is_mobile:
|
||||||
@@ -6366,6 +6367,170 @@ def edit_item(id):
|
|||||||
return redirect(url_for('home_admin'))
|
return redirect(url_for('home_admin'))
|
||||||
|
|
||||||
|
|
||||||
|
@app.route('/item_edit/<id>', methods=['GET', 'POST'])
|
||||||
|
def item_edit(id):
|
||||||
|
"""
|
||||||
|
Endpoint zum Laden und Aktualisieren eines Eintrags (item_edit).
|
||||||
|
"""
|
||||||
|
# 1. Rechte- & Auth-Check
|
||||||
|
if 'username' not in session:
|
||||||
|
if request.method == 'POST' and request.is_json:
|
||||||
|
return jsonify({'success': False, 'message': 'Nicht angemeldet.'}), 401
|
||||||
|
flash('Bitte melden Sie sich an.', 'error')
|
||||||
|
return redirect(url_for('login'))
|
||||||
|
|
||||||
|
current_permissions = us.get_effective_permissions(session['username'])
|
||||||
|
if not current_permissions['actions'].get('can_edit', False):
|
||||||
|
if request.method == 'POST' and request.is_json:
|
||||||
|
return jsonify({'success': False, 'message': 'Keine Berechtigung zum Bearbeiten.'}), 403
|
||||||
|
flash('Keine Berechtigung zum Bearbeiten.', 'error')
|
||||||
|
return redirect(url_for('home_admin'))
|
||||||
|
|
||||||
|
try:
|
||||||
|
obj_id = ObjectId(id)
|
||||||
|
except InvalidId:
|
||||||
|
flash('Ungültige Element-ID.', 'error')
|
||||||
|
return redirect(url_for('home_admin'))
|
||||||
|
|
||||||
|
|
||||||
|
# --- GET: Template anzeigen ---
|
||||||
|
if request.method == 'GET':
|
||||||
|
item = it.get_item(id)
|
||||||
|
if not item:
|
||||||
|
flash('Element nicht gefunden.', 'error')
|
||||||
|
return redirect(url_for('home_admin'))
|
||||||
|
|
||||||
|
item['_id'] = str(item['_id'])
|
||||||
|
show_library = cfg.MODULES.is_enabled('library')
|
||||||
|
|
||||||
|
return render_template(
|
||||||
|
'edit_library.html',
|
||||||
|
username=session['username'],
|
||||||
|
item=item,
|
||||||
|
library_module_enabled=show_library,
|
||||||
|
show_library_features=show_library,
|
||||||
|
page_title=f"Bearbeiten: {item.get('Name', '')}"
|
||||||
|
)
|
||||||
|
|
||||||
|
# --- POST: Speichern ---
|
||||||
|
redirect_target = request.referrer or url_for('home_admin')
|
||||||
|
current_item = it.get_item(obj_id)
|
||||||
|
|
||||||
|
if not current_item:
|
||||||
|
flash('Element in der Datenbank nicht gefunden.', 'error')
|
||||||
|
return redirect(redirect_target)
|
||||||
|
|
||||||
|
# Formulardaten auslesen und bereinigen
|
||||||
|
name = sanitize_form_value(request.form.get('name'))
|
||||||
|
ort = sanitize_form_value(request.form.get('ort'))
|
||||||
|
beschreibung = sanitize_form_value(request.form.get('beschreibung'))
|
||||||
|
code_4 = sanitize_form_value(request.form.get('code_4'))
|
||||||
|
isbn_raw = sanitize_form_value(request.form.get('isbn', ''))
|
||||||
|
|
||||||
|
anschaffungs_jahr = sanitize_form_value(request.form.get('anschaffungsjahr'))
|
||||||
|
anschaffungs_kosten = sanitize_form_value(request.form.get('anschaffungskosten'))
|
||||||
|
reservierbar = 'reservierbar' in request.form
|
||||||
|
|
||||||
|
item_type_input = sanitize_form_value(request.form.get('item_type_input'))
|
||||||
|
library_category = sanitize_form_value(request.form.get('library_category'))
|
||||||
|
|
||||||
|
filter1 = expand_filter_selection(sanitize_form_value(request.form.getlist('filter')), 1)
|
||||||
|
filter2 = expand_filter_selection(sanitize_form_value(request.form.getlist('filter2')), 2)
|
||||||
|
filter3 = sanitize_form_value(request.form.getlist('filter3'))
|
||||||
|
|
||||||
|
# WICHTIG: Den aktuellen Verfügbarkeitsstatus aus der Datenbank übernehmen
|
||||||
|
verfuegbar = current_item.get('Verfuegbar', True)
|
||||||
|
|
||||||
|
# Barcode Prüfen
|
||||||
|
if code_4 and not it.is_code_unique(code_4, exclude_id=str(id)):
|
||||||
|
flash(f'Der Code "{code_4}" wird bereits verwendet.', 'error')
|
||||||
|
return redirect(redirect_target)
|
||||||
|
|
||||||
|
# ISBN und Medientyp verarbeiten
|
||||||
|
item_isbn = ''
|
||||||
|
item_type = item_type_input or current_item.get('ItemType', 'general')
|
||||||
|
if cfg.MODULES.is_enabled('library') and isbn_raw:
|
||||||
|
item_isbn = normalize_and_validate_isbn(isbn_raw)
|
||||||
|
if not item_isbn:
|
||||||
|
flash('Ungültiges ISBN-Format.', 'error')
|
||||||
|
return redirect(redirect_target)
|
||||||
|
|
||||||
|
# Bilder verarbeiten (GridFS)
|
||||||
|
images_to_keep = request.form.getlist('existing_images')
|
||||||
|
original_images = current_item.get('Images', [])
|
||||||
|
images = [img for img in original_images if img in images_to_keep]
|
||||||
|
|
||||||
|
new_files = request.files.getlist('images')
|
||||||
|
if new_files and new_files[0].filename != '':
|
||||||
|
fs = get_gridfs()
|
||||||
|
for file in new_files:
|
||||||
|
if file and file.filename:
|
||||||
|
is_allowed, error_msg = allowed_file(file.filename, file)
|
||||||
|
if not is_allowed:
|
||||||
|
flash(error_msg, 'error')
|
||||||
|
return redirect(redirect_target)
|
||||||
|
|
||||||
|
try:
|
||||||
|
secure_name = secure_filename(file.filename)
|
||||||
|
file.seek(0)
|
||||||
|
image_bytes = file.read()
|
||||||
|
|
||||||
|
if not image_bytes:
|
||||||
|
continue
|
||||||
|
|
||||||
|
optimized_io = io.BytesIO()
|
||||||
|
with Image.open(io.BytesIO(image_bytes)) as img:
|
||||||
|
if img.mode not in ('RGB', 'RGBA'):
|
||||||
|
img = img.convert('RGBA')
|
||||||
|
|
||||||
|
max_width = 800
|
||||||
|
if img.width > max_width:
|
||||||
|
ratio = max_width / img.width
|
||||||
|
img = img.resize((max_width, int(img.height * ratio)), Image.Resampling.LANCZOS)
|
||||||
|
|
||||||
|
img.save(optimized_io, format='WEBP', quality=85, optimize=True)
|
||||||
|
|
||||||
|
optimized_io.seek(0)
|
||||||
|
new_filename = f"{uuid.uuid4().hex}_{int(time.time())}.webp"
|
||||||
|
|
||||||
|
fs.put(
|
||||||
|
optimized_io,
|
||||||
|
filename=new_filename,
|
||||||
|
content_type='image/webp',
|
||||||
|
metadata={'original_filename': secure_name, 'item_id': str(id)}
|
||||||
|
)
|
||||||
|
images.append(new_filename)
|
||||||
|
except Exception as e:
|
||||||
|
app.logger.error(f"Bild-Fehler bei Item {id}: {e}")
|
||||||
|
|
||||||
|
if ort and ort not in it.get_predefined_locations():
|
||||||
|
it.add_predefined_location(ort)
|
||||||
|
|
||||||
|
success = it.update_item(
|
||||||
|
id=str(id),
|
||||||
|
name=name,
|
||||||
|
ort=ort,
|
||||||
|
beschreibung=beschreibung,
|
||||||
|
images=images,
|
||||||
|
verfuegbar=verfuegbar,
|
||||||
|
filter1=filter1,
|
||||||
|
filter2=filter2,
|
||||||
|
filter3=filter3,
|
||||||
|
ansch_jahr=anschaffungs_jahr,
|
||||||
|
ansch_kost=anschaffungs_kosten,
|
||||||
|
code_4=code_4,
|
||||||
|
reservierbar=reservierbar,
|
||||||
|
isbn=item_isbn,
|
||||||
|
item_type=item_type
|
||||||
|
)
|
||||||
|
|
||||||
|
if success:
|
||||||
|
flash('Artikel erfolgreich aktualisiert.', 'success')
|
||||||
|
else:
|
||||||
|
flash('Fehler beim Aktualisieren des Artikels.', 'error')
|
||||||
|
|
||||||
|
return redirect(redirect_target)
|
||||||
|
|
||||||
@app.route('/update_group', methods=['POST'])
|
@app.route('/update_group', methods=['POST'])
|
||||||
def update_group():
|
def update_group():
|
||||||
|
|
||||||
@@ -7697,7 +7862,7 @@ def user_del():
|
|||||||
last_name = ""
|
last_name = ""
|
||||||
fullname = None
|
fullname = None
|
||||||
users_list.append({
|
users_list.append({
|
||||||
'username': username,
|
'username': decrypt_text(username),
|
||||||
'admin': user.get('Admin', False),
|
'admin': user.get('Admin', False),
|
||||||
'fullname': fullname,
|
'fullname': fullname,
|
||||||
'name': name,
|
'name': name,
|
||||||
|
|||||||
@@ -650,7 +650,7 @@ def add_user(
|
|||||||
safe_last_name = last_name.strip() if last_name else ''
|
safe_last_name = last_name.strip() if last_name else ''
|
||||||
|
|
||||||
user_doc = {
|
user_doc = {
|
||||||
'Username': dp.encrypt_text(username),
|
'Username': username,
|
||||||
'Password': hashing(password),
|
'Password': hashing(password),
|
||||||
'Admin': (permission_preset == "full_access"),
|
'Admin': (permission_preset == "full_access"),
|
||||||
'active_ausleihung': None,
|
'active_ausleihung': None,
|
||||||
|
|||||||
File diff suppressed because it is too large
Load Diff
@@ -524,7 +524,7 @@
|
|||||||
<option value="card_only">Nur Ausweis erfassen</option>
|
<option value="card_only">Nur Ausweis erfassen</option>
|
||||||
<option value="quick_toggle">Schnellmodus: Ausweis + Mediencode</option>
|
<option value="quick_toggle">Schnellmodus: Ausweis + Mediencode</option>
|
||||||
</select>
|
</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;">
|
<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="resetCardBtn" class="button" type="button">Ausweis löschen</button>
|
||||||
<button id="toggleScannerBtn" class="button" type="button">Scanner starten</button>
|
<button id="toggleScannerBtn" class="button" type="button">Scanner starten</button>
|
||||||
@@ -800,7 +800,7 @@
|
|||||||
return `
|
return `
|
||||||
<tr>
|
<tr>
|
||||||
<td class="table-title">${escapeHtml(item.Name || 'Untitled')}</td>
|
<td class="table-title">${escapeHtml(item.Name || 'Untitled')}</td>
|
||||||
<td>${escapeHtml(item.ISBN || item.Code_4 || item.Code4 || '-')}</td>
|
<td>${escapeHtml(item.ISBN || '-')}</td>
|
||||||
<td>${getItemTypeLabel(item.ItemType || 'book')}</td>
|
<td>${getItemTypeLabel(item.ItemType || 'book')}</td>
|
||||||
<td style="font-weight:600; text-align:center;">${item.Quantity || item.GroupedDisplayCount || 1}</td>
|
<td style="font-weight:600; text-align:center;">${item.Quantity || item.GroupedDisplayCount || 1}</td>
|
||||||
<td>
|
<td>
|
||||||
@@ -1027,20 +1027,55 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
async function processQuickToggleScan(scannedCode) {
|
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 (!activeStudentCardId) {
|
||||||
// If return-only mode is active, always attempt to return by code
|
setActiveStudentCard(scannedCode);
|
||||||
const returnOnly = (document.getElementById('returnOnlyToggle') || {}).checked;
|
setScanStatus(`Ausweis gesetzt: ${activeStudentCardId}`, 'ok');
|
||||||
if (returnOnly) {
|
return;
|
||||||
await returnByCode(scannedCode);
|
}
|
||||||
|
|
||||||
|
// 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;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!activeStudentCardId) {
|
if (result.action === 'borrowed') {
|
||||||
setActiveStudentCard(scannedCode);
|
setScanStatus(`Ausgeliehen: ${result.item_name}`, 'ok');
|
||||||
setScanStatus(`Ausweis gesetzt: ${activeStudentCardId}`, 'ok');
|
showSmallConfirm(`Ausgeliehen: ${result.item_name}`, 'ok');
|
||||||
return;
|
} 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) {
|
async function returnByCode(code) {
|
||||||
if (!code) return;
|
if (!code) return;
|
||||||
@@ -1068,40 +1103,6 @@
|
|||||||
return false;
|
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() {
|
function scanIntoEditCode() {
|
||||||
const scanReaderWrap = document.getElementById('scanReaderWrap');
|
const scanReaderWrap = document.getElementById('scanReaderWrap');
|
||||||
@@ -1110,15 +1111,15 @@
|
|||||||
if (!scanReaderWrap || !editCodeInput || !scanEditBtn) {
|
if (!scanReaderWrap || !editCodeInput || !scanEditBtn) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (scannerRunning && scanReaderWrap.style.display !== 'none') {
|
if (scannerRunning && scanReaderWrap.style.display !== 'none') {
|
||||||
stopScanner();
|
stopScanner();
|
||||||
scanEditBtn.textContent = 'Barcode scannen';
|
scanEditBtn.textContent = 'Barcode scannen';
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
scanEditBtn.textContent = 'Scanner schließen';
|
scanEditBtn.textContent = 'Scanner schließen';
|
||||||
|
|
||||||
startScanner(function(decodedText) {
|
startScanner(function(decodedText) {
|
||||||
editCodeInput.value = decodedText;
|
editCodeInput.value = decodedText;
|
||||||
if(typeof validateCodeField === "function") {
|
if(typeof validateCodeField === "function") {
|
||||||
@@ -1137,16 +1138,16 @@
|
|||||||
alert('Dieses Medium ist als defekt/zerstört markiert und kann nicht ausgeliehen werden.');
|
alert('Dieses Medium ist als defekt/zerstört markiert und kann nicht ausgeliehen werden.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const defaultCardId = activeStudentCardId || '';
|
const defaultCardId = activeStudentCardId || '';
|
||||||
const cardId = (window.prompt('Bitte Schülerausweis-ID eingeben:', defaultCardId) || '').trim().toUpperCase();
|
const cardId = (window.prompt('Bitte Schülerausweis-ID eingeben:', defaultCardId) || '').trim().toUpperCase();
|
||||||
if (!cardId) {
|
if (!cardId) {
|
||||||
alert('Ausleihe abgebrochen: Für Bibliotheksmedien ist eine gültige Schülerausweis-ID erforderlich.');
|
alert('Ausleihe abgebrochen: Für Bibliotheksmedien ist eine gültige Schülerausweis-ID erforderlich.');
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
setActiveStudentCard(cardId);
|
setActiveStudentCard(cardId);
|
||||||
|
|
||||||
const durationInput = (window.prompt('Ausleihdauer in Tagen (optional):') || '').trim();
|
const durationInput = (window.prompt('Ausleihdauer in Tagen (optional):') || '').trim();
|
||||||
const maxAvailable = Math.max(1, parseInt(selectedItem?.AvailableGroupedCount || selectedItem?.Quantity || 1, 10) || 1);
|
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();
|
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.`);
|
alert(`Es sind nur ${maxAvailable} Exemplar(e) verfügbar.`);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
const form = document.createElement('form');
|
const form = document.createElement('form');
|
||||||
form.method = 'POST';
|
form.method = 'POST';
|
||||||
form.action = `/ausleihen/${itemId}`;
|
form.action = `/ausleihen/${itemId}`;
|
||||||
|
|
||||||
const csrfField = document.createElement('input');
|
const csrfField = document.createElement('input');
|
||||||
csrfField.type = 'hidden';
|
csrfField.type = 'hidden';
|
||||||
csrfField.name = 'csrf_token';
|
csrfField.name = 'csrf_token';
|
||||||
csrfField.value = '{{ csrf_token }}';
|
csrfField.value = '{{ csrf_token }}';
|
||||||
form.appendChild(csrfField);
|
form.appendChild(csrfField);
|
||||||
|
|
||||||
const cardField = document.createElement('input');
|
const cardField = document.createElement('input');
|
||||||
cardField.type = 'hidden';
|
cardField.type = 'hidden';
|
||||||
cardField.name = 'borrower_card_id';
|
cardField.name = 'borrower_card_id';
|
||||||
cardField.value = cardId;
|
cardField.value = cardId;
|
||||||
form.appendChild(cardField);
|
form.appendChild(cardField);
|
||||||
|
|
||||||
const returnTargetField = document.createElement('input');
|
const returnTargetField = document.createElement('input');
|
||||||
returnTargetField.type = 'hidden';
|
returnTargetField.type = 'hidden';
|
||||||
returnTargetField.name = 'return_to';
|
returnTargetField.name = 'return_to';
|
||||||
returnTargetField.value = 'library';
|
returnTargetField.value = 'library';
|
||||||
form.appendChild(returnTargetField);
|
form.appendChild(returnTargetField);
|
||||||
|
|
||||||
if (durationInput) {
|
if (durationInput) {
|
||||||
const durationField = document.createElement('input');
|
const durationField = document.createElement('input');
|
||||||
durationField.type = 'hidden';
|
durationField.type = 'hidden';
|
||||||
@@ -1188,13 +1189,13 @@
|
|||||||
durationField.value = durationInput;
|
durationField.value = durationInput;
|
||||||
form.appendChild(durationField);
|
form.appendChild(durationField);
|
||||||
}
|
}
|
||||||
|
|
||||||
const countField = document.createElement('input');
|
const countField = document.createElement('input');
|
||||||
countField.type = 'hidden';
|
countField.type = 'hidden';
|
||||||
countField.name = 'exemplare_count';
|
countField.name = 'exemplare_count';
|
||||||
countField.value = String(borrowCount || 1);
|
countField.value = String(borrowCount || 1);
|
||||||
form.appendChild(countField);
|
form.appendChild(countField);
|
||||||
|
|
||||||
document.body.appendChild(form);
|
document.body.appendChild(form);
|
||||||
form.submit();
|
form.submit();
|
||||||
}
|
}
|
||||||
@@ -1221,13 +1222,13 @@
|
|||||||
// auto remove after 3 seconds
|
// auto remove after 3 seconds
|
||||||
setTimeout(() => { try { if (el && el.parentNode) el.parentNode.removeChild(el); } catch(e){} }, 3000);
|
setTimeout(() => { try { if (el && el.parentNode) el.parentNode.removeChild(el); } catch(e){} }, 3000);
|
||||||
}
|
}
|
||||||
|
|
||||||
function setActiveStudentCard(cardId) {
|
function setActiveStudentCard(cardId) {
|
||||||
activeStudentCardId = (cardId || '').trim().toUpperCase();
|
activeStudentCardId = (cardId || '').trim().toUpperCase();
|
||||||
const input = document.getElementById('activeStudentCard');
|
const input = document.getElementById('activeStudentCard');
|
||||||
if (input) input.value = activeStudentCardId;
|
if (input) input.value = activeStudentCardId;
|
||||||
}
|
}
|
||||||
|
|
||||||
function normalizeScannedCode(code) {
|
function normalizeScannedCode(code) {
|
||||||
return (code || '').trim();
|
return (code || '').trim();
|
||||||
}
|
}
|
||||||
@@ -1292,7 +1293,7 @@
|
|||||||
const resetBtn = document.getElementById('resetCardBtn');
|
const resetBtn = document.getElementById('resetCardBtn');
|
||||||
const modeSelect = document.getElementById('scanModeSelect');
|
const modeSelect = document.getElementById('scanModeSelect');
|
||||||
const keyboardToggle = document.getElementById('keyboardScannerToggle');
|
const keyboardToggle = document.getElementById('keyboardScannerToggle');
|
||||||
|
|
||||||
if (toggleBtn) {
|
if (toggleBtn) {
|
||||||
toggleBtn.addEventListener('click', async () => {
|
toggleBtn.addEventListener('click', async () => {
|
||||||
if (scannerRunning) {
|
if (scannerRunning) {
|
||||||
@@ -1302,14 +1303,14 @@
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (resetBtn) {
|
if (resetBtn) {
|
||||||
resetBtn.addEventListener('click', () => {
|
resetBtn.addEventListener('click', () => {
|
||||||
setActiveStudentCard('');
|
setActiveStudentCard('');
|
||||||
setScanStatus('Ausweis zurückgesetzt. Bitte neu scannen.', 'warn');
|
setScanStatus('Ausweis zurückgesetzt. Bitte neu scannen.', 'warn');
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (modeSelect) {
|
if (modeSelect) {
|
||||||
modeSelect.addEventListener('change', () => {
|
modeSelect.addEventListener('change', () => {
|
||||||
if (modeSelect.value === 'quick_toggle' && !activeStudentCardId) {
|
if (modeSelect.value === 'quick_toggle' && !activeStudentCardId) {
|
||||||
@@ -1335,8 +1336,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Run when DOM structure is entirely ready
|
// Run when DOM structure is entirely ready
|
||||||
document.addEventListener('DOMContentLoaded', () => {
|
document.addEventListener('DOMContentLoaded', async () => {
|
||||||
wireScannerUi(); // Setup scanner control buttons
|
wireScannerUi(); // Setup scanner control buttons
|
||||||
loadLibraryItems(); // Fetch your database items right away!
|
loadLibraryItems(); // Fetch your database items right away!
|
||||||
|
|
||||||
// Safely connect standard Filters and Search inputs inside DOMContentLoaded
|
// Safely connect standard Filters and Search inputs inside DOMContentLoaded
|
||||||
@@ -1365,7 +1366,7 @@
|
|||||||
document.getElementById('filterISBN').value = '';
|
document.getElementById('filterISBN').value = '';
|
||||||
document.getElementById('filterType').value = '';
|
document.getElementById('filterType').value = '';
|
||||||
document.getElementById('filterStatus').value = '';
|
document.getElementById('filterStatus').value = '';
|
||||||
activeFilters = { isbn: '', type: '', status: '' };
|
activeFilters = {isbn: '', type: '', status: ''};
|
||||||
applyFiltersAndSearch(true);
|
applyFiltersAndSearch(true);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@@ -1401,13 +1402,16 @@
|
|||||||
|
|
||||||
const editForm = document.getElementById('editLibraryForm');
|
const editForm = document.getElementById('editLibraryForm');
|
||||||
if (editForm) {
|
if (editForm) {
|
||||||
editForm.addEventListener('submit', async function(e) {
|
editForm.addEventListener('submit', async function (e) {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|
||||||
const itemId = document.getElementById('editLibraryItemId').value;
|
const itemId = document.getElementById('editLibraryItemId').value;
|
||||||
const currentItem = libraryItems.find(i => i._id === itemId);
|
const currentItem = libraryItems.find(i => i._id === itemId);
|
||||||
if (!currentItem) return;
|
if (!currentItem) return;
|
||||||
|
|
||||||
|
const codeInputs = Array.from(document.querySelectorAll('#editLibraryCodesContainer input[data-item-id]'));
|
||||||
|
|
||||||
|
// Daten aus dem Formular sammeln
|
||||||
const sharedPayload = {
|
const sharedPayload = {
|
||||||
name: document.getElementById('editLibraryName').value,
|
name: document.getElementById('editLibraryName').value,
|
||||||
item_type: document.getElementById('editLibraryType').value,
|
item_type: document.getElementById('editLibraryType').value,
|
||||||
@@ -1419,11 +1423,11 @@
|
|||||||
reservierbar: currentItem.Reservierbar !== false,
|
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 codeByItemId = new Map(codeInputs.map(input => [input.dataset.itemId, (input.value || '').trim()]));
|
||||||
const groupMembers = editLibraryState.groupMembers.length > 0 ? editLibraryState.groupMembers : [currentItem];
|
const groupMembers = editLibraryState.groupMembers.length > 0 ? editLibraryState.groupMembers : [currentItem];
|
||||||
const isGroupedEdit = Boolean(currentItem.SeriesGroupId) && groupMembers.length > 1;
|
const isGroupedEdit = Boolean(currentItem.SeriesGroupId) && groupMembers.length > 1;
|
||||||
|
|
||||||
|
// API-Aufruf
|
||||||
try {
|
try {
|
||||||
if (isGroupedEdit) {
|
if (isGroupedEdit) {
|
||||||
const payload = {
|
const payload = {
|
||||||
@@ -1495,7 +1499,6 @@
|
|||||||
|
|
||||||
async function fetchLibraryGroupMembers(seriesGroupId) {
|
async function fetchLibraryGroupMembers(seriesGroupId) {
|
||||||
if (!seriesGroupId) return [];
|
if (!seriesGroupId) return [];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const response = await fetch(`/api/library_group/${encodeURIComponent(seriesGroupId)}`);
|
const response = await fetch(`/api/library_group/${encodeURIComponent(seriesGroupId)}`);
|
||||||
if (!response.ok) {
|
if (!response.ok) {
|
||||||
@@ -1554,105 +1557,16 @@
|
|||||||
labelParts.push('aktuelles Medium');
|
labelParts.push('aktuelles Medium');
|
||||||
}
|
}
|
||||||
return `
|
return `
|
||||||
<div style="display:flex; flex-direction:column; gap:6px; margin-bottom:10px;">
|
<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>
|
<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;">
|
<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>
|
||||||
`;
|
`;
|
||||||
}).join('');
|
}).join('');
|
||||||
}
|
}
|
||||||
|
|
||||||
window.openEditLibraryItem = async function(itemId) {
|
function openEditLibraryItem(itemId) {
|
||||||
const item = libraryItems.find(i => i._id === itemId);
|
window.location.href = `/item_edit/${itemId}`;
|
||||||
if (!item) return;
|
|
||||||
|
|
||||||
editLibraryState.itemId = item._id;
|
|
||||||
editLibraryState.seriesGroupId = item.SeriesGroupId || '';
|
|
||||||
editLibraryState.groupMembers = [];
|
|
||||||
|
|
||||||
// 1. Felder befüllen
|
|
||||||
document.getElementById('editLibraryItemId').value = item._id;
|
|
||||||
document.getElementById('editLibraryName').value = item.Name;
|
|
||||||
document.getElementById('editLibraryType').value = item.ItemType;
|
|
||||||
document.getElementById('editLibraryIsbn').value = item.ISBN || '';
|
|
||||||
document.getElementById('editLibraryLocation').value = item.Ort;
|
|
||||||
document.getElementById('editLibraryDescription').value = item.Beschreibung;
|
|
||||||
|
|
||||||
const codesContainer = document.getElementById('editLibraryCodesContainer');
|
|
||||||
if (codesContainer) {
|
|
||||||
codesContainer.innerHTML = '<div style="padding:10px 0; color:#6b7280;">Lade Codes...</div>';
|
|
||||||
}
|
|
||||||
|
|
||||||
const groupMembers = item.SeriesGroupId ? await fetchLibraryGroupMembers(item.SeriesGroupId) : [item];
|
|
||||||
renderLibraryGroupCodeFields(groupMembers.length > 0 ? groupMembers : [item], item._id);
|
|
||||||
|
|
||||||
document.getElementById('editLibraryModal').style.display = 'flex';
|
|
||||||
};
|
|
||||||
|
|
||||||
function closeEditLibraryModal() {
|
|
||||||
document.getElementById('editLibraryModal').style.display = 'none';
|
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<div id="editLibraryModal" class="modal" style="display:none;">
|
|
||||||
<div class="modal-content" style="max-width: 760px; padding: 25px; border-radius: 8px;">
|
|
||||||
<span class="close" onclick="closeEditLibraryModal()" style="cursor: pointer; float: right; font-size: 24px;">×</span>
|
|
||||||
<h3 style="margin-top:0;">Bibliotheksmedium bearbeiten</h3>
|
|
||||||
|
|
||||||
<!-- Bereich für Gruppen-Informationen (Hier konsolidiert!) -->
|
|
||||||
<div id="editLibraryGroupWarning" style="display:none; background-color: #fff; padding: 15px; border-radius: 6px; margin-bottom: 20px; border: 1px solid #0ea5e9;">
|
|
||||||
<div style="display: flex; justify-content: space-between; align-items: center; margin-bottom: 10px; border-bottom: 1px solid #eee; padding-bottom: 10px;">
|
|
||||||
<strong style="color: #0ea5e9;">Gruppen-Range (Total: <span id="editLibraryGroupCount"></span>)</strong>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<p id="editLibraryGroupHint" style="margin: 5px 0; font-size: 12px; color: #555;">
|
|
||||||
Änderungen an Titel, Ort und Beschreibung werden auf alle Exemplare der Gruppe übertragen.
|
|
||||||
</p>
|
|
||||||
|
|
||||||
<div style="margin-top: 15px; font-size: 11px; background: #e0f2fe; padding: 8px; border-radius: 4px;">
|
|
||||||
<strong>Hinweis:</strong> Jeder Mediencode wird einzeln gespeichert, damit alle Exemplare der Gruppe korrekt bleiben.
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<form id="editLibraryForm">
|
|
||||||
<input type="hidden" id="editLibraryItemId">
|
|
||||||
<div class="edit-grid">
|
|
||||||
<div class="full">
|
|
||||||
<label for="editLibraryName">Titel</label>
|
|
||||||
<input id="editLibraryName" required style="width: 100%;">
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<label for="editLibraryType">Medientyp</label>
|
|
||||||
<select id="editLibraryType" style="width: 100%;">
|
|
||||||
<option value="Buch">Buch</option>
|
|
||||||
<option value="Schulbuch">Schulbuch</option>
|
|
||||||
<option value="cd">CD</option>
|
|
||||||
<option value="dvd">DVD</option>
|
|
||||||
<option value="other">Sonstige Medien</option>
|
|
||||||
</select>
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<label for="editLibraryIsbn">ISBN</label>
|
|
||||||
<input id="editLibraryIsbn" placeholder="optional ISBN-10/13" style="width: 100%;">
|
|
||||||
</div>
|
|
||||||
<div>
|
|
||||||
<label>Mediencodes</label>
|
|
||||||
<div id="editLibraryCodesContainer"></div>
|
|
||||||
</div>
|
|
||||||
<div class="full">
|
|
||||||
<label for="editLibraryLocation">Ort</label>
|
|
||||||
<input id="editLibraryLocation" required style="width: 100%;">
|
|
||||||
</div>
|
|
||||||
<div class="full">
|
|
||||||
<label for="editLibraryDescription">Beschreibung</label>
|
|
||||||
<textarea id="editLibraryDescription" rows="4" required style="width: 100%;"></textarea>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
<div class="edit-actions" style="margin-top:20px;">
|
|
||||||
<button type="submit" class="button" style="background:#0ea5e9;color:#fff;">Speichern & Synchronisieren</button>
|
|
||||||
<button type="button" class="button" onclick="closeEditLibraryModal()">Abbrechen</button>
|
|
||||||
</div>
|
|
||||||
</form>
|
|
||||||
</div>
|
|
||||||
</div>
|
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
@@ -4315,6 +4315,7 @@ document.addEventListener('DOMContentLoaded', ()=>{
|
|||||||
hiddenInput.value = image;
|
hiddenInput.value = image;
|
||||||
editForm.appendChild(hiddenInput);
|
editForm.appendChild(hiddenInput);
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -5632,6 +5633,61 @@ document.addEventListener('DOMContentLoaded', ()=>{
|
|||||||
futureAppointments.sort((a, b) => new Date(a.date) - new Date(b.date));
|
futureAppointments.sort((a, b) => new Date(a.date) - new Date(b.date));
|
||||||
return futureAppointments[0];
|
return futureAppointments[0];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Load location options
|
||||||
|
function loadLocationOptions() {
|
||||||
|
fetch('/get_predefined_locations')
|
||||||
|
.then(response => response.json())
|
||||||
|
.then(data => {
|
||||||
|
const ortSelect = document.getElementById('ort');
|
||||||
|
if (ortSelect) {
|
||||||
|
// Clear existing options except the first one
|
||||||
|
while (ortSelect.children.length > 1) {
|
||||||
|
ortSelect.removeChild(ortSelect.lastChild);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add new options - data.locations contains the array
|
||||||
|
data.locations.forEach(location => {
|
||||||
|
const option = document.createElement('option');
|
||||||
|
option.value = location;
|
||||||
|
option.textContent = location;
|
||||||
|
ortSelect.appendChild(option);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
console.error('Error loading location options:', error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Function to add new location
|
||||||
|
function addNewLocation() {
|
||||||
|
const newLocationInput = document.getElementById('new-location-input');
|
||||||
|
const newLocation = newLocationInput.value.trim();
|
||||||
|
|
||||||
|
if (!newLocation) {
|
||||||
|
alert('Bitte geben Sie einen Ort ein.');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add to dropdown
|
||||||
|
const ortSelect = document.getElementById('ort');
|
||||||
|
const option = document.createElement('option');
|
||||||
|
option.value = newLocation;
|
||||||
|
option.textContent = newLocation;
|
||||||
|
option.selected = true;
|
||||||
|
ortSelect.appendChild(option);
|
||||||
|
|
||||||
|
// Hide the input container
|
||||||
|
document.getElementById('new-location-container').style.display = 'none';
|
||||||
|
newLocationInput.value = '';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Function to cancel adding new location
|
||||||
|
function cancelAddLocation() {
|
||||||
|
document.getElementById('new-location-container').style.display = 'none';
|
||||||
|
document.getElementById('new-location-input').value = '';
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- Include edit item functions -->
|
<!-- Include edit item functions -->
|
||||||
|
|||||||
Reference in New Issue
Block a user