]> source.dussan.org Git - rspamd.git/commitdiff
[WebUI] Fix disabling and hiding controls on page reload 2421/head
authorAlexander Moisseev <moiseev@mezonplus.ru>
Wed, 15 Aug 2018 10:28:17 +0000 (13:28 +0300)
committerAlexander Moisseev <moiseev@mezonplus.ru>
Wed, 15 Aug 2018 10:28:17 +0000 (13:28 +0300)
interface/index.html
interface/js/app/rspamd.js
interface/js/app/stats.js

index 1b36776463046c0a136a4e57952633e2ebe0c2c7..a10af453fa8f20d213d8c2de9225aec4ebb65a20 100644 (file)
@@ -30,7 +30,7 @@
 
                        <li role="presentation"><a id="configuration_nav" aria-controls="configuration" role="tab" href="#configuration" data-toggle="tab">Configuration</a></li>
                        <li role="presentation"><a id="symbols_nav" aria-controls="symbols" role="tab" href="#symbols" data-toggle="tab">Symbols</a></li>
-                       <li role="presentation"><a id="learning_nav" aria-controls="learning" role="tab" href="#learning" data-toggle="tab">Learning</a></li>
+                       <li role="presentation"><a id="learning_nav" aria-controls="learning" role="tab" href="#learning" data-toggle="tab" style="display: none;">Learning</a></li>
                        <li role="presentation"><a id="scan_nav" aria-controls="scan" role="tab" href="#scan" data-toggle="tab">Scan</a></li>
                        <li role="presentation"><a id="history_nav" aria-controls="history" role="tab" href="#history" data-toggle="tab">History</a></li>
                </ul>
index 70f6fbfd5a247e3ab11c0c59a321b0a938a9c199..06d9a46f9c8d348e692f65e6dc495f23c05a4110 100644 (file)
@@ -35,10 +35,7 @@ function ($, d3pie, visibility, tab_stat, tab_graph, tab_config,
     var tables = {};
     var neighbours = []; // list of clusters
     var checked_server = "All SERVERS";
-    var ui = {
-        read_only: false,
-    };
-
+    var ui = {};
     var timer_id = [];
     var selData; // Graph's dataset selector state
 
@@ -158,7 +155,18 @@ function ($, d3pie, visibility, tab_stat, tab_graph, tab_config,
     }
 
     function displayUI() {
-        // @toggle auth and main
+        // In many browsers local storage can only store string.
+        // So when we store the boolean true or false, it actually stores the strings "true" or "false".
+        ui.read_only = sessionStorage.getItem("read_only") === "true";
+        if (ui.read_only) {
+            $("#learning_nav").hide();
+            $("#resetHistory").attr("disabled", true);
+            $("#errors-history").hide();
+        } else {
+            $("#learning_nav").show();
+            $("#resetHistory").removeAttr("disabled", true);
+        }
+
         var buttons = $("#navBar .pull-right");
         $("#mainUI").show();
         $("#progress").show();
@@ -294,18 +302,6 @@ function ($, d3pie, visibility, tab_stat, tab_graph, tab_config,
 
     ui.connect = function () {
         if (isLogged()) {
-            var data = JSON.parse(sessionStorage.getItem("Credentials"));
-
-            if (data && data[checked_server].read_only) {
-                ui.read_only = true;
-                $("#learning_nav").hide();
-                $("#resetHistory").attr("disabled", true);
-                $("#errors-history").hide();
-            } else {
-                ui.read_only = false;
-                $("#learning_nav").show();
-                $("#resetHistory").removeAttr("disabled", true);
-            }
             displayUI();
             return;
         }
@@ -341,17 +337,7 @@ function ($, d3pie, visibility, tab_stat, tab_graph, tab_config,
                     if (json.auth === "failed") {
                         // Is actually never returned by Rspamd
                     } else {
-                        if (json.read_only) {
-                            ui.read_only = true;
-                            $("#learning_nav").hide();
-                            $("#resetHistory").attr("disabled", true);
-                            $("#errors-history").hide();
-                        } else {
-                            ui.read_only = false;
-                            $("#learning_nav").show();
-                            $("#resetHistory").removeAttr("disabled", true);
-                        }
-
+                        sessionStorage.setItem("read_only", json.read_only);
                         saveCredentials(password);
                         $(dialog).hide();
                         $(backdrop).hide();
index e4020626659569cce6b76f1730e88a31905d3024..ea8edfd8a0d7aad408dd8f2ad879dc5cd495f11b 100644 (file)
@@ -184,7 +184,6 @@ define(["jquery", "d3pie", "humanize"],
                             soft_reject: 0,
                             scanned: 0,
                             learned: 0,
-                            read_only: neighbours_status[0].data.read_only,
                             config_id: ""
                         };
                         var status_count = 0;