diff options
author | Vsevolod Stakhov <vsevolod@rspamd.com> | 2023-12-17 22:56:17 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-12-17 22:56:17 +0000 |
commit | 30a3758751fd23a4119c8e363d704ce439274bde (patch) | |
tree | 184a16fb706d435e7b52d5ff2b25a249a5ed1dfc | |
parent | 83c63b984d7df32cbf3ae5c86798b4b464a90192 (diff) | |
parent | 4faef335693f3b728172a2f01f92ef07c517e690 (diff) | |
download | rspamd-30a3758751fd23a4119c8e363d704ce439274bde.tar.gz rspamd-30a3758751fd23a4119c8e363d704ce439274bde.zip |
Merge pull request #4749 from moisseev/webui
[WebUI] Send only altered symbols in save requests
-rw-r--r-- | interface/js/app/symbols.js | 59 |
1 files changed, 31 insertions, 28 deletions
diff --git a/interface/js/app/symbols.js b/interface/js/app/symbols.js index 6cbe984c3..82f67f3e3 100644 --- a/interface/js/app/symbols.js +++ b/interface/js/app/symbols.js @@ -28,23 +28,22 @@ define(["jquery", "app/rspamd", "footable"], ($, rspamd) => { "use strict"; const ui = {}; + let altered = {}; - function saveSymbols(action, id, server) { + function clear_altered() { + $("#save-alert").addClass("d-none"); + altered = {}; + } + + function saveSymbols(server) { $("#save-alert button").attr("disabled", true); - const inputs = $("#" + id + ' :input[data-role="numerictextbox"]'); - const url = action; const values = []; - $(inputs).each(function () { - values.push({ - name: $(this).attr("id").substring(5), - value: parseFloat($(this).val()) - }); - }); + Object.entries(altered).forEach(([key, value]) => values.push({name: key, value: value})); - rspamd.query(url, { + rspamd.query("./savesymbols", { success: function () { - $("#save-alert").addClass("d-none"); + clear_altered(); rspamd.alertMessage("alert-modal alert-success", "Symbols successfully saved"); }, complete: () => $("#save-alert button").removeAttr("disabled", true), @@ -79,7 +78,7 @@ define(["jquery", "app/rspamd", "footable"], label_class = "scorebar-spam"; } item.weight = '<input class="form-control input-sm mb-disabled scorebar ' + label_class + - '" data-role="numerictextbox" autocomplete="off" type="number" step="0.01" tabindex="1" ' + + '" autocomplete="off" type="number" step="0.01" tabindex="1" ' + 'value="' + formatter.format(item.weight) + '" id="_sym_' + item.symbol + '"></input>'; if (!item.time) { item.time = 0; @@ -124,7 +123,7 @@ define(["jquery", "app/rspamd", "footable"], } // @get symbols into modal form ui.getSymbols = function (checked_server) { - $("#save-alert").addClass("d-none"); + clear_altered(); rspamd.query("symbols", { success: function (json) { const [{data}] = json; @@ -224,26 +223,12 @@ define(["jquery", "app/rspamd", "footable"], }, server: (checked_server === "All SERVERS") ? "local" : checked_server }); - $("#symbolsTable") - .on("input", ".scorebar", ({target}) => { - const t = $(target); - t.removeClass("scorebar-ham scorebar-spam"); - if (target.value < 0) { - t.addClass("scorebar-ham"); - } else if (target.value > 0) { - t.addClass("scorebar-spam"); - } - $("#save-alert").removeClass("d-none"); - }); - $("#save-alert button") - .off("click") - .on("click", ({target}) => saveSymbols("./savesymbols", "symbolsTable", $(target).data("save"))); }; $("#updateSymbols").on("click", (e) => { e.preventDefault(); - $("#save-alert").addClass("d-none"); + clear_altered(); const checked_server = rspamd.getSelector("selSrv"); rspamd.query("symbols", { success: function (data) { @@ -254,5 +239,23 @@ define(["jquery", "app/rspamd", "footable"], }); }); + $("#symbolsTable") + .on("input", ".scorebar", ({target}) => { + const t = $(target); + t.removeClass("scorebar-ham scorebar-spam"); + if (target.value < 0) { + t.addClass("scorebar-ham"); + } else if (target.value > 0) { + t.addClass("scorebar-spam"); + } + }) + .on("change", ".scorebar", ({target}) => { + altered[$(target).attr("id").substring(5)] = parseFloat(target.value); + $("#save-alert").removeClass("d-none"); + }); + + $("#save-alert button") + .on("click", ({target}) => saveSymbols($(target).data("save"))); + return ui; }); |