From a1b7aaddb835a1ef7bf6637c3e6464582c381b0a Mon Sep 17 00:00:00 2001 From: Dimitrios Kaitantzidis Date: Sun, 8 Oct 2023 18:59:43 +0300 Subject: [PATCH 1/9] Changes filename using js, but the old filename persists in download --- .../static/js/multitool/PdfContainer.js | 14 +++++++++++ src/main/resources/templates/multi-tool.html | 24 ++++++++++++++++--- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/main/resources/static/js/multitool/PdfContainer.js b/src/main/resources/static/js/multitool/PdfContainer.js index 45c92be1..c82b6859 100644 --- a/src/main/resources/static/js/multitool/PdfContainer.js +++ b/src/main/resources/static/js/multitool/PdfContainer.js @@ -14,6 +14,7 @@ class PdfContainer { this.rotateElement = this.rotateElement.bind(this); this.rotateAll = this.rotateAll.bind(this); this.exportPdf = this.exportPdf.bind(this); + this.updateFilename = this.updateFilename.bind(this); this.pdfAdapters = pdfAdapters; @@ -28,6 +29,9 @@ class PdfContainer { window.addPdfs = this.addPdfs; window.exportPdf = this.exportPdf; window.rotateAll = this.rotateAll; + + const filenameInput = document.getElementById('filename-input'); + filenameInput.onkeyup = this.updateFilename; } movePageTo(startElement, endElement, scrollTo = false) { @@ -202,10 +206,20 @@ class PdfContainer { // Download the file const downloadLink = document.createElement('a'); downloadLink.href = url; + console.log('filename before download ' + this.filename); downloadLink.download = this.fileName ? this.fileName : 'managed.pdf'; downloadLink.click(); } } + + updateFilename() { + const filenameInput = document.getElementById('filename-input'); + const filenameParagraph = document.getElementById('filename'); + + console.log('updatedFilename fired ' + filenameInput.value); + this.filename = filenameInput.value; + filenameParagraph.innerText = this.filename; + } } export default PdfContainer; diff --git a/src/main/resources/templates/multi-tool.html b/src/main/resources/templates/multi-tool.html index 0b1d7b8a..9e2da94f 100644 --- a/src/main/resources/templates/multi-tool.html +++ b/src/main/resources/templates/multi-tool.html @@ -20,15 +20,25 @@
+
+
+ + +
+
+

Final name of file:

+
+
- + - + +
- +