First version of tasks app

This commit is contained in:
Bart Visscher 2011-09-12 21:28:28 +02:00
parent 8c7aa06088
commit 78863696b7
18 changed files with 438 additions and 0 deletions

View file

@ -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 )));

View file

@ -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 )));

View file

@ -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 )));

View file

@ -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 )));

View file

@ -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 )));

View file

@ -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 )));

View file

@ -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')));

View file

@ -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>

2
apps/tasks/css/style.css Normal file
View file

@ -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; }

52
apps/tasks/index.php Normal file
View file

@ -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();

97
apps/tasks/js/tasks.js Normal file
View file

@ -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;
});
});

View file

@ -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>

View file

@ -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 ?>

View file

@ -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>

View file

@ -0,0 +1,8 @@
<tr>
<th>
<?php echo $_['label'] ?>
</th>
<td>
<?php echo $_['property']->value ?>
</td>
</tr>

View file

@ -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>

View file

@ -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; ?>

View file

@ -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>