diff --git a/apps/tasks/ajax/addtask.php b/apps/tasks/ajax/addtask.php index c768d3e7d9..0c8cb89e7f 100644 --- a/apps/tasks/ajax/addtask.php +++ b/apps/tasks/ajax/addtask.php @@ -8,11 +8,7 @@ OC_JSON::checkAppEnabled('tasks'); $l10n = new OC_L10N('tasks'); $cid = $_POST['id']; -$calendar = OC_Calendar_Calendar::findCalendar( $cid ); -if( $calendar === false || $calendar['userid'] != OC_USER::getUser()){ - OC_JSON::error(array('data' => array( 'message' => $l10n->t('This is not your calendar!')))); - exit(); -} +$calendar = OC_Calendar_App::getCalendar( $cid ); $errors = OC_Task_App::validateRequest($_POST); if (!empty($errors)) { @@ -30,4 +26,7 @@ $tmpl->assign('details',$vcalendar->VTODO); $tmpl->assign('id',$id); $page = $tmpl->fetchPage(); -OC_JSON::success(array('data' => array( 'id' => $id, 'page' => $page ))); +$user_timezone = OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'timezone', date_default_timezone_get()); +$task = OC_Task_App::arrayForJSON($id, $vcalendar->VTODO, $user_timezone); + +OC_JSON::success(array('data' => array( 'id' => $id, 'page' => $page, 'task' => $task ))); diff --git a/apps/tasks/ajax/addtaskform.php b/apps/tasks/ajax/addtaskform.php index 222ccbd79a..d4a0bb0310 100644 --- a/apps/tasks/ajax/addtaskform.php +++ b/apps/tasks/ajax/addtaskform.php @@ -8,8 +8,16 @@ OC_JSON::checkAppEnabled('tasks'); $l10n = new OC_L10N('tasks'); $calendars = OC_Calendar_Calendar::allCalendars(OC_User::getUser(), true); +$category_options = OC_Calendar_Object::getCategoryOptions($l10n); +$percent_options = range(0, 100, 10); +$priority_options = OC_Task_App::getPriorityOptions(); $tmpl = new OC_Template('tasks','part.addtaskform'); $tmpl->assign('calendars',$calendars); +$tmpl->assign('category_options', $category_options); +$tmpl->assign('percent_options', $percent_options); +$tmpl->assign('priority_options', $priority_options); +$tmpl->assign('details', new OC_VObject('VTODO')); +$tmpl->assign('categories', array()); $page = $tmpl->fetchPage(); OC_JSON::success(array('data' => array( 'page' => $page ))); diff --git a/apps/tasks/ajax/edittask.php b/apps/tasks/ajax/edittask.php index a7215ce078..ae937a7dca 100644 --- a/apps/tasks/ajax/edittask.php +++ b/apps/tasks/ajax/edittask.php @@ -26,4 +26,7 @@ $tmpl->assign('details', $vcalendar->VTODO); $tmpl->assign('id', $id); $page = $tmpl->fetchPage(); -OC_JSON::success(array('data' => array( 'id' => $id, 'page' => $page ))); +$user_timezone = OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'timezone', date_default_timezone_get()); +$task = OC_Task_App::arrayForJSON($id, $vcalendar->VTODO, $user_timezone); + +OC_JSON::success(array('data' => array( 'id' => $id, 'page' => $page, 'task' => $task ))); diff --git a/apps/tasks/ajax/gettasks.php b/apps/tasks/ajax/gettasks.php index 7dc94dacb4..ee871c344c 100644 --- a/apps/tasks/ajax/gettasks.php +++ b/apps/tasks/ajax/gettasks.php @@ -26,32 +26,7 @@ foreach( $calendars as $calendar ){ } $object = OC_VObject::parse($task['calendardata']); $vtodo = $object->VTODO; - $task = array( 'id' => $task['id'] ); - $task['summary'] = $vtodo->getAsString('SUMMARY'); - $task['description'] = $vtodo->getAsString('DESCRIPTION'); - $task['location'] = $vtodo->getAsString('LOCATION'); - $task['categories'] = $vtodo->getAsArray('CATEGORIES'); - $due = $vtodo->DUE; - if ($due) { - $due = $due->getDateTime(); - $due->setTimezone(new DateTimeZone($user_timezone)); - $task['due'] = $due->format('Y-m-d H:i:s'); - } - else { - $task['due'] = false; - } - $task['priority'] = $vtodo->getAsString('PRIORITY'); - $completed = $vtodo->COMPLETED; - if ($completed) { - $completed = $completed->getDateTime(); - $completed->setTimezone(new DateTimeZone($user_timezone)); - $task['completed'] = $completed->format('Y-m-d H:i:s'); - } - else { - $task['completed'] = false; - } - $task['complete'] = $vtodo->getAsString('PERCENT-COMPLETE'); - $tasks[] = $task; + $tasks[] = OC_Task_App::arrayForJSON($task['id'], $vtodo, $user_timezone); } } diff --git a/apps/tasks/js/tasks.js b/apps/tasks/js/tasks.js index 37ab504a72..3cf428b33a 100644 --- a/apps/tasks/js/tasks.js +++ b/apps/tasks/js/tasks.js @@ -1,4 +1,52 @@ OC.Tasks = { + create_task_div:function(task) { + var task_container = $('
') + .addClass('task') + .data('task', task) + .data('show_count', 0) + .attr('data-id', task.id) + .append($('

') + .html(''+task.summary+'') + .addClass('summary') + .attr('title', task.description) + ) + //.append(actions.clone().removeAttr('id')) + ; + var checkbox = $(''); + if (task.completed) { + checkbox.attr('checked', 'checked'); + } + $('

') + .addClass('completed') + .append(checkbox) + .prependTo(task_container); + var priority = task.priority; + $('
') + .addClass('tag') + .addClass('priority') + .addClass('priority-'+(priority?priority:'n')) + .text(priority) + .prependTo(task_container); + if (task.location) { + $('
') + .addClass('tag') + .addClass('location') + .text(task.location) + .appendTo(task_container); + } + if (task.categories.length > 0) { + var categories = $('
') + .addClass('categories') + .appendTo(task_container); + $(task.categories).each(function(i, category){ + categories.append($('') + .addClass('tag') + .text(category) + ); + }); + } + return task_container; + }, filter:function(tag, find_filter) { var tag_text = $(tag).text(); var filter = !$(tag).hasClass('active'); @@ -41,50 +89,7 @@ $(document).ready(function(){ var tasks = $('#tasks').empty().data('show_count', 0); var actions = $('#task_actions_template'); $(jsondata).each(function(i, task) { - var task_container = $('
').appendTo(tasks) - .addClass('task') - .data('task', task) - .data('show_count', 0) - .attr('data-id', task.id) - .append($('

') - .html(''+task.summary+'') - .addClass('summary') - ) - //.append(actions.clone().removeAttr('id')) - ; - var checkbox = $(''); - if (task.completed) { - checkbox.attr('checked', 'checked'); - } - $('

') - .addClass('completed') - .append(checkbox) - .prependTo(task_container); - var priority = task.priority; - $('
') - .addClass('tag') - .addClass('priority') - .addClass('priority-'+(priority?priority:'n')) - .text(priority) - .prependTo(task_container); - if (task.location) { - $('
') - .addClass('tag') - .addClass('location') - .text(task.location) - .appendTo(task_container); - } - if (task.categories.length > 0) { - var categories = $('
') - .addClass('categories') - .appendTo(task_container); - $(task.categories).each(function(i, category){ - categories.append($('') - .addClass('tag') - .text(category) - ); - }); - } + tasks.append(OC.Tasks.create_task_div(task)); }); if( $('#tasks div').length > 0 ){ $('#tasks div').first().addClass('active'); @@ -162,6 +167,7 @@ $(document).ready(function(){ if(jsondata.status == 'success'){ $('#task_details').data('id',jsondata.data.id); $('#task_details').html(jsondata.data.page); + $('#tasks').append(OC.Tasks.create_task_div(jsondata.data.task)); } else{ alert(jsondata.data.message); @@ -196,8 +202,13 @@ $(document).ready(function(){ $('.error_msg').remove(); $('.error').removeClass('error'); if(jsondata.status == 'success'){ - $('#task_details').data('id',jsondata.data.id); + var id = jsondata.data.id; + $('#task_details').data('id',id); $('#task_details').html(jsondata.data.page); + var task = jsondata.data.task; + $('#tasks .task[data-id='+id+']') + .data('task', task) + .html(OC.Tasks.create_task_div(task).html()); } else{ var errors = jsondata.data.errors; diff --git a/apps/tasks/lib/app.php b/apps/tasks/lib/app.php index 92be594424..a5f4ff6cdc 100644 --- a/apps/tasks/lib/app.php +++ b/apps/tasks/lib/app.php @@ -43,6 +43,36 @@ class OC_Task_App { ); } + public static function arrayForJSON($id, $vtodo, $user_timezone) + { + $task = array( 'id' => $id ); + $task['summary'] = $vtodo->getAsString('SUMMARY'); + $task['description'] = $vtodo->getAsString('DESCRIPTION'); + $task['location'] = $vtodo->getAsString('LOCATION'); + $task['categories'] = $vtodo->getAsArray('CATEGORIES'); + $due = $vtodo->DUE; + if ($due) { + $due = $due->getDateTime(); + $due->setTimezone(new DateTimeZone($user_timezone)); + $task['due'] = $due->format('Y-m-d H:i:s'); + } + else { + $task['due'] = false; + } + $task['priority'] = $vtodo->getAsString('PRIORITY'); + $completed = $vtodo->COMPLETED; + if ($completed) { + $completed = $completed->getDateTime(); + $completed->setTimezone(new DateTimeZone($user_timezone)); + $task['completed'] = $completed->format('Y-m-d H:i:s'); + } + else { + $task['completed'] = false; + } + $task['complete'] = $vtodo->getAsString('PERCENT-COMPLETE'); + return $task; + } + public static function validateRequest($request) { $errors = array(); @@ -84,22 +114,16 @@ class OC_Task_App { public static function createVCalendarFromRequest($request) { - $vcalendar = new Sabre_VObject_Component('VCALENDAR'); + $vcalendar = new OC_VObject('VCALENDAR'); $vcalendar->add('PRODID', 'ownCloud Calendar'); $vcalendar->add('VERSION', '2.0'); - $now = new DateTime(); - - $vtodo = new Sabre_VObject_Component('VTODO'); + $vtodo = new OC_VObject('VTODO'); $vcalendar->add($vtodo); - $created = new Sabre_VObject_Element_DateTime('CREATED'); - $created->setDateTime($now, Sabre_VObject_Element_DateTime::UTC); - $vtodo->add($created); - - $uid = self::createUID(); - $vtodo->add('UID',$uid); + $vtodo->setDateTime('CREATED', 'now', Sabre_VObject_Element_DateTime::UTC); + $vtodo->setUID(); return self::updateVCalendarFromRequest($request, $vcalendar); }