]> source.dussan.org Git - rspamd.git/commitdiff
[Minor] Move server selection logic to common.js 4796/head
authormoisseev <moiseev@mezonplus.ru>
Tue, 2 Jan 2024 07:10:44 +0000 (10:10 +0300)
committermoisseev <moiseev@mezonplus.ru>
Tue, 2 Jan 2024 07:10:44 +0000 (10:10 +0300)
interface/js/app/common.js
interface/js/app/config.js
interface/js/app/rspamd.js
interface/js/app/selectors.js
interface/js/app/symbols.js
interface/js/app/upload.js

index ea6102f6035888523c2b4959adc6373e65655daa..0364ed0e90e62959c5c94391b199cc70559fe4fc 100644 (file)
@@ -138,6 +138,11 @@ define(["jquery", "nprogress"],
             return e.options[e.selectedIndex].value;
         };
 
+        ui.getServer = function () {
+            const checked_server = ui.getSelector("selSrv");
+            return (checked_server === "All SERVERS") ? "local" : checked_server;
+        };
+
         /**
          * @param {string} url - A string containing the URL to which the request is sent
          * @param {Object} [options] - A set of key/value pairs that configure the Ajax request. All settings are optional.
index 6be1075558bf9aa1d6501f26cf5a77b5d1e99b40..d7b43dfdbcdfeafe9c4df0779f2ed743ec26e096 100644 (file)
@@ -29,7 +29,7 @@ define(["jquery", "app/common"],
         "use strict";
         const ui = {};
 
-        ui.getActions = function getActions(checked_server) {
+        ui.getActions = function getActions() {
             common.query("actions", {
                 success: function (data) {
                     $("#actionsFormField").empty();
@@ -57,7 +57,7 @@ define(["jquery", "app/common"],
                     $("#actionsFormField").html(
                         items.map((e) => e.html).join(""));
                 },
-                server: (checked_server === "All SERVERS") ? "local" : checked_server
+                server: common.getServer()
             });
         };
 
@@ -109,7 +109,7 @@ define(["jquery", "app/common"],
             }
         };
 
-        ui.getMaps = function (checked_server) {
+        ui.getMaps = function () {
             const $listmaps = $("#listMaps");
             $listmaps.closest(".card").hide();
             common.query("maps", {
@@ -135,7 +135,7 @@ define(["jquery", "app/common"],
                     $tbody.appendTo($listmaps);
                     $listmaps.closest(".card").show();
                 },
-                server: (checked_server === "All SERVERS") ? "local" : checked_server
+                server: common.getServer()
             });
         };
 
@@ -158,7 +158,6 @@ define(["jquery", "app/common"],
 
         // Modal form for maps
         $(document).on("click", "[data-bs-toggle=\"modal\"]", function () {
-            const checked_server = common.getSelector("selSrv");
             const item = $(this).data("item");
             common.query("getmap", {
                 headers: {
@@ -197,7 +196,7 @@ define(["jquery", "app/common"],
                     $("#modalDialog").modal("show");
                 },
                 errorMessage: "Cannot receive maps data",
-                server: (checked_server === "All SERVERS") ? "local" : checked_server
+                server: common.getServer()
             });
             return false;
         });
index 938f048e7b36ecca3e76e0cdcec687ed254669d5..fb5c268c9892fe7c3b0fd4c3bc2e0b1f3dc6c9d2 100644 (file)
@@ -168,12 +168,12 @@ define(["jquery", "app/common", "stickytabs", "visibility",
                 break;
             case "#configuration_nav":
                 require(["app/config"], (module) => {
-                    module.getActions(checked_server);
-                    module.getMaps(checked_server);
+                    module.getActions();
+                    module.getMaps();
                 });
                 break;
             case "#symbols_nav":
-                require(["app/symbols"], (module) => module.getSymbols(checked_server));
+                require(["app/symbols"], (module) => module.getSymbols());
                 break;
             case "#scan_nav":
                 require(["app/upload"]);
index 53240d83847736b9e0d7c96cf0dbb6780529c60e..c2b8b27e5eeb5c46e73e64edd71752d57e5d7b0f 100644 (file)
@@ -10,11 +10,6 @@ define(["jquery", "app/common"],
             ));
         }
 
-        function get_server() {
-            const checked_server = common.getSelector("selSrv");
-            return (checked_server === "All SERVERS") ? "local" : checked_server;
-        }
-
         function checkMsg(data) {
             const selector = $("#selectorsSelArea").val();
             common.query("plugins/selectors/check_message?selector=" + encodeURIComponent(selector), {
@@ -30,7 +25,7 @@ define(["jquery", "app/common"],
                         common.alertMessage("alert-error", "Unexpected error processing message");
                     }
                 },
-                server: get_server()
+                server: common.getServer()
             });
         }
 
@@ -50,7 +45,7 @@ define(["jquery", "app/common"],
                             toggle_form_group_class("valid", "invalid");
                         }
                     },
-                    server: get_server()
+                    server: common.getServer()
                 });
             } else {
                 $("#selectorsSelArea").removeClass("is-valid is-invalid");
@@ -76,7 +71,7 @@ define(["jquery", "app/common"],
                         const json = neighbours_status[0].data;
                         build_table_from_json(json, "#selectorsTable-" + list);
                     },
-                    server: get_server()
+                    server: common.getServer()
                 });
             }
 
index 1e3fb5de726a9a095af13c1da3694f4555fc73d9..2d8f359fc7ba791a64f6bb1f20aa45784432a024 100644 (file)
@@ -122,7 +122,7 @@ define(["jquery", "app/common", "footable"],
             return [items, distinct_groups];
         }
         // @get symbols into modal form
-        ui.getSymbols = function (checked_server) {
+        ui.getSymbols = function () {
             clear_altered();
             common.query("symbols", {
                 success: function (json) {
@@ -220,7 +220,7 @@ define(["jquery", "app/common", "footable"],
                         }
                     });
                 },
-                server: (checked_server === "All SERVERS") ? "local" : checked_server
+                server: common.getServer()
             });
         };
 
@@ -228,13 +228,12 @@ define(["jquery", "app/common", "footable"],
         $("#updateSymbols").on("click", (e) => {
             e.preventDefault();
             clear_altered();
-            const checked_server = common.getSelector("selSrv");
             common.query("symbols", {
                 success: function (data) {
                     const [items] = process_symbols_data(data[0].data);
                     common.tables.symbols.rows.load(items);
                 },
-                server: (checked_server === "All SERVERS") ? "local" : checked_server
+                server: common.getServer()
             });
         });
 
index 546f5cc84549ba8f0d4459b03fd6ff607accca78..1cde1d4703e2251b1eaaffa2da09086eec806256 100644 (file)
@@ -73,11 +73,6 @@ define(["jquery", "app/common", "app/libft"],
             });
         }
 
-        function get_server() {
-            const checked_server = common.getSelector("selSrv");
-            return (checked_server === "All SERVERS") ? "local" : checked_server;
-        }
-
         // @upload text
         function scanText(data, headers) {
             common.query("checkv2", {
@@ -136,7 +131,7 @@ define(["jquery", "app/common", "app/libft"],
                         common.alertMessage("alert-error", "Cannot tokenize message: no text data");
                     }
                 },
-                server: get_server()
+                server: common.getServer()
             });
         }
 
@@ -168,7 +163,7 @@ define(["jquery", "app/common", "app/libft"],
                         common.alertMessage("alert-error", "Unexpected error processing message");
                     }
                 },
-                server: get_server()
+                server: common.getServer()
             });
         }