js: code cleanup

This commit is contained in:
Andrew Dolgov 2010-11-18 16:00:00 +03:00
parent a740f4b51d
commit e032e2e733
2 changed files with 26 additions and 59 deletions

View file

@ -352,7 +352,11 @@ function parse_counters(reply, scheduled_call) {
function getFeedUnread(feed, is_cat) { function getFeedUnread(feed, is_cat) {
try { 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) { } catch (e) {
// //
} }
@ -372,30 +376,32 @@ function hideOrShowFeeds(hide) {
} }
function getFeedName(feed, is_cat) { 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) { function getFeedValue(feed, is_cat, key) {
try { try {
if (is_cat) var tree = dijit.byId("feedTree");
treeItem = treeModel.store._itemsByIdentity['CAT:' + feed];
else
treeItem = treeModel.store._itemsByIdentity['FEED:' + feed];
if (treeItem) if (tree && tree.model)
return treeModel.store.getValue(treeItem, key); return tree.model.getFeedValue(feed, is_cat, key);
} catch (e) { } catch (e) {
// //
} }
return ''; return '';
} }
function setFeedUnread(feed, is_cat, unread) { function setFeedUnread(feed, is_cat, unread) {
try { 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) { } catch (e) {
exception_error("setFeedUnread", e); exception_error("setFeedUnread", e);
} }
@ -403,19 +409,13 @@ function setFeedUnread(feed, is_cat, unread) {
function setFeedValue(feed, is_cat, key, value) { function setFeedValue(feed, is_cat, key, value) {
try { try {
if (!value) value = ''; var tree = dijit.byId("feedTree");
if (is_cat) if (tree && tree.model)
treeItem = treeModel.store._itemsByIdentity['CAT:' + feed]; return tree.model.setFeedValue(feed, is_cat, key, value);
else
treeItem = treeModel.store._itemsByIdentity['FEED:' + feed];
if (treeItem)
treeModel.store.setValue(treeItem, key, value);
} catch (e) { } catch (e) {
console.log(e); //
//exception_error("setFeedValue", e);
} }
} }
@ -423,18 +423,7 @@ function selectFeed(feed, is_cat) {
try { try {
var tree = dijit.byId("feedTree"); var tree = dijit.byId("feedTree");
if (!tree) return; if (tree) return tree.selectFeed(feed, is_cat);
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);
}
} catch (e) { } catch (e) {
exception_error("selectFeed", e); exception_error("selectFeed", e);
@ -445,17 +434,7 @@ function setFeedIcon(feed, is_cat, src) {
try { try {
var tree = dijit.byId("feedTree"); var tree = dijit.byId("feedTree");
if (!tree) return; if (tree) return tree.setFeedIcon(feed, is_cat, src);
if (is_cat)
treeNode = tree._itemNodesMap['CAT:' + feed];
else
treeNode = tree._itemNodesMap['FEED:' + feed];
if (treeNode) {
treeNode = treeNode[0];
treeNode.iconNode.src = src;
}
} catch (e) { } catch (e) {
exception_error("setFeedIcon", e); exception_error("setFeedIcon", e);
@ -466,18 +445,7 @@ function setFeedExpandoIcon(feed, is_cat, src) {
try { try {
var tree = dijit.byId("feedTree"); var tree = dijit.byId("feedTree");
if (!tree) return; if (tree) return tree.setFeedExpandoIcon(feed, is_cat, src);
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;
}
} catch (e) { } catch (e) {
exception_error("setFeedIcon", e); exception_error("setFeedIcon", e);

View file

@ -9,7 +9,6 @@ var hotkey_prefix_pressed = false;
var init_params = {}; var init_params = {};
var _force_scheduled_update = false; var _force_scheduled_update = false;
var last_scheduled_update = false; var last_scheduled_update = false;
var treeModel;
var _rpc_seq = 0; var _rpc_seq = 0;
@ -75,7 +74,7 @@ function updateFeedList() {
var store = new dojo.data.ItemFileWriteStore({ var store = new dojo.data.ItemFileWriteStore({
url: "backend.php?op=feeds"}); url: "backend.php?op=feeds"});
treeModel = new fox.FeedStoreModel({ var treeModel = new fox.FeedStoreModel({
store: store, store: store,
query: { query: {
"type": "feed" "type": "feed"