Tasks: Add due property handling

This commit is contained in:
Bart Visscher 2012-04-20 18:16:39 +02:00
parent 921fc59d8f
commit c75bbb59a9
5 changed files with 65 additions and 1 deletions

View file

@ -21,6 +21,21 @@ switch($property) {
$summary = $_POST['summary'];
$vtodo->setString('SUMMARY', $summary);
break;
case 'due':
$due = $_POST['due'];
if ($due != 'false') {
try {
$timezone = OC_Preferences::getValue(OC_User::getUser(), 'calendar', 'timezone', date_default_timezone_get());
$timezone = new DateTimeZone($timezone);
$due = new DateTime('@'.$due);
$due->setTimezone($timezone);
} catch (Exception $e) {
OC_JSON::error(array('data'=>array('message'=>OC_Task_App::$l10n->t('Invalid date/time'))));
exit();
}
}
$vtodo->setDateTime('DUE', $due);
break;
case 'complete':
$checked = $_POST['checked'];
OC_Task_App::setComplete($vtodo, $checked ? '100' : '0', null);

View file

@ -53,3 +53,6 @@
.task .more{display:none;}
.task .description{position:relative;left:4em;}
.task .due{position:absolute;right:0.3em;}
.task .due .date{width:6em;}
.task .due .time{width:6em;}

View file

@ -18,6 +18,8 @@ if( count($calendars) == 0 ) {
exit;
}
OC_Util::addScript('3rdparty/timepicker', 'jquery.ui.timepicker');
OC_Util::addStyle('3rdparty/timepicker', 'jquery.ui.timepicker');
OC_UTIL::addScript('tasks', 'tasks');
OC_UTIL::addStyle('tasks', 'style');
OC_Util::addScript('contacts','jquery.multi-autocomplete');

View file

@ -65,9 +65,32 @@ OC.Tasks = {
var description = $('<textarea>')
.addClass('description')
.text(task.description);
var due = $('<span>')
.addClass('due')
.append(t('tasks', 'Due'));
due
.append($('<input type="date">')
.addClass('date')
.datepicker({
dateFormat: 'dd-mm-yy',
onClose: OC.Tasks.dueUpdateHandler
}),
$('<input type="time">')
.addClass('time')
.timepicker({
showPeriodLabels:false,
onClose: OC.Tasks.dueUpdateHandler
})
);
if (task.due){
var date = new Date(parseInt(task.due)*1000);
due.find('.date').datepicker('setDate', date);
due.find('.time').timepicker('setTime', date.getHours()+':'+date.getMinutes());
}
$('<div>')
.addClass('more')
.append(description)
.append(due)
.appendTo(task_container);
return task_container;
},
@ -156,6 +179,27 @@ OC.Tasks = {
input.focus();
return false;
},
dueUpdateHandler:function(){
var task = $(this).closest('.task').data('task');
var old_due = task.due;
var $date = $(this).parent().children('.date');
var $time = $(this).parent().children('.time');
var date = $date.datepicker('getDate');
var time = $time.timepicker('getTime').split(':');
var due;
if (!date || time.length<2){
due = false;
} else {
date.setHours(time[0]);
date.setMinutes(time[1]);
due = date.getTime()/1000;
}
$.post('ajax/update_property.php', {id:task.id, type:'due', due:due}, function(jsondata){
if(jsondata.status != 'success') {
task.due = old_due;
}
});
},
moreClickHandler:function(event){
var $task = $(this).closest('.task'),
task = $task.data('task');

View file

@ -54,7 +54,7 @@ class OC_Task_App {
if ($due) {
$due = $due->getDateTime();
$due->setTimezone(new DateTimeZone($user_timezone));
$task['due'] = $due->format('Y-m-d H:i:s');
$task['due'] = $due->format('U');
}
else {
$task['due'] = false;