From: Jo-Philipp Wich Date: Wed, 15 Apr 2020 20:18:13 +0000 (+0200) Subject: luci-base: ui.js: use session data api to persist tab selection state X-Git-Url: https://git.librecmc.org/?a=commitdiff_plain;h=51186355ea168dfc6fb1363ace5c57b178f0331e;p=oweals%2Fluci.git luci-base: ui.js: use session data api to persist tab selection state Signed-off-by: Jo-Philipp Wich --- diff --git a/modules/luci-base/htdocs/luci-static/resources/ui.js b/modules/luci-base/htdocs/luci-static/resources/ui.js index 2e4e4ad1c..235f62a98 100644 --- a/modules/luci-base/htdocs/luci-static/resources/ui.js +++ b/modules/luci-base/htdocs/luci-static/resources/ui.js @@ -2,6 +2,7 @@ 'require validation'; 'require baseclass'; 'require request'; +'require session'; 'require poll'; 'require dom'; 'require rpc'; @@ -3463,16 +3464,14 @@ var UI = baseclass.extend(/** @lends LuCI.ui.prototype */ { /** @private */ getActiveTabState: function() { - var page = document.body.getAttribute('data-page'); + var page = document.body.getAttribute('data-page'), + state = session.getLocalData('tab'); - try { - var val = JSON.parse(window.sessionStorage.getItem('tab')); - if (val.page === page && L.isObject(val.paths)) - return val; - } - catch(e) {} + if (L.isObject(state) && state.page === page && L.isObject(state.paths)) + return state; + + session.setLocalData('tab', null); - window.sessionStorage.removeItem('tab'); return { page: page, paths: {} }; }, @@ -3484,17 +3483,12 @@ var UI = baseclass.extend(/** @lends LuCI.ui.prototype */ { /** @private */ setActiveTabId: function(pane, tabIndex) { - var path = this.getPathForPane(pane); + var path = this.getPathForPane(pane), + state = this.getActiveTabState(); - try { - var state = this.getActiveTabState(); - state.paths[path] = tabIndex; - - window.sessionStorage.setItem('tab', JSON.stringify(state)); - } - catch (e) { return false; } + state.paths[path] = tabIndex; - return true; + return session.setLocalData('tab', state); }, /** @private */