diff options
author | Alexander Moisseev <moiseev@mezonplus.ru> | 2018-07-03 12:13:39 +0300 |
---|---|---|
committer | Alexander Moisseev <moiseev@mezonplus.ru> | 2018-07-03 12:13:39 +0300 |
commit | ba2a5ba57c2d0f0c8abc080c3c6aacd2835770c2 (patch) | |
tree | e28e146d65879382754e2da49655053ca29e0655 /interface/js/app/upload.js | |
parent | 54b5410172c7c95948f59ad6ecb48f0f2fc0698e (diff) | |
download | rspamd-ba2a5ba57c2d0f0c8abc080c3c6aacd2835770c2.tar.gz rspamd-ba2a5ba57c2d0f0c8abc080c3c6aacd2835770c2.zip |
[Minor] JS: Use double quotes wherever possible
Diffstat (limited to 'interface/js/app/upload.js')
-rw-r--r-- | interface/js/app/upload.js | 144 |
1 files changed, 72 insertions, 72 deletions
diff --git a/interface/js/app/upload.js b/interface/js/app/upload.js index f56ff9105..9be8d3289 100644 --- a/interface/js/app/upload.js +++ b/interface/js/app/upload.js @@ -22,35 +22,35 @@ THE SOFTWARE. */ -define(['jquery'], +define(["jquery"], function($) { var interface = {} function cleanTextUpload(source) { - $('#' + source + 'TextSource').val(''); + $("#" + source + "TextSource").val(""); } // @upload text function uploadText(rspamd, data, source, headers) { var url; - if (source === 'spam') { - url = 'learnspam'; - } else if (source === 'ham') { - url = 'learnham'; - } else if (source == 'fuzzy') { - url = 'fuzzyadd'; - } else if (source === 'scan') { - url = 'scan'; + if (source === "spam") { + url = "learnspam"; + } else if (source === "ham") { + url = "learnham"; + } else if (source == "fuzzy") { + url = "fuzzyadd"; + } else if (source === "scan") { + url = "scan"; } $.ajax({ data: data, - dataType: 'json', - type: 'POST', + dataType: "json", + type: "POST", url: url, processData: false, jsonp: false, beforeSend: function (xhr) { - xhr.setRequestHeader('Password', rspamd.getPassword()); + xhr.setRequestHeader("Password", rspamd.getPassword()); $.each(headers, function (name, value) { xhr.setRequestHeader(name, value); }); @@ -58,7 +58,7 @@ function($) { success: function (data) { cleanTextUpload(source); if (data.success) { - rspamd.alertMessage('alert-success', 'Data successfully uploaded'); + rspamd.alertMessage("alert-success", "Data successfully uploaded"); } }, error: function (xhr, textStatus, errorThrown) { @@ -66,140 +66,140 @@ function($) { try { var json = $.parseJSON(xhr.responseText); - errorMsg = $('<a>').text(json.error).html(); + errorMsg = $("<a>").text(json.error).html(); } catch (err) { - errorMsg = $('<a>').text("Error: [" + textStatus + "] " + errorThrown).html(); + errorMsg = $("<a>").text("Error: [" + textStatus + "] " + errorThrown).html(); } - rspamd.alertMessage('alert-error', errorMsg); + rspamd.alertMessage("alert-error", errorMsg); } }); } // @upload text function scanText(rspamd, data) { - var url = 'scan'; + var url = "scan"; var items = []; $.ajax({ data: data, - dataType: 'json', - type: 'POST', + dataType: "json", + type: "POST", url: url, processData: false, jsonp: false, beforeSend: function (xhr) { - xhr.setRequestHeader('Password', rspamd.getPassword()); + xhr.setRequestHeader("Password", rspamd.getPassword()); }, success: function (input) { var data = input; if (data.action) { - rspamd.alertMessage('alert-success', 'Data successfully scanned'); - var action = ''; + rspamd.alertMessage("alert-success", "Data successfully scanned"); + var action = ""; - if (data.action === 'clean' || 'no action') { - action = 'label-success'; + if (data.action === "clean" || "no action") { + action = "label-success"; } - else if (data.action === 'rewrite subject' || 'add header' || 'probable spam') { - action = 'label-warning'; + else if (data.action === "rewrite subject" || "add header" || "probable spam") { + action = "label-warning"; } - else if (data.action === 'spam') { - action = 'label-danger'; + else if (data.action === "spam") { + action = "label-danger"; } - var score = ''; + var score = ""; if (data.score <= data.required_score) { - score = 'label-success'; + score = "label-success"; } else if (data.score >= data.required_score) { - score = 'label-danger'; + score = "label-danger"; } - $('<tbody id="tmpBody"><tr>' + - '<td><span class="label ' + action + '">' + data.action + '</span></td>' + - '<td><span class="label ' + score + '">' + data.score.toFixed(2) + '/' + data.required_score.toFixed(2) + '</span></td>' + - '</tr></tbody>') - .insertAfter('#scanOutput thead'); + $("<tbody id=\"tmpBody\"><tr>" + + "<td><span class=\"label " + action + "\">" + data.action + "</span></td>" + + "<td><span class=\"label " + score + "\">" + data.score.toFixed(2) + "/" + data.required_score.toFixed(2) + "</span></td>" + + "</tr></tbody>") + .insertAfter("#scanOutput thead"); var sym_desc = {}; var nsym = 0; $.each(data.symbols, function (i, item) { - if (typeof item == 'object') { + if (typeof item == "object") { var sym_id = "sym_" + nsym; if (item.description) { sym_desc[sym_id] = item.description; } - items.push('<div class="cell-overflow" tabindex="1"><abbr id="' + sym_id + - '">' + item.name + '</abbr>: ' + item.score.toFixed(2) + '</div>'); + items.push("<div class=\"cell-overflow\" tabindex=\"1\"><abbr id=\"" + sym_id + + "\">" + item.name + "</abbr>: " + item.score.toFixed(2) + "</div>"); nsym++; } }); - $('<td/>', { - id: 'tmpSymbols', - html: items.join('') - }).appendTo('#scanResult'); - $('#tmpSymbols').insertAfter('#tmpBody td:last').removeAttr('id'); - $('#tmpBody').removeAttr('id'); - $('#scanResult').show(); + $("<td/>", { + id: "tmpSymbols", + html: items.join("") + }).appendTo("#scanResult"); + $("#tmpSymbols").insertAfter("#tmpBody td:last").removeAttr("id"); + $("#tmpBody").removeAttr("id"); + $("#scanResult").show(); // Show tooltips $.each(sym_desc, function (k, v) { - $('#' + k).tooltip({ + $("#" + k).tooltip({ "placement": "bottom", "title": v }); }); - $('html, body').animate({ - scrollTop: $('#scanResult').offset().top + $("html, body").animate({ + scrollTop: $("#scanResult").offset().top }, 1000); } else { - rspamd.alertMessage('alert-error', 'Cannot scan data'); + rspamd.alertMessage("alert-error", "Cannot scan data"); } }, error: function (jqXHR, textStatus, errorThrown) { - rspamd.alertMessage('alert-error', 'Cannot upload data: ' + + rspamd.alertMessage("alert-error", "Cannot upload data: " + textStatus + ", " + errorThrown); }, statusCode: { 404: function () { - rspamd.alertMessage('alert-error', 'Cannot upload data, no server found'); + rspamd.alertMessage("alert-error", "Cannot upload data, no server found"); }, 500: function () { - rspamd.alertMessage('alert-error', 'Cannot tokenize message: no text data'); + rspamd.alertMessage("alert-error", "Cannot tokenize message: no text data"); }, 503: function () { - rspamd.alertMessage('alert-error', 'Cannot tokenize message: no text data'); + rspamd.alertMessage("alert-error", "Cannot tokenize message: no text data"); } } }); } interface.setup = function(rspamd) { - $('textarea').change(function () { - if ($(this).val().length !== '') { - $(this).closest('form').find('button').removeAttr('disabled').removeClass('disabled'); + $("textarea").change(function () { + if ($(this).val().length !== "") { + $(this).closest("form").find("button").removeAttr("disabled").removeClass("disabled"); } else { - $(this).closest('form').find('button').attr('disabled').addClass('disabled'); + $(this).closest("form").find("button").attr("disabled").addClass("disabled"); } }); - $('#scanClean').on('click', function () { - $('#scanTextSource').val(""); - $('#scanResult').hide(); - $('#scanOutput tbody').remove(); - $('html, body').animate({scrollTop: 0}, 1000); + $("#scanClean").on("click", function () { + $("#scanTextSource").val(""); + $("#scanResult").hide(); + $("#scanOutput tbody").remove(); + $("html, body").animate({scrollTop: 0}, 1000); return false; }); // @init upload - $('[data-upload]').on('click', function () { - var source = $(this).data('upload'); + $("[data-upload]").on("click", function () { + var source = $(this).data("upload"); var data; var headers = {}; - data = $('#' + source + 'TextSource').val(); - if (source == 'fuzzy') { + data = $("#" + source + "TextSource").val(); + if (source == "fuzzy") { //To access the proper - headers.flag = $('#fuzzyFlagText').val(); - headers.weight = $('#fuzzyWeightText').val(); + headers.flag = $("#fuzzyFlagText").val(); + headers.weight = $("#fuzzyWeightText").val(); } else { - data = $('#' + source + 'TextSource').val(); + data = $("#" + source + "TextSource").val(); } if (data.length > 0) { - if (source == 'scan') { + if (source == "scan") { scanText(rspamd, data); } else { uploadText(rspamd, data, source, headers); |