Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| c90cef6dcf | |||
| b5451a4ef0 |
@@ -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 = '<div style="padding:10px 0; color:#6b7280;">Lade Codes...</div>';
|
||||
@@ -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 = '';
|
||||
}
|
||||
</script>
|
||||
|
||||
@@ -1642,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>
|
||||
|
||||
@@ -4315,6 +4315,7 @@ document.addEventListener('DOMContentLoaded', ()=>{
|
||||
hiddenInput.value = image;
|
||||
editForm.appendChild(hiddenInput);
|
||||
}
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
@@ -5632,6 +5633,61 @@ document.addEventListener('DOMContentLoaded', ()=>{
|
||||
futureAppointments.sort((a, b) => new Date(a.date) - new Date(b.date));
|
||||
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>
|
||||
|
||||
<!-- Include edit item functions -->
|
||||
|
||||
Reference in New Issue
Block a user