aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBart Visscher <bartv@thisnet.nl>2011-09-12 21:28:28 +0200
committerBart Visscher <bartv@thisnet.nl>2011-09-17 21:55:06 +0200
commit78863696b7d2c443f742d23dd94acefe60157779 (patch)
tree794a87db9ca042d60382d6c6e1d85aafd67a6f45
parent8c7aa060884fb3eaa1fe39412eb7622b743478b4 (diff)
downloadnextcloud-server-78863696b7d2c443f742d23dd94acefe60157779.tar.gz
nextcloud-server-78863696b7d2c443f742d23dd94acefe60157779.zip
First version of tasks app
-rw-r--r--apps/tasks/ajax/addtask.php38
-rw-r--r--apps/tasks/ajax/addtaskform.php19
-rw-r--r--apps/tasks/ajax/delete.php49
-rw-r--r--apps/tasks/ajax/edittask.php46
-rw-r--r--apps/tasks/ajax/edittaskform.php33
-rw-r--r--apps/tasks/ajax/getdetails.php22
-rw-r--r--apps/tasks/appinfo/app.php15
-rw-r--r--apps/tasks/appinfo/info.xml10
-rw-r--r--apps/tasks/css/style.css2
-rw-r--r--apps/tasks/index.php52
-rw-r--r--apps/tasks/js/tasks.js97
-rw-r--r--apps/tasks/templates/part.addtaskform.php15
-rw-r--r--apps/tasks/templates/part.details.php9
-rw-r--r--apps/tasks/templates/part.edittaskform.php5
-rw-r--r--apps/tasks/templates/part.property.php8
-rw-r--r--apps/tasks/templates/part.taskform.php2
-rw-r--r--apps/tasks/templates/part.tasks.php3
-rw-r--r--apps/tasks/templates/tasks.php13
18 files changed, 438 insertions, 0 deletions
diff --git a/apps/tasks/ajax/addtask.php b/apps/tasks/ajax/addtask.php
new file mode 100644
index 00000000000..434fbc5fdd5
--- /dev/null
+++ b/apps/tasks/ajax/addtask.php
@@ -0,0 +1,38 @@
+<?php
+
+// Init owncloud
+require_once('../../../lib/base.php');
+
+$l10n = new OC_L10N('tasks');
+
+// Check if we are a user
+if( !OC_User::isLoggedIn()){
+ echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('You need to log in!'))));
+ exit();
+}
+
+$cid = $_POST['id'];
+$calendar = OC_Calendar_Calendar::findCalendar( $cid );
+if( $calendar === false || $calendar['userid'] != OC_USER::getUser()){
+ echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('This is not your calendar!'))));
+ exit();
+}
+
+$summary = $_POST['summary'];
+
+$vcalendar = new Sabre_VObject_Component('VCALENDAR');
+$vcalendar->add(new Sabre_VObject_Property('PRODID', 'ownCloud Calendar'));
+$vcalendar->add(new Sabre_VObject_Property('VERSION', '2.0'));
+$vtodo = new Sabre_VObject_Component('VTODO');
+$vtodo->add(new Sabre_VObject_Property('SUMMARY',$summary));
+$vtodo->add(new Sabre_VObject_Property('UID',OC_Calendar_Calendar::createUID()));
+$vcalendar->add($vtodo);
+$id = OC_Calendar_Object::add($cid, $vcalendar->serialize());
+
+$details = OC_Contacts_Addressbook::structureContact($vtodo);
+$tmpl = new OC_Template('tasks','part.details');
+$tmpl->assign('details',$details);
+$tmpl->assign('id',$id);
+$page = $tmpl->fetchPage();
+
+echo json_encode( array( 'status' => 'success', 'data' => array( 'id' => $id, 'page' => $page )));
diff --git a/apps/tasks/ajax/addtaskform.php b/apps/tasks/ajax/addtaskform.php
new file mode 100644
index 00000000000..297c590060d
--- /dev/null
+++ b/apps/tasks/ajax/addtaskform.php
@@ -0,0 +1,19 @@
+<?php
+
+// Init owncloud
+require_once('../../../lib/base.php');
+
+$l10n = new OC_L10N('tasks');
+
+// Check if we are a user
+if( !OC_User::isLoggedIn()){
+ echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('You need to log in!'))));
+ exit();
+}
+
+$calendars = OC_Calendar_Calendar::allCalendars(OC_User::getUser(), true);
+$tmpl = new OC_Template('tasks','part.addtaskform');
+$tmpl->assign('calendars',$calendars);
+$page = $tmpl->fetchPage();
+
+echo json_encode( array( 'status' => 'success', 'data' => array( 'page' => $page )));
diff --git a/apps/tasks/ajax/delete.php b/apps/tasks/ajax/delete.php
new file mode 100644
index 00000000000..1d96a058d79
--- /dev/null
+++ b/apps/tasks/ajax/delete.php
@@ -0,0 +1,49 @@
+<?php
+/**
+ * ownCloud - Addressbook
+ *
+ * @author Jakob Sack
+ * @copyright 2011 Jakob Sack mail@jakobsack.de
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU AFFERO GENERAL PUBLIC LICENSE for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public
+ * License along with this library. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+// Init owncloud
+require_once('../../../lib/base.php');
+
+$l10n = new OC_L10N('tasks');
+
+// Check if we are a user
+if( !OC_User::isLoggedIn()){
+ echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('You need to log in!'))));
+ exit();
+}
+
+
+$id = $_GET['id'];
+$task = OC_Calendar_Object::find( $id );
+if( $task === false ){
+ echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('Can not find Task!'))));
+ exit();
+}
+
+$calendar = OC_Calendar_Calendar::findCalendar( $task['calendarid'] );
+if( $calendar === false || $calendar['userid'] != OC_USER::getUser()){
+ echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('This is not your task!'))));
+ exit();
+}
+
+OC_Calendar_Object::delete($id);
+echo json_encode( array( 'status' => 'success', 'data' => array( 'id' => $id )));
diff --git a/apps/tasks/ajax/edittask.php b/apps/tasks/ajax/edittask.php
new file mode 100644
index 00000000000..f98bcf3f596
--- /dev/null
+++ b/apps/tasks/ajax/edittask.php
@@ -0,0 +1,46 @@
+<?php
+
+// Init owncloud
+require_once('../../../lib/base.php');
+
+$l10n = new OC_L10N('tasks');
+
+// Check if we are a user
+if( !OC_User::isLoggedIn()){
+ echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('You need to log in!'))));
+ exit();
+}
+
+$id = $_POST['id'];
+$task = OC_Calendar_Object::find( $id );
+if( $task === false ){
+ echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('Can not find Task!'))));
+ exit();
+}
+
+$calendar = OC_Calendar_Calendar::findCalendar( $task['calendarid'] );
+if( $calendar === false || $calendar['userid'] != OC_USER::getUser()){
+ echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('This is not your task!'))));
+ exit();
+}
+
+$summary = $_POST['summary'];
+
+$vtodo = Sabre_VObject_Reader::read($task['calendardata'])->VTODO[0];
+$uid = $vtodo->UID[0]->value;
+
+$vcalendar = new Sabre_VObject_Component('VCALENDAR');
+$vcalendar->add(new Sabre_VObject_Property('PRODID', 'ownCloud Calendar'));
+$vcalendar->add(new Sabre_VObject_Property('VERSION', '2.0'));
+$vtodo = new Sabre_VObject_Component('VTODO');
+$vtodo->add(new Sabre_VObject_Property('SUMMARY',$summary));
+$vtodo->add(new Sabre_VObject_Property('UID', $uid));
+$vcalendar->add($vtodo);
+OC_Calendar_Object::edit($id, $vcalendar->serialize());
+
+$tmpl = new OC_Template('tasks','part.details');
+$tmpl->assign('details',$vtodo);
+$tmpl->assign('id',$id);
+$page = $tmpl->fetchPage();
+
+echo json_encode( array( 'status' => 'success', 'data' => array( 'id' => $id, 'page' => $page )));
diff --git a/apps/tasks/ajax/edittaskform.php b/apps/tasks/ajax/edittaskform.php
new file mode 100644
index 00000000000..6cc7d2787cf
--- /dev/null
+++ b/apps/tasks/ajax/edittaskform.php
@@ -0,0 +1,33 @@
+<?php
+
+// Init owncloud
+require_once('../../../lib/base.php');
+
+$l10n = new OC_L10N('tasks');
+
+// Check if we are a user
+if( !OC_User::isLoggedIn()){
+ echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('You need to log in!'))));
+ exit();
+}
+
+$id = $_GET['id'];
+$task = OC_Calendar_Object::find( $id );
+if( $task === false ){
+ echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('Can not find Task!'))));
+ exit();
+}
+
+$calendar = OC_Calendar_Calendar::findCalendar( $task['calendarid'] );
+if( $calendar === false || $calendar['userid'] != OC_USER::getUser()){
+ echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('This is not your task!'))));
+ exit();
+}
+
+$details = Sabre_VObject_Reader::read($task['calendardata'])->VTODO;
+$tmpl = new OC_Template('tasks','part.edittaskform');
+$tmpl->assign('task',$task);
+$tmpl->assign('details',$details);
+$page = $tmpl->fetchPage();
+
+echo json_encode( array( 'status' => 'success', 'data' => array( 'page' => $page )));
diff --git a/apps/tasks/ajax/getdetails.php b/apps/tasks/ajax/getdetails.php
new file mode 100644
index 00000000000..d264aeab853
--- /dev/null
+++ b/apps/tasks/ajax/getdetails.php
@@ -0,0 +1,22 @@
+<?php
+
+// Init owncloud
+require_once('../../../lib/base.php');
+
+$l10n = new OC_L10N('tasks');
+
+// Check if we are a user
+if( !OC_User::isLoggedIn()){
+ echo json_encode( array( 'status' => 'error', 'data' => array( 'message' => $l10n->t('You need to log in!'))));
+ exit();
+}
+
+$id = $_GET['id'];
+$task = OC_Calendar_Object::find($id);
+$details = Sabre_VObject_Reader::read($task['calendardata'])->VTODO;
+$tmpl = new OC_Template('tasks','part.details');
+$tmpl->assign('details',$details);
+$tmpl->assign('id',$id);
+$page = $tmpl->fetchPage();
+
+echo json_encode( array( 'status' => 'success', 'data' => array( 'id' => $id, 'page' => $page )));
diff --git a/apps/tasks/appinfo/app.php b/apps/tasks/appinfo/app.php
new file mode 100644
index 00000000000..8bcc6085ec8
--- /dev/null
+++ b/apps/tasks/appinfo/app.php
@@ -0,0 +1,15 @@
+<?php
+$l=new OC_L10N('tasks');
+OC::$CLASSPATH['OC_Calendar_Calendar'] = 'apps/calendar/lib/calendar.php';
+
+OC_App::register( array(
+ 'order' => 11,
+ 'id' => 'tasks',
+ 'name' => 'Tasks' ));
+
+OC_App::addNavigationEntry( array(
+ 'id' => 'tasks_index',
+ 'order' => 11,
+ 'href' => OC_Helper::linkTo( 'tasks', 'index.php' ),
+ //'icon' => OC_Helper::imagePath( 'tasks', 'icon.png' ),
+ 'name' => $l->t('Tasks')));
diff --git a/apps/tasks/appinfo/info.xml b/apps/tasks/appinfo/info.xml
new file mode 100644
index 00000000000..21ab9a24762
--- /dev/null
+++ b/apps/tasks/appinfo/info.xml
@@ -0,0 +1,10 @@
+<?xml version="1.0"?>
+<info>
+ <id>tasks</id>
+ <name>Tasks</name>
+ <version>0.1</version>
+ <licence>AGPL</licence>
+ <author>Bart Visscher</author>
+ <require>2</require>
+ <description>Tasks view from calendar</description>
+</info>
diff --git a/apps/tasks/css/style.css b/apps/tasks/css/style.css
new file mode 100644
index 00000000000..3867f07012c
--- /dev/null
+++ b/apps/tasks/css/style.css
@@ -0,0 +1,2 @@
+#task_details th { padding:2px; text-align:right ;vertical-align:top; }
+#task_details td { padding:2px; text-align:left ;vertical-align:top; }
diff --git a/apps/tasks/index.php b/apps/tasks/index.php
new file mode 100644
index 00000000000..696ab11dd68
--- /dev/null
+++ b/apps/tasks/index.php
@@ -0,0 +1,52 @@
+<?php
+/*************************************************
+ * ownCloud - Tasks Plugin *
+ * *
+ * (c) Copyright 2011 Bart Visscher *
+ * This file is licensed under the Affero General *
+ * Public License version 3 or later. *
+ * See the COPYING-README file. *
+ *************************************************/
+
+require_once ('../../lib/base.php');
+if(!OC_USER::isLoggedIn()) {
+ header('Location: ' . OC_HELPER::linkTo('', 'index.php'));
+ exit;
+}
+
+$calendars = OC_Calendar_Calendar::allCalendars(OC_User::getUser(), true);
+if( count($calendars) == 0){
+ header('Location: ' . OC_HELPER::linkTo('calendar', 'index.php'));
+ exit;
+}
+
+$id = isset( $_GET['id'] ) ? $_GET['id'] : null;
+
+$tasks = array();
+foreach( $calendars as $calendar ){
+ $calendar_tasks = OC_Calendar_Object::all($calendar['id']);
+ foreach( $calendar_tasks as $task ){
+ if($task['objecttype']!='VTODO'){
+ continue;
+ }
+ if(is_null($task['summary'])){
+ continue;
+ }
+ $tasks[] = array( 'name' => $task['summary'], 'id' => $task['id'] );
+ }
+}
+
+if( !is_null($id) || count($tasks)){
+ if(is_null($id)) $id = $tasks[0]['id'];
+ $task = OC_Calendar_Object::find($id);
+ $details = Sabre_VObject_Reader::read($task['calendardata'])->VTODO;
+}
+
+OC_UTIL::addScript('tasks', 'tasks');
+OC_UTIL::addStyle('tasks', 'style');
+OC_APP::setActiveNavigationEntry('tasks_index');
+$output = new OC_Template('tasks', 'tasks', 'user');
+$output->assign('tasks', $tasks);
+$output->assign('details', $details);
+$output->assign('id',$id);
+$output -> printPage();
diff --git a/apps/tasks/js/tasks.js b/apps/tasks/js/tasks.js
new file mode 100644
index 00000000000..528363f4237
--- /dev/null
+++ b/apps/tasks/js/tasks.js
@@ -0,0 +1,97 @@
+$(document).ready(function(){
+ /*-------------------------------------------------------------------------
+ * Actions for startup
+ *-----------------------------------------------------------------------*/
+ if( $('#tasks li').length > 0 ){
+ $('#tasks li').first().addClass('active');
+ }
+
+ /*-------------------------------------------------------------------------
+ * Event handlers
+ *-----------------------------------------------------------------------*/
+ $('#tasks li').live('click',function(){
+ var id = $(this).data('id');
+ var oldid = $('#task_details').data('id');
+ if(oldid != 0){
+ $('#tasks li[data-id="'+oldid+'"]').removeClass('active');
+ }
+ $.getJSON('ajax/getdetails.php',{'id':id},function(jsondata){
+ if(jsondata.status == 'success'){
+ $('#task_details').data('id',jsondata.data.id);
+ $('#task_details').html(jsondata.data.page);
+ $('#tasks li[data-id="'+jsondata.data.id+'"]').addClass('active');
+ }
+ else{
+ alert(jsondata.data.message);
+ }
+ });
+ return false;
+ });
+
+ $('#tasks_delete').live('click',function(){
+ var id = $('#task_details').data('id');
+ $.getJSON('ajax/delete.php',{'id':id},function(jsondata){
+ if(jsondata.status == 'success'){
+ $('#tasks [data-id="'+jsondata.data.id+'"]').remove();
+ $('#task_details').data('id','');
+ $('#task_details').html('');
+ }
+ else{
+ alert(jsondata.data.message);
+ }
+ });
+ return false;
+ });
+
+ $('#tasks_newtask').click(function(){
+ $.getJSON('ajax/addtaskform.php',{},function(jsondata){
+ if(jsondata.status == 'success'){
+ $('#task_details').data('id','');
+ $('#task_details').html(jsondata.data.page);
+ }
+ else{
+ alert(jsondata.data.message);
+ }
+ });
+ return false;
+ });
+
+ $('#tasks_addtaskform input[type="submit"]').live('click',function(){
+ $.post('ajax/addtask.php',$('#tasks_addtaskform').serialize(),function(jsondata){
+ if(jsondata.status == 'success'){
+ $('#task_details').data('id',jsondata.data.id);
+ $('#task_details').html(jsondata.data.page);
+ }
+ else{
+ alert(jsondata.data.message);
+ }
+ }, 'json');
+ return false;
+ });
+
+ $('#tasks_edit').live('click',function(){
+ var id = $('#task_details').data('id');
+ $.getJSON('ajax/edittaskform.php',{'id':id},function(jsondata){
+ if(jsondata.status == 'success'){
+ $('#task_details').html(jsondata.data.page);
+ }
+ else{
+ alert(jsondata.data.message);
+ }
+ });
+ return false;
+ });
+
+ $('#tasks_edittaskform input[type="submit"]').live('click',function(){
+ $.post('ajax/edittask.php',$('#tasks_edittaskform').serialize(),function(jsondata){
+ if(jsondata.status == 'success'){
+ $('#task_details').data('id',jsondata.data.id);
+ $('#task_details').html(jsondata.data.page);
+ }
+ else{
+ alert(jsondata.data.message);
+ }
+ }, 'json');
+ return false;
+ });
+});
diff --git a/apps/tasks/templates/part.addtaskform.php b/apps/tasks/templates/part.addtaskform.php
new file mode 100644
index 00000000000..0fad5592aa7
--- /dev/null
+++ b/apps/tasks/templates/part.addtaskform.php
@@ -0,0 +1,15 @@
+<form id="tasks_addtaskform">
+ <?php if(count($_['calendars'])==1): ?>
+ <input type="hidden" name="id" value="<?php echo $_['calendars'][0]['id']; ?>">
+ <?php else: ?>
+ <label for="id"><?php echo $l->t('Calendar'); ?></label>
+ <select name="id" size="1">
+ <?php foreach($_['calendars'] as $calendar): ?>
+ <option value="<?php echo $calendar['id']; ?>"><?php echo $calendar['displayname']; ?></option>
+ <?php endforeach; ?>
+ </select>
+ <br>
+ <?php endif; ?>
+ <?php echo $this->inc('part.taskform'); ?>
+ <input type="submit" name="submit" value="<?php echo $l->t('Create Task'); ?>">
+</form>
diff --git a/apps/tasks/templates/part.details.php b/apps/tasks/templates/part.details.php
new file mode 100644
index 00000000000..574f4c6b8e4
--- /dev/null
+++ b/apps/tasks/templates/part.details.php
@@ -0,0 +1,9 @@
+<?php if(isset($_['details']->SUMMARY)): ?>
+<table>
+<?php echo $this->inc('part.property', array('label' => $l->t('Summary'), 'property' => $_['details']->SUMMARY)); ?>
+</table>
+<form>
+ <input type="button" id="tasks_delete" value="<?php echo $l->t('Delete');?>">
+ <input type="button" id="tasks_edit" value="<?php echo $l->t('Edit');?>">
+</form>
+<?php endif ?>
diff --git a/apps/tasks/templates/part.edittaskform.php b/apps/tasks/templates/part.edittaskform.php
new file mode 100644
index 00000000000..3e26c420380
--- /dev/null
+++ b/apps/tasks/templates/part.edittaskform.php
@@ -0,0 +1,5 @@
+<form id="tasks_edittaskform">
+ <input type="hidden" name="id" value="<?php echo $_['task']['id']; ?>">
+ <?php echo $this->inc('part.taskform'); ?>
+ <input type="submit" name="submit" value="<?php echo $l->t('Update Task'); ?>">
+</form>
diff --git a/apps/tasks/templates/part.property.php b/apps/tasks/templates/part.property.php
new file mode 100644
index 00000000000..68acd68954c
--- /dev/null
+++ b/apps/tasks/templates/part.property.php
@@ -0,0 +1,8 @@
+<tr>
+ <th>
+ <?php echo $_['label'] ?>
+ </th>
+ <td>
+ <?php echo $_['property']->value ?>
+ </td>
+</tr>
diff --git a/apps/tasks/templates/part.taskform.php b/apps/tasks/templates/part.taskform.php
new file mode 100644
index 00000000000..8fe917c9466
--- /dev/null
+++ b/apps/tasks/templates/part.taskform.php
@@ -0,0 +1,2 @@
+ <label for="summary"><?php echo $l->t('Summary'); ?></label>
+ <input type="text" id="summary" name="summary" value="<?php echo isset($_['details']->SUMMARY) ? $_['details']->SUMMARY[0]->value : '' ?>"><br>
diff --git a/apps/tasks/templates/part.tasks.php b/apps/tasks/templates/part.tasks.php
new file mode 100644
index 00000000000..50be1cd6bed
--- /dev/null
+++ b/apps/tasks/templates/part.tasks.php
@@ -0,0 +1,3 @@
+<?php foreach( $_['tasks'] as $task ): ?>
+ <li data-id="<?php echo $task['id']; ?>"><a href="index.php?id=<?php echo $task['id']; ?>"><?php echo $task['name']; ?></a> </li>
+<?php endforeach; ?>
diff --git a/apps/tasks/templates/tasks.php b/apps/tasks/templates/tasks.php
new file mode 100644
index 00000000000..70f14b4215e
--- /dev/null
+++ b/apps/tasks/templates/tasks.php
@@ -0,0 +1,13 @@
+<div id="controls">
+ <form>
+ <input type="button" id="tasks_newtask" value="<?php echo $l->t('Add Task'); ?>">
+ </form>
+</div>
+<div id="tasks" class="leftcontent">
+ <ul>
+ <?php echo $this->inc("part.tasks"); ?>
+ </ul>
+</div>
+<div id="task_details" class="rightcontent" data-id="<?php echo $_['id']; ?>">
+ <?php echo $this->inc("part.details"); ?>
+</div>