Clear file inputs after jobs (#2248)

This commit is contained in:
Rafael Encinas
2024-11-15 13:21:23 -07:00
committed by GitHub
parent fd93dad9a5
commit 1833d7cd73
7 changed files with 66 additions and 2 deletions

View File

@@ -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'");
}
}
})();

View File

@@ -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();
};
}

View File

@@ -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;