/**
* ownCloud - News app
*
* @author Bernhard Posselt
* Copyright (c) 2012 - Bernhard Posselt <nukeawhale@gmail.com>
*
* This file is licensed under the Affero General Public License version 3 or later.
* See the COPYING-README file
*
*/
/**
* This file includes objects for binding and accessing the feed menu
*/
/**
* HOWTO
*
We create a new instance of the menu. Then we need to bind it on an ul which contains
all the items:
var updateIntervalMiliseconds = 2000;
var items = new News.Items('#feed_items');
var menu = new News.Menu(updateIntervalMiliseconds, items);
menu.bindOn('#feeds ul');
Updating nodes (you dont have to set all values in data):
var nodeType = News.MenuNodeType.Feed;
var nodeId = 2;
var nodeData = {
unreadCount: 4,
title: 'The verge'
}
menu.updateNode(nodeType, nodeId, nodeData);
Deleting nodes:
var id = 2;
var type = News.MenuNodeType.Feed;
var removedObject = menu.removeNode(type, id);
Creating nodes:
var parentId = 0;
var nodeType = News.MenuNodeType.Feed;
var nodeId = 6;
var nodeData = {
title: 'hi',
icon: 'some/icon.png',
unreadCount: 3
};
menu.addNode(parentId, nodeType, nodeId, nodeData);
If you want to show all feeds, also feeds which contain only read items, use
menu.setShowAll(true);
If you want to hide feeds and folders with only read items, use
menu.setShowAll(false);
The default value is false. If you want to toggle this behaviour, theres a shortcut
menu.toggleShowAll();
To hide all articles with read feeds, the setShowAll has to be set to false. The
hiding is only triggered after a new feed/folder was being loaded. If you wish to
trigger this manually, use:
menu.triggerHideRead();
If you want to load a feed or folder directly, use
var id = 2;
var type = News.MenuNodeType.Folder;
menu.load(type, id);
*/
var News = News || {};
(function(){
/*##########################################################################
* MenuNodeType
*########################################################################*/
/**
* Enumeration for menu items
*/
MenuNodeType = {
'Feed': 0,
'Folder': 1,
'Starred': 2,
'Subscriptions': 3
};
// map css classes to MenuNodeTypes
MenuNodeTypeClass = {};
MenuNodeTypeClass[MenuNodeType.Feed] = 'feed';
MenuNodeTypeClass[MenuNodeType.Folder] = 'folder';
MenuNodeTypeClass[MenuNodeType.Starred] = 'starred';
MenuNodeTypeClass[MenuNodeType.Subscriptions] = 'subscriptions';
News.MenuNodeType = MenuNodeType;
/*##########################################################################
* Menu
*########################################################################*/
/**
* This is the basic menu used to construct and maintain the menu
* @param updateIntervalMiliseconds how often the menu should refresh
* @param items the items object
*/
Menu = function(updateIntervalMiliseconds, items){
var self = this;
this._updatingCount = 0;
this._updateInterval = updateIntervalMiliseconds;
setInterval(function(){
self._updateUnreadCountAll();
}, self._updateInterval);
this._items = items;
this._showAll = $('#view').hasClass('show_all');
this._unreadCount = {
Feed: {},
Folder: {},
Starred: 0,
Subscriptions: 0
};
};
News.Menu = Menu;
/**
* Adds a node to the menu. A node can only be added to a folder or to the root
* @param parentId the id of the parent folder, 0 for root
* @param type the type (MenuNodeType)
* @param id the id
* @param data a json array with the data for the element:
* {title: '', icon: 'img/png.png', 'unreadCount': 3}
*/
Menu.prototype.addNode = function(parentId, type, id, data){
parentId = parseInt(parentId);
id = parseInt(id);
var $parentNode;
if(parseInt(parentId) === 0){
$parentNode = this._$root;
} else {
$parentNode = this._getNodeFromTypeAndId(MenuNodeType.Folder, parentId).children('ul');
// every folder we add to should be opened again
$parentNode.parent().addClass('open');
$parentNode.show();
$parentNode.siblings('.collapsable_trigger').removeClass('triggered');
}
var $html;
var icon;
switch(type){
case MenuNodeType.Feed:
$html = this._$mockFeed.clone();
break;
case MenuNodeType.Folder:
$html = this._$mockFolder.clone();
break;
default:
console.log('Can only create folders or feeds');
break;
}
$html.children('.title').html(data.title);
if(data.icon !== undefined){
$html.children