commit 1c1829a: [Minor] WebUI: Use public getSelector() function
moisseev
moiseev at mezonplus.ru
Wed Aug 21 07:35:07 UTC 2019
Author: moisseev
Date: 2019-08-20 19:38:25 +0300
URL: https://github.com/rspamd/rspamd/commit/1c1829a328e3fc51fd2aeb4ccfcb86155305c865 (refs/pull/3010/head)
[Minor] WebUI: Use public getSelector() function
---
interface/js/app/config.js | 6 +-----
interface/js/app/graph.js | 22 ++++++++--------------
interface/js/app/rspamd.js | 3 ++-
interface/js/app/symbols.js | 15 +++++----------
4 files changed, 16 insertions(+), 30 deletions(-)
diff --git a/interface/js/app/config.js b/interface/js/app/config.js
index e679780f4..701640f91 100644
--- a/interface/js/app/config.js
+++ b/interface/js/app/config.js
@@ -166,11 +166,7 @@ define(["jquery"],
ui.setup = function (rspamd) {
// Modal form for maps
$(document).on("click", "[data-toggle=\"modal\"]", function () {
- function getSelector(id) {
- var e = document.getElementById(id);
- return e.options[e.selectedIndex].value;
- }
- var checked_server = getSelector("selSrv");
+ var checked_server = rspamd.getSelector("selSrv");
var item = $(this).data("item");
rspamd.query("getmap", {
headers: {
diff --git a/interface/js/app/graph.js b/interface/js/app/graph.js
index 2fd66b555..624566a8a 100644
--- a/interface/js/app/graph.js
+++ b/interface/js/app/graph.js
@@ -86,18 +86,12 @@ define(["jquery", "d3evolution", "footable"],
}
};
- // Get selectors' current state
- function getSelector(id) {
- var e = document.getElementById(id);
- return e.options[e.selectedIndex].value;
- }
-
- function initGraph() {
+ function initGraph(rspamd) {
var graph = new D3Evolution("graph", $.extend({}, graph_options, {
- yScale: getSelector("selYScale"),
- type: getSelector("selType"),
- interpolate: getSelector("selInterpolate"),
- convert: getSelector("selConvert"),
+ yScale: rspamd.getSelector("selYScale"),
+ type: rspamd.getSelector("selType"),
+ interpolate: rspamd.getSelector("selInterpolate"),
+ convert: rspamd.getSelector("selConvert"),
}));
$("#selYScale").change(function () {
graph.yScale(this.value);
@@ -251,7 +245,7 @@ define(["jquery", "d3evolution", "footable"],
}
if (!graphs.graph) {
- graphs.graph = initGraph();
+ graphs.graph = initGraph(rspamd);
}
rspamd.query("graph", {
@@ -297,7 +291,7 @@ define(["jquery", "d3evolution", "footable"],
});
};
- ui.setup = function () {
+ ui.setup = function (rspamd) {
// Handling mouse events on overlapping elements
$("#rrd-pie").mouseover(function () {
$("#rrd-pie").css("z-index", "200");
@@ -308,7 +302,7 @@ define(["jquery", "d3evolution", "footable"],
$("#rrd-table_toggle").css("z-index", "0");
});
- return getSelector("selData");
+ return rspamd.getSelector("selData");
};
return ui;
diff --git a/interface/js/app/rspamd.js b/interface/js/app/rspamd.js
index da22495c5..155a544e1 100644
--- a/interface/js/app/rspamd.js
+++ b/interface/js/app/rspamd.js
@@ -150,6 +150,7 @@ function ($, D3pie, visibility, NProgress, stickyTabs, tab_stat, tab_graph, tab_
return sessionStorage.getItem("Password");
}
+ // Get selectors' current state
function getSelector(id) {
var e = document.getElementById(id);
return e.options[e.selectedIndex].value;
@@ -375,7 +376,7 @@ function ($, D3pie, visibility, NProgress, stickyTabs, tab_stat, tab_graph, tab_
tab_history.setup(ui, tables);
tab_symbols.setup(ui, tables);
tab_upload.setup(ui, tables);
- selData = tab_graph.setup();
+ selData = tab_graph.setup(ui);
};
ui.connect = function () {
diff --git a/interface/js/app/symbols.js b/interface/js/app/symbols.js
index ed0a67583..a64c7c931 100644
--- a/interface/js/app/symbols.js
+++ b/interface/js/app/symbols.js
@@ -29,11 +29,6 @@ define(["jquery", "footable"],
"use strict";
var ui = {};
- function getSelector(id) {
- var e = document.getElementById(id);
- return e.options[e.selectedIndex].value;
- }
-
function saveSymbols(rspamd, action, id, server) {
var inputs = $("#" + id + " :input[data-role=\"numerictextbox\"]");
var url = action;
@@ -62,12 +57,12 @@ define(["jquery", "footable"],
var digits = Number(number).toFixed(20).replace(/^-?\d*\.?|0+$/g, "").length;
return (digits === 0 || digits > 4) ? 0.1 : 1.0 / Math.pow(10, digits);
}
- function process_symbols_data(data) {
+ function process_symbols_data(rspamd, data) {
var items = [];
var lookup = {};
var freqs = [];
var distinct_groups = [];
- var selected_server = getSelector("selSrv");
+ var selected_server = rspamd.getSelector("selSrv");
data.forEach(function (group) {
group.rules.forEach(function (item) {
@@ -147,7 +142,7 @@ define(["jquery", "footable"],
rspamd.query("symbols", {
success: function (json) {
var data = json[0].data;
- var items = process_symbols_data(data);
+ var items = process_symbols_data(rspamd, data);
/* eslint-disable consistent-this, no-underscore-dangle, one-var-declaration-per-line */
FooTable.groupFilter = FooTable.Filtering.extend({
@@ -250,10 +245,10 @@ define(["jquery", "footable"],
ui.setup = function (rspamd, tables) {
$("#updateSymbols").on("click", function (e) {
e.preventDefault();
- var checked_server = getSelector("selSrv");
+ var checked_server = rspamd.getSelector("selSrv");
rspamd.query("symbols", {
success: function (data) {
- var items = process_symbols_data(data[0].data)[0];
+ var items = process_symbols_data(rspamd, data[0].data)[0];
tables.symbols.rows.load(items);
},
server: (checked_server === "All SERVERS") ? "local" : checked_server
More information about the Commits
mailing list