diff --git a/src/main/resources/messages_en_GB.properties b/src/main/resources/messages_en_GB.properties index 6fcc5e48..d9f71870 100644 --- a/src/main/resources/messages_en_GB.properties +++ b/src/main/resources/messages_en_GB.properties @@ -81,6 +81,7 @@ page=Page pages=Pages loading=Loading... addToDoc=Add to Document +reset=Reset legal.privacy=Privacy Policy legal.terms=Terms and Conditions diff --git a/src/main/resources/static/js/downloader.js b/src/main/resources/static/js/downloader.js index 1933c4fb..e447c373 100644 --- a/src/main/resources/static/js/downloader.js +++ b/src/main/resources/static/js/downloader.js @@ -64,6 +64,8 @@ await handleSingleDownload(url, formData); } } + + clearFileInput(); clearTimeout(timeoutId); $("#submitBtn").text(originalButtonText); @@ -85,6 +87,7 @@ } } catch (error) { + clearFileInput(); clearTimeout(timeoutId); handleDownloadError(error); $("#submitBtn").text(originalButtonText); @@ -116,11 +119,15 @@ const blob = await response.blob(); if (contentType.includes("application/pdf") || contentType.includes("image/")) { + clearFileInput(); return handleResponse(blob, filename, !isMulti, isZip); } else { + clearFileInput(); return handleResponse(blob, filename, false, isZip); } + } catch (error) { + clearFileInput(); console.error("Error in handleSingleDownload:", error); throw error; } @@ -291,4 +298,27 @@ } }); + // Clear file input after job + function clearFileInput(){ + let pathname = document.location.pathname; + if(pathname != "/merge-pdfs"){ + let formElement = document.querySelector("#fileInput-input"); + formElement.value = ''; + let editSectionElement = document.querySelector("#editSection"); + if(editSectionElement){ + editSectionElement.style.display = "none"; + } + let cropPdfCanvas = document.querySelector("#crop-pdf-canvas"); + let overlayCanvas = document.querySelector("#overlayCanvas"); + if(cropPdfCanvas && overlayCanvas){ + cropPdfCanvas.width = 0; + cropPdfCanvas.heigth = 0; + + overlayCanvas.width = 0; + overlayCanvas.heigth = 0; + } + } else{ + console.log("Disabled for 'Merge'"); + } + } })(); diff --git a/src/main/resources/static/js/merge.js b/src/main/resources/static/js/merge.js index 2c9a3939..8c263da6 100644 --- a/src/main/resources/static/js/merge.js +++ b/src/main/resources/static/js/merge.js @@ -21,7 +21,7 @@ async function displayFiles(files) { for (let i = 0; i < files.length; i++) { const pageCount = await getPDFPageCount(files[i]); const pageLabel = pageCount === 1 ? pageTranslation : pagesTranslation; - + // Create list item const item = document.createElement("li"); item.className = "list-group-item"; @@ -173,3 +173,18 @@ function updateFiles() { } document.getElementById("fileInput-input").files = dataTransfer.files; } + +document.querySelector("#resetFileInputBtn").addEventListener("click", ()=>{ + let formElement = document.querySelector("#fileInput-input"); + formElement.value = ''; + clearLiElements(); + updateFiles(); + +}); + +function clearLiElements(){ + let listGroupItemNodeList = document.querySelectorAll(".list-group-item"); + for (let i = 0; i < listGroupItemNodeList.length; i++) { + listGroupItemNodeList[i].remove(); + }; + } diff --git a/src/main/resources/static/js/multitool/PdfContainer.js b/src/main/resources/static/js/multitool/PdfContainer.js index a9642bb4..809e8532 100644 --- a/src/main/resources/static/js/multitool/PdfContainer.js +++ b/src/main/resources/static/js/multitool/PdfContainer.js @@ -28,6 +28,7 @@ class PdfContainer { this.toggleSelectPageVisibility = this.toggleSelectPageVisibility.bind(this); this.updatePagesFromCSV = this.updatePagesFromCSV.bind(this); this.addFilesBlankAll = this.addFilesBlankAll.bind(this) + this.removeAllElements = this.removeAllElements.bind(this); this.pdfAdapters = pdfAdapters; @@ -53,6 +54,7 @@ class PdfContainer { window.updateSelectedPagesDisplay = this.updateSelectedPagesDisplay; window.updatePageNumbersAndCheckboxes = this.updatePageNumbersAndCheckboxes; window.addFilesBlankAll = this.addFilesBlankAll + window.removeAllElements = this.removeAllElements; const filenameInput = document.getElementById("filename-input"); const downloadBtn = document.getElementById("export-button"); @@ -294,6 +296,16 @@ class PdfContainer { } } + removeAllElements(){ + let pageContainerNodeList = document.querySelectorAll(".page-container"); + for (var i = 0; i < pageContainerNodeList.length; i++) { + pageContainerNodeList[i].remove(); + } + document.querySelectorAll(".enable-on-file").forEach((element) => { + element.disabled = true; + }); + } + deleteSelected() { window.selectedPages.sort((a, b) => a - b); let deletions = 0; diff --git a/src/main/resources/templates/merge-pdfs.html b/src/main/resources/templates/merge-pdfs.html index 7b76ad50..f6ace6d7 100644 --- a/src/main/resources/templates/merge-pdfs.html +++ b/src/main/resources/templates/merge-pdfs.html @@ -40,6 +40,9 @@ +