diff --git a/templates/gallery/upload.image.html.twig b/templates/gallery/upload.image.html.twig index 5b4996c206..76b1b2d481 100644 --- a/templates/gallery/upload.image.html.twig +++ b/templates/gallery/upload.image.html.twig @@ -27,6 +27,7 @@ upload.disabled = true; abort.disabled = false; + let count = 0; for (let index = 0; index < files.length; index++) { const file = files[index]; @@ -48,6 +49,7 @@ continue; } + count++; filename.innerText = file.name; uploadFile(index, file); @@ -55,6 +57,10 @@ progressBars.classList.remove('d-none'); + if (count === 0) { + resetForm(); + } + return false; } @@ -69,6 +75,7 @@ client.onerror = function(e) { alert("{{ 'gallery.upload.error'|trans }}"); + resetForm(); }; client.onload = function(e) { @@ -86,10 +93,7 @@ imageProgress.append(infoDiv); clients = clients.filter((value)=>value!==client); if (clients.length === 0) { - let form = document.querySelector('form'); - form.reset() - upload.disabled = false; - abort.disabled = true; + resetForm(); } }; @@ -101,7 +105,6 @@ const filename = document.getElementById('filename-' + index); filename.innerText = file.name + " - " + p + "%"; - console.log(file.name, percent, filename, " - " + p); }; client.onabort = function(e) { @@ -119,10 +122,7 @@ } alert("{{ 'upload.canceled'|trans }}"); - let form = document.querySelector('form'); - form.reset() - upload.disabled = false; - abort.disabled = true; + resetForm(); return false; } @@ -164,6 +164,13 @@ const objectUrl = window.URL.createObjectURL(file); image.firstChild.src = objectUrl; } + + function resetForm() { + let form = document.querySelector('form'); + form.reset() + upload.disabled = false; + abort.disabled = true; + } {% endblock javascripts %}