From e032e2e7332421ddf1ce3dbd53da8813c7dda51c Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Thu, 18 Nov 2010 16:00:00 +0300 Subject: [PATCH] js: code cleanup --- feedlist.js | 82 ++++++++++++++++------------------------------------- tt-rss.js | 3 +- 2 files changed, 26 insertions(+), 59 deletions(-) diff --git a/feedlist.js b/feedlist.js index e96aa63d..f3332477 100644 --- a/feedlist.js +++ b/feedlist.js @@ -352,7 +352,11 @@ function parse_counters(reply, scheduled_call) { function getFeedUnread(feed, is_cat) { try { - return parseInt(getFeedValue(feed, is_cat, 'unread')); + var tree = dijit.byId("feedTree"); + + if (tree && tree.model) + return tree.model.getFeedUnread(feed, is_cat); + } catch (e) { // } @@ -372,30 +376,32 @@ function hideOrShowFeeds(hide) { } function getFeedName(feed, is_cat) { - return getFeedValue(feed, is_cat, 'name'); + var tree = dijit.byId("feedTree"); + + if (tree && tree.model) + return tree.model.getFeedValue(feed, is_cat, 'name'); } function getFeedValue(feed, is_cat, key) { - try { - if (is_cat) - treeItem = treeModel.store._itemsByIdentity['CAT:' + feed]; - else - treeItem = treeModel.store._itemsByIdentity['FEED:' + feed]; - - if (treeItem) - return treeModel.store.getValue(treeItem, key); + var tree = dijit.byId("feedTree"); + if (tree && tree.model) + return tree.model.getFeedValue(feed, is_cat, key); + } catch (e) { // } - return ''; } function setFeedUnread(feed, is_cat, unread) { try { - setFeedValue(feed, is_cat, 'unread', parseInt(unread)); + var tree = dijit.byId("feedTree"); + + if (tree && tree.model) + return tree.model.setFeedUnread(feed, is_cat, unread); + } catch (e) { exception_error("setFeedUnread", e); } @@ -403,19 +409,13 @@ function setFeedUnread(feed, is_cat, unread) { function setFeedValue(feed, is_cat, key, value) { try { - if (!value) value = ''; + var tree = dijit.byId("feedTree"); - if (is_cat) - treeItem = treeModel.store._itemsByIdentity['CAT:' + feed]; - else - treeItem = treeModel.store._itemsByIdentity['FEED:' + feed]; - - if (treeItem) - treeModel.store.setValue(treeItem, key, value); + if (tree && tree.model) + return tree.model.setFeedValue(feed, is_cat, key, value); } catch (e) { - console.log(e); - //exception_error("setFeedValue", e); + // } } @@ -423,18 +423,7 @@ function selectFeed(feed, is_cat) { try { var tree = dijit.byId("feedTree"); - if (!tree) return; - - if (is_cat) - treeNode = tree._itemNodesMap['CAT:' + feed]; - else - treeNode = tree._itemNodesMap['FEED:' + feed]; - - if (treeNode) { - treeNode = treeNode[0]; - if (!is_cat) tree._expandNode(treeNode); - tree._selectNode(treeNode); - } + if (tree) return tree.selectFeed(feed, is_cat); } catch (e) { exception_error("selectFeed", e); @@ -445,17 +434,7 @@ function setFeedIcon(feed, is_cat, src) { try { var tree = dijit.byId("feedTree"); - if (!tree) return; - - if (is_cat) - treeNode = tree._itemNodesMap['CAT:' + feed]; - else - treeNode = tree._itemNodesMap['FEED:' + feed]; - - if (treeNode) { - treeNode = treeNode[0]; - treeNode.iconNode.src = src; - } + if (tree) return tree.setFeedIcon(feed, is_cat, src); } catch (e) { exception_error("setFeedIcon", e); @@ -466,18 +445,7 @@ function setFeedExpandoIcon(feed, is_cat, src) { try { var tree = dijit.byId("feedTree"); - if (!tree) return; - - if (is_cat) - treeNode = tree._itemNodesMap['CAT:' + feed]; - else - treeNode = tree._itemNodesMap['FEED:' + feed]; - - if (treeNode) { - treeNode = treeNode[0]; - treeNode.expandoNode.src = src; - return true; - } + if (tree) return tree.setFeedExpandoIcon(feed, is_cat, src); } catch (e) { exception_error("setFeedIcon", e); diff --git a/tt-rss.js b/tt-rss.js index b9e93e1b..4ad6ca2f 100644 --- a/tt-rss.js +++ b/tt-rss.js @@ -9,7 +9,6 @@ var hotkey_prefix_pressed = false; var init_params = {}; var _force_scheduled_update = false; var last_scheduled_update = false; -var treeModel; var _rpc_seq = 0; @@ -75,7 +74,7 @@ function updateFeedList() { var store = new dojo.data.ItemFileWriteStore({ url: "backend.php?op=feeds"}); - treeModel = new fox.FeedStoreModel({ + var treeModel = new fox.FeedStoreModel({ store: store, query: { "type": "feed"