diff options
-rw-r--r-- | ajax/createfeed.php | 7 | ||||
-rw-r--r-- | ajax/loadfeed.php | 30 | ||||
-rw-r--r-- | css/news.css | 7 | ||||
-rw-r--r-- | js/news.js | 55 | ||||
-rw-r--r-- | templates/main.php | 4 | ||||
-rw-r--r-- | templates/part.feeds.php | 3 | ||||
-rw-r--r-- | templates/part.listfeed.php | 4 |
7 files changed, 80 insertions, 30 deletions
diff --git a/ajax/createfeed.php b/ajax/createfeed.php index 884958b08..627b0e36b 100644 --- a/ajax/createfeed.php +++ b/ajax/createfeed.php @@ -17,7 +17,7 @@ function shutdown() { $l = OC_L10N::get('news'); $error = error_get_last(); if($error['type'] & (E_ERROR | E_COMPILE_ERROR | E_CORE_ERROR)) { //all fatal errors - if (strpos($error['message'], 'get_uri')) { + if (strpos($error['message'], 'get_uri')) { //handle a fatal error caused by a SimplePie bug (https://github.com/simplepie/simplepie/issues/214) OCP\Util::writeLog('news','ajax/createfeed.php: Fatal error:' . $error['message'] , OCP\Util::ERROR); exit(); @@ -67,13 +67,8 @@ $tmpl_newfeed = new OCP\Template("news", "part.items.new"); $tmpl_newfeed->assign('title', $feed->getTitle()); $part_newfeed = $tmpl_newfeed->fetchPage(); -$tmpl_items = new OCP\Template("news", "part.items"); -$tmpl_items->assign('feedid', $feedid); -$part_items = $tmpl_items->fetchPage(); - OCP\JSON::success(array('data' => array( 'message' => $l->t('Feed added!'), 'feedid' => $feedid, 'listfeed' => $listfeed, - 'part_items' => $part_items, 'part_newfeed' => $part_newfeed ))); diff --git a/ajax/loadfeed.php b/ajax/loadfeed.php new file mode 100644 index 000000000..40c873e2b --- /dev/null +++ b/ajax/loadfeed.php @@ -0,0 +1,30 @@ +<?php +/** +* ownCloud - News app +* +* @author Alessandro Cosentino +* Copyright (c) 2012 - Alessandro Cosentino <cosenal@gmail.com> +* +* This file is licensed under the Affero General Public License version 3 or later. +* See the COPYING-README file +* +*/ + +// Check if we are a user +OCP\JSON::checkLoggedIn(); +OCP\JSON::checkAppEnabled('news'); +OCP\JSON::callCheck(); + +$userid = OCP\USER::getUser(); + +$feedid = trim($_POST['feedid']); + +$l = OC_L10N::get('news'); + +$tmpl_items = new OCP\Template("news", "part.items"); +$tmpl_items->assign('feedid', $feedid); +$part_items = $tmpl_items->fetchPage(); + +OCP\JSON::success(array('data' => array( 'message' => $l->t('Feed loaded!'), + 'part_items' => $part_items ))); + diff --git a/css/news.css b/css/news.css index a60eb04b8..5a86edd5b 100644 --- a/css/news.css +++ b/css/news.css @@ -54,8 +54,9 @@ ul#feedfoldermenu { position:fixed; margin-left: 0; bottom: 2.8em; border-left:1 li { padding: 0px !important; } li.menuItem { margin-left:0.7em; margin-right:0.7em; float: none !important; text-align: left; } -li.feeds_list { margin-left: 16px !important; text-align: right; border-radius: 5px; padding-left: 5px !important; background-color: rgb(255,255,255) !important; } -li.feeds_list a { padding: 0 0 0 20px !important; overflow: hidden; text-overflow: ellipsis; text-align: left; width: 65%; } +li.feed { margin-left: 16px !important; text-align: right; border-radius: 5px; padding-left: 5px !important; background-color: rgb(255,255,255) !important; } +li.feed a { padding: 0 0 0 20px !important; overflow: hidden; text-overflow: ellipsis; text-align: left; width: 65%; } +li#selected_feed { background-color: #FF9933 !important; } li.folder_list { background-color: rgb(255,255,255) !important; } div.collapsable { position: relative; border-radius: 5px; } .collapsable_trigger { border: none ; margin: 0 0 0 5px; padding: 0; border-radius: 0; box-shadow: none; vertical-align: middle !important; background: url('%webroot%/core/img/places/folder.svg') no-repeat; height:16px; width:16px; } @@ -66,7 +67,7 @@ ul.folders { margin-left: 16px !important; } li.folder_list:hover { color: rgb(0, 0, 0) !important; background-color: rgb(255,255,255) !important; } -li.feeds_list:hover { background-color: rgb(221, 221, 221) !important; } +li.feed:hover { background-color: rgb(221, 221, 221) !important; } div.collapsable:hover { background-color: rgb(221, 221, 221); } div.add_parentfolder { position: relative; } diff --git a/js/news.js b/js/news.js index 1aa6fd37d..7f27a8486 100644 --- a/js/news.js +++ b/js/news.js @@ -106,7 +106,7 @@ News={ Feed: { id:'', submit:function(button){ - + var feedurl = $("#feed_add_url").val().trim(); if(feedurl.length == 0) { @@ -116,9 +116,9 @@ News={ $(button).attr("disabled", true); $(button).prop('value', t('news', 'Adding...')); - + var folderid = $('#inputfolderid:input[name="folderid"]').val(); - + $.ajax({ type: "POST", url: OC.filePath('news', 'ajax', 'createfeed.php'), @@ -128,16 +128,12 @@ News={ if(jsondata.status == 'success'){ $('div[data-id="' + folderid + '"] > ul').append(jsondata.data.listfeed); setupFeedList(); + News.Feed.load(jsondata.data.feedid); + OC.dialogs.confirm(t('news', 'Do you want to add another feed?'), t('news', 'Feed added!'), function(answer) { if(!answer) { $('#addfeed_dialog').dialog('destroy').remove(); - var rightcontent = $('div.rightcontent'); - rightcontent.empty(); - rightcontent.attr('data-id', jsondata.data.feedid); - rightcontent.html(jsondata.data.part_items); - rightcontent.find('ul.accordion').before(jsondata.data.part_newfeed); - setupRightContent(); - transformCollapsableTrigger(); + $('ul.accordion').before(jsondata.data.part_newfeed); } }); } else { @@ -154,7 +150,7 @@ News={ $(button).prop('value', t('news', 'Add feed')); } }); - + // $.post(OC.filePath('news', 'ajax', 'createfeed.php'), { feedurl: feedurl, folderid: folderid }, // function(jsondata){ // if(jsondata.status == 'success'){ @@ -187,7 +183,7 @@ News={ if(answer == true) { $.post(OC.filePath('news', 'ajax', 'deletefeed.php'),{'feedid':feedid},function(jsondata){ if(jsondata.status == 'success'){ - $('li.feeds_list[data-id="'+jsondata.data.feedid+'"]').remove(); + $('li.feed[data-id="'+jsondata.data.feedid+'"]').remove(); var rightcontent = $('div.rightcontent'); if(rightcontent.attr('data-id') == feedid) { rightcontent.find('div#feedadded').remove(); @@ -212,7 +208,7 @@ News={ currentitem.addClass('title_read'); // decrement counter - var counterplace = $('.feeds_list[data-id="'+feedid+'"]').find('#unreaditemcounter'); + var counterplace = $('.feed[data-id="'+feedid+'"]').find('#unreaditemcounter'); var oldcount = counterplace.html(); counterplace.empty(); if (oldcount <= 1) { @@ -229,6 +225,25 @@ News={ }) }; }, + load:function(feedid) { + $.post(OC.filePath('news', 'ajax', 'loadfeed.php'),{'feedid':feedid},function(jsondata) { + if(jsondata.status == 'success'){ + var rightcontent = $('div.rightcontent'); + rightcontent.empty(); + rightcontent.attr('data-id', feedid); + rightcontent.html(jsondata.data.part_items); + + $('li#selected_feed').attr('id', ''); + $('li.feed[data-id="' + feedid + '"]').attr('id', 'selected_feed'); + + setupRightContent(); + transformCollapsableTrigger(); + } + else { + OC.dialogs.alert(t('news', 'Error while loading the feed'), t('news', 'Error')); + } + }); + }, updateAll:function() { $.post(OC.filePath('news', 'ajax', 'feedlist.php'),function(jsondata){ if(jsondata.status == 'success'){ @@ -243,7 +258,7 @@ News={ }); }, update:function(feedid, feedurl, folderid) { - var counterplace = $('.feeds_list[data-id="'+feedid+'"]').find('#unreaditemcounter'); + var counterplace = $('.feed[data-id="'+feedid+'"]').find('#unreaditemcounter'); var oldcount = counterplace.html(); counterplace.removeClass(); counterplace.html('<img style="vertical-align: middle;" src="' + OC.imagePath('core','loader.gif') + '" alt="refresh" />'); @@ -305,7 +320,7 @@ function transformCollapsableTrigger() { } function setupFeedList() { - var list = $('.collapsable,.feeds_list').hover( + var list = $('.collapsable,.feed').hover( function() { $(this).find('#feeds_delete,#feeds_edit').css('display', 'inline'); $(this).find('#unreaditemcounter').css('display', 'none'); @@ -319,6 +334,14 @@ function setupFeedList() { list.find('#feeds_edit').hide(); list.find('#unreaditemcounter').show(); + $('.feed').click(function() { + News.Feed.load($(this).attr('data-id')); + }); + + // select initial loaded feed + var loadedfeed = $('div.rightcontent').attr('data-id'); + $('li.feed[data-id="' + loadedfeed + '"]').attr('id', 'selected_feed'); + transformCollapsableTrigger(); } @@ -362,7 +385,7 @@ $(document).ready(function(){ News.Feed.updateAll(); var updateInterval = 200000; //how often the feeds should update (in msec) setInterval('News.Feed.updateAll()', updateInterval); - + }); $(document).click(function(event) { diff --git a/templates/main.php b/templates/main.php index 21a05dec1..fc74193f0 100644 --- a/templates/main.php +++ b/templates/main.php @@ -32,9 +32,9 @@ echo $this->inc("part.nofeeds"); } ?> - + <div id="appsettings" class="popup bottomleft hidden"></div> - + </div> <!-- Dialogs --> diff --git a/templates/part.feeds.php b/templates/part.feeds.php index 81712a475..da46de0e1 100644 --- a/templates/part.feeds.php +++ b/templates/part.feeds.php @@ -31,5 +31,6 @@ echo '</ul></div></li></ul>'; } - print_folder($_['allfeeds']); + $allfeeds = isset($_['allfeeds']) ? $_['allfeeds'] : ''; + print_folder($allfeeds); ?>
\ No newline at end of file diff --git a/templates/part.listfeed.php b/templates/part.listfeed.php index 6aabe5d3c..070a32dd9 100644 --- a/templates/part.listfeed.php +++ b/templates/part.listfeed.php @@ -9,8 +9,8 @@ if ($favicon == null) { $favicon = OCP\Util::imagePath('news', 'rss.svg'); } -echo '<li class="feeds_list" data-id="' . $child->getId() . '">'; -echo '<a href="' . OCP\Util::linkTo('news', 'index.php'). '?feedid=' . $child->getId() . '" style="background: url(' . $favicon . ') left center no-repeat; background-size:16px 16px;">' . $child->getTitle() .'</a>'; +echo '<li class="feed" data-id="' . $child->getId() . '">'; +echo '<a href="#" style="background: url(' . $favicon . ') left center no-repeat; background-size:16px 16px;">' . $child->getTitle() .'</a>'; if ($unreadItems > 0) { echo '<span id="unreaditemcounter" class="nonzero">' . $unreadItems . '</span>'; } |