summaryrefslogtreecommitdiffstats
path: root/js
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2012-09-01 01:03:55 +0200
committerBernhard Posselt <nukeawhale@gmail.com>2012-09-01 01:03:55 +0200
commit069f27346d84d9cb39cba4190d81e73402df61d1 (patch)
tree8f8a80e7f501614f41a52766a5ccf1b7f97451e8 /js
parent5cfa3376a02526fc05543bd27f3299789840e33f (diff)
set unreadcount affects the whole menu now
Diffstat (limited to 'js')
-rw-r--r--js/items.js6
-rw-r--r--js/menu.js64
2 files changed, 58 insertions, 12 deletions
diff --git a/js/items.js b/js/items.js
index b8251a492..cd54afda8 100644
--- a/js/items.js
+++ b/js/items.js
@@ -498,11 +498,11 @@ var t = t || function(app, string){ return string; }; // mock translation for lo
if(!self._$html.hasClass('read') && read){
self._$html.addClass('read');
self._read = true;
- // notify feedlist
+ News.Objects.Menu.decrementUnreadCount(News.MenuNodeType.Feed, self._feedId);
} else if(self._$html.hasClass('read') && !read){
self._$html.removeClass('read');
self._read = false;
- // notify feedlist
+ News.Objects.Menu.incrementUnreadCount(News.MenuNodeType.Feed, self._feedId);
}
} else {
OC.dialogs.alert(jsonData.data.message, t('news', 'Error'));
@@ -535,8 +535,10 @@ var t = t || function(app, string){ return string; }; // mock translation for lo
if(jsondata.status == 'success'){
if(self._important){
$star.removeClass('important');
+ News.Objects.Menu.decrementUnreadCount(News.MenuNodeType.Starred, self._feedId);
} else {
$star.addClass('important');
+ News.Objects.Menu.incrementUnreadCount(News.MenuNodeType.Starred, self._feedId);
}
self._important = !self._important;
} else{
diff --git a/js/menu.js b/js/menu.js
index 1bf535091..19fb2ab5e 100644
--- a/js/menu.js
+++ b/js/menu.js
@@ -306,6 +306,48 @@ var News = News || {};
};
/**
+ * Increments the unreadcount of a folder by 1
+ * @param type the type (MenuNodeType)
+ * @param id the id
+ */
+ Menu.prototype.incrementUnreadCount = function(type, id) {
+ var unreadCount;
+ switch(type){
+ case MenuNodeType.Feed:
+ unreadCount = this._unreadCount.Feed[id];
+ break;
+ case MenuNodeType.Starred:
+ unreadCount = this._unreadCount.Starred;
+ break;
+ default:
+ console.log('Can only set unreadcount of starred items or feeds');
+ break;
+ }
+ this._setUnreadCount(type, id, unreadCount+1);
+ };
+
+ /**
+ * Decrements the unreadcount of a folder by 1
+ * @param type the type (MenuNodeType)
+ * @param id the id
+ */
+ Menu.prototype.decrementUnreadCount = function(type, id) {
+ var unreadCount;
+ switch(type){
+ case MenuNodeType.Feed:
+ unreadCount = this._unreadCount.Feed[id];
+ break;
+ case MenuNodeType.Starred:
+ unreadCount = this._unreadCount.Starred;
+ break;
+ default:
+ console.log('Can only set unreadcount of starred items or feeds');
+ break;
+ }
+ this._setUnreadCount(type, id, unreadCount-1);
+ };
+
+ /**
* Binds the menu on an existing menu
* @param css Selector the selector to get the element with jquery
*/
@@ -735,6 +777,9 @@ var News = News || {};
*/
Menu.prototype._setUnreadCount = function(type, id, unreadCount){
unreadCount = parseInt(unreadCount);
+ if(unreadCount < 0){
+ unreadCount = 0;
+ }
var $node = this._getNodeFromTypeAndId(type, id);
@@ -753,15 +798,6 @@ var News = News || {};
break;
}
- // update subscriptions
- var subscriptionsUnreadCount = 0;
- for(key in this._unreadCount.Feed){
- subscriptionsUnreadCount += this._unreadCount.Feed[key];
- }
- this._unreadCount.Subscriptions = subscriptionsUnreadCount;
- this._applyUnreadCountStyle(MenuNodeType.Subscriptions, 0,
- subscriptionsUnreadCount);
-
// check if we got a parent folder and update its unread count
if(type === MenuNodeType.Feed){
var $folder = $node.parent().parent();
@@ -780,9 +816,17 @@ var News = News || {};
}
}
+ // update subscriptions
+ var subscriptionsUnreadCount = 0;
+ $.each(this._unreadCount.Feed, function(key, value){
+ subscriptionsUnreadCount += value;
+ });
+ this._unreadCount.Subscriptions = subscriptionsUnreadCount;
+ this._applyUnreadCountStyle(MenuNodeType.Subscriptions, 0,
+ subscriptionsUnreadCount);
+
// lastly apply the new style to the feed
this._applyUnreadCountStyle(type, id, unreadCount);
-
};
/**