From 78863696b7d2c443f742d23dd94acefe60157779 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Mon, 12 Sep 2011 21:28:28 +0200 Subject: [PATCH] First version of tasks app --- apps/tasks/ajax/addtask.php | 38 +++++++++ apps/tasks/ajax/addtaskform.php | 19 +++++ apps/tasks/ajax/delete.php | 49 +++++++++++ apps/tasks/ajax/edittask.php | 46 ++++++++++ apps/tasks/ajax/edittaskform.php | 33 ++++++++ apps/tasks/ajax/getdetails.php | 22 +++++ apps/tasks/appinfo/app.php | 15 ++++ apps/tasks/appinfo/info.xml | 10 +++ apps/tasks/css/style.css | 2 + apps/tasks/index.php | 52 ++++++++++++ apps/tasks/js/tasks.js | 97 ++++++++++++++++++++++ apps/tasks/templates/part.addtaskform.php | 15 ++++ apps/tasks/templates/part.details.php | 9 ++ apps/tasks/templates/part.edittaskform.php | 5 ++ apps/tasks/templates/part.property.php | 8 ++ apps/tasks/templates/part.taskform.php | 2 + apps/tasks/templates/part.tasks.php | 3 + apps/tasks/templates/tasks.php | 13 +++ 18 files changed, 438 insertions(+) create mode 100644 apps/tasks/ajax/addtask.php create mode 100644 apps/tasks/ajax/addtaskform.php create mode 100644 apps/tasks/ajax/delete.php create mode 100644 apps/tasks/ajax/edittask.php create mode 100644 apps/tasks/ajax/edittaskform.php create mode 100644 apps/tasks/ajax/getdetails.php create mode 100644 apps/tasks/appinfo/app.php create mode 100644 apps/tasks/appinfo/info.xml create mode 100644 apps/tasks/css/style.css create mode 100644 apps/tasks/index.php create mode 100644 apps/tasks/js/tasks.js create mode 100644 apps/tasks/templates/part.addtaskform.php create mode 100644 apps/tasks/templates/part.details.php create mode 100644 apps/tasks/templates/part.edittaskform.php create mode 100644 apps/tasks/templates/part.property.php create mode 100644 apps/tasks/templates/part.taskform.php create mode 100644 apps/tasks/templates/part.tasks.php create mode 100644 apps/tasks/templates/tasks.php diff --git a/apps/tasks/ajax/addtask.php b/apps/tasks/ajax/addtask.php new file mode 100644 index 0000000000..434fbc5fdd --- /dev/null +++ b/apps/tasks/ajax/addtask.php @@ -0,0 +1,38 @@ + '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 0000000000..297c590060 --- /dev/null +++ b/apps/tasks/ajax/addtaskform.php @@ -0,0 +1,19 @@ + '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 0000000000..1d96a058d7 --- /dev/null +++ b/apps/tasks/ajax/delete.php @@ -0,0 +1,49 @@ +. + * + */ + +// 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 0000000000..f98bcf3f59 --- /dev/null +++ b/apps/tasks/ajax/edittask.php @@ -0,0 +1,46 @@ + '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 0000000000..6cc7d2787c --- /dev/null +++ b/apps/tasks/ajax/edittaskform.php @@ -0,0 +1,33 @@ + '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 0000000000..d264aeab85 --- /dev/null +++ b/apps/tasks/ajax/getdetails.php @@ -0,0 +1,22 @@ + '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 0000000000..8bcc6085ec --- /dev/null +++ b/apps/tasks/appinfo/app.php @@ -0,0 +1,15 @@ + 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 0000000000..21ab9a2476 --- /dev/null +++ b/apps/tasks/appinfo/info.xml @@ -0,0 +1,10 @@ + + + tasks + Tasks + 0.1 + AGPL + Bart Visscher + 2 + Tasks view from calendar + diff --git a/apps/tasks/css/style.css b/apps/tasks/css/style.css new file mode 100644 index 0000000000..3867f07012 --- /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 0000000000..696ab11dd6 --- /dev/null +++ b/apps/tasks/index.php @@ -0,0 +1,52 @@ + $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 0000000000..528363f423 --- /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 0000000000..0fad5592aa --- /dev/null +++ b/apps/tasks/templates/part.addtaskform.php @@ -0,0 +1,15 @@ +
+ + + + + +
+ + inc('part.taskform'); ?> + +
diff --git a/apps/tasks/templates/part.details.php b/apps/tasks/templates/part.details.php new file mode 100644 index 0000000000..574f4c6b8e --- /dev/null +++ b/apps/tasks/templates/part.details.php @@ -0,0 +1,9 @@ +SUMMARY)): ?> + +inc('part.property', array('label' => $l->t('Summary'), 'property' => $_['details']->SUMMARY)); ?> +
+
+ + +
+ diff --git a/apps/tasks/templates/part.edittaskform.php b/apps/tasks/templates/part.edittaskform.php new file mode 100644 index 0000000000..3e26c42038 --- /dev/null +++ b/apps/tasks/templates/part.edittaskform.php @@ -0,0 +1,5 @@ +
+ + inc('part.taskform'); ?> + +
diff --git a/apps/tasks/templates/part.property.php b/apps/tasks/templates/part.property.php new file mode 100644 index 0000000000..68acd68954 --- /dev/null +++ b/apps/tasks/templates/part.property.php @@ -0,0 +1,8 @@ + + + + + + value ?> + + diff --git a/apps/tasks/templates/part.taskform.php b/apps/tasks/templates/part.taskform.php new file mode 100644 index 0000000000..8fe917c946 --- /dev/null +++ b/apps/tasks/templates/part.taskform.php @@ -0,0 +1,2 @@ + +
diff --git a/apps/tasks/templates/part.tasks.php b/apps/tasks/templates/part.tasks.php new file mode 100644 index 0000000000..50be1cd6be --- /dev/null +++ b/apps/tasks/templates/part.tasks.php @@ -0,0 +1,3 @@ + +
  • + diff --git a/apps/tasks/templates/tasks.php b/apps/tasks/templates/tasks.php new file mode 100644 index 0000000000..70f14b4215 --- /dev/null +++ b/apps/tasks/templates/tasks.php @@ -0,0 +1,13 @@ +
    +
    + +
    +
    +
    + +
    +
    + inc("part.details"); ?> +