]> source.dussan.org Git - rspamd.git/commitdiff
[WebUI] Fix multiple JS issues
authorVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 30 Jan 2017 17:20:26 +0000 (17:20 +0000)
committerVsevolod Stakhov <vsevolod@highsecure.ru>
Mon, 30 Jan 2017 17:20:26 +0000 (17:20 +0000)
interface/js/rspamd.js

index 0b386afb1031e989163aa3d01b971e518c5c2e45..17ed5949034958ca889e49f723b982f52cda7daf 100644 (file)
         }
         // @return password
         function getPassword() {
-          return password = sessionStorage.getItem('Password');
+          return sessionStorage.getItem('Password');
         }
 
         // @detect session storate
         }
 
         function isLogged() {
-            if (sessionStorage.getItem('Credentials') != null) {
+            if (sessionStorage.getItem('Credentials') !== null) {
                 return true;
             }
             return false;
                     $.each(data, function (i, item) {
                         var caption;
                         var label;
-                        if ((item.editable == false || read_only)) {
+                        if ((item.editable === false || read_only)) {
                             caption = 'View';
                             label = '<span class="label label-default">Read</span>';
                         } else {
             });
         }
         // @get map by id
-        function getMapById(mode) {
+        function getMapById() {
             var data = JSON.parse(sessionStorage.getItem('Maps'));
             $('#modalBody').empty();
 
                     },
                     success: function (text) {
                         var disabled = '';
-                        if ((item.editable == false || read_only)) {
+                        if ((item.editable === false || read_only)) {
                             disabled = 'disabled="disabled"';
                         }
 
 
         // @ ms to date
         function msToTime(seconds) {
-             years = seconds / 31536000 >> 0 // 3600*24*365
+             years = seconds / 31536000 >> 0; // 3600*24*365
              months = seconds % 31536000 / 2628000 >> 0; //3600*24*365/12
              days = seconds % 31536000 % 2628000 / 86400 >> 0; //24*3600
              hours = seconds % 31536000 % 2628000 % 86400 / 3600 >> 0;
           $(widgets).empty().hide();
           var servers = JSON.parse(sessionStorage.getItem('Credentials'));
 
-          var data = {}
+          var data = {};
+
           if (servers && servers[checked_server]) {
               data = servers[checked_server].data;
           }
         // Query neighbours and call the specified function at the end,
         // Data received will be pushed inside object:
         // {server1: data, server2: data} and passed to a callback
-        function queryNeighbours(req_url, on_success, on_error) {
+        function queryNeighbours(req_url, on_success, on_error, method, headers, params) {
             $.ajax({
                 dataType: "json",
                 type: "GET",
                     });
                     $.each(neighbours_status, function (ind) {
                         "use strict";
-                        $.ajax({
+                        method = typeof method !== 'undefined' ? method : "GET";
+                        var req_params = {
                             jsonp: false,
                             beforeSend: function (xhr) {
                                 xhr.setRequestHeader("Password", getPassword());
+
+                                if (headers) {
+                                    $.each(headers, function(hname, hvalue){
+                                        xhr.setRequestHeader(hname, hvalue);
+                                    });
+                                }
                             },
                             url: neighbours_status[ind].url + req_url,
                             success: function (data) {
                                 }
                             }
                             //error display
-                        });
+                        };
+                        if (params) {
+                            $.each(params, function(k, v) {
+                                req_params.k = v;
+                            });
+                        }
+                        $.ajax(req_params);
                     });
                 },
                 error: function () {
                 };
                 var status_count = 0;
                 for(var e in neighbours_status) {
-                    if(neighbours_status[e].status == true) {
+                    if(neighbours_status[e].status === true) {
                         // Remove alert status
                         localStorage.removeItem(e + '_alerted');
                         neighbours_sum.clean += neighbours_status[e].data.clean;
                         checked: true,
                         data: neighbours_sum,
                         status: true
-                }
+                };
                 neighbours_status.forEach(function (elmt) {
                     to_Credentials[elmt.name] = elmt;
                 });
             });
         }
 
-        $(document).on('click', 'input:radio[name="clusterName"]', function (e) {
+        $(document).on('click', 'input:radio[name="clusterName"]', function () {
             if (!this.disabled) {
                 checked_server = this.value;
                 tabClick("#status_nav");
         });
 
         // @opem modal with target form enabled
-        $(document).on('click', '[data-toggle="modal"]', function (e) {
+        $(document).on('click', '[data-toggle="modal"]', function () {
             var source = $(this).data('source');
             var editable = $(this).data('editable');
             var title = $(this).data('title');
-            var caption = $('#modalTitle').html(title);
-            var body = $('#modalBody ' + source).show();
+            $('#modalTitle').html(title);
+            $('#modalBody ' + source).show();
             var target = $(this).data('target');
-            var progress = $(target + ' .progress').hide();
+            $(target + ' .progress').hide();
             $(target).modal(show = true, backdrop = true, keyboard = show);
             if (editable === false) {
                 $('#modalSave').hide();
             return false;
         });
         // close modal without saving
-        $(document).on('click', '[data-dismiss="modal"]', function (e) {
+        $(document).on('click', '[data-dismiss="modal"]', function () {
             $('#modalBody form').hide();
         });
 
                 ],
 
                 "fnRowCallback": function (nRow, aData) {
-                    $(nRow).css("color", aData.color)
+                    $(nRow).css("color", aData.color);
                 }
             });
         }
 
         function decimalStep(number) {
             var digits = ((+number).toFixed(20)).replace(/^-?\d*\.?|0+$/g, '').length;
-            if (digits == 0 || digits > 4) {
+            if (digits === 0 || digits > 4) {
                 return 0.1;
             } else {
                 return 1.0 / (Math.pow(10, digits));
                             if (item.weight < min) {
                                 min = item.weight * 2;
                             }
-                            var label;
+                            var label_class = '';
                             if (item.weight < 0) {
                                 label_class = 'scorebar-ham';
                             } else {
                     });
                     symbols.columns.adjust().draw();
                     $('#symbolsTable :button').on('click',
-                        function(){saveSymbols("./savesymbols", "symbolsTable")});
+                        function(){saveSymbols("./savesymbols", "symbolsTable");});
                   if (read_only) {
                     $( ".mb-disabled" ).attr('disabled', true);
                   }
         // @reset history log
         $('#resetHistory').on('click', function () {
             if (!confirm("Are you sure you want to reset history log?")) {
-                return
-            };
+                return;
+            }
             if (history) {
                 history.destroy();
                 $('#historyLog').children('tbody').remove();
                 beforeSend: function (xhr) {
                     xhr.setRequestHeader('Password', getPassword());
                 },
-                success: function (data) {
+                success: function () {
                     getHistory();
                     getErrors();
                 },
 
         // @upload text
         function uploadText(data, source, headers) {
+            var url;
             if (source === 'spam') {
-                var url = 'learnspam';
+                url = 'learnspam';
             } else if (source === 'ham') {
-                var url = 'learnham';
+                url = 'learnham';
             } else if (source == 'fuzzy') {
-                var url = 'fuzzyadd';
+                url = 'fuzzyadd';
             } else if (source === 'scan') {
-                var url = 'scan';
+                url = 'scan';
             }
             $.ajax({
                 data: data,
                     }
                 },
                 error: function (xhr, textStatus, errorThrown) {
+                    var errorMsg;
+
                     try {
                         var json = $.parseJSON(xhr.responseText);
-                        var errorMsg = $('<a>').text(json.error).html();
+                        errorMsg = $('<a>').text(json.error).html();
                     } catch (err) {
-                        var errorMsg = $('<a>').text("Error: [" + textStatus + "] " + errorThrown).html();
+                        errorMsg = $('<a>').text("Error: [" + textStatus + "] " + errorThrown).html();
                     }
                     alertMessage('alert-error', errorMsg);
                 }
                     var data = input['default'];
                     if (data.action) {
                         alertMessage('alert-success', 'Data successfully scanned');
+                        var action = '';
+
                         if (data.action === 'clean' || 'no action') {
-                            var action = 'label-success';
+                            action = 'label-success';
                         }
-                        if (data.action === 'rewrite subject' || 'add header' || 'probable spam') {
-                            var action = 'label-warning';
+                        else if (data.action === 'rewrite subject' || 'add header' || 'probable spam') {
+                            action = 'label-warning';
                         }
-                        if (data.action === 'spam') {
-                            var action = 'label-danger';
+                        else if (data.action === 'spam') {
+                            action = 'label-danger';
                         }
+
+                        var score = '';
                         if (data.score <= data.required_score) {
-                            var score = 'label-success';
+                            score = 'label-success';
                         }
-                        if (data.score >= data.required_score) {
-                            var score = 'label-danger';
+                        else if (data.score >= data.required_score) {
+                            score = 'label-danger';
                         }
                         $('<tbody id="tmpBody"><tr>' +
                                 '<td><span class="label ' + action + '">' + data.action + '</span></td>' +
         }
         // @get acions
         function getActions() {
-            var items = [];
             $.ajax({
                 dataType: 'json',
                 type: 'GET',
                         '<br><div class="form-group">' +
                         '<button class="btn btn-primary" type="submit">Save actions</button></div></fieldset></form>');
                     if (read_only) {
-                      $('#actionsFormField').attr('disabled', true)
+                      $('#actionsFormField').attr('disabled', true);
                     }
                 }
             });
             });
             return false;
         });
-        // @catch changes of file upload form
-        $(window).resize(function (e) {
-            var form = $(this).attr('id');
-            var height = $(form).height();
-        });
         // @watch textarea changes
         $('textarea').change(function () {
-            if ($(this).val().length != '') {
+            if ($(this).val().length !== '') {
                 $(this).closest('form').find('button').removeAttr('disabled').removeClass('disabled');
             } else {
                 $(this).closest('form').find('button').attr('disabled').addClass('disabled');
             // var type = $(form).data('type');
             var action = $(form).attr('action');
             var id = $(form).attr('id');
-            var type = $(form).data('type');
-            if (type === 'symbols') {
-                saveSymbols(action, id);
-            } else if (type === 'map') {
-                saveMap(action, id);
-            }
+            saveMap(action, id);
+        });
+        $(document).on('click', '#modalSaveAll', function () {
+            var form = $('#modalBody').children().filter(':visible');
+            // var map = $(form).data('map');
+            // var type = $(form).data('type');
+            var action = $(form).attr('action');
+            var id = $(form).attr('id');
+            saveMap(action, id);
         });
         // @upload map from modal
         function saveMap(action, id) {
                 error: function (data) {
                     alertMessage('alert-modal alert-error', data.statusText);
                 },
-                success: function (data) {
+                success: function () {
                     alertMessage('alert-modal alert-success', 'Map data successfully saved');
                     $('#modalDialog').modal('hide');
                 }
                 return;
             }
 
-            var nav = $('#navBar');
             var ui = $('#mainUI');
             var dialog = $('#connectDialog');
             var backdrop = $('#backDrop');
-            var disconnect = $('#navBar .pull-right');
             $(ui).hide();
             $(dialog).show();
             $(backdrop).show();
         $.ajaxSetup({
             timeout: 2000,
             jsonp: false
-        })
+        });
         connectRSPAMD();
 
         $(document).ajaxStart(function () {
         });
 
         $('a[data-toggle="tab"]').on('click', function (e) {
-            const tab_id = "#" + $(e.target).attr("id")
+            const tab_id = "#" + $(e.target).attr("id");
             tabClick(tab_id);
         });
     });