From: Andrew Dolgov Date: Wed, 17 Nov 2010 19:51:44 +0000 (+0300) Subject: add FeedTree X-Git-Tag: 1.5.0~163 X-Git-Url: https://git.wh0rd.org/?a=commitdiff_plain;h=05f224a3d706aa32e504d23823e91c0ef7b36aa3;p=tt-rss.git add FeedTree --- diff --git a/FeedTree.js b/FeedTree.js new file mode 100644 index 00000000..d0da80c8 --- /dev/null +++ b/FeedTree.js @@ -0,0 +1,170 @@ +dojo.provide("fox.FeedTree"); +dojo.provide("fox.FeedStoreModel"); + +dojo.require("dijit.Tree"); + +dojo.declare("fox.FeedStoreModel", dijit.tree.ForestStoreModel, { + getItemById: function(id) { + return this.store._itemsByIdentity[id]; + }, + getFeedValue: function(feed, is_cat, key) { + if (is_cat) + treeItem = this.store._itemsByIdentity['CAT:' + feed]; + else + treeItem = this.store._itemsByIdentity['FEED:' + feed]; + + if (treeItem) + return this.store.getValue(treeItem, key); + }, + getFeedName: function(feed, is_cat) { + return this.getFeedValue(feed, is_cat, 'name'); + }, + getFeedUnread: function(feed, is_cat) { + var unread = parseInt(this.getFeedValue(feed, is_cat, 'unread')); + return (isNaN(unread)) ? 0 : unread; + }, + setFeedUnread: function(feed, is_cat, unread) { + return this.setFeedValue(feed, is_cat, 'unread', parseInt(unread)); + }, + setFeedValue: function(feed, is_cat, key, value) { + if (!value) value = ''; + + if (is_cat) + treeItem = this.store._itemsByIdentity['CAT:' + feed]; + else + treeItem = this.store._itemsByIdentity['FEED:' + feed]; + + if (treeItem) + return this.store.setValue(treeItem, key, value); + }, +}); + +dojo.declare("fox.FeedTree", dijit.Tree, { + _createTreeNode: function(args) { + var tnode = new dijit._TreeNode(args); + + if (args.item.icon) + tnode.iconNode.src = args.item.icon[0]; + + //tnode.labelNode.innerHTML = args.label; + return tnode; + }, + getIconClass: function (item, opened) { + return (!item || this.model.mayHaveChildren(item)) ? (opened ? "dijitFolderOpened" : "dijitFolderClosed") : "feedIcon"; + }, + getLabelClass: function (item, opened) { + return (item.unread == 0) ? "dijitTreeLabel" : "dijitTreeLabel Unread"; + }, + getRowClass: function (item, opened) { + return (!item.error || item.error == '') ? "dijitTreeRow" : + "dijitTreeRow Error"; + }, + getLabel: function(item) { + if (item.unread > 0) { + return item.name + " (" + item.unread + ")"; + } else { + return item.name; + } + }, + selectFeed: function(feed, is_cat) { + if (is_cat) + treeNode = this._itemNodesMap['CAT:' + feed]; + else + treeNode = this._itemNodesMap['FEED:' + feed]; + + if (treeNode) { + treeNode = treeNode[0]; + if (!is_cat) this._expandNode(treeNode); + this._selectNode(treeNode); + } + }, + setFeedIcon: function(feed, is_cat, src) { + if (is_cat) + treeNode = this._itemNodesMap['CAT:' + feed]; + else + treeNode = this._itemNodesMap['FEED:' + feed]; + + if (treeNode) { + treeNode = treeNode[0]; + treeNode.iconNode.src = src; + return true; + } + return false; + }, + setFeedExpandoIcon: function(feed, is_cat, src) { + if (is_cat) + treeNode = this._itemNodesMap['CAT:' + feed]; + else + treeNode = this._itemNodesMap['FEED:' + feed]; + + if (treeNode) { + treeNode = treeNode[0]; + treeNode.expandoNode.src = src; + return true; + } + + return false; + }, + hasCats: function() { + if (this.model.store && this.model.store._itemsByIdentity) + return this.model.store._itemsByIdentity['CAT:-1'] != undefined; + else + return false; + }, + hideRead: function (hide, show_special) { + if (this.hasCats()) { + + var tree = this; + var cats = this.model.store._arrayOfTopLevelItems; + + cats.each(function(cat) { + var cat_unread = tree.hideReadFeeds(cat.items, hide, show_special); + + var id = String(cat.id); + var node = tree._itemNodesMap[id]; + var bare_id = parseInt(id.substr(id.indexOf(":")+1)); + + if (node) { + var check_unread = tree.model.getFeedUnread(bare_id, true); + + if (hide && cat_unread == 0 && check_unread == 0) { + Effect.Fade(node[0].rowNode, {duration : 0.3, + queue: { position: 'end', scope: 'FFADE-' + id, limit: 1 }}); + } else { + Element.show(node[0].rowNode); + ++cat_unread; + } + } + }); + console.log(this); + + } else { + this.hideReadFeeds(this.model.store._arrayOfTopLevelItems, hide, + show_special); + } + }, + hideReadFeeds: function (items, hide, show_special) { + var tree = this; + var cat_unread = 0; + + items.each(function(feed) { + var id = String(feed.id); + var bare_id = parseInt(feed.bare_id);; + + var unread = feed.unread[0]; + var node = tree._itemNodesMap[id]; + + if (node) { + if (hide && unread == 0 && (bare_id > 0 || !show_special)) { + Effect.Fade(node[0].rowNode, {duration : 0.3, + queue: { position: 'end', scope: 'FFADE-' + id, limit: 1 }}); + } else { + Element.show(node[0].rowNode); + ++cat_unread; + } + } + }); + + return cat_unread; + }, +}); diff --git a/feedlist.js b/feedlist.js index 607b13d5..e96aa63d 100644 --- a/feedlist.js +++ b/feedlist.js @@ -367,70 +367,8 @@ function resort_feedlist() { function hideOrShowFeeds(hide) { var tree = dijit.byId("feedTree"); - if (!tree) return; - - if (getInitParam("enable_feed_cats")) { - - var cats = tree.model.store._arrayOfTopLevelItems; - - cats.each(function(cat) { - var cat_unread = hideOrShowFeedsCategory(cat.items, hide); - - var id = String(cat.id); - var node = tree._itemNodesMap[id]; - var bare_id = parseInt(id.substr(id.indexOf(":")+1)); - - if (node) { - var check_unread = getFeedUnread(bare_id, true); - - if (hide && cat_unread == 0 && check_unread == 0) { - Effect.Fade(node[0].rowNode, {duration : 0.3, - queue: { position: 'end', scope: 'FFADE-' + id, limit: 1 }}); - } else { - Element.show(node[0].rowNode); - ++cat_unread; - } - } - - }); - - } else { - hideOrShowFeedsCategory(tree.model.store._arrayOfTopLevelItems, hide); - } -} - -function hideOrShowFeedsCategory(feeds, hide) { - try { - - var tree = dijit.byId("feedTree"); - - if (!tree) return; - - var cat_unread = 0; - - feeds.each(function(feed) { - var id = String(feed.id); - var bare_id = parseInt(id.substr(id.indexOf(":")+1)); - - var unread = feed.unread[0]; - var node = tree._itemNodesMap[id]; - - if (node) { - if (hide && unread == 0 && (bare_id > 0 || !getInitParam("hide_read_shows_special"))) { - Effect.Fade(node[0].rowNode, {duration : 0.3, - queue: { position: 'end', scope: 'FFADE-' + id, limit: 1 }}); - } else { - Element.show(node[0].rowNode); - ++cat_unread; - } - } - }); - - return cat_unread; - - } catch (e) { - exception_error("hideOrShowFeedsCategory", e); - } + if (tree) + return tree.hideRead(hide, getInitParam("hide_read_shows_special")); } function getFeedName(feed, is_cat) { @@ -481,10 +419,6 @@ function setFeedValue(feed, is_cat, key, value) { } } -function toggleCollapseCat(id) { - console.warn("toggleCollapseCat: function not implemented"); -} - function selectFeed(feed, is_cat) { try { var tree = dijit.byId("feedTree"); diff --git a/tt-rss.js b/tt-rss.js index 47ccf415..b9e93e1b 100644 --- a/tt-rss.js +++ b/tt-rss.js @@ -75,7 +75,7 @@ function updateFeedList() { var store = new dojo.data.ItemFileWriteStore({ url: "backend.php?op=feeds"}); - treeModel = new dijit.tree.ForestStoreModel({ + treeModel = new fox.FeedStoreModel({ store: store, query: { "type": "feed" @@ -85,34 +85,8 @@ function updateFeedList() { childrenAttrs: ["items"] }); - var tree = new dijit.Tree({ + var tree = new fox.FeedTree({ model: treeModel, - _createTreeNode: function(args) { - var tnode = new dijit._TreeNode(args); - - if (args.item.icon) - tnode.iconNode.src = args.item.icon[0]; - - //tnode.labelNode.innerHTML = args.label; - return tnode; - }, - getIconClass: function (item, opened) { - return (!item || this.model.mayHaveChildren(item)) ? (opened ? "dijitFolderOpened" : "dijitFolderClosed") : "feedIcon"; - }, - getLabelClass: function (item, opened) { - return (item.unread == 0) ? "dijitTreeLabel" : "dijitTreeLabel Unread"; - }, - getRowClass: function (item, opened) { - return (!item.error || item.error == '') ? "dijitTreeRow" : - "dijitTreeRow Error"; - }, - getLabel: function(item) { - if (item.unread > 0) { - return item.name + " (" + item.unread + ")"; - } else { - return item.name; - } - }, onOpen: function (item, node) { var id = String(item.id); var cat_id = id.substr(id.indexOf(":")+1); @@ -283,6 +257,10 @@ function init() { dojo.require("dijit.Toolbar"); dojo.require("dojo.parser"); + dojo.registerModulePath("fox", "../.."); + + dojo.require("fox.FeedTree"); + if (typeof themeBeforeLayout == 'function') { themeBeforeLayout(); } @@ -446,10 +424,11 @@ function toggleDispRead() { var query = "?op=rpc&subop=setpref&key=HIDE_READ_FEEDS&value=" + param_escape(hide); + setInitParam("hide_read_feeds", hide); + new Ajax.Request("backend.php", { parameters: query, onComplete: function(transport) { - setInitParam("hide_read_feeds", hide); } }); } catch (e) {