diff options
Diffstat (limited to 'js')
-rw-r--r-- | js/menu.js | 56 | ||||
-rw-r--r-- | js/news.js | 31 |
2 files changed, 16 insertions, 71 deletions
diff --git a/js/menu.js b/js/menu.js index 2f1ce3dcf..e4453599c 100644 --- a/js/menu.js +++ b/js/menu.js @@ -46,14 +46,8 @@ Deleting nodes: 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); + var html = '<nodehtml>'; + menu.addNode(parentId, html); If you want to show all feeds, also feeds which contain only read items, use @@ -142,17 +136,16 @@ var News = News || {}; /** * 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} + * @param html the html to add */ - Menu.prototype.addNode = function(parentId, type, id, data){ + Menu.prototype.addNode = function(parentId, html){ parentId = parseInt(parentId); - id = parseInt(id); - var $parentNode; - if(parseInt(parentId) === 0){ + var $html = $(html); + + console.log($html); + + if(parentId === 0){ $parentNode = this._$root; } else { $parentNode = this._getNodeFromTypeAndId(MenuNodeType.Folder, parentId).children('ul'); @@ -162,30 +155,7 @@ var News = News || {}; $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('.title').css('background-image', 'url("' + data.icon + '")'); - } - $html.children('.unread_items_counter').html(data.unreadCount); - $html.attr('data-id', id); - $html.children('ul').attr('data-id', id); - - switch(type){ + switch(this._getIdAndTypeFromNode($html).type){ case MenuNodeType.Feed: this._bindFeed($html); break; @@ -363,12 +333,6 @@ var News = News || {}; */ Menu.prototype.bindOn = function(cssSelector){ var self = this; - // remove mock elements - this._$mockFolder = $('.mock.folder').detach(); - this._$mockFolder.removeClass('mock open'); - this._$mockFeed = $('.mock.feed').detach(); - this._$mockFeed.removeClass('mock'); - // bind menu this._$root = $(cssSelector); this._id = this._$root.data('id'); diff --git a/js/news.js b/js/news.js index 9ca511360..deb3bfaba 100644 --- a/js/news.js +++ b/js/news.js @@ -40,14 +40,7 @@ News = { $.post(url, { name: displayname, parentid: folderid }, function(jsondata){ if(jsondata.status == 'success'){ - // FIXME: this should receive json by default - var $folder = $(jsondata.data.listfolder); - var title = $folder.children('.title').html(); - var id = $folder.data('id'); - var data = { - title: title - }; - News.Objects.Menu.addNode(0, News.MenuNodeType.Folder, id, data); + News.Objects.Menu.addNode(0, jsondata.data.listfolder); $('#addfolder_dialog').dialog('close'); } else { OC.dialogs.alert(jsondata.data.message, t('news', 'Error')); @@ -82,28 +75,16 @@ News = { url: OC.filePath('news', 'ajax', 'createfeed.php'), data: { 'feedurl': feedurl, 'folderid': folderid }, dataType: "json", - success: function(jsondata){ + success: function(jsonData){ if($('#firstrun').length > 0){ window.location.reload(); } else { - if(jsondata.status == 'success'){ - // FIXME: this should receive json by default - var $feed = $(jsondata.data.listfeed); - var title = $feed.children('.title').html(); - var icon = $feed.children('.title').css('background-image').replace(/"/g,"").replace(/url\(|\)$/ig, "");; - var unreadCount = $feed.children('.unread_items_count').html(); - var id = $feed.data('id'); - var data = { - title: title, - unreadCount: unreadCount, - icon: icon - }; - News.Objects.Menu.addNode(folderid, News.MenuNodeType.Feed, id, data); - News.Objects.Menu.load(News.MenuNodeType.Feed, jsondata.data.feedid); - + if(jsonData.status == 'success'){ + News.Objects.Menu.addNode(folderid, jsonData.data.listfeed); + News.Objects.Menu.load(News.MenuNodeType.Feed, jsonData.data.feedid); $('#addfeed_dialog').dialog('close'); } else { - OC.dialogs.alert(jsondata.data.message, t('news', 'Error')); + OC.dialogs.alert(jsonData.data.message, t('news', 'Error')); } $("#feed_add_url").val(''); $(button).attr("disabled", false); |