diff options
author | moisseev <moiseev@mezonplus.ru> | 2023-11-16 17:42:18 +0300 |
---|---|---|
committer | moisseev <moiseev@mezonplus.ru> | 2023-11-16 17:42:18 +0300 |
commit | b48b703a363a31cc2058fc444082d4b2966b14f5 (patch) | |
tree | e654022f664a5ab322c94a244f1ba3de38489d1b /interface | |
parent | 57dac6a925c55f79687fe82c8b5ac7a6e244b8f5 (diff) | |
download | rspamd-b48b703a363a31cc2058fc444082d4b2966b14f5.tar.gz rspamd-b48b703a363a31cc2058fc444082d4b2966b14f5.zip |
[Minor] Remove temporary IIFEs
Diffstat (limited to 'interface')
-rw-r--r-- | interface/js/app/config.js | 193 | ||||
-rw-r--r-- | interface/js/app/graph.js | 22 | ||||
-rw-r--r-- | interface/js/app/history.js | 59 | ||||
-rw-r--r-- | interface/js/app/rspamd.js | 288 | ||||
-rw-r--r-- | interface/js/app/selectors.js | 93 | ||||
-rw-r--r-- | interface/js/app/symbols.js | 23 | ||||
-rw-r--r-- | interface/js/app/upload.js | 113 |
7 files changed, 393 insertions, 398 deletions
diff --git a/interface/js/app/config.js b/interface/js/app/config.js index df912eeea..dd47578ae 100644 --- a/interface/js/app/config.js +++ b/interface/js/app/config.js @@ -144,109 +144,108 @@ define(["jquery", "app/rspamd"], }); }; - (() => { - var jar = {}; - const editor = { - advanced: { - codejar: true, - elt: "div", - class: "editor language-clike", - readonly_attr: {contenteditable: false}, - }, - basic: { - elt: "textarea", - class: "form-control map-textarea", - readonly_attr: {readonly: true}, - } - }; - let mode = "advanced"; - - // Modal form for maps - $(document).on("click", "[data-bs-toggle=\"modal\"]", function () { - var checked_server = rspamd.getSelector("selSrv"); - var item = $(this).data("item"); - rspamd.query("getmap", { - headers: { - Map: item.map - }, - success: function (data) { - // Highlighting a large amount of text is unresponsive - mode = (new Blob([data[0].data]).size > 5120) ? "basic" : $("input[name=editorMode]:checked").val(); - - $("<" + editor[mode].elt + ' id="editor" class="' + editor[mode].class + '" data-id="' + item.map + '">' + - "</" + editor[mode].elt + ">").appendTo("#modalBody"); - - if (editor[mode].codejar) { - require(["codejar", "linenumbers", "prism"], function (CodeJar, withLineNumbers, Prism) { - jar = new CodeJar( - document.querySelector("#editor"), - withLineNumbers((el) => Prism.highlightElement(el)) - ); - jar.updateCode(data[0].data); - }); - } else { - document.querySelector("#editor").innerHTML = rspamd.escapeHTML(data[0].data); - } - var icon = "fa-edit"; - if (item.editable === false || rspamd.read_only) { - $("#editor").attr(editor[mode].readonly_attr); - icon = "fa-eye"; - $("#modalSaveGroup").hide(); - } else { - $("#modalSaveGroup").show(); - } - $("#modalDialog .modal-header").find("[data-fa-i2svg]").addClass(icon); - $("#modalTitle").html(item.uri); + var jar = {}; + const editor = { + advanced: { + codejar: true, + elt: "div", + class: "editor language-clike", + readonly_attr: {contenteditable: false}, + }, + basic: { + elt: "textarea", + class: "form-control map-textarea", + readonly_attr: {readonly: true}, + } + }; + let mode = "advanced"; + + // Modal form for maps + $(document).on("click", "[data-bs-toggle=\"modal\"]", function () { + var checked_server = rspamd.getSelector("selSrv"); + var item = $(this).data("item"); + rspamd.query("getmap", { + headers: { + Map: item.map + }, + success: function (data) { + // Highlighting a large amount of text is unresponsive + mode = (new Blob([data[0].data]).size > 5120) ? "basic" : $("input[name=editorMode]:checked").val(); + + $("<" + editor[mode].elt + ' id="editor" class="' + editor[mode].class + '" data-id="' + item.map + '">' + + "</" + editor[mode].elt + ">").appendTo("#modalBody"); + + if (editor[mode].codejar) { + require(["codejar", "linenumbers", "prism"], function (CodeJar, withLineNumbers, Prism) { + jar = new CodeJar( + document.querySelector("#editor"), + withLineNumbers((el) => Prism.highlightElement(el)) + ); + jar.updateCode(data[0].data); + }); + } else { + document.querySelector("#editor").innerHTML = rspamd.escapeHTML(data[0].data); + } - $("#modalDialog").modal("show"); - }, - errorMessage: "Cannot receive maps data", - server: (checked_server === "All SERVERS") ? "local" : checked_server - }); - return false; - }); - $("#modalDialog").on("hidden.bs.modal", function () { - if (editor[mode].codejar) { - jar.destroy(); - $(".codejar-wrap").remove(); - } else { - $("#editor").remove(); - } - }); + var icon = "fa-edit"; + if (item.editable === false || rspamd.read_only) { + $("#editor").attr(editor[mode].readonly_attr); + icon = "fa-eye"; + $("#modalSaveGroup").hide(); + } else { + $("#modalSaveGroup").show(); + } + $("#modalDialog .modal-header").find("[data-fa-i2svg]").addClass(icon); + $("#modalTitle").html(item.uri); - $("#saveActionsBtn").on("click", function () { - ui.saveActions(); - }); - $("#saveActionsClusterBtn").on("click", function () { - ui.saveActions("All SERVERS"); + $("#modalDialog").modal("show"); + }, + errorMessage: "Cannot receive maps data", + server: (checked_server === "All SERVERS") ? "local" : checked_server }); - - function saveMap(server) { - rspamd.query("savemap", { - success: function () { - rspamd.alertMessage("alert-success", "Map data successfully saved"); - $("#modalDialog").modal("hide"); - }, - errorMessage: "Save map error", - method: "POST", - headers: { - Map: $("#editor").data("id"), - }, - params: { - data: editor[mode].codejar ? jar.toString() : $("#editor").val(), - dataType: "text", - }, - server: server - }); + return false; + }); + $("#modalDialog").on("hidden.bs.modal", function () { + if (editor[mode].codejar) { + jar.destroy(); + $(".codejar-wrap").remove(); + } else { + $("#editor").remove(); } - $("#modalSave").on("click", function () { - saveMap(); - }); - $("#modalSaveAll").on("click", function () { - saveMap("All SERVERS"); + }); + + $("#saveActionsBtn").on("click", function () { + ui.saveActions(); + }); + $("#saveActionsClusterBtn").on("click", function () { + ui.saveActions("All SERVERS"); + }); + + function saveMap(server) { + rspamd.query("savemap", { + success: function () { + rspamd.alertMessage("alert-success", "Map data successfully saved"); + $("#modalDialog").modal("hide"); + }, + errorMessage: "Save map error", + method: "POST", + headers: { + Map: $("#editor").data("id"), + }, + params: { + data: editor[mode].codejar ? jar.toString() : $("#editor").val(), + dataType: "text", + }, + server: server }); - })(); + } + $("#modalSave").on("click", function () { + saveMap(); + }); + $("#modalSaveAll").on("click", function () { + saveMap("All SERVERS"); + }); return ui; }); diff --git a/interface/js/app/graph.js b/interface/js/app/graph.js index e55214c95..3dca7da9c 100644 --- a/interface/js/app/graph.js +++ b/interface/js/app/graph.js @@ -199,6 +199,7 @@ define(["jquery", "app/rspamd", "d3evolution", "d3pie", "d3", "footable"], graphs.graph = initGraph(); } + rspamd.query("graph", { success: function (req_data) { var data = null; @@ -243,17 +244,16 @@ define(["jquery", "app/rspamd", "d3evolution", "d3pie", "d3", "footable"], }); }; - (() => { - // Handling mouse events on overlapping elements - $("#rrd-pie").mouseover(function () { - $("#rrd-pie,#rrd-pie-tooltip").css("z-index", "200"); - $("#rrd-table_toggle").css("z-index", "300"); - }); - $("#rrd-table_toggle").mouseover(function () { - $("#rrd-pie,#rrd-pie-tooltip").css("z-index", "0"); - $("#rrd-table_toggle").css("z-index", "0"); - }); - })(); + + // Handling mouse events on overlapping elements + $("#rrd-pie").mouseover(function () { + $("#rrd-pie,#rrd-pie-tooltip").css("z-index", "200"); + $("#rrd-table_toggle").css("z-index", "300"); + }); + $("#rrd-table_toggle").mouseover(function () { + $("#rrd-pie,#rrd-pie-tooltip").css("z-index", "0"); + $("#rrd-table_toggle").css("z-index", "0"); + }); return ui; }); diff --git a/interface/js/app/history.js b/interface/js/app/history.js index add8e86bd..4118bc61d 100644 --- a/interface/js/app/history.js +++ b/interface/js/app/history.js @@ -379,36 +379,6 @@ define(["jquery", "app/rspamd", "d3", "footable"], }); }; - (() => { - rspamd.set_page_size("history", $("#history_page_size").val()); - rspamd.bindHistoryTableEventHandlers("history", 8); - - $("#updateHistory").off("click"); - $("#updateHistory").on("click", function (e) { - e.preventDefault(); - ui.getHistory(); - }); - - // @reset history log - $("#resetHistory").off("click"); - $("#resetHistory").on("click", function (e) { - e.preventDefault(); - if (!confirm("Are you sure you want to reset history log?")) { // eslint-disable-line no-alert - return; - } - rspamd.destroyTable("history"); - rspamd.destroyTable("errors"); - - rspamd.query("historyreset", { - success: function () { - ui.getHistory(); - ui.getErrors(); - }, - errorMessage: "Cannot reset history log" - }); - }); - })(); - function initErrorsTable(rows) { rspamd.tables.errors = FooTable.init("#errorsLog", { columns: [ @@ -479,5 +449,34 @@ define(["jquery", "app/rspamd", "d3", "footable"], }); }; + + rspamd.set_page_size("history", $("#history_page_size").val()); + rspamd.bindHistoryTableEventHandlers("history", 8); + + $("#updateHistory").off("click"); + $("#updateHistory").on("click", function (e) { + e.preventDefault(); + ui.getHistory(); + }); + + // @reset history log + $("#resetHistory").off("click"); + $("#resetHistory").on("click", function (e) { + e.preventDefault(); + if (!confirm("Are you sure you want to reset history log?")) { // eslint-disable-line no-alert + return; + } + rspamd.destroyTable("history"); + rspamd.destroyTable("errors"); + + rspamd.query("historyreset", { + success: function () { + ui.getHistory(); + ui.getErrors(); + }, + errorMessage: "Cannot reset history log" + }); + }); + return ui; }); diff --git a/interface/js/app/rspamd.js b/interface/js/app/rspamd.js index 2f1f66394..faec47f7f 100644 --- a/interface/js/app/rspamd.js +++ b/interface/js/app/rspamd.js @@ -439,150 +439,6 @@ function ($, NProgress) { // Public functions ui.alertMessage = alertMessage; - (() => { - (function initSettings() { - var selected_locale = null; - var custom_locale = null; - const localeTextbox = ".popover #settings-popover #locale"; - - function validateLocale(saveToLocalStorage) { - function toggle_form_group_class(remove, add) { - $(localeTextbox).removeClass("is-" + remove).addClass("is-" + add); - } - - var now = new Date(); - - if (custom_locale.length) { - try { - now.toLocaleString(custom_locale); - - if (saveToLocalStorage) localStorage.setItem("custom_locale", custom_locale); - locale = (selected_locale === "custom") ? custom_locale : null; - toggle_form_group_class("invalid", "valid"); - } catch (err) { - locale = null; - toggle_form_group_class("valid", "invalid"); - } - } else { - if (saveToLocalStorage) localStorage.setItem("custom_locale", null); - locale = null; - $(localeTextbox).removeClass("is-valid is-invalid"); - } - - // Display date example - $(".popover #settings-popover #date-example").text( - (locale) - ? now.toLocaleString(locale) - : now.toLocaleString() - ); - } - - $("#settings").popover({ - container: "body", - placement: "bottom", - html: true, - sanitize: false, - content: function () { - // Using .clone() has the side-effect of producing elements with duplicate id attributes. - return $("#settings-popover").clone(); - } - // Restore the tooltip of the element that the popover is attached to. - }).attr("title", function () { - return $(this).attr("data-original-title"); - }); - $("#settings").on("click", function (e) { - e.preventDefault(); - }); - $("#settings").on("inserted.bs.popover", function () { - selected_locale = localStorage.getItem("selected_locale") || "browser"; - custom_locale = localStorage.getItem("custom_locale") || ""; - validateLocale(); - - $('.popover #settings-popover input:radio[name="locale"]').val([selected_locale]); - $(localeTextbox).val(custom_locale); - - ajaxSetup(localStorage.getItem("ajax_timeout"), true); - }); - $(document).on("change", '.popover #settings-popover input:radio[name="locale"]', function () { - selected_locale = this.value; - localStorage.setItem("selected_locale", selected_locale); - validateLocale(); - }); - $(document).on("input", localeTextbox, function () { - custom_locale = $(localeTextbox).val(); - validateLocale(true); - }); - $(document).on("input", ajaxTimeoutBox, function () { - ajaxSetup($(ajaxTimeoutBox).val(), false, true); - }); - $(document).on("click", ".popover #settings-popover #ajax-timeout-restore", function () { - ajaxSetup(null, true, true); - }); - - // Dismiss Bootstrap popover by clicking outside - $("body").on("click", function (e) { - $(".popover").each(function () { - if ( - // Popover's descendant - $(this).has(e.target).length || - // Button (or icon within a button) that triggers the popover. - $(e.target).closest("button").attr("aria-describedby") === this.id - ) return; - $("#settings").popover("hide"); - }); - }); - }()); - - $("#selData").change(function () { - tabClick("#throughput_nav"); - }); - - $(document).ajaxStart(function () { - $("#refresh > svg").addClass("fa-spin"); - }); - $(document).ajaxComplete(function () { - setTimeout(function () { - $("#refresh > svg").removeClass("fa-spin"); - }, 1000); - }); - - $('a[data-bs-toggle="tab"]').on("shown.bs.tab", function () { - tabClick("#" + $(this).attr("id")); - }); - $("#refresh, #disconnect").on("click", function (e) { - e.preventDefault(); - tabClick("#" + $(this).attr("id")); - }); - $(".dropdown-menu a").click(function (e) { - e.preventDefault(); - var classList = $(this).attr("class"); - var menuClass = (/\b(?:dynamic|history|preset)\b/).exec(classList)[0]; - $(".dropdown-menu a.active." + menuClass).removeClass("active"); - $(this).addClass("active"); - tabClick("#autoRefresh"); - }); - - $("#selSrv").change(function () { - checked_server = this.value; - $("#selSrv [value=\"" + checked_server + "\"]").prop("checked", true); - if (checked_server === "All SERVERS") { - $("#learnServers").show(); - } else { - $("#learnServers").hide(); - } - tabClick("#" + $("#tablist > .nav-item > .nav-link.active").attr("id")); - }); - - // Radio buttons - $(document).on("click", "input:radio[name=\"clusterName\"]", function () { - if (!this.disabled) { - checked_server = this.value; - tabClick("#status_nav"); - } - }); - - $("#loading").addClass("d-none"); - })(); ui.connect = function () { // Prevent locking out of the WebUI if timeout is too low. @@ -1078,5 +934,149 @@ function ($, NProgress) { return null; }; + + (function initSettings() { + var selected_locale = null; + var custom_locale = null; + const localeTextbox = ".popover #settings-popover #locale"; + + function validateLocale(saveToLocalStorage) { + function toggle_form_group_class(remove, add) { + $(localeTextbox).removeClass("is-" + remove).addClass("is-" + add); + } + + var now = new Date(); + + if (custom_locale.length) { + try { + now.toLocaleString(custom_locale); + + if (saveToLocalStorage) localStorage.setItem("custom_locale", custom_locale); + locale = (selected_locale === "custom") ? custom_locale : null; + toggle_form_group_class("invalid", "valid"); + } catch (err) { + locale = null; + toggle_form_group_class("valid", "invalid"); + } + } else { + if (saveToLocalStorage) localStorage.setItem("custom_locale", null); + locale = null; + $(localeTextbox).removeClass("is-valid is-invalid"); + } + + // Display date example + $(".popover #settings-popover #date-example").text( + (locale) + ? now.toLocaleString(locale) + : now.toLocaleString() + ); + } + + $("#settings").popover({ + container: "body", + placement: "bottom", + html: true, + sanitize: false, + content: function () { + // Using .clone() has the side-effect of producing elements with duplicate id attributes. + return $("#settings-popover").clone(); + } + // Restore the tooltip of the element that the popover is attached to. + }).attr("title", function () { + return $(this).attr("data-original-title"); + }); + $("#settings").on("click", function (e) { + e.preventDefault(); + }); + $("#settings").on("inserted.bs.popover", function () { + selected_locale = localStorage.getItem("selected_locale") || "browser"; + custom_locale = localStorage.getItem("custom_locale") || ""; + validateLocale(); + + $('.popover #settings-popover input:radio[name="locale"]').val([selected_locale]); + $(localeTextbox).val(custom_locale); + + ajaxSetup(localStorage.getItem("ajax_timeout"), true); + }); + $(document).on("change", '.popover #settings-popover input:radio[name="locale"]', function () { + selected_locale = this.value; + localStorage.setItem("selected_locale", selected_locale); + validateLocale(); + }); + $(document).on("input", localeTextbox, function () { + custom_locale = $(localeTextbox).val(); + validateLocale(true); + }); + $(document).on("input", ajaxTimeoutBox, function () { + ajaxSetup($(ajaxTimeoutBox).val(), false, true); + }); + $(document).on("click", ".popover #settings-popover #ajax-timeout-restore", function () { + ajaxSetup(null, true, true); + }); + + // Dismiss Bootstrap popover by clicking outside + $("body").on("click", function (e) { + $(".popover").each(function () { + if ( + // Popover's descendant + $(this).has(e.target).length || + // Button (or icon within a button) that triggers the popover. + $(e.target).closest("button").attr("aria-describedby") === this.id + ) return; + $("#settings").popover("hide"); + }); + }); + }()); + + $("#selData").change(function () { + tabClick("#throughput_nav"); + }); + + $(document).ajaxStart(function () { + $("#refresh > svg").addClass("fa-spin"); + }); + $(document).ajaxComplete(function () { + setTimeout(function () { + $("#refresh > svg").removeClass("fa-spin"); + }, 1000); + }); + + $('a[data-bs-toggle="tab"]').on("shown.bs.tab", function () { + tabClick("#" + $(this).attr("id")); + }); + $("#refresh, #disconnect").on("click", function (e) { + e.preventDefault(); + tabClick("#" + $(this).attr("id")); + }); + $(".dropdown-menu a").click(function (e) { + e.preventDefault(); + var classList = $(this).attr("class"); + var menuClass = (/\b(?:dynamic|history|preset)\b/).exec(classList)[0]; + $(".dropdown-menu a.active." + menuClass).removeClass("active"); + $(this).addClass("active"); + tabClick("#autoRefresh"); + }); + + $("#selSrv").change(function () { + checked_server = this.value; + $("#selSrv [value=\"" + checked_server + "\"]").prop("checked", true); + if (checked_server === "All SERVERS") { + $("#learnServers").show(); + } else { + $("#learnServers").hide(); + } + tabClick("#" + $("#tablist > .nav-item > .nav-link.active").attr("id")); + }); + + // Radio buttons + $(document).on("click", "input:radio[name=\"clusterName\"]", function () { + if (!this.disabled) { + checked_server = this.value; + tabClick("#status_nav"); + } + }); + + $("#loading").addClass("d-none"); + return ui; }); diff --git a/interface/js/app/selectors.js b/interface/js/app/selectors.js index b47488ad0..8e9da052b 100644 --- a/interface/js/app/selectors.js +++ b/interface/js/app/selectors.js @@ -91,56 +91,55 @@ define(["jquery", "app/rspamd"], if (!$("#selectorsSelArea").is(".is-valid, .is-invalid")) checkSelectors(); }; - (() => { - function toggleSidebar(side) { - $("#sidebar-" + side).toggleClass("collapsed"); - var contentClass = "col-lg-6"; - var openSidebarsCount = $("#sidebar-left").hasClass("collapsed") + - $("#sidebar-right").hasClass("collapsed"); - switch (openSidebarsCount) { - case 1: - contentClass = "col-lg-9"; - break; - case 2: - contentClass = "col-lg-12"; - break; - default: - } - $("#content").removeClass("col-lg-12 col-lg-9 col-lg-6") - .addClass(contentClass); + + function toggleSidebar(side) { + $("#sidebar-" + side).toggleClass("collapsed"); + var contentClass = "col-lg-6"; + var openSidebarsCount = $("#sidebar-left").hasClass("collapsed") + + $("#sidebar-right").hasClass("collapsed"); + switch (openSidebarsCount) { + case 1: + contentClass = "col-lg-9"; + break; + case 2: + contentClass = "col-lg-12"; + break; + default: } - $("#sidebar-tab-left>a").click(function () { - toggleSidebar("left"); - return false; - }); - $("#sidebar-tab-right>a").click(function () { - toggleSidebar("right"); - return false; - }); + $("#content").removeClass("col-lg-12 col-lg-9 col-lg-6") + .addClass(contentClass); + } + $("#sidebar-tab-left>a").click(function () { + toggleSidebar("left"); + return false; + }); + $("#sidebar-tab-right>a").click(function () { + toggleSidebar("right"); + return false; + }); - $("#selectorsMsgClean").on("click", function () { - $("#selectorsChkMsgBtn").attr("disabled", true); - $("#selectorsMsgArea").val(""); - return false; - }); - $("#selectorsClean").on("click", function () { - $("#selectorsSelArea").val(""); - checkSelectors(); - return false; - }); - $("#selectorsChkMsgBtn").on("click", function () { - $("#selectorsResArea").val(""); - checkMsg($("#selectorsMsgArea").val()); - return false; - }); + $("#selectorsMsgClean").on("click", function () { + $("#selectorsChkMsgBtn").attr("disabled", true); + $("#selectorsMsgArea").val(""); + return false; + }); + $("#selectorsClean").on("click", function () { + $("#selectorsSelArea").val(""); + checkSelectors(); + return false; + }); + $("#selectorsChkMsgBtn").on("click", function () { + $("#selectorsResArea").val(""); + checkMsg($("#selectorsMsgArea").val()); + return false; + }); - $("#selectorsMsgArea").on("input", function () { - enable_disable_check_btn(); - }); - $("#selectorsSelArea").on("input", function () { - checkSelectors(); - }); - })(); + $("#selectorsMsgArea").on("input", function () { + enable_disable_check_btn(); + }); + $("#selectorsSelArea").on("input", function () { + checkSelectors(); + }); return ui; }); diff --git a/interface/js/app/symbols.js b/interface/js/app/symbols.js index a183a270c..8718599d7 100644 --- a/interface/js/app/symbols.js +++ b/interface/js/app/symbols.js @@ -242,19 +242,18 @@ define(["jquery", "app/rspamd", "footable"], }); }; - (() => { - $("#updateSymbols").on("click", function (e) { - e.preventDefault(); - var checked_server = rspamd.getSelector("selSrv"); - rspamd.query("symbols", { - success: function (data) { - var items = process_symbols_data(data[0].data)[0]; - rspamd.tables.symbols.rows.load(items); - }, - server: (checked_server === "All SERVERS") ? "local" : checked_server - }); + + $("#updateSymbols").on("click", function (e) { + e.preventDefault(); + var checked_server = rspamd.getSelector("selSrv"); + rspamd.query("symbols", { + success: function (data) { + var items = process_symbols_data(data[0].data)[0]; + rspamd.tables.symbols.rows.load(items); + }, + server: (checked_server === "All SERVERS") ? "local" : checked_server }); - })(); + }); return ui; }); diff --git a/interface/js/app/upload.js b/interface/js/app/upload.js index a63fd4f66..269d32460 100644 --- a/interface/js/app/upload.js +++ b/interface/js/app/upload.js @@ -240,72 +240,71 @@ define(["jquery", "app/rspamd"], }); } - (() => { - rspamd.set_page_size("scan", $("#scan_page_size").val()); - rspamd.bindHistoryTableEventHandlers("scan", 3); - $("#cleanScanHistory").off("click"); - $("#cleanScanHistory").on("click", function (e) { - e.preventDefault(); - if (!confirm("Are you sure you want to clean scan history?")) { // eslint-disable-line no-alert - return; - } - rspamd.destroyTable("scan"); - rspamd.symbols.scan.length = 0; - $("#cleanScanHistory").attr("disabled", true); - }); + rspamd.set_page_size("scan", $("#scan_page_size").val()); + rspamd.bindHistoryTableEventHandlers("scan", 3); - function enable_disable_scan_btn() { - $("#scan button:not(#cleanScanHistory, #scanOptionsToggle)").prop("disabled", ($.trim($("textarea").val()).length === 0)); + $("#cleanScanHistory").off("click"); + $("#cleanScanHistory").on("click", function (e) { + e.preventDefault(); + if (!confirm("Are you sure you want to clean scan history?")) { // eslint-disable-line no-alert + return; } + rspamd.destroyTable("scan"); + rspamd.symbols.scan.length = 0; + $("#cleanScanHistory").attr("disabled", true); + }); + + function enable_disable_scan_btn() { + $("#scan button:not(#cleanScanHistory, #scanOptionsToggle)").prop("disabled", ($.trim($("textarea").val()).length === 0)); + } + enable_disable_scan_btn(); + $("textarea").on("input", function () { enable_disable_scan_btn(); - $("textarea").on("input", function () { - enable_disable_scan_btn(); - }); + }); - $("#scanClean").on("click", function () { - $("#scan button:not(#cleanScanHistory, #scanOptionsToggle)").attr("disabled", true); - $("#scanForm")[0].reset(); - $("#scanResult").hide(); - $("#scanOutput tbody").remove(); - $("html, body").animate({scrollTop:0}, 1000); - return false; - }); + $("#scanClean").on("click", function () { + $("#scan button:not(#cleanScanHistory, #scanOptionsToggle)").attr("disabled", true); + $("#scanForm")[0].reset(); + $("#scanResult").hide(); + $("#scanOutput tbody").remove(); + $("html, body").animate({scrollTop:0}, 1000); + return false; + }); - $(".card-close-btn").on("click", function () { - $(this).closest(".card").slideUp(); - }); + $(".card-close-btn").on("click", function () { + $(this).closest(".card").slideUp(); + }); - $("[data-upload]").on("click", function () { - var source = $(this).data("upload"); - var data = $("#scanMsgSource").val(); - var headers = {}; - if ($.trim(data).length > 0) { - if (source === "scan") { - headers = ["IP", "User", "From", "Rcpt", "Helo", "Hostname"].reduce(function (o, header) { - var value = $("#scan-opt-" + header.toLowerCase()).val(); - if (value !== "") o[header] = value; - return o; - }, {}); - if ($("#scan-opt-pass-all").prop("checked")) headers.Pass = "all"; - scanText(data, headers); - } else if (source === "compute-fuzzy") { - getFuzzyHashes(data); - } else { - if (source === "fuzzy") { - headers = { - flag: $("#fuzzyFlagText").val(), - weight: $("#fuzzyWeightText").val() - }; - } - uploadText(data, source, headers); - } + $("[data-upload]").on("click", function () { + var source = $(this).data("upload"); + var data = $("#scanMsgSource").val(); + var headers = {}; + if ($.trim(data).length > 0) { + if (source === "scan") { + headers = ["IP", "User", "From", "Rcpt", "Helo", "Hostname"].reduce(function (o, header) { + var value = $("#scan-opt-" + header.toLowerCase()).val(); + if (value !== "") o[header] = value; + return o; + }, {}); + if ($("#scan-opt-pass-all").prop("checked")) headers.Pass = "all"; + scanText(data, headers); + } else if (source === "compute-fuzzy") { + getFuzzyHashes(data); } else { - rspamd.alertMessage("alert-error", "Message source field cannot be blank"); + if (source === "fuzzy") { + headers = { + flag: $("#fuzzyFlagText").val(), + weight: $("#fuzzyWeightText").val() + }; + } + uploadText(data, source, headers); } - return false; - }); - })(); + } else { + rspamd.alertMessage("alert-error", "Message source field cannot be blank"); + } + return false; + }); return ui; }); |