aboutsummaryrefslogtreecommitdiffstats
path: root/interface/js/app
diff options
context:
space:
mode:
authorAlexander Moisseev <moiseev@mezonplus.ru>2018-08-16 22:49:50 +0300
committerAlexander Moisseev <moiseev@mezonplus.ru>2018-08-16 22:49:50 +0300
commit88354ed54216aed337324f460690ae45a81ef41b (patch)
tree75c5b3a801d7d3c482de6bfca78cdb93a2e0858e /interface/js/app
parent0f5c83a3f6bc5e3f446bff337292b9a5e2703344 (diff)
downloadrspamd-88354ed54216aed337324f460690ae45a81ef41b.tar.gz
rspamd-88354ed54216aed337324f460690ae45a81ef41b.zip
[Minor] Refactor upload.js module to use query function
Diffstat (limited to 'interface/js/app')
-rw-r--r--interface/js/app/rspamd.js6
-rw-r--r--interface/js/app/upload.js78
2 files changed, 36 insertions, 48 deletions
diff --git a/interface/js/app/rspamd.js b/interface/js/app/rspamd.js
index 031a86a86..300313159 100644
--- a/interface/js/app/rspamd.js
+++ b/interface/js/app/rspamd.js
@@ -234,7 +234,8 @@ function ($, d3pie, visibility, tab_stat, tab_graph, tab_config,
alertMessage("alert-error", "Request failed");
}
}
- }
+ },
+ statusCode: o.statusCode
};
if (o.method) {
req_params.method = o.method;
@@ -458,7 +459,8 @@ function ($, d3pie, visibility, tab_stat, tab_graph, tab_config,
// Force options to be an object
var o = options || {};
Object.keys(o).forEach(function (option) {
- if (["data", "error", "errorMessage", "errorOnceId", "headers", "method", "params", "server", "success"]
+ if (["data", "error", "errorMessage", "errorOnceId", "headers", "method", "params", "server", "statusCode",
+ "success"]
.indexOf(option) < 0) {
throw new Error("Unknown option: " + option);
}
diff --git a/interface/js/app/upload.js b/interface/js/app/upload.js
index bbd109639..e542667a6 100644
--- a/interface/js/app/upload.js
+++ b/interface/js/app/upload.js
@@ -43,53 +43,32 @@ define(["jquery"],
} else if (source === "scan") {
url = "scan";
}
- $.ajax({
+ rspamd.query(url, {
data: data,
- dataType: "json",
- type: "POST",
- url: url,
- processData: false,
- jsonp: false,
- beforeSend: function (xhr) {
- xhr.setRequestHeader("Password", rspamd.getPassword());
- $.each(headers, function (name, value) {
- xhr.setRequestHeader(name, value);
- });
+ params: {
+ processData: false,
},
+ method: "POST",
+ headers: headers,
success: function (json) {
cleanTextUpload(source);
- if (json.success) {
+ if (json[0].data.success) {
rspamd.alertMessage("alert-success", "Data successfully uploaded");
}
- },
- error: function (xhr, textStatus, errorThrown) {
- var errorMsg;
-
- try {
- var json = $.parseJSON(xhr.responseText);
- errorMsg = $("<a>").text(json.error).html();
- } catch (err) {
- errorMsg = $("<a>").text("Error: [" + textStatus + "] " + errorThrown).html();
- }
- rspamd.alertMessage("alert-error", errorMsg);
}
});
}
// @upload text
- function scanText(rspamd, data) {
- var url = "scan";
+ function scanText(rspamd, data, server) {
var items = [];
- $.ajax({
+ rspamd.query("scan", {
data: data,
- dataType: "json",
- type: "POST",
- url: url,
- processData: false,
- jsonp: false,
- beforeSend: function (xhr) {
- xhr.setRequestHeader("Password", rspamd.getPassword());
+ params: {
+ processData: false,
},
- success: function (json) {
+ method: "POST",
+ success: function (neighbours_status) {
+ var json = neighbours_status[0].data;
if (json.action) {
rspamd.alertMessage("alert-success", "Data successfully scanned");
var action = "";
@@ -159,11 +138,17 @@ define(["jquery"],
503: function () {
rspamd.alertMessage("alert-error", "Cannot tokenize message: no text data");
}
- }
+ },
+ server: server
});
}
ui.setup = function (rspamd) {
+ function getSelector(id) {
+ var e = document.getElementById(id);
+ return e.options[e.selectedIndex].value;
+ }
+
$("textarea").change(function () {
if ($(this).val().length !== "") {
$(this).closest("form").find("button").removeAttr("disabled").removeClass("disabled");
@@ -182,22 +167,23 @@ define(["jquery"],
// @init upload
$("[data-upload]").on("click", function () {
var source = $(this).data("upload");
- var data;
- var headers = {};
- data = $("#" + source + "TextSource").val();
- if (source === "fuzzy") {
- // To access the proper
- headers.flag = $("#fuzzyFlagText").val();
- headers.weight = $("#fuzzyWeightText").val();
- } else {
- data = $("#" + source + "TextSource").val();
- }
+ var data = $("#" + source + "TextSource").val();
+ var headers = (source === "fuzzy")
+ ? {
+ flag: $("#fuzzyFlagText").val(),
+ weight: $("#fuzzyWeightText").val()
+ }
+ : {};
if (data.length > 0) {
if (source === "scan") {
- scanText(rspamd, data);
+ var checked_server = getSelector("selSrv");
+ var server = (checked_server === "All SERVERS") ? "local" : checked_server;
+ scanText(rspamd, data, server);
} else {
uploadText(rspamd, data, source, headers);
}
+ } else {
+ rspamd.alertMessage("alert-error", "Message source field cannot be blank");
}
return false;
});