luci-base: ui.js: use session data api to persist tab selection state
authorJo-Philipp Wich <jo@mein.io>
Wed, 15 Apr 2020 20:18:13 +0000 (22:18 +0200)
committerJo-Philipp Wich <jo@mein.io>
Thu, 16 Apr 2020 11:30:35 +0000 (13:30 +0200)
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
modules/luci-base/htdocs/luci-static/resources/ui.js

index 2e4e4ad1c491517c3b9fc1ee0f57f62fc0b582a0..235f62a98db0a5aa99989bb7db51a56234892696 100644 (file)
@@ -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 */