From: Alexander Moisseev Date: Wed, 15 Aug 2018 10:28:17 +0000 (+0300) Subject: [WebUI] Fix disabling and hiding controls on page reload X-Git-Tag: 1.8.0~258^2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=refs%2Fpull%2F2421%2Fhead;p=rspamd.git [WebUI] Fix disabling and hiding controls on page reload --- diff --git a/interface/index.html b/interface/index.html index 1b3677646..a10af453f 100644 --- a/interface/index.html +++ b/interface/index.html @@ -30,7 +30,7 @@
  • Configuration
  • Symbols
  • -
  • Learning
  • +
  • Scan
  • History
  • diff --git a/interface/js/app/rspamd.js b/interface/js/app/rspamd.js index 70f6fbfd5..06d9a46f9 100644 --- a/interface/js/app/rspamd.js +++ b/interface/js/app/rspamd.js @@ -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(); diff --git a/interface/js/app/stats.js b/interface/js/app/stats.js index e40206266..ea8edfd8a 100644 --- a/interface/js/app/stats.js +++ b/interface/js/app/stats.js @@ -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;