diff --git a/Web/templates/library_table.html b/Web/templates/library_table.html index 0e92c99..bb7047f 100644 --- a/Web/templates/library_table.html +++ b/Web/templates/library_table.html @@ -1578,9 +1578,11 @@ 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; + // Orte laden und bestehenden Ort setzen + await loadEditLocationOptions(item.Ort); + const codesContainer = document.getElementById('editLibraryCodesContainer'); if (codesContainer) { codesContainer.innerHTML = '
Lade Codes...
'; @@ -1594,6 +1596,87 @@ 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 = ''; } @@ -1642,10 +1725,27 @@
-
+ + +
- +
+ + +
+
+ +