Browse Source

Merge pull request #2398 from moisseev/eslint

[Minor] Use query function to get maps list
tags/1.8.0
Vsevolod Stakhov 5 years ago
parent
commit
fef2462d71
No account linked to committer's email address
2 changed files with 70 additions and 89 deletions
  1. 64
    82
      interface/js/app/config.js
  2. 6
    7
      interface/js/app/rspamd.js

+ 64
- 82
interface/js/app/config.js View File

@@ -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>&nbsp;<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>&nbsp;<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;
});

+ 6
- 7
interface/js/app/rspamd.js View File

@@ -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();

Loading…
Cancel
Save