From ba2a5ba57c2d0f0c8abc080c3c6aacd2835770c2 Mon Sep 17 00:00:00 2001 From: Alexander Moisseev Date: Tue, 3 Jul 2018 12:13:39 +0300 Subject: [PATCH] [Minor] JS: Use double quotes wherever possible --- interface/js/app/config.js | 184 ++++++++++++++++++------------------ interface/js/app/graph.js | 28 +++--- interface/js/app/history.js | 118 +++++++++++------------ interface/js/app/rspamd.js | 148 ++++++++++++++--------------- interface/js/app/stats.js | 92 +++++++++--------- interface/js/app/symbols.js | 108 ++++++++++----------- interface/js/app/upload.js | 144 ++++++++++++++-------------- interface/js/main.js | 36 +++---- 8 files changed, 429 insertions(+), 429 deletions(-) diff --git a/interface/js/app/config.js b/interface/js/app/config.js index d10fd6a60..e580b2497 100644 --- a/interface/js/app/config.js +++ b/interface/js/app/config.js @@ -22,34 +22,34 @@ THE SOFTWARE. */ -define(['jquery'], +define(["jquery"], function($) { var interface = {} function save_map_success(rspamd) { - rspamd.alertMessage('alert-modal alert-success', 'Map data successfully saved'); - $('#modalDialog').modal('hide'); + rspamd.alertMessage("alert-modal alert-success", "Map data successfully saved"); + $("#modalDialog").modal("hide"); } function save_map_error(rspamd, serv, jqXHR, textStatus, errorThrown) { - rspamd.alertMessage('alert-modal alert-error', 'Save map error on ' + - serv.name + ': ' + errorThrown); + rspamd.alertMessage("alert-modal alert-error", "Save map error on " + + serv.name + ": " + errorThrown); } // @upload map from modal function saveMap(rspamd, action, id) { - var data = $('#' + id).find('textarea').val(); + var data = $("#" + id).find("textarea").val(); $.ajax({ data: data, - dataType: 'text', - type: 'POST', + dataType: "text", + type: "POST", jsonp: false, url: action, beforeSend: function (xhr) { - xhr.setRequestHeader('Password', rspamd.getPassword()); - xhr.setRequestHeader('Map', id); - xhr.setRequestHeader('Debug', true); + xhr.setRequestHeader("Password", rspamd.getPassword()); + xhr.setRequestHeader("Map", id); + xhr.setRequestHeader("Debug", true); }, error: function (data) { - save_map_error(rspamd, 'local', null, null, data.statusText); + save_map_error(rspamd, "local", null, null, data.statusText); }, success: function() {save_map_success(rspamd)}, }); @@ -58,73 +58,73 @@ function($) { // @get maps id function getMaps(rspamd) { var items = []; - var $listmaps = $('#listMaps') - $listmaps.closest('.widget-box').hide(); + var $listmaps = $("#listMaps") + $listmaps.closest(".widget-box").hide(); $.ajax({ - dataType: 'json', - url: 'maps', + dataType: "json", + url: "maps", jsonp: false, beforeSend: function (xhr) { - xhr.setRequestHeader('Password', rspamd.getPassword()); + xhr.setRequestHeader("Password", rspamd.getPassword()); }, error: function (data) { - rspamd.alertMessage('alert-modal alert-error', data.statusText); + rspamd.alertMessage("alert-modal alert-error", data.statusText); }, success: function (data) { $listmaps.empty(); - $('#modalBody').empty(); - $tbody = $(''); + $("#modalBody").empty(); + $tbody = $(""); $.each(data, function (i, item) { if ((item.editable === false || rspamd.read_only)) { - var label = 'Read'; + var label = "Read"; } else { - var label = 'Read Write'; + var label = "Read Write"; } var $tr = $(""); - $('' + label + '').appendTo($tr); - $span = $('' + item.uri + '').data("item",item); + $("" + label + "").appendTo($tr); + $span = $("" + item.uri + "").data("item",item); $span.wrap("").parent().appendTo($tr); - $('' + item.description + '').appendTo($tr); + $("" + item.description + "").appendTo($tr); $tr.appendTo($tbody); }); $tbody.appendTo($listmaps); - $listmaps.closest('.widget-box').show(); + $listmaps.closest(".widget-box").show(); } }); } // @get map by id function getMapById(rspamd, item) { return $.ajax({ - dataType: 'text', - url: 'getmap', + dataType: "text", + url: "getmap", jsonp: false, beforeSend: function (xhr) { - xhr.setRequestHeader('Password', rspamd.getPassword()); - xhr.setRequestHeader('Map', item.map); + xhr.setRequestHeader("Password", rspamd.getPassword()); + xhr.setRequestHeader("Map", item.map); }, error: function () { - rspamd.alertMessage('alert-error', 'Cannot receive maps data'); + rspamd.alertMessage("alert-error", "Cannot receive maps data"); }, success: function (text) { - var disabled = ''; + var disabled = ""; if ((item.editable === false || rspamd.read_only)) { - disabled = 'disabled="disabled"'; + disabled = "disabled=\"disabled\""; } $("#"+item.map).remove(); - $('"); if (rspamd.read_only) { - $('#saveActionsClusterBtn').attr('disabled', true); - $('#saveActionsBtn').attr('disabled', true); - $('#actionsFormField').attr('disabled', true); + $("#saveActionsClusterBtn").attr("disabled", true); + $("#saveActionsBtn").attr("disabled", true); + $("#actionsFormField").attr("disabled", true); } function saveActions(callback) { @@ -222,10 +222,10 @@ function($) { } } - $('#saveActionsBtn').on('click', function() { + $("#saveActionsBtn").on("click", function() { saveActions(rspamd.queryLocal); }); - $('#saveActionsClusterBtn').on('click', function() { + $("#saveActionsClusterBtn").on("click", function() { saveActions(rspamd.queryNeighbours); }); }, @@ -235,39 +235,39 @@ function($) { // @upload edited actions interface.setup = function(rspamd) { // Modal form for maps - $(document).on('click', '[data-toggle="modal"]', function () { - var item = $(this).data('item'); + $(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(show = true, backdrop = true, keyboard = show); + $("#modalTitle").html(item.uri); + $("#" + item.map).first().show(); + $("#modalDialog .progress").hide(); + $("#modalDialog").modal(show = true, backdrop = true, keyboard = show); if (item.editable === false) { - $('#modalSave').hide(); - $('#modalSaveAll').hide(); + $("#modalSave").hide(); + $("#modalSaveAll").hide(); } else { - $('#modalSave').show(); - $('#modalSaveAll').show(); + $("#modalSave").show(); + $("#modalSaveAll").show(); } }); return false; }); // close modal without saving - $('[data-dismiss="modal"]').on('click', function () { - $('#modalBody form').hide(); + $("[data-dismiss=\"modal\"]").on("click", function () { + $("#modalBody form").hide(); }); // @save forms from modal - $('#modalSave').on('click', function () { - var form = $('#modalBody').children().filter(':visible'); - var action = $(form).attr('action'); - var id = $(form).attr('id'); + $("#modalSave").on("click", function () { + var form = $("#modalBody").children().filter(":visible"); + var action = $(form).attr("action"); + var id = $(form).attr("id"); saveMap(rspamd, action, id); }); - $('#modalSaveAll').on('click', function () { - var form = $('#modalBody').children().filter(':visible'); - var action = $(form).attr('action'); - var id = $(form).attr('id'); - var data = $('#' + id).find('textarea').val(); + $("#modalSaveAll").on("click", function () { + var form = $("#modalBody").children().filter(":visible"); + var action = $(form).attr("action"); + var id = $(form).attr("id"); + var data = $("#" + id).find("textarea").val(); rspamd.queryNeighbours(action, save_map_success, save_map_error, "POST", { "Map": id, }, { diff --git a/interface/js/app/graph.js b/interface/js/app/graph.js index 20fa36f53..da9f6068f 100644 --- a/interface/js/app/graph.js +++ b/interface/js/app/graph.js @@ -23,7 +23,7 @@ THE SOFTWARE. */ -define(['jquery', 'd3evolution', 'footable'], +define(["jquery", "d3evolution", "footable"], function($, D3Evolution, unused) { var rrd_pie_config = { header: {}, @@ -148,9 +148,9 @@ function($, D3Evolution, unused) { }; }, []); - document.getElementById('rrd-total-value').innerHTML = total_messages; + document.getElementById("rrd-total-value").innerHTML = total_messages; - $('#rrd-table').footable({ + $("#rrd-table").footable({ sorting: { enabled: true }, @@ -219,8 +219,8 @@ function($, D3Evolution, unused) { neighbours_data.reduce(function (res, curr) { if ((curr[0][0].x !== res[0][0].x) || (curr[0][curr[0].length - 1].x !== res[0][res[0].length - 1].x)) { - rspamd.alertMessage('alert-error', - 'Neighbours time extents do not match. Check if time is synchronized on all servers.'); + rspamd.alertMessage("alert-error", + "Neighbours time extents do not match. Check if time is synchronized on all servers."); updateWidgets(); return; } @@ -244,12 +244,12 @@ function($, D3Evolution, unused) { } }, function (serv, jqXHR, textStatus, errorThrown) { - var alert_status = serv.name + '_alerted'; + var alert_status = serv.name + "_alerted"; if (!(alert_status in sessionStorage)) { sessionStorage.setItem(alert_status, true); - rspamd.alertMessage('alert-error', 'Cannot receive RRD data from: ' + - serv.name + ', error: ' + errorThrown); + rspamd.alertMessage("alert-error", "Cannot receive RRD data from: " + + serv.name + ", error: " + errorThrown); } }, "GET", {}, {}, { type: type @@ -258,22 +258,22 @@ function($, D3Evolution, unused) { } $.ajax({ - dataType: 'json', - type: 'GET', - url: neighbours[checked_server].url + 'graph', + dataType: "json", + type: "GET", + url: neighbours[checked_server].url + "graph", jsonp: false, data: { "type": type }, beforeSend: function (xhr) { - xhr.setRequestHeader('Password', rspamd.getPassword()); + xhr.setRequestHeader("Password", rspamd.getPassword()); }, success: function (data) { updateWidgets(data); }, error: function (jqXHR, textStatus, errorThrown) { - rspamd.alertMessage('alert-error', 'Cannot receive throughput data: ' + - textStatus + ' ' + jqXHR.status + ' ' + errorThrown); + rspamd.alertMessage("alert-error", "Cannot receive throughput data: " + + textStatus + " " + jqXHR.status + " " + errorThrown); } }); }; diff --git a/interface/js/app/history.js b/interface/js/app/history.js index fbae27959..57c37a77c 100644 --- a/interface/js/app/history.js +++ b/interface/js/app/history.js @@ -22,25 +22,25 @@ THE SOFTWARE. */ -define(['jquery', 'footable', 'humanize'], +define(["jquery", "footable", "humanize"], function($, _, Humanize) { var interface = {}; var ft = {}; var htmlEscapes = { - '&': '&', - '<': '<', - '>': '>', - '"': '"', - "'": ''', - '/': '/', - '`': '`', - '=': '=' + "&": "&", + "<": "<", + ">": ">", + "\"": """, + "'": "'", + "/": "/", + "`": "`", + "=": "=" }; var htmlEscaper = /[&<>"'\/`=]/g; var symbolDescriptions = {}; EscapeHTML = function(string) { - return ('' + string).replace(htmlEscaper, function(match) { + return ("" + string).replace(htmlEscaper, function(match) { return htmlEscapes[match]; }); }; @@ -84,11 +84,11 @@ function($, _, Humanize) { } } - if (item.action === 'clean' || item.action === 'no action') { + if (item.action === "clean" || item.action === "no action") { item.action = "
" + item.action + "
"; - } else if (item.action === 'rewrite subject' || item.action === 'add header' || item.action === 'probable spam') { + } else if (item.action === "rewrite subject" || item.action === "add header" || item.action === "probable spam") { item.action = "
" + item.action + "
"; - } else if (item.action === 'spam' || item.action === 'reject') { + } else if (item.action === "spam" || item.action === "reject") { item.action = "
" + item.action + "
"; } else { item.action = "
" + item.action + "
"; @@ -158,16 +158,16 @@ function($, _, Humanize) { var sym = item.symbols[key]; if (sym.description) { - var str = '' + sym.name + '' + "(" + sym.score + ")"; + var str = "" + sym.name + "" + "(" + sym.score + ")"; // Store description for tooltip symbolDescriptions[key] = sym.description; } else { - var str = '' + sym.name + '' + "(" + sym.score + ")"; + var str = "" + sym.name + "" + "(" + sym.score + ")"; } if (sym.options) { - str += '[' + sym.options.join(",") + "]"; + str += "[" + sym.options.join(",") + "]"; } item.symbols[key].str = str; }); @@ -184,7 +184,7 @@ function($, _, Humanize) { "sortValue": item.unix_time } }; - var scan_time = item.time_real.toFixed(3) + ' / ' + + var scan_time = item.time_real.toFixed(3) + " / " + item.time_virtual.toFixed(3); item.scan_time = { "options": { @@ -192,7 +192,7 @@ function($, _, Humanize) { }, "value": scan_time }; - item.id = item['message-id']; + item.id = item["message-id"]; var rcpt = {}; if (!item.rcpt_mime.length) { @@ -487,52 +487,52 @@ function($, _, Humanize) { FooTable.actionFilter = FooTable.Filtering.extend({ construct : function(instance) { this._super(instance); - this.actions = [ 'reject', 'add header', 'greylist', - 'no action', 'soft reject', 'rewrite subject' ]; - this.def = 'Any action'; + this.actions = [ "reject", "add header", "greylist", + "no action", "soft reject", "rewrite subject" ]; + this.def = "Any action"; this.$action = null; }, $create : function() { this._super(); - var self = this, $form_grp = $('
', { - 'class' : 'form-group' - }).append($('