|
|
|
@@ -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,47 +1027,21 @@
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
async function processQuickToggleScan(scannedCode) {
|
|
|
|
|
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);
|
|
|
|
|
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;
|
|
|
|
|
// 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) {
|
|
|
|
|
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', {
|
|
|
|
@@ -1103,6 +1077,33 @@
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function scanIntoEditCode() {
|
|
|
|
|
const scanReaderWrap = document.getElementById('scanReaderWrap');
|
|
|
|
|
const editCodeInput = document.getElementById('edit-code4');
|
|
|
|
@@ -1399,74 +1400,8 @@
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Edit Modal Form processing
|
|
|
|
|
const editForm = document.getElementById('editLibraryForm');
|
|
|
|
|
if (editForm) {
|
|
|
|
|
try {
|
|
|
|
|
if (isGroupedEdit) {
|
|
|
|
|
const payload = {
|
|
|
|
|
series_group_id: currentItem.SeriesGroupId,
|
|
|
|
|
...sharedPayload,
|
|
|
|
|
items: groupMembers.map(member => ({
|
|
|
|
|
id: member._id,
|
|
|
|
|
code_4: codeByItemId.get(member._id) || ''
|
|
|
|
|
}))
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const response = await fetch('/update_group', {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
'X-CSRFToken': '{{ csrf_token }}',
|
|
|
|
|
'X-CSRF-Token': '{{ csrf_token }}'
|
|
|
|
|
},
|
|
|
|
|
body: JSON.stringify(payload)
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const result = await response.json();
|
|
|
|
|
if (response.ok && result.success) {
|
|
|
|
|
alert(result.message || 'Gruppe erfolgreich aktualisiert!');
|
|
|
|
|
closeEditLibraryModal();
|
|
|
|
|
pagingState.loading = false;
|
|
|
|
|
await loadLibraryItems();
|
|
|
|
|
} else {
|
|
|
|
|
alert(result.message || 'Fehler beim Speichern der Gruppenänderungen.');
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
const primaryCodeInput = codeInputs[0];
|
|
|
|
|
const payload = {
|
|
|
|
|
name: sharedPayload.name,
|
|
|
|
|
item_type: sharedPayload.item_type,
|
|
|
|
|
isbn: sharedPayload.isbn,
|
|
|
|
|
code_4: primaryCodeInput ? primaryCodeInput.value.trim() : (currentItem.Code_4 || currentItem.Code4 || '').trim(),
|
|
|
|
|
ort: sharedPayload.ort,
|
|
|
|
|
beschreibung: sharedPayload.beschreibung
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const response = await fetch(`/api/library_item/${itemId}/update`, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
'X-CSRFToken': '{{ csrf_token }}',
|
|
|
|
|
'X-CSRF-Token': '{{ csrf_token }}'
|
|
|
|
|
},
|
|
|
|
|
body: JSON.stringify(payload)
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const result = await response.json();
|
|
|
|
|
if (response.ok && result.ok) {
|
|
|
|
|
alert(result.message || 'Medium erfolgreich aktualisiert!');
|
|
|
|
|
closeEditLibraryModal();
|
|
|
|
|
pagingState.loading = false;
|
|
|
|
|
await loadLibraryItems();
|
|
|
|
|
} else {
|
|
|
|
|
alert(result.message || 'Fehler beim Speichern der Änderungen.');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('Update failed:', error);
|
|
|
|
|
alert('Netzwerkfehler beim Aktualisieren des Mediums.');
|
|
|
|
|
}
|
|
|
|
|
editForm.addEventListener('submit', async function (e) {
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
|
|
|
|
@@ -1476,6 +1411,7 @@
|
|
|
|
|
|
|
|
|
|
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,
|
|
|
|
@@ -1486,113 +1422,261 @@
|
|
|
|
|
ansch_kost: currentItem.Anschaffungskosten || '',
|
|
|
|
|
reservierbar: currentItem.Reservierbar !== false,
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
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 = {
|
|
|
|
|
series_group_id: currentItem.SeriesGroupId,
|
|
|
|
|
...sharedPayload,
|
|
|
|
|
items: groupMembers.map(member => ({
|
|
|
|
|
id: member._id,
|
|
|
|
|
code_4: codeByItemId.get(member._id) || ''
|
|
|
|
|
}))
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const response = await fetch('/update_group', {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
'X-CSRFToken': '{{ csrf_token }}',
|
|
|
|
|
'X-CSRF-Token': '{{ csrf_token }}'
|
|
|
|
|
},
|
|
|
|
|
body: JSON.stringify(payload)
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const result = await response.json();
|
|
|
|
|
if (response.ok && result.success) {
|
|
|
|
|
alert(result.message || 'Gruppe erfolgreich aktualisiert!');
|
|
|
|
|
closeEditLibraryModal();
|
|
|
|
|
pagingState.loading = false;
|
|
|
|
|
await loadLibraryItems();
|
|
|
|
|
} else {
|
|
|
|
|
alert(result.message || 'Fehler beim Speichern der Gruppenänderungen.');
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
const primaryCodeInput = codeInputs[0];
|
|
|
|
|
const payload = {
|
|
|
|
|
name: sharedPayload.name,
|
|
|
|
|
item_type: sharedPayload.item_type,
|
|
|
|
|
isbn: sharedPayload.isbn,
|
|
|
|
|
code_4: primaryCodeInput ? primaryCodeInput.value.trim() : (currentItem.Code_4 || currentItem.Code4 || '').trim(),
|
|
|
|
|
ort: sharedPayload.ort,
|
|
|
|
|
beschreibung: sharedPayload.beschreibung
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
const response = await fetch(`/api/library_item/${itemId}/update`, {
|
|
|
|
|
method: 'POST',
|
|
|
|
|
headers: {
|
|
|
|
|
'Content-Type': 'application/json',
|
|
|
|
|
'X-CSRFToken': '{{ csrf_token }}',
|
|
|
|
|
'X-CSRF-Token': '{{ csrf_token }}'
|
|
|
|
|
},
|
|
|
|
|
body: JSON.stringify(payload)
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
const result = await response.json();
|
|
|
|
|
if (response.ok && result.ok) {
|
|
|
|
|
alert(result.message || 'Medium erfolgreich aktualisiert!');
|
|
|
|
|
closeEditLibraryModal();
|
|
|
|
|
pagingState.loading = false;
|
|
|
|
|
await loadLibraryItems();
|
|
|
|
|
} else {
|
|
|
|
|
alert(result.message || 'Fehler beim Speichern der Änderungen.');
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('Update failed:', error);
|
|
|
|
|
alert('Netzwerkfehler beim Aktualisieren des Mediums.');
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
async function fetchLibraryGroupMembers(seriesGroupId) {
|
|
|
|
|
if (!seriesGroupId) return [];
|
|
|
|
|
|
|
|
|
|
try {
|
|
|
|
|
const response = await fetch(`/api/library_group/${encodeURIComponent(seriesGroupId)}`);
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
throw new Error(`HTTP ${response.status}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const payload = await response.json();
|
|
|
|
|
return Array.isArray(payload.items) ? payload.items : [];
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.warn('Falling back to loaded library items for group editing:', error);
|
|
|
|
|
return (libraryItems || []).filter(item => item.SeriesGroupId === seriesGroupId);
|
|
|
|
|
try {
|
|
|
|
|
const response = await fetch(`/api/library_group/${encodeURIComponent(seriesGroupId)}`);
|
|
|
|
|
if (!response.ok) {
|
|
|
|
|
throw new Error(`HTTP ${response.status}`);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const payload = await response.json();
|
|
|
|
|
return Array.isArray(payload.items) ? payload.items : [];
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.warn('Falling back to loaded library items for group editing:', error);
|
|
|
|
|
return (libraryItems || []).filter(item => item.SeriesGroupId === seriesGroupId);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function renderLibraryGroupCodeFields(groupMembers, currentItemId) {
|
|
|
|
|
const codesContainer = document.getElementById('editLibraryCodesContainer');
|
|
|
|
|
const groupWarning = document.getElementById('editLibraryGroupWarning');
|
|
|
|
|
const groupCount = document.getElementById('editLibraryGroupCount');
|
|
|
|
|
const groupHint = document.getElementById('editLibraryGroupHint');
|
|
|
|
|
|
|
|
|
|
if (!codesContainer) return;
|
|
|
|
|
|
|
|
|
|
const items = Array.isArray(groupMembers) ? groupMembers.slice() : [];
|
|
|
|
|
items.sort((a, b) => (a.SeriesPosition || 0) - (b.SeriesPosition || 0) || String(a.Name || '').localeCompare(String(b.Name || '')));
|
|
|
|
|
|
|
|
|
|
editLibraryState.groupMembers = items;
|
|
|
|
|
|
|
|
|
|
if (groupWarning) {
|
|
|
|
|
groupWarning.style.display = items.length > 1 ? 'block' : 'none';
|
|
|
|
|
}
|
|
|
|
|
if (groupCount) {
|
|
|
|
|
const totalCount = items.length || 1;
|
|
|
|
|
const declaredCount = items[0]?.SeriesCount || totalCount;
|
|
|
|
|
groupCount.textContent = `${totalCount} / ${declaredCount}`;
|
|
|
|
|
}
|
|
|
|
|
if (groupHint) {
|
|
|
|
|
groupHint.textContent = items.length > 1
|
|
|
|
|
? 'Jeder Code gehört zu einem eigenen Exemplar. Änderungen werden für alle Codes gespeichert.'
|
|
|
|
|
: 'Einzelnes Exemplar. Der Code wird direkt gespeichert.';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function renderLibraryGroupCodeFields(groupMembers, currentItemId) {
|
|
|
|
|
const codesContainer = document.getElementById('editLibraryCodesContainer');
|
|
|
|
|
const groupWarning = document.getElementById('editLibraryGroupWarning');
|
|
|
|
|
const groupCount = document.getElementById('editLibraryGroupCount');
|
|
|
|
|
const groupHint = document.getElementById('editLibraryGroupHint');
|
|
|
|
|
if (!items.length) {
|
|
|
|
|
codesContainer.innerHTML = '<div style="padding:10px 0; color:#6b7280;">Keine Codes geladen.</div>';
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!codesContainer) return;
|
|
|
|
|
|
|
|
|
|
const items = Array.isArray(groupMembers) ? groupMembers.slice() : [];
|
|
|
|
|
items.sort((a, b) => (a.SeriesPosition || 0) - (b.SeriesPosition || 0) || String(a.Name || '').localeCompare(String(b.Name || '')));
|
|
|
|
|
|
|
|
|
|
editLibraryState.groupMembers = items;
|
|
|
|
|
|
|
|
|
|
if (groupWarning) {
|
|
|
|
|
groupWarning.style.display = items.length > 1 ? 'block' : 'none';
|
|
|
|
|
codesContainer.innerHTML = items.map((member, index) => {
|
|
|
|
|
const codeValue = member.Code_4 || member.Code4 || '';
|
|
|
|
|
const labelParts = [];
|
|
|
|
|
if (member.SeriesPosition !== undefined && member.SeriesPosition !== null) {
|
|
|
|
|
labelParts.push(`Exemplar ${member.SeriesPosition}`);
|
|
|
|
|
} else {
|
|
|
|
|
labelParts.push(`Exemplar ${index + 1}`);
|
|
|
|
|
}
|
|
|
|
|
if (groupCount) {
|
|
|
|
|
const totalCount = items.length || 1;
|
|
|
|
|
const declaredCount = items[0]?.SeriesCount || totalCount;
|
|
|
|
|
groupCount.textContent = `${totalCount} / ${declaredCount}`;
|
|
|
|
|
if (member._id === currentItemId) {
|
|
|
|
|
labelParts.push('aktuelles Medium');
|
|
|
|
|
}
|
|
|
|
|
if (groupHint) {
|
|
|
|
|
groupHint.textContent = items.length > 1
|
|
|
|
|
? 'Jeder Code gehört zu einem eigenen Exemplar. Änderungen werden für alle Codes gespeichert.'
|
|
|
|
|
: 'Einzelnes Exemplar. Der Code wird direkt gespeichert.';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (!items.length) {
|
|
|
|
|
codesContainer.innerHTML = '<div style="padding:10px 0; color:#6b7280;">Keine Codes geladen.</div>';
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
codesContainer.innerHTML = items.map((member, index) => {
|
|
|
|
|
const codeValue = member.Code_4 || member.Code4 || '';
|
|
|
|
|
const labelParts = [];
|
|
|
|
|
if (member.SeriesPosition !== undefined && member.SeriesPosition !== null) {
|
|
|
|
|
labelParts.push(`Exemplar ${member.SeriesPosition}`);
|
|
|
|
|
} else {
|
|
|
|
|
labelParts.push(`Exemplar ${index + 1}`);
|
|
|
|
|
}
|
|
|
|
|
if (member._id === currentItemId) {
|
|
|
|
|
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>
|
|
|
|
|
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>
|
|
|
|
|
`;
|
|
|
|
|
}).join('');
|
|
|
|
|
}).join('');
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
window.openEditLibraryItem = async function (itemId) {
|
|
|
|
|
const item = libraryItems.find(i => i._id === itemId);
|
|
|
|
|
if (!item) return;
|
|
|
|
|
|
|
|
|
|
editLibraryState.itemId = item._id;
|
|
|
|
|
editLibraryState.seriesGroupId = item.SeriesGroupId || '';
|
|
|
|
|
editLibraryState.groupMembers = [];
|
|
|
|
|
|
|
|
|
|
// 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('editLibraryDescription').value = item.Beschreibung;
|
|
|
|
|
|
|
|
|
|
// Orte laden und bestehenden Ort setzen
|
|
|
|
|
await loadEditLocationOptions(item.Ort);
|
|
|
|
|
|
|
|
|
|
const codesContainer = document.getElementById('editLibraryCodesContainer');
|
|
|
|
|
if (codesContainer) {
|
|
|
|
|
codesContainer.innerHTML = '<div style="padding:10px 0; color:#6b7280;">Lade Codes...</div>';
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
window.openEditLibraryItem = async function (itemId) {
|
|
|
|
|
const item = libraryItems.find(i => i._id === itemId);
|
|
|
|
|
if (!item) return;
|
|
|
|
|
const groupMembers = item.SeriesGroupId ? await fetchLibraryGroupMembers(item.SeriesGroupId) : [item];
|
|
|
|
|
renderLibraryGroupCodeFields(groupMembers.length > 0 ? groupMembers : [item], item._id);
|
|
|
|
|
|
|
|
|
|
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';
|
|
|
|
|
};
|
|
|
|
|
document.getElementById('editLibraryModal').style.display = 'flex';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
function closeEditLibraryModal() {
|
|
|
|
|
document.getElementById('editLibraryModal').style.display = 'none';
|
|
|
|
|
// Setzt das Feld für neuen Ort sicherheitshalber zurück, wenn geschlossen wird
|
|
|
|
|
cancelEditAddLocation();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Lädt die Optionen in das Dropdown und wählt den aktuellen Ort des Mediums aus
|
|
|
|
|
async function loadEditLocationOptions(currentLocation) {
|
|
|
|
|
try {
|
|
|
|
|
const response = await fetch('/get_predefined_locations');
|
|
|
|
|
const data = await response.json();
|
|
|
|
|
const ortSelect = document.getElementById('editLibraryLocation');
|
|
|
|
|
|
|
|
|
|
if (ortSelect) {
|
|
|
|
|
// Bestehende Optionen löschen (außer die erste Platzhalter-Option)
|
|
|
|
|
while (ortSelect.children.length > 1) {
|
|
|
|
|
ortSelect.removeChild(ortSelect.lastChild);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
let locationFound = false;
|
|
|
|
|
|
|
|
|
|
// Neue Optionen aus der Datenbank hinzufügen
|
|
|
|
|
data.locations.forEach(location => {
|
|
|
|
|
const option = document.createElement('option');
|
|
|
|
|
option.value = location;
|
|
|
|
|
option.textContent = location;
|
|
|
|
|
ortSelect.appendChild(option);
|
|
|
|
|
|
|
|
|
|
if (location === currentLocation) {
|
|
|
|
|
locationFound = true;
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// WICHTIG: Falls der aktuell hinterlegte Ort nicht in der Datenbank-Liste ist,
|
|
|
|
|
// fügen wir ihn als temporäre Option hinzu, damit er nicht beim Speichern überschrieben wird.
|
|
|
|
|
if (currentLocation && !locationFound) {
|
|
|
|
|
const option = document.createElement('option');
|
|
|
|
|
option.value = currentLocation;
|
|
|
|
|
option.textContent = currentLocation;
|
|
|
|
|
ortSelect.appendChild(option);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Zuletzt den aktuellen Ort anwählen
|
|
|
|
|
if (currentLocation) {
|
|
|
|
|
ortSelect.value = currentLocation;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
} catch (error) {
|
|
|
|
|
console.error('Error loading location options:', error);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Funktion um einen neuen Ort ins Bearbeiten-Dropdown aufzunehmen
|
|
|
|
|
function addEditNewLocation() {
|
|
|
|
|
const newLocationInput = document.getElementById('edit-new-location-input');
|
|
|
|
|
const newLocation = newLocationInput.value.trim();
|
|
|
|
|
|
|
|
|
|
if (!newLocation) {
|
|
|
|
|
alert('Bitte geben Sie einen Ort ein.');
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Füge Option dem Dropdown hinzu
|
|
|
|
|
const ortSelect = document.getElementById('editLibraryLocation');
|
|
|
|
|
const option = document.createElement('option');
|
|
|
|
|
option.value = newLocation;
|
|
|
|
|
option.textContent = newLocation;
|
|
|
|
|
ortSelect.appendChild(option);
|
|
|
|
|
|
|
|
|
|
// Wähle die neue Option direkt aus
|
|
|
|
|
ortSelect.value = newLocation;
|
|
|
|
|
|
|
|
|
|
// Verstecke die Eingabemaske wieder
|
|
|
|
|
cancelEditAddLocation();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Funktion zum Abbrechen der Orteingabe
|
|
|
|
|
function cancelEditAddLocation() {
|
|
|
|
|
const container = document.getElementById('edit-new-location-container');
|
|
|
|
|
if(container) container.style.display = 'none';
|
|
|
|
|
|
|
|
|
|
const input = document.getElementById('edit-new-location-input');
|
|
|
|
|
if(input) input.value = '';
|
|
|
|
|
}
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
@@ -1641,10 +1725,27 @@
|
|
|
|
|
<label>Mediencodes</label>
|
|
|
|
|
<div id="editLibraryCodesContainer"></div>
|
|
|
|
|
</div>
|
|
|
|
|
<div class="full">
|
|
|
|
|
|
|
|
|
|
<!-- NEUER BEREICH FÜR DIE ORTS-AUSWAHL -->
|
|
|
|
|
<div class="full form-group">
|
|
|
|
|
<label for="editLibraryLocation">Ort</label>
|
|
|
|
|
<input id="editLibraryLocation" required style="width: 100%;">
|
|
|
|
|
<div style="display: flex; gap: 10px; margin-bottom: 5px;">
|
|
|
|
|
<select id="editLibraryLocation" required style="flex-grow: 1; padding: 8px;">
|
|
|
|
|
<option value="">-- Bitte Ort auswählen --</option>
|
|
|
|
|
<!-- Options will be loaded by JavaScript -->
|
|
|
|
|
</select>
|
|
|
|
|
<button type="button" class="button" id="edit-add-new-location-btn" onclick="document.getElementById('edit-new-location-container').style.display = 'flex';" style="white-space: nowrap;">
|
|
|
|
|
Neuen Ort hinzufügen
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
<div id="edit-new-location-container" class="edit-new-location-container" style="display: none; gap: 10px; margin-top: 5px;">
|
|
|
|
|
<input type="text" id="edit-new-location-input" placeholder="Neuen Ort eingeben" style="flex-grow: 1; padding: 8px;">
|
|
|
|
|
<button type="button" class="button" onclick="addEditNewLocation()" style="background:#10b981; color:#fff;">Hinzufügen</button>
|
|
|
|
|
<button type="button" class="button" onclick="cancelEditAddLocation()" style="background:#ef4444; color:#fff;">Abbrechen</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
<!-- ENDE ORTS-AUSWAHL -->
|
|
|
|
|
|
|
|
|
|
<div class="full">
|
|
|
|
|
<label for="editLibraryDescription">Beschreibung</label>
|
|
|
|
|
<textarea id="editLibraryDescription" rows="4" required style="width: 100%;"></textarea>
|
|
|
|
|