From 7efe48d3d7d746b62ea8daf19edf8b3542520bb7 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Sun, 12 Aug 2012 17:43:11 +0200 Subject: added an keep unread checkbox, cleaned up javascript that handled setting of item status, improved design of feedentries --- ajax/importantitem.php | 42 --------------------------------------- ajax/markitem.php | 35 --------------------------------- ajax/setitemstatus.php | 53 ++++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 53 insertions(+), 77 deletions(-) delete mode 100644 ajax/importantitem.php delete mode 100644 ajax/markitem.php create mode 100644 ajax/setitemstatus.php (limited to 'ajax') diff --git a/ajax/importantitem.php b/ajax/importantitem.php deleted file mode 100644 index 72a07f747..000000000 --- a/ajax/importantitem.php +++ /dev/null @@ -1,42 +0,0 @@ - -* -* 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(); - -$itemId = $_POST['itemId']; -$isImportant = $_POST['isImportant']; - -$itemMapper = new OCA\News\ItemMapper(); -$item = $itemMapper->find($itemId); - -if($isImportant){ - $item->setImportant(); -} else { - $item->setUnimportant(); -} - -$success = $itemMapper->update($item); - -$l = OC_L10N::get('news'); - -if(!$success) { - OCP\JSON::error(array('data' => array('message' => $l->t('Error marking item as important.')))); - OCP\Util::writeLog('news','ajax/importantitem.php: Error marking item as important: '.$_POST['itemId'], OCP\Util::ERROR); - exit(); -} - -//TODO: replace the following with a real success case. see contact/ajax/createaddressbook.php for inspirations -OCP\JSON::success(array('data' => array('itemId' => $itemId))); - diff --git a/ajax/markitem.php b/ajax/markitem.php deleted file mode 100644 index a6efc8521..000000000 --- a/ajax/markitem.php +++ /dev/null @@ -1,35 +0,0 @@ - -* -* 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(); - -$itemid = $_POST['itemid']; - -$itemmapper = new OCA\News\ItemMapper(); -$item = $itemmapper->find($itemid); -$item->setRead(); -$success = $itemmapper->update($item); - -$l = OC_L10N::get('news'); - -if(!$success) { - OCP\JSON::error(array('data' => array('message' => $l->t('Error marking item as read.')))); - OCP\Util::writeLog('news','ajax/markitem.php: Error marking item as read: '.$_POST['itemid'], OCP\Util::ERROR); - exit(); -} - -//TODO: replace the following with a real success case. see contact/ajax/createaddressbook.php for inspirations -OCP\JSON::success(array('data' => array('itemid' => $itemid ))); - diff --git a/ajax/setitemstatus.php b/ajax/setitemstatus.php new file mode 100644 index 000000000..1d1849a5b --- /dev/null +++ b/ajax/setitemstatus.php @@ -0,0 +1,53 @@ + +* +* 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(); + +$itemId = $_POST['itemId']; +$status = $_POST['status']; + +$itemMapper = new OCA\News\ItemMapper(); +$item = $itemMapper->find($itemId); + +switch ($status) { + case 'read': + $item->setRead(); + break; + case 'unread': + $item->setUnread(); + break; + case 'important': + $item->setImportant(); + break; + case 'unimportant': + $item->setUnimportant(); + break; + default: + break; +} + +$success = $itemMapper->update($item); + +$l = OC_L10N::get('news'); + +if(!$success) { + OCP\JSON::error(array('data' => array('message' => $l->t('Error marking item as read.')))); + OCP\Util::writeLog('news','ajax/markitem.php: Error setting itemstatus to '. $status .': '.$_POST['itemid'], OCP\Util::ERROR); + exit(); +} + +//TODO: replace the following with a real success case. see contact/ajax/createaddressbook.php for inspirations +OCP\JSON::success(array('data' => array('itemId' => $itemId ))); + -- cgit v1.2.3 From 6c327bd5f8cdbebf45c6aa87f2d54f3dd26663a2 Mon Sep 17 00:00:00 2001 From: Bernhard Posselt Date: Mon, 13 Aug 2012 03:01:11 +0200 Subject: new layout and design for feed items, mark all as read is now faster because it uses an own ajax request, css and javascript refactor, the titlebar is now only loaded once --- ajax/loadfeed.php | 18 +++++++++--------- ajax/setallitemsread.php | 41 +++++++++++++++++++++++++++++++++++++++++ ajax/setitemstatus.php | 2 +- 3 files changed, 51 insertions(+), 10 deletions(-) create mode 100644 ajax/setallitemsread.php (limited to 'ajax') diff --git a/ajax/loadfeed.php b/ajax/loadfeed.php index 992e65019..020f7a706 100644 --- a/ajax/loadfeed.php +++ b/ajax/loadfeed.php @@ -17,19 +17,19 @@ OCP\JSON::callCheck(); $userid = OCP\USER::getUser(); -$feedid = trim($_POST['feedid']); +$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(); +$itemsTpl = new OCP\Template("news", "part.items"); +$itemsTpl->assign('feedid', $feedId); +$feedItems = $itemsTpl->fetchPage(); -$tmpl_items_header = new OCP\Template("news", "part.items.header"); -$tmpl_items_header->assign('feedid', $feedid); -$items_header = $tmpl_items_header->fetchPage(); +$feedMapper = new OCA\News\FeedMapper(); +$feed = $feedMapper->findById($feedId); +$feedTitle = $feed->getTitle(); OCP\JSON::success(array('data' => array( 'message' => $l->t('Feed loaded!'), - 'items_header' => $items_header, - 'part_items' => $part_items ))); + 'feedTitle' => $feedTitle, + 'feedItems' => $feedItems ))); diff --git a/ajax/setallitemsread.php b/ajax/setallitemsread.php new file mode 100644 index 000000000..4c1876b50 --- /dev/null +++ b/ajax/setallitemsread.php @@ -0,0 +1,41 @@ + +* +* 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(); + +$feedId = $_POST['feedId']; + +$itemMapper = new OCA\News\ItemMapper(); +$items = $itemMapper->findAllStatus($feedId, OCA\News\StatusFlag::Unread); + +// FIXME: maybe there is a way to set all items read in the +// FeedMapper instead of iterating through every item and updating as +// necessary +foreach($items as $item){ + $item->setRead(); + $success = $itemMapper->update($item); +} + +$l = OC_L10N::get('news'); + +if(!$success) { + OCP\JSON::error(array('data' => array('message' => $l->t('Error setting all items as read.')))); + OCP\Util::writeLog('news','ajax/setallitemsread.php: Error setting all items as read of feed '. $feedId, OCP\Util::ERROR); + exit(); +} + +//TODO: replace the following with a real success case. see contact/ajax/createaddressbook.php for inspirations +OCP\JSON::success(array('data' => array('feedId' => $feedId ))); + diff --git a/ajax/setitemstatus.php b/ajax/setitemstatus.php index 1d1849a5b..03dff7d94 100644 --- a/ajax/setitemstatus.php +++ b/ajax/setitemstatus.php @@ -44,7 +44,7 @@ $l = OC_L10N::get('news'); if(!$success) { OCP\JSON::error(array('data' => array('message' => $l->t('Error marking item as read.')))); - OCP\Util::writeLog('news','ajax/markitem.php: Error setting itemstatus to '. $status .': '.$_POST['itemid'], OCP\Util::ERROR); + OCP\Util::writeLog('news','ajax/setitemstatus.php: Error setting itemstatus to '. $status .': '.$_POST['itemid'], OCP\Util::ERROR); exit(); } -- cgit v1.2.3