From 53a0291cc2e969519622d9786b502dc61e6f774b Mon Sep 17 00:00:00 2001 From: Dimitrios Kaitantzidis Date: Sun, 15 Oct 2023 16:49:12 +0300 Subject: [PATCH] Adds requested changes --- .../static/js/multitool/PdfContainer.js | 21 ++++++++++++++----- src/main/resources/templates/multi-tool.html | 5 +---- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/main/resources/static/js/multitool/PdfContainer.js b/src/main/resources/static/js/multitool/PdfContainer.js index f8eb36e6..f51bfade 100644 --- a/src/main/resources/static/js/multitool/PdfContainer.js +++ b/src/main/resources/static/js/multitool/PdfContainer.js @@ -6,7 +6,6 @@ class PdfContainer { downloadLink; constructor(id, wrapperId, pdfAdapters) { - this.fileName = null; this.pagesContainer = document.getElementById(id) this.pagesContainerWrapper = document.getElementById(wrapperId); this.downloadLink = null; @@ -34,13 +33,11 @@ class PdfContainer { window.rotateAll = this.rotateAll; const filenameInput = document.getElementById('filename-input'); - const filenameParagraph = document.getElementById('filename'); const downloadBtn = document.getElementById('export-button'); filenameInput.onkeyup = this.updateFilename; filenameInput.disabled = true; filenameInput.innerText = ""; - filenameParagraph.innerText = ""; downloadBtn.disabled = true; } @@ -83,8 +80,18 @@ class PdfContainer { if (pagesContainer.childElementCount === 0) { filenameInput.value = ""; + this.filename = null; downloadBtn.disabled = true; + } else { + this.filename = filenameInput.value; } + + if (this.filename === null || this.filename === undefined) { + filenameInput.value = files[0].name; + } else { + filenameInput.value = this.filename; + } + } this.addPdfsFromFiles(files, nextSiblingElement); @@ -219,6 +226,12 @@ class PdfContainer { const url = URL.createObjectURL(pdfBlob); const downloadOption = localStorage.getItem('downloadOption'); + const filenameInput = document.getElementById('filename-input'); + + if (!filenameInput.value.includes('.pdf')) { + filenameInput.value = filenameInput.value + '.pdf'; + } + if (downloadOption === 'sameWindow') { // Open the file in the same window window.location.href = url; @@ -245,11 +258,9 @@ class PdfContainer { updateFilename() { const filenameInput = document.getElementById('filename-input'); - const filenameParagraph = document.getElementById('filename'); const downloadBtn = document.getElementById('export-button'); if (filenameInput.value === "") { - filenameParagraph.innerText = ""; downloadBtn.disabled = true; return; } diff --git a/src/main/resources/templates/multi-tool.html b/src/main/resources/templates/multi-tool.html index 4e1276de..4994c078 100644 --- a/src/main/resources/templates/multi-tool.html +++ b/src/main/resources/templates/multi-tool.html @@ -23,10 +23,7 @@
- -
-
-

Final name of file:

+