diff --git a/static/js/receipt_upload.js b/static/js/receipt_upload.js index 1b27f32..4fbf803 100644 --- a/static/js/receipt_upload.js +++ b/static/js/receipt_upload.js @@ -3,29 +3,16 @@ window.receiptToastShown = window.receiptToastShown || false; if (!window.receiptUploaderInitialized) { document.addEventListener("DOMContentLoaded", function () { const form = document.getElementById("receiptForm"); - const input = document.getElementById("receiptInput"); - const gallery = document.getElementById("receiptGallery"); + const inputCamera = document.getElementById("cameraInput"); + const inputGallery = document.getElementById("galleryInput"); const progressContainer = document.getElementById("progressContainer"); const progressBar = document.getElementById("progressBar"); - const fileLabel = document.getElementById("fileLabel"); + const gallery = document.getElementById("receiptGallery"); - if (!form || !input || !gallery) return; + if (!form || !inputCamera || !inputGallery || !gallery) return; - // Zmiana labela po wyborze pliku - if (input && fileLabel) { - input.addEventListener("change", function () { - if (input.files.length > 0) { - fileLabel.textContent = input.files[0].name; - } else { - fileLabel.textContent = "Wybierz zdjęcie paragonu"; - } - }); - } - - form.addEventListener("submit", function (e) { - e.preventDefault(); - - const file = input.files[0]; + function handleFileUpload(inputElement) { + const file = inputElement.files[0]; if (!file) { showToast("Nie wybrano pliku!", "warning"); return; @@ -56,11 +43,7 @@ if (!window.receiptUploaderInitialized) { progressContainer.style.display = "none"; progressBar.style.width = "0%"; progressBar.textContent = ""; - input.value = ""; - - if (fileLabel) { - fileLabel.textContent = "Wybierz zdjęcie paragonu"; - } + inputElement.value = ""; }; xhr.onreadystatechange = function () { @@ -77,10 +60,10 @@ if (!window.receiptUploaderInitialized) { if (newGallery) { gallery.innerHTML = newGallery.innerHTML; - lightbox.destroy(); - lightbox = GLightbox({ - selector: '.glightbox' - }); + if (typeof lightbox !== "undefined") { + lightbox.destroy(); + } + lightbox = GLightbox({ selector: ".glightbox" }); if (!window.receiptToastShown) { showToast("Wgrano paragon", "success"); @@ -98,7 +81,10 @@ if (!window.receiptUploaderInitialized) { }; xhr.send(formData); - }); + } + + inputCamera.addEventListener("change", () => handleFileUpload(inputCamera)); + inputGallery.addEventListener("change", () => handleFileUpload(inputGallery)); }); window.receiptUploaderInitialized = true; diff --git a/templates/admin/admin_panel.html b/templates/admin/admin_panel.html index 3aa115b..6c3d3f6 100644 --- a/templates/admin/admin_panel.html +++ b/templates/admin/admin_panel.html @@ -75,80 +75,82 @@ -
-
-

📄 Wszystkie listy zakupowe

-
-
- - - - - - - - - - - - - - - - - - - {% for e in enriched_lists %} - {% set l = e.list %} - - - - - - - - - - - - - - - {% endfor %} - +
+
+

📄 Wszystkie listy zakupowe

+ +
+
IDTytułStatusUtworzonoWłaścicielProduktyWypełnienieKomentarzeParagonyWydatkiAkcje
{{ l.id }} - {{ l.title }} - - {% if l.is_archived %} - Archiwalna - {% elif e.expired %} - Wygasła - {% else %} - Aktywna - {% endif %} - {{ l.created_at.strftime('%Y-%m-%d %H:%M') if l.created_at else '-' }} - {% if l.owner_id %} - {{ l.owner_id }} / {{ l.owner.username if l.owner else 'Brak użytkownika' }} - {% else %} - - - {% endif %} - {{ e.total_count }}{{ e.purchased_count }}/{{ e.total_count }} ({{ e.percent }}%){{ e.comments_count }}{{ e.receipts_count }} - {% if e.total_expense > 0 %} - {{ '%.2f'|format(e.total_expense) }} PLN - {% else %} - - - {% endif %} - - ✏️ Edytuj - 🗑️ Usuń -
+ + + + + + + + + + + + + + + + + + {% for e in enriched_lists %} + {% set l = e.list %} + + + + + + + + + + + + + + + {% endfor %} + -
IDTytułStatusUtworzonoWłaścicielProduktyWypełnienieKomentarzeParagonyWydatkiAkcje
{{ l.id }} + {{ l.title }} + + {% if l.is_archived %} + Archiwalna + {% elif e.expired %} + Wygasła + {% else %} + Aktywna + {% endif %} + {{ l.created_at.strftime('%Y-%m-%d %H:%M') if l.created_at else '-' }} + {% if l.owner_id %} + {{ l.owner_id }} / {{ l.owner.username if l.owner else 'Brak użytkownika' }} + {% else %} + - + {% endif %} + {{ e.total_count }}{{ e.purchased_count }}/{{ e.total_count }} ({{ e.percent }}%){{ e.comments_count }}{{ e.receipts_count }} + {% if e.total_expense > 0 %} + {{ '%.2f'|format(e.total_expense) }} PLN + {% else %} + - + {% endif %} + + ✏️ + Edytuj + 🗑️ + Usuń +
+ +
+ +
- -
- - +