]> git.wh0rd.org - tt-rss.git/blame - js/FeedStoreModel.js
pngcrush.sh
[tt-rss.git] / js / FeedStoreModel.js
CommitLineData
a3e2f1a9
AD
1define(["dojo/_base/declare", "dijit/tree/ForestStoreModel"], function (declare) {
2
3 return declare("fox.FeedStoreModel", dijit.tree.ForestStoreModel, {
4 getItemsInCategory: function (id) {
5 if (!this.store._itemsByIdentity) return undefined;
6
02672124 7 let cat = this.store._itemsByIdentity['CAT:' + id];
a3e2f1a9
AD
8
9 if (cat && cat.items)
10 return cat.items;
11 else
12 return undefined;
13
14 },
15 getItemById: function (id) {
16 return this.store._itemsByIdentity[id];
17 },
18 getFeedValue: function (feed, is_cat, key) {
19 if (!this.store._itemsByIdentity) return undefined;
20
21 if (is_cat)
22 treeItem = this.store._itemsByIdentity['CAT:' + feed];
23 else
24 treeItem = this.store._itemsByIdentity['FEED:' + feed];
25
26 if (treeItem)
27 return this.store.getValue(treeItem, key);
28 },
29 getFeedName: function (feed, is_cat) {
30 return this.getFeedValue(feed, is_cat, 'name');
31 },
32 getFeedUnread: function (feed, is_cat) {
02672124 33 const unread = parseInt(this.getFeedValue(feed, is_cat, 'unread'));
a3e2f1a9
AD
34 return (isNaN(unread)) ? 0 : unread;
35 },
36 setFeedUnread: function (feed, is_cat, unread) {
37 return this.setFeedValue(feed, is_cat, 'unread', parseInt(unread));
38 },
39 setFeedValue: function (feed, is_cat, key, value) {
40 if (!value) value = '';
41 if (!this.store._itemsByIdentity) return undefined;
42
43 if (is_cat)
44 treeItem = this.store._itemsByIdentity['CAT:' + feed];
45 else
46 treeItem = this.store._itemsByIdentity['FEED:' + feed];
47
48 if (treeItem)
49 return this.store.setValue(treeItem, key, value);
50 },
51 getNextUnreadFeed: function (feed, is_cat) {
52 if (!this.store._itemsByIdentity)
53 return null;
54
55 if (is_cat) {
56 treeItem = this.store._itemsByIdentity['CAT:' + feed];
57 } else {
58 treeItem = this.store._itemsByIdentity['FEED:' + feed];
59 }
60
02672124 61 let items = this.store._arrayOfAllItems;
a3e2f1a9 62
02672124 63 for (let i = 0; i < items.length; i++) {
a3e2f1a9
AD
64 if (items[i] == treeItem) {
65
66 for (var j = i + 1; j < items.length; j++) {
02672124
AD
67 let unread = this.store.getValue(items[j], 'unread');
68 let id = this.store.getValue(items[j], 'id');
a3e2f1a9
AD
69
70 if (unread > 0 && ((is_cat && id.match("CAT:")) || (!is_cat && id.match("FEED:")))) {
71 if (!is_cat || !(this.store.hasAttribute(items[j], 'parent_id') && this.store.getValue(items[j], 'parent_id') == feed)) return items[j];
72 }
73 }
74
75 for (var j = 0; j < i; j++) {
02672124
AD
76 let unread = this.store.getValue(items[j], 'unread');
77 let id = this.store.getValue(items[j], 'id');
a3e2f1a9
AD
78
79 if (unread > 0 && ((is_cat && id.match("CAT:")) || (!is_cat && id.match("FEED:")))) {
80 if (!is_cat || !(this.store.hasAttribute(items[j], 'parent_id') && this.store.getValue(items[j], 'parent_id') == feed)) return items[j];
81 }
82 }
83 }
84 }
85
86 return null;
87 },
88 hasCats: function () {
89 if (this.store && this.store._itemsByIdentity)
90 return this.store._itemsByIdentity['CAT:-1'] != undefined;
91 else
92 return false;
93 },
94
95 });
96});
97
98