mirror of
https://github.com/Stirling-Tools/Stirling-PDF.git
synced 2025-06-06 18:30:57 +00:00
Clear file inputs after jobs (#2248)
This commit is contained in:
parent
fd93dad9a5
commit
1833d7cd73
@ -81,6 +81,7 @@ page=Page
|
|||||||
pages=Pages
|
pages=Pages
|
||||||
loading=Loading...
|
loading=Loading...
|
||||||
addToDoc=Add to Document
|
addToDoc=Add to Document
|
||||||
|
reset=Reset
|
||||||
|
|
||||||
legal.privacy=Privacy Policy
|
legal.privacy=Privacy Policy
|
||||||
legal.terms=Terms and Conditions
|
legal.terms=Terms and Conditions
|
||||||
|
@ -64,6 +64,8 @@
|
|||||||
await handleSingleDownload(url, formData);
|
await handleSingleDownload(url, formData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
clearFileInput();
|
||||||
clearTimeout(timeoutId);
|
clearTimeout(timeoutId);
|
||||||
$("#submitBtn").text(originalButtonText);
|
$("#submitBtn").text(originalButtonText);
|
||||||
|
|
||||||
@ -85,6 +87,7 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
clearFileInput();
|
||||||
clearTimeout(timeoutId);
|
clearTimeout(timeoutId);
|
||||||
handleDownloadError(error);
|
handleDownloadError(error);
|
||||||
$("#submitBtn").text(originalButtonText);
|
$("#submitBtn").text(originalButtonText);
|
||||||
@ -116,11 +119,15 @@
|
|||||||
|
|
||||||
const blob = await response.blob();
|
const blob = await response.blob();
|
||||||
if (contentType.includes("application/pdf") || contentType.includes("image/")) {
|
if (contentType.includes("application/pdf") || contentType.includes("image/")) {
|
||||||
|
clearFileInput();
|
||||||
return handleResponse(blob, filename, !isMulti, isZip);
|
return handleResponse(blob, filename, !isMulti, isZip);
|
||||||
} else {
|
} else {
|
||||||
|
clearFileInput();
|
||||||
return handleResponse(blob, filename, false, isZip);
|
return handleResponse(blob, filename, false, isZip);
|
||||||
}
|
}
|
||||||
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
clearFileInput();
|
||||||
console.error("Error in handleSingleDownload:", error);
|
console.error("Error in handleSingleDownload:", error);
|
||||||
throw 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'");
|
||||||
|
}
|
||||||
|
}
|
||||||
})();
|
})();
|
||||||
|
@ -173,3 +173,18 @@ function updateFiles() {
|
|||||||
}
|
}
|
||||||
document.getElementById("fileInput-input").files = dataTransfer.files;
|
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();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
@ -28,6 +28,7 @@ class PdfContainer {
|
|||||||
this.toggleSelectPageVisibility = this.toggleSelectPageVisibility.bind(this);
|
this.toggleSelectPageVisibility = this.toggleSelectPageVisibility.bind(this);
|
||||||
this.updatePagesFromCSV = this.updatePagesFromCSV.bind(this);
|
this.updatePagesFromCSV = this.updatePagesFromCSV.bind(this);
|
||||||
this.addFilesBlankAll = this.addFilesBlankAll.bind(this)
|
this.addFilesBlankAll = this.addFilesBlankAll.bind(this)
|
||||||
|
this.removeAllElements = this.removeAllElements.bind(this);
|
||||||
|
|
||||||
this.pdfAdapters = pdfAdapters;
|
this.pdfAdapters = pdfAdapters;
|
||||||
|
|
||||||
@ -53,6 +54,7 @@ class PdfContainer {
|
|||||||
window.updateSelectedPagesDisplay = this.updateSelectedPagesDisplay;
|
window.updateSelectedPagesDisplay = this.updateSelectedPagesDisplay;
|
||||||
window.updatePageNumbersAndCheckboxes = this.updatePageNumbersAndCheckboxes;
|
window.updatePageNumbersAndCheckboxes = this.updatePageNumbersAndCheckboxes;
|
||||||
window.addFilesBlankAll = this.addFilesBlankAll
|
window.addFilesBlankAll = this.addFilesBlankAll
|
||||||
|
window.removeAllElements = this.removeAllElements;
|
||||||
|
|
||||||
const filenameInput = document.getElementById("filename-input");
|
const filenameInput = document.getElementById("filename-input");
|
||||||
const downloadBtn = document.getElementById("export-button");
|
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() {
|
deleteSelected() {
|
||||||
window.selectedPages.sort((a, b) => a - b);
|
window.selectedPages.sort((a, b) => a - b);
|
||||||
let deletions = 0;
|
let deletions = 0;
|
||||||
|
@ -40,6 +40,9 @@
|
|||||||
<button type="button" id="sortByDateBtn" class="btn btn-info" th:text="#{merge.sortByDate}"></button>
|
<button type="button" id="sortByDateBtn" class="btn btn-info" th:text="#{merge.sortByDate}"></button>
|
||||||
<button type="submit" id="submitBtn" class="btn btn-primary" th:text="#{merge.submit}"></button>
|
<button type="submit" id="submitBtn" class="btn btn-primary" th:text="#{merge.submit}"></button>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<button type="button" id="resetFileInputBtn" class="btn btn-danger" th:text="#{reset}">Reset</button>
|
||||||
|
</div>
|
||||||
</form>
|
</form>
|
||||||
<span id="pageTranslation" th:text="#{page}" style="display:none;"></span>
|
<span id="pageTranslation" th:text="#{page}" style="display:none;"></span>
|
||||||
<span id="pagesTranslation" th:text="#{pages}" style="display:none;"></span>
|
<span id="pagesTranslation" th:text="#{pages}" style="display:none;"></span>
|
||||||
|
@ -83,6 +83,9 @@
|
|||||||
</span>
|
</span>
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="mb-3">
|
||||||
|
<button type="button" id="resetFileInputBtn" class="btn btn-danger" onclick="removeAllElements()" th:text="#{reset}">Reset</button>
|
||||||
|
</div>
|
||||||
<div id="selected-pages-display" class="selected-pages-container hidden">
|
<div id="selected-pages-display" class="selected-pages-container hidden">
|
||||||
<div style="display:flex; height:3rem; margin-right:1rem">
|
<div style="display:flex; height:3rem; margin-right:1rem">
|
||||||
<h5 th:text="#{multiTool.selectedPages}" style="white-space: nowrap; margin-right: 1rem;">Selected
|
<h5 th:text="#{multiTool.selectedPages}" style="white-space: nowrap; margin-right: 1rem;">Selected
|
||||||
|
@ -68,7 +68,7 @@
|
|||||||
fileInput.addEventListener("change", async function () {
|
fileInput.addEventListener("change", async function () {
|
||||||
console.log("loading pdf");
|
console.log("loading pdf");
|
||||||
|
|
||||||
document.querySelector("#editSection").style.display = "";
|
document.querySelector("#editSection").style.display = "block";
|
||||||
|
|
||||||
const existingPreview = document.getElementById("pdf-preview");
|
const existingPreview = document.getElementById("pdf-preview");
|
||||||
if (existingPreview) {
|
if (existingPreview) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user