From 947d2e5705ed606469d99ec4115b60f4eae3a0c4 Mon Sep 17 00:00:00 2001 From: Bart Visscher Date: Sun, 15 Apr 2012 15:39:49 +0200 Subject: Tasks: Mark task as complete when checking the checkbox --- apps/tasks/ajax/complete.php | 24 ++++++++++++++++++++++++ apps/tasks/css/style.css | 1 + apps/tasks/js/tasks.js | 24 +++++++++++++++++++++++- apps/tasks/lib/app.php | 10 +++++++--- 4 files changed, 55 insertions(+), 4 deletions(-) create mode 100644 apps/tasks/ajax/complete.php (limited to 'apps') diff --git a/apps/tasks/ajax/complete.php b/apps/tasks/ajax/complete.php new file mode 100644 index 00000000000..22c65c0bc83 --- /dev/null +++ b/apps/tasks/ajax/complete.php @@ -0,0 +1,24 @@ + + * This file is licensed under the Affero General Public License version 3 or + * later. + * See the COPYING-README file. + */ + +// Init owncloud +require_once('../../../lib/base.php'); +OC_JSON::checkLoggedIn(); +OC_JSON::checkAppEnabled('tasks'); + +$id = $_POST['id']; +$checked = $_POST['checked']; +$vcalendar = OC_Calendar_App::getVCalendar( $id ); + +$vtodo = $vcalendar->VTODO; +OC_Task_App::setComplete($vtodo, $checked ? '100' : '0', null); +OC_Calendar_Object::edit($id, $vcalendar->serialize()); + +$user_timezone = OC_Preferences::getValue(OC_USER::getUser(), 'calendar', 'timezone', date_default_timezone_get()); +$task_info = OC_Task_App::arrayForJSON($id, $vtodo, $user_timezone); +OC_JSON::success(array('data' => $task_info)); diff --git a/apps/tasks/css/style.css b/apps/tasks/css/style.css index cedb21b1374..52c7178e973 100644 --- a/apps/tasks/css/style.css +++ b/apps/tasks/css/style.css @@ -24,6 +24,7 @@ .task .completed {position:absolute;left:3em;top:0.3em;} .task .summary{padding-left:4em;} +.task.done .summary{text-decoration:line-through;} .task .tag{border-radius:0.4em;display:inline-block;opacity:0.2;margin:0 0.2em;border:1px solid transparent;padding:0 0.4em;} .task .tag:hover{opacity:0.5;} diff --git a/apps/tasks/js/tasks.js b/apps/tasks/js/tasks.js index 25a2e3f2687..719c49f7891 100644 --- a/apps/tasks/js/tasks.js +++ b/apps/tasks/js/tasks.js @@ -24,9 +24,11 @@ OC.Tasks = { ) //.append(actions.clone().removeAttr('id')) ; - var checkbox = $(''); + var checkbox = $('') + .click(OC.Tasks.complete_task); if (task.completed) { checkbox.attr('checked', 'checked'); + task_container.addClass('done'); } $('
') .addClass('completed') @@ -112,6 +114,26 @@ OC.Tasks = { } container.append(this); }); + }, + complete_task:function() { + var $task = $(this).closest('.task'), + task = $task.data('task'), + checked = $(this).is(':checked'); + $.post('ajax/complete.php', {id:task.id, checked:checked?1:0}, function(jsondata){ + if(jsondata.status == 'success') { + task = jsondata.data; + $task.data('task', task) + if (task.completed) { + $task.addClass('done'); + } + else { + $task.removeClass('done'); + } + } + else{ + alert(jsondata.data.message); + } + }, 'json'); } }; diff --git a/apps/tasks/lib/app.php b/apps/tasks/lib/app.php index 01294b132b3..b564866b805 100644 --- a/apps/tasks/lib/app.php +++ b/apps/tasks/lib/app.php @@ -154,6 +154,13 @@ class OC_Task_App { unset($vtodo->DUE); } + self::setComplete($vtodo, $percent_complete, $completed); + + return $vcalendar; + } + + public static function setComplete($vtodo, $percent_complete, $completed) + { if (!empty($percent_complete)) { $vtodo->setString('PERCENT-COMPLETE', $percent_complete); }else{ @@ -175,8 +182,5 @@ class OC_Task_App { } else { unset($vtodo->COMPLETED); } - - return $vcalendar; } } - -- cgit v1.2.3