diff --git a/Web/templates/edit_item_functions.html b/Web/templates/edit_item_functions.html deleted file mode 100755 index dbbfda1..0000000 --- a/Web/templates/edit_item_functions.html +++ /dev/null @@ -1,288 +0,0 @@ - - - diff --git a/Web/templates/main_admin.html b/Web/templates/main_admin.html index 205bbd4..534ac8a 100755 --- a/Web/templates/main_admin.html +++ b/Web/templates/main_admin.html @@ -1951,11 +1951,6 @@ display: none; } - /* Edit new location container */ - .edit-new-location-container { - display: none; - margin-top: 10px; - } /* Modal dialog styling */ .modal-dialog-white { @@ -1969,11 +1964,6 @@ margin-top: 10px; } - /* Element text colors for better visibility */ - .edit-button, .duplicate-button, .generate-qr-button { - color: var(--ui-title) !important; - } - /* Standardized button styles across the application */ .search-button, .scan-button, .filter-toggle, .clear-filter, .add-new-btn, .popup-close-button, .prev-image-button, .next-image-button, @@ -2474,187 +2464,6 @@ document.addEventListener('DOMContentLoaded', ()=>{ - - - {% if current_permissions.actions.get('can_edit', False) %} -
- -
- {% endif %} @@ -2889,58 +2698,6 @@ document.addEventListener('DOMContentLoaded', ()=>{ } }); - function scanIntoEditCode() { - const qrReader = document.getElementById('qr-reader'); - const editCodeInput = document.getElementById('edit-code4'); - const scanEditBtn = document.getElementById('scan-edit-code-btn'); - if (!qrReader || !editCodeInput || !scanEditBtn) { - return; - } - - // Toggle close if it's already running - if (isScanning && qrReader.style.display !== 'none') { - stopScanner(); - scanEditBtn.textContent = 'Barcode scannen'; - return; - } - - scanEditBtn.textContent = 'Scanner schließen'; - - // Start scanner with custom logic mapping to the Code input field - startScanner(function(decodedText) { - editCodeInput.value = decodedText; - validateCodeField(editCodeInput, document.getElementById('edit-item-id')?.value || null); - scanEditBtn.textContent = 'Barcode scannen'; - }); - } - - function scanIntoEditIsbn() { - const qrReader = document.getElementById('qr-reader'); - const editIsbnInput = document.getElementById('edit-isbn'); - const scanIsbnBtn = document.getElementById('scan-edit-isbn-btn'); - if (!qrReader || !editIsbnInput || !scanIsbnBtn) { - return; - } - - // Toggle close if it's already running - if (isScanning && qrReader.style.display !== 'none') { - stopScanner(); - scanIsbnBtn.textContent = 'ISBN scannen'; - return; - } - - scanIsbnBtn.textContent = 'Scanner schließen'; - - // Start scanner with custom logic mapping to the ISBN input field - startScanner(function(decodedText) { - editIsbnInput.value = decodedText; - scanIsbnBtn.textContent = 'ISBN scannen'; - if (typeof fetchBookInfo === 'function') { - fetchBookInfo('edit'); - } - }); - } - function rebuildFilter3Options() { if (!allItems) return; @@ -3324,21 +3081,11 @@ document.addEventListener('DOMContentLoaded', ()=>{ loadPredefinedFilterValues(1); loadPredefinedFilterValues(2); loadPredefinedFilterValues(3); - - // Set up edit form submission - setupEditFormSubmission(); + // Set up schedule form submission setupScheduleFormSubmission(); - - // Set up add new location buttons - const editAddLocationBtn = document.getElementById('edit-add-new-location-btn'); - if (editAddLocationBtn) { - editAddLocationBtn.addEventListener('click', function() { - const container = document.getElementById('edit-new-location-container'); - container.style.display = container.style.display === 'none' ? 'block' : 'none'; - }); - } + // Find and attach event listener to all logout links const logoutLinks = document.querySelectorAll('a[href*="logout"]'); @@ -3391,35 +3138,11 @@ document.addEventListener('DOMContentLoaded', ()=>{ // Close modals when clicking outside window.onclick = function(event) { const itemModal = document.getElementById('item-modal'); - const editModal = document.getElementById('edit-modal'); if (event.target === itemModal) { itemModal.style.display = 'none'; } - if (event.target === editModal) { - editModal.style.display = 'none'; - } }; - - // Set up code validation for edit form - const editCodeField = document.getElementById('edit-code4'); - if (editCodeField) { - editCodeField.addEventListener('blur', function() { - const itemIdField = document.getElementById('edit-item-id'); - const excludeId = itemIdField ? itemIdField.value : null; - validateCodeField(this, excludeId); - }); - } - - const scanEditCodeBtn = document.getElementById('scan-edit-code-btn'); - if (scanEditCodeBtn) { - scanEditCodeBtn.addEventListener('click', scanIntoEditCode); - } - - const scanEditIsbnBtn = document.getElementById('scan-edit-isbn-btn'); - if (scanEditIsbnBtn) { - scanEditIsbnBtn.addEventListener('click', scanIntoEditIsbn); - } }); // Function to load items from server @@ -4171,163 +3894,6 @@ document.addEventListener('DOMContentLoaded', ()=>{ }); } - function openEditModalForSelectedUnit(defaultItemId, selectId) { - let targetItemId = defaultItemId; - - try { - const selectedUnit = selectId ? document.getElementById(selectId) : null; - if (selectedUnit && selectedUnit.value) { - targetItemId = selectedUnit.value; - } - } catch (e) { - // Keep default item id as fallback. - } - - openEditModalFromServer(targetItemId); - } - - function closeEditModal() { - const editModal = document.getElementById('edit-modal'); - if (editModal) { - editModal.style.display = 'none'; - } - } - - function openEditModalFromServer(itemId) { - const editModal = document.getElementById('edit-modal'); - if (!editModal) { - console.error('Edit modal nicht gefunden'); - return; - } - - console.log('DEBUG: openEditModal called with itemId:', itemId); - - // Fetch the item data from the backend - fetch(`/get_item/${itemId}`) - .then(response => { - console.log('DEBUG: Response status:', response.status); - if (!response.ok) throw new Error(`HTTP ${response.status}`); - return response.json(); - }) - .then(data => { - console.log('DEBUG: Fetched data:', data); - // Backend returns the item directly or wrapped in error/success - const item = data.error ? null : (data.item || data); - - console.log('DEBUG: Parsed item:', item); - - if (!item || !item._id) { - console.error('DEBUG: Item not found or invalid'); - alert('Item nicht gefunden'); - return; - } - - // Fill in the form fields with the item data - document.getElementById('edit-item-id').value = item._id || ''; - document.getElementById('edit-name').value = item.Name || ''; - document.getElementById('edit-location').value = item.Ort || ''; - document.getElementById('edit-description').value = item.Beschreibung || ''; - document.getElementById('edit-year').value = item.Anschaffungsjahr || ''; - document.getElementById('edit-cost').value = item.Anschaffungskosten || ''; - document.getElementById('edit-code4').value = item.Code_4 || ''; - document.getElementById('edit-isbn').value = item.ISBN || ''; - document.getElementById('edit-reservierbar').checked = item.Reservierbar !== false; - - // Fill in filter 1 (Unterrichtsfach) - const filter1Array = Array.isArray(item.Filter) ? item.Filter : (item.Filter ? [item.Filter] : []); - document.getElementById('edit-filter1-1').value = filter1Array[0] || ''; - document.getElementById('edit-filter1-2').value = filter1Array[1] || ''; - document.getElementById('edit-filter1-3').value = filter1Array[2] || ''; - document.getElementById('edit-filter1-4').value = filter1Array[3] || ''; - - // Fill in filter 2 (Jahrgangsstufe) - const filter2Array = Array.isArray(item.Filter2) ? item.Filter2 : (item.Filter2 ? [item.Filter2] : []); - document.getElementById('edit-filter2-1').value = filter2Array[0] || ''; - document.getElementById('edit-filter2-2').value = filter2Array[1] || ''; - document.getElementById('edit-filter2-3').value = filter2Array[2] || ''; - document.getElementById('edit-filter2-4').value = filter2Array[3] || ''; - - // Fill in filter 3 (Schlagwort) - const filter3Array = Array.isArray(item.Filter3) ? item.Filter3 : (item.Filter3 ? [item.Filter3] : []); - document.getElementById('edit-filter3-1').value = filter3Array[0] || ''; - document.getElementById('edit-filter3-2').value = filter3Array[1] || ''; - document.getElementById('edit-filter3-3').value = filter3Array[2] || ''; - document.getElementById('edit-filter3-4').value = filter3Array[3] || ''; - - // Display existing images - const existingImagesContainer = document.getElementById('edit-existing-images'); - const editForm = document.getElementById('edit-item-form'); - existingImagesContainer.innerHTML = ''; - if (editForm) { - editForm.querySelectorAll('input[name="existing_images"], input[name="removed_images"]').forEach(input => input.remove()); - } - if (item.Images && Array.isArray(item.Images)) { - item.Images.forEach((image, index) => { - const isVideo = isVideoFile(image); - const imageDiv = document.createElement('div'); - imageDiv.className = 'existing-image-item'; - imageDiv.style.marginBottom = '10px'; - - const thumbnailInfo = item.ThumbnailInfo && item.ThumbnailInfo[index]; - const imageSrc = thumbnailInfo && thumbnailInfo.has_preview ? - thumbnailInfo.preview_url : - (image.startsWith('/uploads/') || image.startsWith('http') ? - image : - `{{ url_for('uploaded_file', filename='') }}${image}`); - - const row = document.createElement('div'); - row.style.display = 'flex'; - row.style.gap = '8px'; - row.style.alignItems = 'center'; - - if (isVideo) { - const video = document.createElement('video'); - video.src = imageSrc; - video.style.maxWidth = '100px'; - video.style.maxHeight = '100px'; - video.style.objectFit = 'contain'; - video.controls = true; - row.appendChild(video); - } else { - const img = document.createElement('img'); - img.src = imageSrc; - img.style.maxWidth = '100px'; - img.style.maxHeight = '100px'; - img.style.objectFit = 'contain'; - img.alt = `Existierendes Bild ${index + 1}`; - row.appendChild(img); - } - - const deleteButton = document.createElement('button'); - deleteButton.type = 'button'; - deleteButton.className = 'delete-image-button'; - deleteButton.textContent = 'Löschen'; - deleteButton.addEventListener('click', () => removeExistingImage(image, deleteButton)); - row.appendChild(deleteButton); - - imageDiv.appendChild(row); - existingImagesContainer.appendChild(imageDiv); - - if (editForm) { - const hiddenInput = document.createElement('input'); - hiddenInput.type = 'hidden'; - hiddenInput.name = 'existing_images'; - hiddenInput.value = image; - editForm.appendChild(hiddenInput); - } - - }); - } - - // Display the modal - editModal.style.display = 'block'; - }) - .catch(error => { - console.error('Fehler beim Laden des Items:', error); - alert('Fehler beim Laden des Items'); - }); - } - function escapeHtml(value) { return String(value ?? '').replace(/[&<>'"]/g, (char) => { const map = { @@ -4687,7 +4253,9 @@ document.addEventListener('DOMContentLoaded', ()=>{ `; - + + + modal.style.display = 'block'; const closeButton = modal.querySelector('.close-modal'); @@ -4924,6 +4492,13 @@ document.addEventListener('DOMContentLoaded', ()=>{ }); } + function openEditModalForSelectedUnit(itemId, selectId) { + const select = document.getElementById(selectId); + const targetId = (select && select.value) ? select.value : itemId; + // Leitet auf die Bearbeiten-Seite weiter und übergibt die aktuelle URL für den Redirect nach dem Speichern + window.location.href = `/item_edit/${targetId}`; + } + function changeModalImage(direction) { const currentIndex = window.currentModalImageIndex; const total = window.totalModalImages; @@ -5350,8 +4925,6 @@ document.addEventListener('DOMContentLoaded', ()=>{ }); } - // Load location options for edit modal - // Edit-related functions moved to edit_item_functions.html // Schedule modal functions function openScheduleModal(itemId) { @@ -5471,50 +5044,6 @@ document.addEventListener('DOMContentLoaded', ()=>{ } } - // Setup edit form submission - function setupEditFormSubmission() { - const editForm = document.getElementById('edit-item-form'); - if (editForm) { - editForm.addEventListener('submit', function(e) { - e.preventDefault(); - - const itemId = document.getElementById('edit-item-id').value; - const formData = new FormData(this); - - fetch(`/edit_item/${itemId}`, { - method: 'POST', - body: formData - }) - .then(response => { - if (response.ok) { - closeEditModal(); - // Reload items to show updated information - loadItems(); - // Show success message - const successMsg = document.createElement('div'); - successMsg.className = 'alert alert-success'; - successMsg.textContent = 'Item wurde erfolgreich aktualisiert!'; - successMsg.style.position = 'fixed'; - successMsg.style.top = '20px'; - successMsg.style.right = '20px'; - successMsg.style.zIndex = '9999'; - document.body.appendChild(successMsg); - setTimeout(() => { - if (successMsg.parentNode) { - successMsg.parentNode.removeChild(successMsg); - } - }, 3000); - } else { - alert('Fehler beim Aktualisieren des Items'); - } - }) - .catch(error => { - console.error('Error updating item:', error); - alert('Fehler beim Aktualisieren des Items'); - }); - }); - } - } // Duplication function function duplicateItem(itemId) { @@ -5690,9 +5219,6 @@ document.addEventListener('DOMContentLoaded', ()=>{ } - -{% include "edit_item_functions.html" %} - {% include "reset_item_functions.html" %} @@ -5920,16 +5446,4 @@ document.addEventListener('DOMContentLoaded', ()=>{ } } - -{% if open_item %} - -{% endif %} {% endblock %}