From 18d289d3b7d6c1f4ecf57be383f125df3385cace Mon Sep 17 00:00:00 2001 From: Dan Henry Date: Thu, 18 Jan 2024 12:07:02 +1100 Subject: [PATCH] Move filename input logic to its own function --- .../static/js/multitool/PdfContainer.js | 45 ++++++++++--------- 1 file changed, 24 insertions(+), 21 deletions(-) diff --git a/src/main/resources/static/js/multitool/PdfContainer.js b/src/main/resources/static/js/multitool/PdfContainer.js index 4a53c961..4ae7f434 100644 --- a/src/main/resources/static/js/multitool/PdfContainer.js +++ b/src/main/resources/static/js/multitool/PdfContainer.js @@ -74,26 +74,7 @@ class PdfContainer { input.onchange = async(e) => { const files = e.target.files; if (files.length > 0) { - const filenameInput = document.getElementById('filename-input'); - const pagesContainer = document.getElementById('pages-container'); - const downloadBtn = document.getElementById('export-button'); - - filenameInput.disabled = false; - - 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; - } - + updateFilenameInput() } this.addPdfsFromFiles(files, nextSiblingElement); @@ -102,6 +83,28 @@ class PdfContainer { input.click(); } + updateFilenameInput() { + const filenameInput = document.getElementById('filename-input'); + const pagesContainer = document.getElementById('pages-container'); + const downloadBtn = document.getElementById('export-button'); + + filenameInput.disabled = false; + + 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; + } + } + async addPdfsFromFiles(files, nextSiblingElement) { this.fileName = files[0].name; for (var i=0; i < files.length; i++) { @@ -275,7 +278,7 @@ class PdfContainer { } updateFilename() { - const filenameInput = document.getElementById('filename-input'); + const filenameInput = document.getElementById('filename-input'); const downloadBtn = document.getElementById('export-button'); if (filenameInput.value === "") {