commit 3637e1e: [WebUI] Add missing handler for file input

moisseev moiseev at mezonplus.ru
Mon Jul 29 17:55:36 UTC 2024


Author: moisseev
Date: 2024-04-12 20:55:47 +0300
URL: https://github.com/rspamd/rspamd/commit/3637e1ee4d810d94887614a5a57ed3739fc2abcb (refs/pull/4922/head)

[WebUI] Add missing handler for file input

---
 interface/index.html       |  2 +-
 interface/js/app/upload.js | 36 ++++++++++++++++++++----------------
 2 files changed, 21 insertions(+), 17 deletions(-)

diff --git a/interface/index.html b/interface/index.html
index 5b3187309..329446a87 100644
--- a/interface/index.html
+++ b/interface/index.html
@@ -383,7 +383,7 @@
 						<span class="h6 fw-bolder my-auto">Scan suspected message</span>
 						<div class="d-flex input-group-sm align-items-center ms-auto">
 							<label for="formFile" class="col-auto col-form-label-sm me-1">Choose a file:</label>
-							<input class="form-control form-control-sm btn btn-secondary" id="formFile" type="file">
+							<input class="form-control form-control-sm btn btn-secondary" id="formFile" type="file" multiple>
 						</div>
 					</div>
 					<div class="card-body">
diff --git a/interface/js/app/upload.js b/interface/js/app/upload.js
index 5f330002b..a484a41aa 100644
--- a/interface/js/app/upload.js
+++ b/interface/js/app/upload.js
@@ -259,6 +259,24 @@ define(["jquery", "app/common", "app/libft"],
             return false;
         });
 
+        function fileInputHandler(obj) {
+            ({files} = obj);
+            filesIdx = 0;
+
+            if (files.length === 1) {
+                setFileInputFiles(0);
+                enable_disable_scan_btn();
+                readFile((result) => {
+                    $("#scanMsgSource").val(result);
+                    enable_disable_scan_btn();
+                });
+            // eslint-disable-next-line no-alert
+            } else if (files.length < 10 || confirm("Are you sure you want to scan " + files.length + " files?")) {
+                getScanTextHeaders();
+                readFile((result) => scanText(result));
+            }
+        }
+
         const dragoverClassList = "outline-dashed-primary bg-primary-subtle";
         $("#scanMsgSource")
             .on("dragenter dragover dragleave drop", (e) => {
@@ -271,23 +289,9 @@ define(["jquery", "app/common", "app/libft"],
             .on("dragleave drop", () => {
                 $("#scanMsgSource").removeClass(dragoverClassList);
             })
-            .on("drop", (e) => {
-                ({files} = e.originalEvent.dataTransfer);
-                filesIdx = 0;
+            .on("drop", (e) => fileInputHandler(e.originalEvent.dataTransfer));
 
-                if (files.length === 1) {
-                    setFileInputFiles(0);
-                    enable_disable_scan_btn();
-                    readFile((result) => {
-                        $("#scanMsgSource").val(result);
-                        enable_disable_scan_btn();
-                    });
-                // eslint-disable-next-line no-alert
-                } else if (files.length < 10 || confirm("Are you sure you want to scan " + files.length + " files?")) {
-                    getScanTextHeaders();
-                    readFile((result) => scanText(result));
-                }
-            });
+        $("#formFile").on("change", (e) => fileInputHandler(e.target));
 
         return ui;
     });


More information about the Commits mailing list