]> source.dussan.org Git - rspamd.git/commitdiff
[WebUI] Use unified tab click event handler, 1294/head
authorAlexander Moisseev <moiseev@mezonplus.ru>
Sat, 31 Dec 2016 17:58:07 +0000 (20:58 +0300)
committerAlexander Moisseev <moiseev@mezonplus.ru>
Sat, 31 Dec 2016 18:14:36 +0000 (21:14 +0300)
stop refreshing widgets on hidden tabs,
make `refresh` button functional for some more tabs

interface/js/rspamd.js

index 6f3fc5040c8ed3bc9e689181f8eb7f86f50c817e..2ea7eeca761d29023f8cbed5738d7dd300b5fcf0 100644 (file)
@@ -51,7 +51,7 @@
             graph.interpolate(this.value);
         });
 
-        $('#disconnect').on('click', function (event) {
+        function disconnect() {
             if (pie) {
                 pie.destroy();
             }
             connectRSPAMD();
             // window.location.reload();
             return false;
-        });
-        $('#refresh').on('click', function (event) {
-            if (!$(this).attr('disabled')) {
-                $(this).attr('disabled', true);
-                Visibility.stop(stat_timeout);
+        }
 
-                statWidgets();
-                stat_timeout = Visibility.every(10000, function () {
-                    statWidgets();
-                });
-                getChart();
-                getGraphData(selected.selData);
+        function tabClick(tab_id) {
+            if ($(tab_id).attr('disabled')) return;
+            $(tab_id).attr('disabled', true);
 
-                setTimeout(function () {
-                    $('#refresh').removeAttr('disabled');
-                }, 1000);
+            Visibility.stop(stat_timeout);
+
+            if (tab_id === "#refresh") {
+                tab_id = "#" + $('.navbar-nav .active > a' ).attr('id');
             }
-        });
+
+            switch (tab_id) {
+                case "#status_nav":
+                    statWidgets();
+                    stat_timeout = Visibility.every(10000, function () {
+                        statWidgets();
+                    });
+                    getChart();
+                    break;
+                case "#throughput_nav":
+                    getGraphData(selected.selData);
+                    break;
+                case "#configuration_nav":
+                    getActions();
+                    $('#modalBody').empty();
+                    getMaps();
+                    break;
+                case "#symbols_nav":
+                    getSymbols();
+                    break;
+                case "#history_nav":
+                    getHistory();
+                    getErrors();
+                    break;
+                case "#disconnect":
+                    disconnect();
+                    break;
+            }
+
+            setTimeout(function () {
+                $(tab_id).removeAttr('disabled');
+                $('#refresh').removeAttr('disabled');
+            }, 1000);
+        }
+
         // @supports session storage
         function supportsSessionStorage() {
             return typeof (Storage) !== "undefined";
         function displayUI() {
             // @toggle auth and main
             var disconnect = $('#navBar .pull-right');
-            statWidgets();
-            stat_timeout = Visibility.every(10000, function () {
-                statWidgets();
-            });
             $('#mainUI').show();
             $('#progress').show();
 
-            getChart();
             initGraph();
-            if ($("#throughput_nav").attr("aria-expanded") === "true") {
-                getGraphData(selected.selData);
-            }
+            tabClick("#refresh");
 
             $('#progress').hide();
             $(disconnect).show();
 
         connectRSPAMD();
 
-        $('#configuration_nav').bind('click', function (e) {
-            getActions();
-            $('#modalBody').empty();
-            getMaps();
-        });
-
         $(document).ajaxStart(function () {
             $('#navBar').addClass('loading');
         });
                 $('#navBar').removeClass('loading');
             }, 1000);
         });
-        $('#status_nav').bind('click', function (e) {
-            getChart();
-        });
-        $('#throughput_nav').bind('click', function () {
-            getGraphData(selected.selData);
-        });
-        $('#history_nav').bind('click', function () {
-            getHistory();
-            getErrors();
-        });
-        $('#symbols_nav').bind('click', function () {
-            getSymbols();
+
+        $('a[data-toggle="tab"]').on('click', function (e) {
+            const tab_id = "#" + $(e.target).attr("id")
+            tabClick(tab_id);
         });
     });
 })();