upload z zjec z galerii + prettycode
This commit is contained in:
@@ -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;
|
||||
|
Reference in New Issue
Block a user