summaryrefslogtreecommitdiffstats
path: root/js/news.js
diff options
context:
space:
mode:
authorBernhard Posselt <nukeawhale@gmail.com>2012-08-31 16:44:15 +0200
committerBernhard Posselt <nukeawhale@gmail.com>2012-09-01 00:31:38 +0200
commitf3195d57429ffadc8484448112548f2ec77aa5ac (patch)
tree19b42a391372fbece19b94181ec06079e0629845 /js/news.js
parent409c6d509a39b88bca33389665daa00da5dc5f59 (diff)
more cleanup
Diffstat (limited to 'js/news.js')
-rw-r--r--js/news.js441
1 files changed, 1 insertions, 440 deletions
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(_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(); };
- },
-
-}
-function transformCollapsableTrigger() {
- // we need this here to detect and toggle new children instantly
- $('.collapsable_trigger').unbind();
- $('.collapsable_trigger').each(function(){
- $container = $(this).parent().parent();
- $sublist = $container.children('ul');
- if($sublist.children('li').length > 0){
- $(this).addClass('triggerable');
- $container.addClass('open');
- }
- });
- $('.collapsable_trigger').click(function(){
- $(this).toggleClass('triggerable');
- $(this).toggleClass('triggered');
- $sublist = $(this).parent().parent().children('ul');
- $sublist.toggle();
- $container = $(this).parent().parent();
- $container.toggleClass('open');
- });
-}
-function setupFeedList() {
- /*
- $('.feed').draggable({
- revert: true,
- stack: '> li',
- zIndex: 1000,
- axis: 'y',
- });
- $('.collapsable_container').droppable({
- accept: '.feed',
- hoverClass: 'dnd_over',
- drop: function(event, ui){
- return News.Feed.moveToFolder(this, ui.draggable);
- }
- });*/
- $('.feed').click(function() {
- News.Feed.load($(this).attr('data-id'));
- });
-
- // select initially loaded feed
- var loadedfeed = $('div.rightcontent').attr('data-id');
- $('li.feed[data-id="' + loadedfeed + '"]').attr('id', 'selected_feed');
-
- transformCollapsableTrigger();
}
-/**
- * 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);
- }
- }
-}
-
-$(document).click(function(event) {
- $('#feedfoldermenu').hide();
-});