From 3eb97904d4e9b131e19153d48bd414b8749b3337 Mon Sep 17 00:00:00 2001 From: Vsevolod Stakhov Date: Tue, 1 Nov 2016 11:25:12 +0000 Subject: [WebUI] Further rework of symbols scores --- interface/js/rspamd.js | 313 ++++++++++++++++++++++++++++--------------------- 1 file changed, 181 insertions(+), 132 deletions(-) (limited to 'interface/js') diff --git a/interface/js/rspamd.js b/interface/js/rspamd.js index 7cd267da1..15aa47b7c 100644 --- a/interface/js/rspamd.js +++ b/interface/js/rspamd.js @@ -75,26 +75,24 @@ }); // @supports session storage function supportsSessionStorage() { - return typeof(Storage) !== "undefined"; + return typeof (Storage) !== "undefined"; } // @return password function getPassword() { if (sessionState()) { if (!supportsSessionStorage()) { return password = $.cookie('rspamdpasswd'); - } - else { + } else { return password = sessionStorage.getItem('Password'); } } } // @return session state function sessionState() { - if ((supportsSessionStorage() && (sessionStorage.getItem('Password') !== null)) - || (!supportsSessionStorage() && ($.cookie('rspamdsession')) !== null)) { + if ((supportsSessionStorage() && (sessionStorage.getItem('Password') !== null)) || + (!supportsSessionStorage() && ($.cookie('rspamdsession')) !== null)) { return true; - } - else { + } else { return false; } } @@ -135,10 +133,17 @@ // @save credentials function saveCredentials(data, password) { if (!supportsSessionStorage()) { - $.cookie('rspamdsession', data, { expires: 1 }, { path: '/' }); - $.cookie('rspamdpasswd', password, { expires: 1 }, { path: '/' }); - } - else { + $.cookie('rspamdsession', data, { + expires: 1 + }, { + path: '/' + }); + $.cookie('rspamdpasswd', password, { + expires: 1 + }, { + path: '/' + }); + } else { sessionStorage.setItem('Password', password); sessionStorage.setItem('Credentials', JSON.stringify(data)); } @@ -147,17 +152,19 @@ function saveActions(data) { if (!supportsSessionStorage()) { $.cookie('rspamdactions', data); - } - else { + } else { sessionStorage.setItem('Actions', JSON.stringify(data)); } } // @update credentials function saveMaps(data) { if (!supportsSessionStorage()) { - $.cookie('rspamdmaps', data, { expires: 1 }, { path: '/' }); - } - else { + $.cookie('rspamdmaps', data, { + expires: 1 + }, { + path: '/' + }); + } else { sessionStorage.setItem('Maps', JSON.stringify(data)); } } @@ -167,8 +174,7 @@ $.removeCookie('rspamdlogged'); $.removeCookie('rspamdsession'); $.removeCookie('rspamdpasswd'); - } - else { + } else { sessionStorage.clear(); } $('#statWidgets').empty(); @@ -178,13 +184,13 @@ $('#symbolsTable tbody').remove(); password = ''; } + function isLogged() { if (!supportsSessionStorage()) { if ($.cookie('rspamdpasswd') != null) { return true; } - } - else { + } else { if (sessionStorage.getItem('Password') != null) { return true; } @@ -197,8 +203,8 @@ $(alert).hide().remove(); } var alert = $(''); + nsym++; } }); - $('', { id: 'tmpSymbols', html: items.join('') }).appendTo('#scanResult'); + $('', { + 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) { + $.each(sym_desc, function (k, v) { $('#' + k).tooltip({ "placement": "bottom", "title": v @@ -851,8 +899,7 @@ $('html, body').animate({ scrollTop: $('#scanResult').offset().top }, 1000); - } - else { + } else { alertMessage('alert-error', 'Cannot scan data'); } }, @@ -892,15 +939,13 @@ //To access the proper headers.flag = $('#fuzzyFlagText').val(); headers.weigth = $('#fuzzyWeightText').val(); - } - else { + } else { data = $('#' + source + 'TextSource').val(); } if (data.length > 0) { if (source == 'scan') { scanText(data); - } - else { + } else { uploadText(data, source, headers); } } @@ -934,21 +979,19 @@ if (item.action === 'add header') { label = 'Probably Spam'; idx = 1; - } - else if (item.action === 'greylist') { + } else if (item.action === 'greylist') { label = 'Greylist'; idx = 0; - } - else if (item.action === 'rewrite subject') { + } else if (item.action === 'rewrite subject') { label = 'Rewrite subject'; idx = 2; - } - else if (item.action === 'reject') { + } else if (item.action === 'reject') { label = 'Spam'; idx = 3; } if (idx >= 0) { - items.push({idx: idx, + items.push({ + idx: idx, html: '
' + '' + '
' + @@ -965,10 +1008,14 @@ } }); - items.sort(function(a, b) { return a.idx - b.idx; }); + items.sort(function (a, b) { + return a.idx - b.idx; + }); $('#actionsBody').html('' + - items.map(function(e) { return e.html; }).join('') + + items.map(function (e) { + return e.html; + }).join('') + '
' + '
'); @@ -1012,8 +1059,7 @@ $('textarea').change(function () { if ($(this).val().length != '') { $(this).closest('form').find('button').removeAttr('disabled').removeClass('disabled'); - } - else { + } else { $(this).closest('form').find('button').attr('disabled').addClass('disabled'); } }); @@ -1027,8 +1073,7 @@ var type = $(form).data('type'); if (type === 'symbols') { saveSymbols(action, id); - } - else if (type === 'map') { + } else if (type === 'map') { saveMap(action, id); } }); @@ -1061,7 +1106,10 @@ var url = action; var values = []; $(inputs).each(function () { - values.push({ name: $(this).attr('id'), value: parseFloat($(this).val()) }); + values.push({ + name: $(this).attr('id').substring(5), + value: parseFloat($(this).val()) + }); }); $.ajax({ data: JSON.stringify(values), @@ -1077,7 +1125,8 @@ }, error: function (data) { alertMessage('alert-modal alert-error', data.statusText); - } }); + } + }); $('#modalDialog').modal('hide'); return false; } @@ -1125,8 +1174,7 @@ $(form).each(function () { $('.form-group').addClass('error'); }); - } - else { + } else { saveCredentials(data, password); $(dialog).hide(); $(backdrop).hide(); @@ -1139,6 +1187,7 @@ }); }); } + function displayUI() { // @toggle auth and main var disconnect = $('#navBar .pull-right'); @@ -1171,10 +1220,10 @@ $('#throughput_nav').bind('click', function () { getGraphData(selected.selData); }); - $('#history_nav').bind('click', function() { + $('#history_nav').bind('click', function () { getHistory(); }); - $('#symbols_nav').bind('click', function() { + $('#symbols_nav').bind('click', function () { getSymbols(); }); }); -- cgit v1.2.3