diff options
author | Bernhard Posselt <nukeawhale@gmail.com> | 2012-08-31 16:44:15 +0200 |
---|---|---|
committer | Bernhard Posselt <nukeawhale@gmail.com> | 2012-09-01 00:31:38 +0200 |
commit | f3195d57429ffadc8484448112548f2ec77aa5ac (patch) | |
tree | 19b42a391372fbece19b94181ec06079e0629845 | |
parent | 409c6d509a39b88bca33389665daa00da5dc5f59 (diff) |
more cleanup
-rw-r--r-- | js/items.js | 236 | ||||
-rw-r--r-- | js/main.js | 62 | ||||
-rw-r--r-- | js/menu.js | 168 | ||||
-rw-r--r-- | js/news.js | 441 | ||||
-rw-r--r-- | templates/part.feeds.php | 3 |
5 files changed, 402 insertions, 508 deletions
diff --git a/js/items.js b/js/items.js index 8bcfd9279..7946e796a 100644 --- a/js/items.js +++ b/js/items.js @@ -18,9 +18,239 @@ var t = t || function(app, string){ return string; }; // mock translation for lo (function(){ - var Items = function(){ - + var Items = function(cssSelector){ + this._$articleList = $(cssSelector); + this._$articleList.scrollTop(0); } + Items.prototype.length = function(type, id) { + return 0; + }; + + Items.prototype.mostRecentItemId = function(type, id) { + return 0; + }; + News.Items = Items; -})();
\ No newline at end of file +})(); + + + + +// TODO: integrate This +/** + * Binds a listener on the feed item list to detect scrolling and mark previous + * items as read + */ +function bindItemEventListeners(){ + + // single hover on item should mark it as read too + $('#feed_items h1.item_title a').click(function(){ + var $item = $(this).parent().parent('.feed_item'); + var itemId = $item.data('id'); + var handler = new News.ItemStatusHandler(itemId); + handler.setRead(true); + }); + + // single hover on item should mark it as read too + $('#feed_items .body').click(function(){ + var $item = $(this).parent('.feed_item'); + var itemId = $item.data('id'); + var handler = new News.ItemStatusHandler(itemId); + handler.setRead(true); + }); + + // mark or unmark as important + $('#feed_items li.star').click(function(){ + var $item = $(this).parent().parent().parent('.feed_item'); + var itemId = $item.data('id'); + var handler = new News.ItemStatusHandler(itemId); + handler.toggleImportant(); + }); + + // toggle logic for the keep unread handler + $('#feed_items .keep_unread').click(function(){ + var $item = $(this).parent().parent().parent('.feed_item'); + var itemId = $item.data('id'); + var handler = new News.ItemStatusHandler(itemId); + handler.toggleKeepUnread(); + }); + $('#feed_items .keep_unread input[type=checkbox]').click(function(){ + var $item = $(this).parent().parent().parent().parent('.feed_item'); + var itemId = $item.data('id'); + var handler = new News.ItemStatusHandler(itemId); + handler.toggleKeepUnread(); + }); + + // bind the mark all as read button + $('#mark_all_as_read').unbind(); + $('#mark_all_as_read').click(function(){ + var feedId = News.Feed.activeFeedId; + News.Feed.setAllItemsRead(feedId); + }); + + $("time.timeago").timeago(); + +} + + +/** + * Marks an item as read which is called by the timeout + * @param item the dom item + */ +function markItemAsRead(scrollArea, item){ + var itemId = parseInt($(item).data('id')); + var itemOffset = $(item).position().top; + var boxHeight = $(scrollArea).height(); + var scrollHeight = $(scrollArea).prop('scrollHeight'); + var scrolled = $(scrollArea).scrollTop() + boxHeight; + if(itemOffset < 0 || scrolled >= scrollHeight){ + if(News.Feed.processing[itemId] === undefined || News.Feed.processing[itemId] === false){ + // mark item as processing to prevent unecessary post requests + News.Feed.processing[itemId] = true; + var handler = new News.ItemStatusHandler(itemId); + handler.setRead(true); + } + } +} + + /** + * This handler handles changes in the ui when the itemstatus changes + */ + ItemStatusHandler = function(itemId){ + var _itemId = parseInt(itemId); + var _$currentItem = $('#feed_items li[data-id="' + itemId + '"]'); + var _feedId = _$currentItem.data('feedid'); + var _read = _$currentItem.hasClass('read'); + + /** + * Switches important items to unimportant and vice versa + */ + var _toggleImportant = function(){ + var _$currentItemStar = _$currentItem.children('.utils').children('.primary_item_utils').children('.star'); + var _important = _$currentItemStar.hasClass('important'); + if(_important){ + status = 'unimportant'; + } else { + status = 'important'; + } + + var data = { + itemId: _itemId, + status: status + }; + + $.post(OC.filePath('news', 'ajax', 'setitemstatus.php'), data, function(jsondata){ + if(jsondata.status == 'success'){ + if(_important){ + _$currentItemStar.removeClass('important'); + } else { + _$currentItemStar.addClass('important'); + } + } else{ + OC.dialogs.alert(jsondata.data.message, t('news', 'Error')); + } + }); + }; + + /** + * Checks the state of the keep read checkbox + * @return true if its checked, otherwise false + */ + var _isKeptRead = function(){ + var _$currentItemKeepUnread = _$currentItem.children('.bottom_utils').children('.secondary_item_utils').children('.keep_unread').children('input[type=checkbox]'); + return _$currentItemKeepUnread.prop('checked'); + } + + /** + * Toggles an item as "keep unread". This prevents all handlers to mark it as unread + * except the current one + */ + var _toggleKeepUnread = function(){ + var _$currentItemKeepUnread = _$currentItem.children('.bottom_utils').children('.secondary_item_utils').children('.keep_unread').children('input[type=checkbox]'); + if(_isKeptRead()){ + _$currentItemKeepUnread.prop("checked", false); + } else { + _$currentItemKeepUnread.prop("checked", true); + News.Feed.processing[_itemId] = true; + _setRead(false); + } + }; + + /** + * Sets the current item as read or unread + * @param read true sets the item to read, false to unread + */ + var _setRead = function(read){ + var status; + + // if we already have the status, do nothing + if(read === _read){ + News.Feed.processing[_itemId] = false; + return; + } + // check if the keep unread flag was set + if(read && _isKeptRead()){ + News.Feed.processing[_itemId] = false; + return; + } + + if(read){ + status = 'read'; + } else { + status = 'unread'; + } + + var data = { + itemId: _itemId, + status: status + }; + + $.post(OC.filePath('news', 'ajax', 'setitemstatus.php'), data, function(jsonData){ + if(jsonData.status == 'success'){ + var feedHandler = new News.FeedStatusHandler(_feedId); + if(!_$currentItem.hasClass('read') && read){ + _$currentItem.addClass('read'); + feedHandler.decrrementUnreadCount(); + } else if(_$currentItem.hasClass('read') && !read){ + _$currentItem.removeClass('read'); + feedHandler.incrementUnreadCount(); + } + } else { + OC.dialogs.alert(jsonData.data.message, t('news', 'Error')); + } + News.Feed.processing[_itemId] = false; + }) + + }; + + // set public methods + this.setRead = function(read){ _setRead(read); }; + this.isRead = function(){ return _read; }; + this.toggleImportant = function(){ _toggleImportant(); }; + this.toggleKeepUnread = function(){ _toggleKeepUnread(); }; + }; + + // mark items whose title was hid under the top edge as read + // when the bottom is reached, mark all items as read + $('#feed_items').scroll(function(){ + var boxHeight = $(this).height(); + var scrollHeight = $(this).prop('scrollHeight'); + var scrolled = $(this).scrollTop() + boxHeight; + var scrollArea = this; + $(this).children('ul').children('.feed_item:not(.read)').each(function(){ + var item = this; + var itemOffset = $(this).position().top; + if(itemOffset <= 0 || scrolled >= scrollHeight){ + // wait and check if the item is still under the top edge + setTimeout(function(){ markItemAsRead(scrollArea, item);}, 1000); + } + }) + + }); + + $(document).keydown(function(e) { + if ((e.keyCode || e.which) == 74) { // 'j' key shortcut + + } + });
\ No newline at end of file diff --git a/js/main.js b/js/main.js index 5ca0af58e..23955ae8e 100644 --- a/js/main.js +++ b/js/main.js @@ -14,20 +14,14 @@ var News = News || {}; $(document).ready(function(){ + // config values + var menuUpdateIntervalMiliseconds = 200000; + // global object array for accessing instances News.Objects = {}; - News.Objects.Menu = new News.Menu($('#view').hasClass('show_all')); - News.Objects.Items = new News.Items(); - + News.Objects.Menu = new News.Menu(menuUpdateIntervalMiliseconds); News.Objects.Menu.bindOn('#feeds > ul'); - // basic setup - News.Feed.updateAll(); - var updateInterval = 200000; //how often the feeds should update (in msec) - setInterval('News.Feed.updateAll()', updateInterval); - - - /* first run script begins */ $('#browsebtn_firstrun, #cloudbtn_firstrun, #importbtn_firstrun').hide(); @@ -60,41 +54,33 @@ $(document).ready(function(){ }); $('#view').click(function(){ - var term; + var data = {}; if($(this).hasClass('show_all')){ - term = 'unread'; + data.show = 'unread'; $(this).addClass('show_unread').removeClass('show_all'); } else { - term = 'all'; + data.show = 'all'; $(this).addClass('show_all').removeClass('show_unread'); } - News.Feed.filter(term); - }); - // mark items whose title was hid under the top edge as read - // when the bottom is reached, mark all items as read - $('#feed_items').scroll(function(){ - var boxHeight = $(this).height(); - var scrollHeight = $(this).prop('scrollHeight'); - var scrolled = $(this).scrollTop() + boxHeight; - var scrollArea = this; - $(this).children('ul').children('.feed_item:not(.read)').each(function(){ - var item = this; - var itemOffset = $(this).position().top; - if(itemOffset <= 0 || scrolled >= scrollHeight){ - // wait and check if the item is still under the top edge - setTimeout(function(){ markItemAsRead(scrollArea, item);}, 1000); + $.post(OC.filePath('news', 'ajax', 'usersettings.php'), data, function(jsondata){ + if(jsondata.status == 'success'){ + var showAll; + if(data.show === 'all'){ + showAll = true; + } else { + showAll = false; + } + News.Objects.Menu.setShowAll(showAll); + } else { + OC.dialogs.alert(jsonData.data.message, t('news', 'Error')); } - }) - - }); - - $('#feed_items').scrollTop(0); - - $(document).keydown(function(e) { - if ((e.keyCode || e.which) == 74) { // 'j' key shortcut - - } + }); }); + + $(document).click(function(event) { + $('#feedfoldermenu').hide(); + }); }); + diff --git a/js/menu.js b/js/menu.js index 76f7568e3..2600948c9 100644 --- a/js/menu.js +++ b/js/menu.js @@ -19,8 +19,9 @@ We create a new instance of the menu. Then we need to bind it on an ul which contains all the items: - - var menu = new News.Menu(); + + var updateIntervalMiliseconds = 2000; + var menu = new News.Menu(updateIntervalMiliseconds); menu.bindOn('#feeds ul'); Updating nodes (you dont have to set all values in data): @@ -107,10 +108,19 @@ var News = News || {}; *#########################################################################/ /** * This is the basic menu used to construct and maintain the menu - * @param showAll if all items should be shown by default + * @param updateIntervalMiliseconds how often the menu should refresh */ - Menu = function(showAll){ - this._showAll = showAll; + Menu = function(updateIntervalMiliseconds){ + var self = this; + + this._updateInterval = updateIntervalMiliseconds; + setInterval(function(){ + self._updateUnreadCountAll(); + }, self._updateInterval); + + this._items = new News.Items('#feed_items'); + this._showAll = $('#view').hasClass('show_all'); + this._unreadCount = { Feed: {}, Folder: {}, @@ -134,7 +144,7 @@ var News = News || {}; if(parseInt(parentId) === 0){ $parentNode = this._$root; } else { - $parentNode = $('.' + this._menuNodeTypeToClass(MenuNodeType.Folder) + '[data-id="' + parentId + '"] ul'); + $parentNode = this._getNodeFromTypeAndId(type, id).children('ul'); // every folder we add to should be opened again $parentNode.parent().addClass('open'); $parentNode.show(); @@ -181,7 +191,7 @@ var News = News || {}; * @param data a json array with the data for the node {title: '', 'unreadCount': 3} */ Menu.prototype.updateNode = function(type, id, data){ - var $node = $('.' + this._menuNodeTypeToClass(type) + '[data-id="' + id + '"]'); + var $node = this._getNodeFromTypeAndId(type, id); if(data.title !== undefined){ $node.children('.title').html(data.title); @@ -198,7 +208,7 @@ var News = News || {}; * @param id the id */ Menu.prototype.removeNode = function(type, id){ - var $node = $('.' + this._menuNodeTypeToClass(type) + '[data-id="' + id + '"]'); + var $node = this._getNodeFromTypeAndId(type, id); $node.remove(); }; @@ -269,6 +279,7 @@ var News = News || {}; this._activeFeedId = this._$activeFeed.data('id'); this._activeFeedType = this._listItemToMenuNodeType(this._$activeFeed); + this._updateUnreadCountAll(); }; /** @@ -305,9 +316,6 @@ var News = News || {}; var id = $listItem.data('id'); var $children = $listItem.children('ul').children('li'); - this._setUnreadCount(MenuNodeType.Folder, id, - this._getAndRemoveUnreadCount($listItem)); - this._resetOpenFolders(); // bind subitems @@ -398,6 +406,10 @@ var News = News || {}; self._load(MenuNodeType.Subscriptions, id); return false; }); + + $listItem.children('.feeds_markread').click(function(){ + self._markRead(MenuNodeType.Folder, id); + }); }; /** @@ -406,9 +418,8 @@ var News = News || {}; * @param id the id */ Menu.prototype._load = function(type, id){ - // set the item to the currently selected one this._setActiveFeed(type, id); - // TODO: + this._items.load(type, id); }; /** @@ -435,7 +446,81 @@ var News = News || {}; * @param id the id */ Menu.prototype._markRead = function(type, id){ - // TODO: + // make sure only feeds get past + switch(type){ + + case MenuNodeType.Folder: + var $folder = this._getNodeFromTypeAndId(type, id); + $folder.children('ul').children('li').each(function(){ + var childData = this._getIdAndTypeFromNode($(this)); + this._markRead(childData.type, childData.id); + }); + break; + + case MenuNodeType.Subscriptions: + this._root.children('li').each(function(){ + var childData = this._getIdAndTypeFromNode($(this)); + this._markRead(childData.type, childData.id); + }); + break; + + case MenuNodeType.Feed: + var data = { + feedId: id, + mostRecentItemId: this._items.getMostRecentItemId(id) + }; + + $.post(OC.filePath('news', 'ajax', 'setallitemsread.php'), data, function(jsonData) { + if(jsonData.status == 'success'){ + this._items.markAllRead(type, id); + this._updateUnreadCountAll(); + } else { + OC.dialogs.alert(jsonData.data.message, t('news', 'Error')); + } + }); + break; + } + }; + + /** + * Requests an update for unreadCount for all feeds and folders + */ + Menu.prototype._updateUnreadCountAll = function() { + var self = this; + $.post(OC.filePath('news', 'ajax', 'feedlist.php'),function(jsonData){ + if(jsonData.status == 'success'){ + var feeds = jsonData.data; + for (var i = 0; i<feeds.length; i++) { + self._updateUnreadCount(feeds[i]['id'], feeds[i]['url'], feeds[i]['folderid']); + } + } else { + OC.dialogs.alert(jsonData.data.message, t('news', 'Error')); + } + }); + }; + + /** + * Request unreadCount for one feed + * @param feedId the id of the feed + * @param feedUrl the url of the feed that should be updated + * @param folderId the folderId fo the folder the feed is in + */ + Menu.prototype._updateUnreadCount = function(feedId, feedUrl, folderId) { + var self = this; + var data = { + 'feedid':feedId, + 'feedurl':feedUrl, + 'folderid':folderId + }; + $.post(OC.filePath('news', 'ajax', 'updatefeed.php'), data, function(jsondata){ + if(jsondata.status == 'success'){ + var newUnreadCount = jsondata.data.unreadcount; + // FIXME: starred items should also be set + self._setUnreadCount(MenuNodeType.Feed, feedId, newUnreadCount); + } else { + OC.dialogs.alert(jsonData.data.message, t('news', 'Error')); + } + }); }; /** @@ -455,7 +540,7 @@ var News = News || {}; */ Menu.prototype._setActiveFeed = function(type, id){ var $oldFeed = this._$activeFeed; - var $newFeed = $('.' + this._menuNodeTypeToClass(type) + '[data-id="' + id + '"]'); + var $newFeed = this._getNodeFromTypeAndId(type, id); $oldFeed.removeClass('.active'); $newFeed.addClass('.active'); this._$activeFeed = $newFeed; @@ -478,6 +563,36 @@ var News = News || {}; }; /** + * Returns the jquery element for a type and an id + * @param type the type (MenuNodeType) + * @param id the id + * @return the jquery node + */ + Menu.prototype._getNodeFromTypeAndId = function(type, id) { + if(id === 0){ + return this._$root; + } + + if(type === MenuNodeType.Starred || type === MenuNodeType.Subscriptions){ + return $('.' + this._menuNodeTypeToClass(type)); + } else { + return $('.' + this._menuNodeTypeToClass(type) + '[data-id="' + id + '"]'); + } + }; + + /** + * Returns id and type from a listnode + * @param $listItem the list item + * @return a json array with the id and type for instance { id: 1, type: MenuNodeType.Feed} + */ + Menu.prototype._getIdAndTypeFromNode = function($listItem) { + return { + id: $listItem.data('id'), + type: this._listItemToMenuNodeType($listItem), + }; + }; + + /** * Returns the MenuNodeType of a list item * @param $listItem the jquery list element * @return the MenuNodeType of the jquery element @@ -527,31 +642,27 @@ var News = News || {}; * @param unreadCount the count of unread items */ Menu.prototype._setUnreadCount = function(type, id, unreadCount){ - var $node; + var $node = this._getNodeFromTypeAndId(type, id); var currentUnreadCount; // get the node and the storred values switch(type){ case MenuNodeType.Feed: - $node = $('.' + this._menuNodeTypeToClass(type) + '[data-id="' + id + '"]'); currentUnreadCount = this._unreadCount.Feed[id]; this._unreadCount.Feed[id] = unreadCount; break; case MenuNodeType.Folder: - $node = $('.' + this._menuNodeTypeToClass(type) + '[data-id="' + id + '"]'); currentUnreadCount = this._unreadCount.Folder[id]; this._unreadCount.Folder[id] = unreadCount; break; case MenuNodeType.Starred: - $node = $('.' + this._menuNodeTypeToClass(type)); currentUnreadCount = this._unreadCount.Starred; this._unreadCount.Starred = unreadCount; break; case MenuNodeType.Subscriptions: - $node = $('.' + this._menuNodeTypeToClass(type)); currentUnreadCount = this._unreadCount.Subscriptions; this._unreadCount.Subscriptions = unreadCount; break; @@ -596,18 +707,27 @@ var News = News || {}; } self._resetOpenFolders(); - self._moveItemToFolder(feedId, folderId); + self._moveFeedToFolder(feedId, folderId); } }); }; /** - * Marks all items of a feed as read + * Moves a feed to a folder * @param feedId the feed that should be moved (can only be a feed) * @param id the id of the folder where it should be moved, 0 for root */ - Menu.prototype._moveItemToFolder = function(feedId, folderId){ - // TODO: + Menu.prototype._moveFeedToFolder = function(feedId, folderId){ + data = { + feedId: feedId, + folderId: folderId + }; + + $.post(OC.filePath('news', 'ajax', 'movefeedtofolder.php'), data, function(jsonData) { + if(jsonData.status !== 'success'){ + OC.dialogs.alert(jsonData.data.message, t('news', 'Error')); + } + }); }; diff --git a/js/news.js b/js/news.js index 00bdc02b3..2c6a20e6a 100644 --- a/js/news.js +++ b/js/news.js @@ -185,30 +185,6 @@ News={ }); return false; }, - setAllItemsRead:function(feedId) { - $items = $('.feed_item'); - // dont execute if there are not read - if($items.length <= 0){ - return; - } - // get the first items id to set lower ids as read - data = { - 'feedId' : feedId, - 'mostRecentItemId': $('.feed_item:first').data('id'), - }; - $.post(OC.filePath('news', 'ajax', 'setallitemsread.php'), data, function(jsonData) { - if(jsonData.status == 'success'){ - // mark ui items as read - $("#feed_items .feed_item:not(.read)").each(function(){ - $(this).addClass('read'); - }); - var feedHandler = new News.FeedStatusHandler(feedId); - feedHandler.setUnreadCount(0); - } else { - OC.dialogs.alert(t('news', 'Error while loading the feed'), t('news', 'Error')); - } - }); - }, load:function(feedId) { var $feedItems = $('#feed_items'); $feedItems.empty(); @@ -247,431 +223,16 @@ News={ $feedItems.removeClass('loading'); }); }, - updateAll:function() { - $.post(OC.filePath('news', 'ajax', 'feedlist.php'),function(jsondata){ - if(jsondata.status == 'success'){ - var feeds = jsondata.data; - for (var i = 0; i < feeds.length; i++) { - News.Feed.update(feeds[i]['id'], feeds[i]['url'], feeds[i]['folderid']); - } - } - else { - //TODO:handle error case - } - }); - }, - update:function(feedId, feedurl, folderid) { - var feedHandler = new News.FeedStatusHandler(feedId); - feedHandler.setUpdating(true); - data = { - 'feedid':feedId, - 'feedurl':feedurl, - 'folderid':folderid - }; - $.post(OC.filePath('news', 'ajax', 'updatefeed.php'), data, function(jsondata){ - if(jsondata.status == 'success'){ - var newUnreadCount = jsondata.data.unreadcount; - feedHandler.setUnreadCount(newUnreadCount); - } - feedHandler.setUpdating(false); - }); - }, - filter:function(value){ - var data; - switch(value){ - case 'all': - data = { - show: 'all' - }; - break; - case 'unread': - data = { - show: 'unread' - }; - break; - default: - break; - } - $.post(OC.filePath('news', 'ajax', 'usersettings.php'), data, function(jsondata){ - if(jsondata.status == 'success'){ - News.Feed.load(News.Feed.activeFeedId); - } else { - //TODO - } - }); - }, - moveToFolder:function(folder, feed){ - var folderId = $(folder).data('id'); - var feedId = $(feed).data('id'); - if($(feed).parent().parent().data('id') == folderId){ - // FIXME uncomment the return and remove the following lines - // in the if part to prevent dropping in the same folder - // return; - folderId = 0; - $('#feeds > ul').append(feed); - } else { - $(folder).children('ul').append(feed); - } - - transformCollapsableTrigger(); - data = { - folderId: folderId, - feedId: feedId - }; - $.post(OC.filePath('news', 'ajax', 'movefeedtofolder.php'), data, function(jsondata){ - if(jsondata.status != 'success'){ - OC.dialogs.alert(t('news', 'Error while saving the feed in a folder'), t('news', 'Error')); - window.location.reload(); - } - }); - return false; - }, + // this array is used to store ids to prevent sending too // many posts when scrolling. the structure is: feed_id: boolean processing:{}, activeFeedId: -1000, }, - /** - * This class is responsible for setting and updating items - * in the feedlist - */ - FeedStatusHandler: function(feedId){ - var _feedId = feedId; - var _activeFeedId = News.Feed.activeFeedId; - var _$feed = $('li.feed[data-id="'+feedId+'"]'); - var _$feedUnreadCounter = _$feed.find('.unreaditemcounter'); - var _$feedLink = _$feed.children('a'); - - /** - * Returns the current unread count - * @return the number of unread items - */ - var _getUnreadCount = function(){ - var unreadContent = _$feedUnreadCounter.html(); - if(unreadContent === ''){ - return 0; - } else { - return parseInt(unreadContent); - } - }; - - - /** - * Writes the current value into all fields - */ - var _refresh = function(){ - _setUnreadCount(_getUnreadCount); - } - - /** - * Decreases the current unread count by 1 - */ - var _decrrementUnreadCount = function(){ - _setUnreadCount(_getUnreadCount() - 1); - }; - - /** - * Increases the current unread count by 1 - */ - var _incrementUnreadCount = function(){ - _setUnreadCount(_getUnreadCount() + 1); - }; - - /** - * Show an icon and hide the unread count - * @param isUpdating if true show the icon and hide count, otherwise - * hide the icon and show the unread count - */ - var _setUpdating = function(isUpdating){ - // we dont use this anymore - return; - if(isUpdating){ - _$feed.addClass('updating'); - _$feedUnreadCounter.hide(); - } else { - _$feed.removeClass('updating'); - _$feedUnreadCounter.show(); - } - }; - - /** - * Set the unread count to a number - * @param count the unread count that will be set - */ - var _setUnreadCount = function(count){ - count = parseInt(count); - // dont allow setting the count below 0 - if(count < 0){ - count = 0; - } - // if the count is 0 we have to add special classes - if(count === 0){ - _$feedLink.addClass('all_read'); - _$feedUnreadCounter.addClass('all_read'); - } else { - var currentCount = _getUnreadCount(); - // if the previous count was 0 we need to remove certain classes - if(currentCount === 0){ - _$feedLink.removeClass('all_read'); - _$feedUnreadCounter.removeClass('all_read'); - } - } - _$feedUnreadCounter.html(count); - }; - - // public - this.decrrementUnreadCount = function(){ return _decrrementUnreadCount(); }; - this.incrementUnreadCount = function(){ return _incrementUnreadCount(); }; - this.setUpdating = function(isUpdating){ return _setUpdating(isUpdating); }; - this.setUnreadCount = function(count){ return _setUnreadCount(count); }; - this.refresh = function(){ return _refresh(); }; - }, - - /** - * This handler handles changes in the ui when the itemstatus changes - */ - ItemStatusHandler: function(itemId){ - var _itemId = parseInt(itemId); - var _$currentItem = $('#feed_items li[data-id="' + itemId + '"]'); - var _feedId = _$currentItem.data('feedid'); - var _read = _$currentItem.hasClass('read'); - - /** - * Switches important items to unimportant and vice versa - */ - var _toggleImportant = function(){ - var _$currentItemStar = _$currentItem.children('.utils').children('.primary_item_utils').children('.star'); - var _important = _$currentItemStar.hasClass('important'); - if(_important){ - status = 'unimportant'; - } else { - status = 'important'; - } - - var data = { - itemId: _itemId, - status: status - }; - - $.post(OC.filePath('news', 'ajax', 'setitemstatus.php'), data, function(jsondata){ - if(jsondata.status == 'success'){ - if(_imp |