From 2196b517cd16683db12cca7c7a6da3e4a0a755ca Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 26 Mar 2013 16:31:36 +0400 Subject: [PATCH] manually find and expand all parent nodes of a selected feed in feedTree because dojo is incapable of doing it itself in a situation where tree persistence cookie is at initial state, bloody fucking hell --- js/FeedTree.js | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++ js/feedlist.js | 2 ++ 2 files changed, 58 insertions(+) diff --git a/js/FeedTree.js b/js/FeedTree.js index 2e686c156..e0b068f17 100644 --- a/js/FeedTree.js +++ b/js/FeedTree.js @@ -218,7 +218,63 @@ dojo.declare("fox.FeedTree", dijit.Tree, { return label; }, + expandParentNodes: function(feed, is_cat, list) { + try { + for (var i = 0; i < list.length; i++) { + var id = String(list[i].id); + var item = this._itemNodesMap[id]; + + if (item) { + item = item[0]; + this._expandNode(item); + } + } + } catch (e) { + exception_error("expandParentNodes", e); + } + }, + findNodeParentsAndExpandThem: function(feed, is_cat, root, parents) { + // expands all parents of specified feed to properly mark it as active + // my fav thing about frameworks is doing everything myself + try { + var test_id = is_cat ? 'CAT:' + feed : 'FEED:' + feed; + + if (!root) { + if (!this.model || !this.model.store) return false; + + var items = this.model.store._arrayOfTopLevelItems; + + for (var i = 0; i < items.length; i++) { + if (String(items[i].id) == test_id) { + this.expandParentNodes(feed, is_cat, parents); + } else { + this.findNodeParentsAndExpandThem(feed, is_cat, items[i], []); + } + } + } else { + if (root.items) { + parents.push(root); + + for (var i = 0; i < root.items.length; i++) { + if (String(root.items[i].id) == test_id) { + this.expandParentNodes(feed, is_cat, parents); + } else { + this.findNodeParentsAndExpandThem(feed, is_cat, root.items[i], parents); + } + } + } else { + if (String(root.id) == test_id) { + this.expandParentNodes(feed, is_cat, parents); + } + } + } + } catch (e) { + exception_error("findNodeParentsAndExpandThem", e); + } + }, selectFeed: function(feed, is_cat) { + this.findNodeParentsAndExpandThem(feed, is_cat, false, false); + if (is_cat) treeNode = this._itemNodesMap['CAT:' + feed]; else diff --git a/js/feedlist.js b/js/feedlist.js index aaf6c2aa6..7385177d1 100644 --- a/js/feedlist.js +++ b/js/feedlist.js @@ -513,3 +513,5 @@ function decrementFeedCounter(feed, is_cat) { exception_error("decrement_feed_counter", e); } } + +