]>
git.wh0rd.org - tt-rss.git/blob - js/FeedStoreModel.js
7f2af22ec6853c0e9f1468d903c2879666b16936
1 define(["dojo/_base/declare", "dijit/tree/ForestStoreModel"], function (declare
) {
3 return declare("fox.FeedStoreModel", dijit
.tree
.ForestStoreModel
, {
4 getItemsInCategory: function (id
) {
5 if (!this.store
._itemsByIdentity
) return undefined;
7 let cat
= this.store
._itemsByIdentity
['CAT:' + id
];
15 getItemById: function (id
) {
16 return this.store
._itemsByIdentity
[id
];
18 getFeedValue: function (feed
, is_cat
, key
) {
19 if (!this.store
._itemsByIdentity
) return undefined;
22 treeItem
= this.store
._itemsByIdentity
['CAT:' + feed
];
24 treeItem
= this.store
._itemsByIdentity
['FEED:' + feed
];
27 return this.store
.getValue(treeItem
, key
);
29 getFeedName: function (feed
, is_cat
) {
30 return this.getFeedValue(feed
, is_cat
, 'name');
32 getFeedUnread: function (feed
, is_cat
) {
33 const unread
= parseInt(this.getFeedValue(feed
, is_cat
, 'unread'));
34 return (isNaN(unread
)) ? 0 : unread
;
36 setFeedUnread: function (feed
, is_cat
, unread
) {
37 return this.setFeedValue(feed
, is_cat
, 'unread', parseInt(unread
));
39 setFeedValue: function (feed
, is_cat
, key
, value
) {
40 if (!value
) value
= '';
41 if (!this.store
._itemsByIdentity
) return undefined;
44 treeItem
= this.store
._itemsByIdentity
['CAT:' + feed
];
46 treeItem
= this.store
._itemsByIdentity
['FEED:' + feed
];
49 return this.store
.setValue(treeItem
, key
, value
);
51 getNextUnreadFeed: function (feed
, is_cat
) {
52 if (!this.store
._itemsByIdentity
)
56 treeItem
= this.store
._itemsByIdentity
['CAT:' + feed
];
58 treeItem
= this.store
._itemsByIdentity
['FEED:' + feed
];
61 let items
= this.store
._arrayOfAllItems
;
63 for (let i
= 0; i
< items
.length
; i
++) {
64 if (items
[i
] == treeItem
) {
66 for (var j
= i
+ 1; j
< items
.length
; j
++) {
67 let unread
= this.store
.getValue(items
[j
], 'unread');
68 let id
= this.store
.getValue(items
[j
], 'id');
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
];
75 for (var j
= 0; j
< i
; j
++) {
76 let unread
= this.store
.getValue(items
[j
], 'unread');
77 let id
= this.store
.getValue(items
[j
], 'id');
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
];
88 hasCats: function () {
89 if (this.store
&& this.store
._itemsByIdentity
)
90 return this.store
._itemsByIdentity
['CAT:-1'] != undefined;