From 96041641949c55abf2b432bc08ea493b40dec873 Mon Sep 17 00:00:00 2001 From: Alessandro Cosentino Date: Thu, 5 Jul 2012 15:12:17 -0400 Subject: button to edit and delete feeds --- ajax/deletefeed.php | 35 ++++++++++++++++++++++++++++++++++ css/news.css | 2 ++ js/news.js | 49 ++++++++++++++++++++++++++++++++++++++++++++++-- templates/part.feeds.php | 8 ++++++-- 4 files changed, 90 insertions(+), 4 deletions(-) create mode 100644 ajax/deletefeed.php diff --git a/ajax/deletefeed.php b/ajax/deletefeed.php new file mode 100644 index 000000000..b54620d48 --- /dev/null +++ b/ajax/deletefeed.php @@ -0,0 +1,35 @@ + +* +* 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(); + +$feedurl = trim($_POST['feedurl']); + +$feed = OC_News_Utils::fetch($feedurl); +$feedmapper = new OC_News_FeedMapper(); +$feedid = $feedmapper->save($feed, 0); + +$l = OC_L10N::get('news'); + +if(!$feedid) { + OCP\JSON::error(array('data' => array('message' => $l->t('Error adding folder.')))); + OCP\Util::writeLog('news','ajax/newfeed.php: Error adding feed: '.$_POST['feedurl'], 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('message' => $l->t('Feed added!')))); diff --git a/css/news.css b/css/news.css index 8f89ef378..cbfef64c2 100644 --- a/css/news.css +++ b/css/news.css @@ -3,6 +3,8 @@ #feeds { background: #fff; width: 20em; left: 12.5em; top: 3.7em; bottom:3em; position: fixed; overflow: auto; padding: 0; margin: 0; } #feeds a { height: 23px; display: block; margin: 0 0 0 0; padding: 0 0 0 25px; } #bottomcontrols { padding: 0; bottom:0px; height:2.8em; width: 20em; margin:0; background:#eee; border-top:1px solid #ccc; position:fixed; -moz-box-shadow: 0 -3px 3px -3px #000; -webkit-box-shadow: 0 -3px 3px -3px #000; box-shadow: 0 -3px 3px -3px #000;} +#feeds_delete { position:relative; float:right; background:url('%webroot%/core/img/actions/delete.svg') no-repeat center; } +#feeds_edit { position:relative; float:right; background:url('%webroot%/core/img/actions/rename.svg') no-repeat center; } .svg { border: inherit; background: inherit; } diff --git a/js/news.js b/js/news.js index 699b8ce2f..3675fb0db 100644 --- a/js/news.js +++ b/js/news.js @@ -64,6 +64,50 @@ News={ OC.dialogs.alert(jsondata.data.message, t('news', 'Error')); } }); + }, + doDelete:function() { + $('#feeds_delete').tipsy('hide'); + OC.dialogs.confirm(t('news', 'Are you sure you want to delete this feed?'), t('news', 'Warning'), function(answer) { + if(answer == true) { + $.post(OC.filePath('contacts', 'ajax', 'deletefeed.php'),{'id':Contacts.UI.Card.id},function(jsondata){ + if(jsondata.status == 'success'){ + var newid = ''; + var curlistitem = $('#leftcontent [data-id="'+jsondata.data.id+'"]'); + var newlistitem = curlistitem.prev(); + if(newlistitem == undefined) { + newlistitem = curlistitem.next(); + } + curlistitem.remove(); + if(newlistitem != undefined) { + newid = newlistitem.data('id'); + } + $('#rightcontent').data('id',newid); + this.id = this.fn = this.fullname = this.shortname = this.famname = this.givname = this.addname = this.honpre = this.honsuf = ''; + this.data = undefined; + + if($('#contacts li').length > 0) { // Load first in list. + Contacts.UI.Card.update(newid); + } else { + // load intro page + $.getJSON(OC.filePath('contacts', 'ajax', 'loadintro.php'),{},function(jsondata){ + if(jsondata.status == 'success'){ + id = ''; + $('#rightcontent').data('id',''); + $('#rightcontent').html(jsondata.data.page); + } + else{ + OC.dialogs.alert(jsondata.data.message, t('contacts', 'Error')); + } + }); + } + } + else{ + OC.dialogs.alert(jsondata.data.message, t('contacts', 'Error')); + } + }); + } + }); + return false; } } } @@ -71,7 +115,6 @@ News={ $(document).ready(function(){ $('#addfeedfolder').click(News.UI.overview); - $('#addfeedfolder').keydown(News.UI.overview); $('.collapsable').click(function(){ $(this).parent().children().toggle(); @@ -82,5 +125,7 @@ $(document).ready(function(){ $(this).next().toggle(); return false; }).next().hide(); - + + $('#feeds_delete').click( function() { News.Feed.doDelete(); return false;} ); + }); \ No newline at end of file diff --git a/templates/part.feeds.php b/templates/part.feeds.php index 52716c804..5adb70d1c 100644 --- a/templates/part.feeds.php +++ b/templates/part.feeds.php @@ -1,6 +1,7 @@
  • ' . '' . $folder->getName() .'