]> git.wh0rd.org - tt-rss.git/blobdiff - FeedTree.js
refactor feed edit dialog
[tt-rss.git] / FeedTree.js
index f01fd24cf0dddf56c1dd812283fd58412600436a..93ccf002505b734a13f9c90e69162587b5d36026 100644 (file)
@@ -5,6 +5,17 @@ dojo.require("dijit.Tree");
 dojo.require("dijit.Menu");
 
 dojo.declare("fox.FeedStoreModel", dijit.tree.ForestStoreModel, {
+       getItemsInCategory: function (id) {
+               if (!this.store._itemsByIdentity) return undefined;
+
+               cat = this.store._itemsByIdentity['CAT:' + id];
+
+               if (cat && cat.items)
+                       return cat.items;
+               else
+                       return undefined;
+
+       },
        getItemById: function(id) {
                return this.store._itemsByIdentity[id];
        },
@@ -41,6 +52,42 @@ dojo.declare("fox.FeedStoreModel", dijit.tree.ForestStoreModel, {
                if (treeItem)
                        return this.store.setValue(treeItem, key, value);
        },
+       getNextUnreadFeed: function (feed, is_cat) {
+               if (is_cat) {
+                       treeItem = this.store._itemsByIdentity['CAT:' + feed];
+                       items = this.store._arrayOfTopLevelItems;
+               } else {
+                       treeItem = this.store._itemsByIdentity['FEED:' + feed];
+                       items = this.store._arrayOfAllItems;
+               }
+
+               for (var i = 0; i < items.length; i++) {
+                       if (items[i] == treeItem) {
+
+                               for (j = i+1; j < items.length; j++) {
+                                       var unread = this.store.getValue(items[j], 'unread');
+                                       var id = this.store.getValue(items[j], 'id');
+
+                                       if (unread > 0 && (is_cat || id.match("FEED:"))) return items[j];
+                               }
+
+                               for (j = 0; j < i; j++) {
+                                       var unread = this.store.getValue(items[j], 'unread');
+                                       var id = this.store.getValue(items[j], 'id');
+
+                                       if (unread > 0 && (is_cat || id.match("FEED:"))) return items[j];
+                               }
+                       }
+               }
+               
+               return null;
+       },
+       hasCats: function() {
+               if (this.store && this.store._itemsByIdentity)
+                       return this.store._itemsByIdentity['CAT:-1'] != undefined;
+               else
+                       return false;
+       },
 });
 
 dojo.declare("fox.FeedTree", dijit.Tree, {
@@ -60,7 +107,7 @@ dojo.declare("fox.FeedTree", dijit.Tree, {
                        menu.addChild(new dijit.MenuItem({
                                label: __("Edit feed"),
                                onClick: function() {
-                                       editFeedDlg(this.getParent().row_id);
+                                       editFeed(this.getParent().row_id);
                                }}));
 
                        menu.addChild(new dijit.MenuItem({
@@ -133,10 +180,7 @@ dojo.declare("fox.FeedTree", dijit.Tree, {
                return false;
        },
        hasCats: function() {
-               if (this.model.store && this.model.store._itemsByIdentity)
-                       return this.model.store._itemsByIdentity['CAT:-1'] != undefined;
-               else
-                       return false;
+               return this.model.hasCats();
        },
        hideRead: function (hide, show_special) {
                if (this.hasCats()) {
@@ -193,4 +237,22 @@ dojo.declare("fox.FeedTree", dijit.Tree, {
        
                return cat_unread;
        },
+       collapseHiddenCats: function() {
+               if (!this.model.hasCats()) return;
+
+               var cats = this.model.store._arrayOfTopLevelItems;
+               var tree = this;
+
+               dojo.forEach(cats, function(cat) {
+                       var hidden = tree.model.store.getValue(cat, 'hidden');
+                       var id = tree.model.store.getValue(cat, 'id');
+                       var node = tree._itemNodesMap[id][0];
+
+                       if (hidden) 
+                               tree._collapseNode(node);
+                       else
+                               tree._expandNode(node);
+
+               });
+       },
 });