From 7d053462fcbb5317f528918b9b0e63abf8d5ce5c Mon Sep 17 00:00:00 2001 From: Alexander Moisseev Date: Sat, 4 Aug 2018 12:44:41 +0300 Subject: [Minor] Use query function to get maps list --- interface/js/app/config.js | 71 ++++++++++++++++++++-------------------------- interface/js/app/rspamd.js | 2 +- 2 files changed, 32 insertions(+), 41 deletions(-) (limited to 'interface') diff --git a/interface/js/app/config.js b/interface/js/app/config.js index 78f27c23d..b98aed4c3 100644 --- a/interface/js/app/config.js +++ b/interface/js/app/config.js @@ -57,44 +57,6 @@ define(["jquery"], }); } - // @get maps id - function getMaps(rspamd) { - var $listmaps = $("#listMaps"); - $listmaps.closest(".widget-box").hide(); - $.ajax({ - dataType: "json", - url: "maps", - jsonp: false, - beforeSend: function (xhr) { - xhr.setRequestHeader("Password", rspamd.getPassword()); - }, - error: function (data) { - rspamd.alertMessage("alert-modal alert-error", data.statusText); - }, - success: function (data) { - $listmaps.empty(); - $("#modalBody").empty(); - var $tbody = $(""); - - $.each(data, function (i, item) { - var label; - if ((item.editable === false || rspamd.read_only)) { - label = "Read"; - } else { - label = "Read Write"; - } - var $tr = $(""); - $("" + label + "").appendTo($tr); - var $span = $("" + item.uri + "").data("item", item); - $span.wrap("").parent().appendTo($tr); - $("" + item.description + "").appendTo($tr); - $tr.appendTo($tbody); - }); - $tbody.appendTo($listmaps); - $listmaps.closest(".widget-box").show(); - } - }); - } // @get map by id function getMapById(rspamd, item) { return $.ajax({ @@ -231,6 +193,37 @@ define(["jquery"], }); }; + ui.getMaps = function (rspamd, checked_server) { + var $listmaps = $("#listMaps"); + $listmaps.closest(".widget-box").hide(); + rspamd.query("maps", { + success: function (json) { + var data = json[0].data; + $listmaps.empty(); + $("#modalBody").empty(); + var $tbody = $(""); + + $.each(data, function (i, item) { + var label; + if ((item.editable === false || rspamd.read_only)) { + label = "Read"; + } else { + label = "Read Write"; + } + var $tr = $(""); + $("" + label + "").appendTo($tr); + var $span = $("" + item.uri + "").data("item", item); + $span.wrap("").parent().appendTo($tr); + $("" + item.description + "").appendTo($tr); + $tr.appendTo($tbody); + }); + $tbody.appendTo($listmaps); + $listmaps.closest(".widget-box").show(); + }, + server: (checked_server === "All SERVERS") ? "local" : checked_server + }); + }; + // @upload edited actions ui.setup = function (rspamd) { // Modal form for maps @@ -284,7 +277,5 @@ define(["jquery"], }); }; - ui.getMaps = getMaps; - return ui; }); diff --git a/interface/js/app/rspamd.js b/interface/js/app/rspamd.js index c703d9367..b83bb5cff 100644 --- a/interface/js/app/rspamd.js +++ b/interface/js/app/rspamd.js @@ -120,7 +120,7 @@ function ($, d3pie, visibility, tab_stat, tab_graph, tab_config, break; case "#configuration_nav": tab_config.getActions(ui, checked_server); - tab_config.getMaps(ui); + tab_config.getMaps(ui, checked_server); break; case "#symbols_nav": tab_symbols.getSymbols(ui, checked_server); -- cgit v1.2.3