2020-06-05 04:54:32 +00:00
|
|
|
/* global define, dijit */
|
|
|
|
|
2018-08-23 06:56:34 +00:00
|
|
|
define(["dojo/_base/declare", "dijit/tree/ForestStoreModel"], function (declare) {
|
|
|
|
|
|
|
|
return declare("fox.FeedStoreModel", dijit.tree.ForestStoreModel, {
|
|
|
|
getItemsInCategory: function (id) {
|
|
|
|
if (!this.store._itemsByIdentity) return undefined;
|
|
|
|
|
2020-06-05 04:54:32 +00:00
|
|
|
const cat = this.store._itemsByIdentity['CAT:' + id];
|
2018-08-23 06:56:34 +00:00
|
|
|
|
|
|
|
if (cat && cat.items)
|
|
|
|
return cat.items;
|
|
|
|
else
|
|
|
|
return undefined;
|
|
|
|
|
|
|
|
},
|
|
|
|
getItemById: function (id) {
|
|
|
|
return this.store._itemsByIdentity[id];
|
|
|
|
},
|
|
|
|
getFeedValue: function (feed, is_cat, key) {
|
|
|
|
if (!this.store._itemsByIdentity) return undefined;
|
|
|
|
|
2020-06-05 04:54:32 +00:00
|
|
|
let treeItem;
|
|
|
|
|
2018-08-23 06:56:34 +00:00
|
|
|
if (is_cat)
|
|
|
|
treeItem = this.store._itemsByIdentity['CAT:' + feed];
|
|
|
|
else
|
|
|
|
treeItem = this.store._itemsByIdentity['FEED:' + feed];
|
|
|
|
|
|
|
|
if (treeItem)
|
|
|
|
return this.store.getValue(treeItem, key);
|
|
|
|
},
|
|
|
|
getFeedName: function (feed, is_cat) {
|
|
|
|
return this.getFeedValue(feed, is_cat, 'name');
|
|
|
|
},
|
|
|
|
getFeedUnread: function (feed, is_cat) {
|
2018-11-29 18:21:06 +00:00
|
|
|
const unread = parseInt(this.getFeedValue(feed, is_cat, 'unread'));
|
2019-05-07 03:03:44 +00:00
|
|
|
return (isNaN(unread)) ? -1 : unread;
|
2018-08-23 06:56:34 +00:00
|
|
|
},
|
|
|
|
setFeedUnread: function (feed, is_cat, unread) {
|
|
|
|
return this.setFeedValue(feed, is_cat, 'unread', parseInt(unread));
|
|
|
|
},
|
|
|
|
setFeedValue: function (feed, is_cat, key, value) {
|
|
|
|
if (!value) value = '';
|
|
|
|
if (!this.store._itemsByIdentity) return undefined;
|
|
|
|
|
2020-06-05 04:54:32 +00:00
|
|
|
let treeItem;
|
|
|
|
|
2018-08-23 06:56:34 +00:00
|
|
|
if (is_cat)
|
|
|
|
treeItem = this.store._itemsByIdentity['CAT:' + feed];
|
|
|
|
else
|
|
|
|
treeItem = this.store._itemsByIdentity['FEED:' + feed];
|
|
|
|
|
|
|
|
if (treeItem)
|
|
|
|
return this.store.setValue(treeItem, key, value);
|
|
|
|
},
|
|
|
|
getNextUnreadFeed: function (feed, is_cat) {
|
|
|
|
if (!this.store._itemsByIdentity)
|
|
|
|
return null;
|
|
|
|
|
2020-06-05 04:54:32 +00:00
|
|
|
let treeItem;
|
|
|
|
|
2018-08-23 06:56:34 +00:00
|
|
|
if (is_cat) {
|
|
|
|
treeItem = this.store._itemsByIdentity['CAT:' + feed];
|
|
|
|
} else {
|
|
|
|
treeItem = this.store._itemsByIdentity['FEED:' + feed];
|
|
|
|
}
|
|
|
|
|
2020-06-05 04:54:32 +00:00
|
|
|
const items = this.store._arrayOfAllItems;
|
2018-08-23 06:56:34 +00:00
|
|
|
|
2018-11-29 18:21:06 +00:00
|
|
|
for (let i = 0; i < items.length; i++) {
|
2018-08-23 06:56:34 +00:00
|
|
|
if (items[i] == treeItem) {
|
|
|
|
|
2020-06-05 04:54:32 +00:00
|
|
|
for (let j = i + 1; j < items.length; j++) {
|
|
|
|
const unread = this.store.getValue(items[j], 'unread');
|
|
|
|
const id = this.store.getValue(items[j], 'id');
|
2018-08-23 06:56:34 +00:00
|
|
|
|
|
|
|
if (unread > 0 && ((is_cat && id.match("CAT:")) || (!is_cat && id.match("FEED:")))) {
|
|
|
|
if (!is_cat || !(this.store.hasAttribute(items[j], 'parent_id') && this.store.getValue(items[j], 'parent_id') == feed)) return items[j];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-06-05 04:54:32 +00:00
|
|
|
for (let j = 0; j < i; j++) {
|
|
|
|
const unread = this.store.getValue(items[j], 'unread');
|
|
|
|
const id = this.store.getValue(items[j], 'id');
|
2018-08-23 06:56:34 +00:00
|
|
|
|
|
|
|
if (unread > 0 && ((is_cat && id.match("CAT:")) || (!is_cat && id.match("FEED:")))) {
|
|
|
|
if (!is_cat || !(this.store.hasAttribute(items[j], 'parent_id') && this.store.getValue(items[j], 'parent_id') == feed)) return items[j];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
hasCats: function () {
|
|
|
|
if (this.store && this.store._itemsByIdentity)
|
|
|
|
return this.store._itemsByIdentity['CAT:-1'] != undefined;
|
|
|
|
else
|
|
|
|
return false;
|
|
|
|
},
|
|
|
|
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|