diff options
author | Alessandro Cosentino <cosenal@gmail.com> | 2012-06-29 19:01:41 -0400 |
---|---|---|
committer | Alessandro Cosentino <cosenal@gmail.com> | 2012-06-29 19:01:41 -0400 |
commit | 6f3404ee971a130b90cf1773b9e67f4feef0be74 (patch) | |
tree | 50dc6137a02b73327e7ae9a6ae081a99f0295085 | |
parent | 6d54ff8c008058f6a90924a88b16f44bca0c0b25 (diff) |
adds controller to add a folder
-rw-r--r-- | ajax/createfolder.php | 35 | ||||
-rw-r--r-- | js/news.js | 26 | ||||
-rw-r--r-- | lib/foldermapper.php | 2 | ||||
-rw-r--r-- | templates/part.addfeedfolder.php | 2 | ||||
-rw-r--r-- | templates/part.feeds.php | 9 |
5 files changed, 64 insertions, 10 deletions
diff --git a/ajax/createfolder.php b/ajax/createfolder.php new file mode 100644 index 000000000..ecc44df49 --- /dev/null +++ b/ajax/createfolder.php @@ -0,0 +1,35 @@ +<?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(); + +$name = trim($_POST['name']); +$folder = new OC_News_Folder($name); +$foldermapper = new OC_News_FolderMapper($userid); +$folderid = $foldermapper->save($folder); + +$l = OC_L10N::get('news'); + +if(!$folderid) { + OCP\JSON::error(array('data' => array('message' => $l->t('Error adding folder.')))); + OCP\Util::writeLog('news','ajax/createfolder.php: Error adding folder: '.$_POST['name'], OCP\Util::ERROR); + exit(); +} + +//TODO: replace the following with the success case. see contact/ajax/createaddressbook.php for inspirations +OCP\JSON::error(array('data' => array('message' => $l->t('Error adding folder.')))); + diff --git a/js/news.js b/js/news.js index 728ba6df0..6ef7de93b 100644 --- a/js/news.js +++ b/js/news.js @@ -19,6 +19,28 @@ News={ } return false; } + }, + Feeds: { + submit:function(button){ + var displayname = $("#folder_add_name").val().trim(); + + if(displayname.length == 0) { + OC.dialogs.alert(t('news', 'Displayname cannot be empty.'), t('news', 'Error')); + return false; + } + + var url; + url = OC.filePath('news', 'ajax', 'createfolder.php'); + + $.post(url, { name: displayname }, + function(jsondata){ + if(jsondata.status == 'success'){ + $(button).closest('tr').prev().html(jsondata.page).show().next().remove(); + } else { + OC.dialogs.alert(jsondata.data.message, t('news', 'Error')); + } + }); + } } } @@ -26,7 +48,5 @@ $(document).ready(function(){ $('#addfeedfolder').click(News.UI.overview); $('#addfeedfolder').keydown(News.UI.overview); - - $('#feed_add_submit').click(addBookmark); - + });
\ No newline at end of file diff --git a/lib/foldermapper.php b/lib/foldermapper.php index d6dcea632..97b146dcd 100644 --- a/lib/foldermapper.php +++ b/lib/foldermapper.php @@ -90,7 +90,7 @@ class OC_News_FolderMapper { $params=array( htmlspecialchars_decode($name), $parentid, - OCP\USER::getUser() + $this->userid ); $query->execute($params); $folderid = OCP\DB::insertid(self::tableName); diff --git a/templates/part.addfeedfolder.php b/templates/part.addfeedfolder.php index d8f29efa7..693a55e53 100644 --- a/templates/part.addfeedfolder.php +++ b/templates/part.addfeedfolder.php @@ -28,7 +28,7 @@ <input type="text" id="folder_add_name" placeholder="<?php echo $l->t('Folder name'); ?>" class="news_input" /> </td> <td> - <input type="submit" value="<?php echo $l->t('Add folder'); ?>" id="folder_add_submit" /> + <input type="submit" value="<?php echo $l->t('Add folder'); ?>" onclick="News.Feeds.submit(this)" id="folder_add_submit" /> </td> </tr> </table>
\ No newline at end of file diff --git a/templates/part.feeds.php b/templates/part.feeds.php index a3edb993a..a10848e8f 100644 --- a/templates/part.feeds.php +++ b/templates/part.feeds.php @@ -1,10 +1,9 @@ <?php - echo $_['allfeeds']->getName(); - $children = $_['allfeeds']->getChildren(); + $allfeeds = $_['allfeeds']->getChildren(); - foreach($children as $child) { - if ($child instanceOf OC_News_Folder){ - echo $child->getName(); + foreach($allfeeds as $collection) { + if ($collection instanceOf OC_News_Folder){ + echo $collection->getName() . '<br>'; } } ?> |