diff options
author | Vsevolod Stakhov <vsevolod@highsecure.ru> | 2018-08-05 19:45:41 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2018-08-05 19:45:41 +0100 |
commit | fef2462d71d7741420c0b1734e88de29d15174c4 (patch) | |
tree | fbee92955bddf9e0e54da32bd5c1c3e651960756 | |
parent | dd92e8e9b2b20fc6b1759ad0ac63dea01acff859 (diff) | |
parent | 218f1f57c7ece0e8418641f5cbbd7fc8d17b831b (diff) | |
download | rspamd-fef2462d71d7741420c0b1734e88de29d15174c4.tar.gz rspamd-fef2462d71d7741420c0b1734e88de29d15174c4.zip |
Merge pull request #2398 from moisseev/eslint
[Minor] Use query function to get maps list
-rw-r--r-- | interface/js/app/config.js | 146 | ||||
-rw-r--r-- | interface/js/app/rspamd.js | 13 |
2 files changed, 70 insertions, 89 deletions
diff --git a/interface/js/app/config.js b/interface/js/app/config.js index 78f27c23d..19bc234ec 100644 --- a/interface/js/app/config.js +++ b/interface/js/app/config.js @@ -57,73 +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 = $("<tbody>"); - - $.each(data, function (i, item) { - var label; - if ((item.editable === false || rspamd.read_only)) { - label = "<span class=\"label label-default\">Read</span>"; - } else { - label = "<span class=\"label label-default\">Read</span> <span class=\"label label-success\">Write</span>"; - } - var $tr = $("<tr>"); - $("<td class=\"col-md-2 maps-cell\">" + label + "</td>").appendTo($tr); - var $span = $("<span class=\"map-link\" data-toggle=\"modal\" data-target=\"#modalDialog\">" + item.uri + "</span>").data("item", item); - $span.wrap("<td>").parent().appendTo($tr); - $("<td>" + item.description + "</td>").appendTo($tr); - $tr.appendTo($tbody); - }); - $tbody.appendTo($listmaps); - $listmaps.closest(".widget-box").show(); - } - }); - } - // @get map by id - function getMapById(rspamd, item) { - return $.ajax({ - dataType: "text", - url: "getmap", - jsonp: false, - beforeSend: function (xhr) { - xhr.setRequestHeader("Password", rspamd.getPassword()); - xhr.setRequestHeader("Map", item.map); - }, - error: function () { - rspamd.alertMessage("alert-error", "Cannot receive maps data"); - }, - success: function (text) { - var disabled = ""; - if ((item.editable === false || rspamd.read_only)) { - disabled = "disabled=\"disabled\""; - } - - $("#" + item.map).remove(); - $("<form class=\"form-horizontal form-map\" method=\"post\" action=\"savemap\" data-type=\"map\" id=\"" + - item.map + "\" style=\"display:none\">" + - "<textarea class=\"list-textarea\"" + disabled + ">" + text + - "</textarea>" + - "</form").appendTo("#modalBody"); - } - }); - } - function loadActionsFromForm() { var values = []; var inputs = $("#actionsForm :input[data-id=\"action\"]"); @@ -231,23 +164,74 @@ 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 = $("<tbody>"); + + $.each(data, function (i, item) { + var label; + if ((item.editable === false || rspamd.read_only)) { + label = "<span class=\"label label-default\">Read</span>"; + } else { + label = "<span class=\"label label-default\">Read</span> <span class=\"label label-success\">Write</span>"; + } + var $tr = $("<tr>"); + $("<td class=\"col-md-2 maps-cell\">" + label + "</td>").appendTo($tr); + var $span = $("<span class=\"map-link\" data-toggle=\"modal\" data-target=\"#modalDialog\">" + item.uri + "</span>").data("item", item); + $span.wrap("<td>").parent().appendTo($tr); + $("<td>" + item.description + "</td>").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) { + ui.setup = function (rspamd, checked_server) { // Modal form for maps $(document).on("click", "[data-toggle=\"modal\"]", function () { var item = $(this).data("item"); - getMapById(rspamd, item).done(function () { - $("#modalTitle").html(item.uri); - $("#" + item.map).first().show(); - $("#modalDialog .progress").hide(); - $("#modalDialog").modal({backdrop: true, keyboard: "show", show: true}); - if (item.editable === false) { - $("#modalSave").hide(); - $("#modalSaveAll").hide(); - } else { - $("#modalSave").show(); - $("#modalSaveAll").show(); - } + rspamd.query("getmap", { + headers: { + Map: item.map + }, + success: function (data) { + var disabled = ""; + var text = data[0].data; + if ((item.editable === false || rspamd.read_only)) { + disabled = "disabled=\"disabled\""; + } + + $("#" + item.map).remove(); + $("<form id=\"" + item.map + "\" class=\"form-horizontal form-map\" style=\"display:none\"" + + " data-type=\"map\" action=\"savemap\" method=\"post\">" + + "<textarea class=\"list-textarea\"" + disabled + ">" + text + + "</textarea>" + + "</form>").appendTo("#modalBody"); + + $("#modalTitle").html(item.uri); + $("#" + item.map).first().show(); + $("#modalDialog .progress").hide(); + $("#modalDialog").modal({backdrop: true, keyboard: "show", show: true}); + if (item.editable === false) { + $("#modalSave").hide(); + $("#modalSaveAll").hide(); + } else { + $("#modalSave").show(); + $("#modalSaveAll").show(); + } + }, + errorMessage: "Cannot receive maps data", + server: (checked_server === "All SERVERS") ? "local" : checked_server }); return false; }); @@ -284,7 +268,5 @@ define(["jquery"], }); }; - ui.getMaps = getMaps; - return ui; }); diff --git a/interface/js/app/rspamd.js b/interface/js/app/rspamd.js index 7ca11ae74..e983e4074 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); @@ -199,16 +199,15 @@ function ($, d3pie, visibility, tab_stat, tab_graph, tab_config, url: neighbours_status[ind].url + req_url, success: function (json) { neighbours_status[ind].checked = true; - if (!jQuery.isEmptyObject(json) || req_url === "neighbours") { - neighbours_status[ind].status = true; - neighbours_status[ind].data = json; - } + neighbours_status[ind].status = true; + neighbours_status[ind].data = json; }, error: function (jqXHR, textStatus, errorThrown) { neighbours_status[ind].checked = true; function errorMessage() { alertMessage("alert-error", neighbours_status[ind].name + " > " + - ((o.errorMessage) ? o.errorMessage : "Request failed") + ": " + errorThrown); + (o.errorMessage ? o.errorMessage : "Request failed") + + (errorThrown ? (": " + errorThrown) : "")); } if (o.error) { o.error(neighbours_status[ind], @@ -287,7 +286,7 @@ function ($, d3pie, visibility, tab_stat, tab_graph, tab_config, tabClick("#status_nav"); } }); - tab_config.setup(ui); + tab_config.setup(ui, checked_server); tab_symbols.setup(ui); tab_upload.setup(ui); selData = tab_graph.setup(); |