summaryrefslogtreecommitdiff
path: root/js/PrefFeedTree.js
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2021-02-13 18:32:02 +0300
committerAndrew Dolgov <[email protected]>2021-02-13 18:32:02 +0300
commit17413078a72e1298c6dc8953c40e8d83ce38c49c (patch)
tree3951793b50ded20a5b15cf78b1727e787c014ad2 /js/PrefFeedTree.js
parent9684ce5c4b94c21002209f88c26f5ead94406198 (diff)
pref feeds: index cleanup, split into several methods, use tabs to maximize space for feed tree, persist feed tree state
Diffstat (limited to 'js/PrefFeedTree.js')
-rw-r--r--js/PrefFeedTree.js37
1 files changed, 36 insertions, 1 deletions
diff --git a/js/PrefFeedTree.js b/js/PrefFeedTree.js
index 89195e616..7684c7f9d 100644
--- a/js/PrefFeedTree.js
+++ b/js/PrefFeedTree.js
@@ -1,9 +1,44 @@
/* eslint-disable prefer-rest-params */
/* global __, lib, dijit, define, dojo, CommonDialogs, Notify, Tables, xhrPost, fox, App */
-define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree"], function (declare, domConstruct) {
+define(["dojo/_base/declare", "dojo/dom-construct", "lib/CheckBoxTree", "dojo/_base/array", "dojo/cookie"],
+ function (declare, domConstruct, checkBoxTree, array, cookie) {
return declare("fox.PrefFeedTree", lib.CheckBoxTree, {
+ // save state in localStorage instead of cookies
+ // reference: https://stackoverflow.com/a/27968996
+ _saveExpandedNodes: function(){
+ if (this.persist && this.cookieName){
+ const ary = [];
+ for (const id in this._openedNodes){
+ ary.push(id);
+ }
+ // Was:
+ // cookie(this.cookieName, ary.join(","), {expires: 365});
+ localStorage.setItem(this.cookieName, ary.join(","));
+ }
+ },
+ _initState: function(){
+ this.cookieName = 'prefs:' + this.cookieName;
+ // summary:
+ // Load in which nodes should be opened automatically
+ this._openedNodes = {};
+ if (this.persist && this.cookieName){
+ // Was:
+ // var oreo = cookie(this.cookieName);
+ let oreo = localStorage.getItem(this.cookieName);
+ // migrate old data if nothing in localStorage
+ if (oreo == null || oreo === '') {
+ oreo = cookie(this.cookieName);
+ cookie(this.cookieName, null, { expires: -1 });
+ }
+ if (oreo){
+ array.forEach(oreo.split(','), function(item){
+ this._openedNodes[item] = true;
+ }, this);
+ }
+ }
+ },
_createTreeNode: function(args) {
const tnode = this.inherited(arguments);