From b34d6550bec76e0ff130028626590410bf7e1a33 Mon Sep 17 00:00:00 2001 From: Jan Schneider Date: Fri, 13 Nov 2009 00:15:28 +0100 Subject: [PATCH] Implement task viewing. --- kronolith/ajax.php | 21 +++++++++++ kronolith/js/kronolith.js | 77 ++++++++++++++++++++++++++++++++------ kronolith/templates/index/task.inc | 10 ++--- nag/lib/Api.php | 15 ++++++++ nag/lib/Task.php | 16 +++++--- 5 files changed, 118 insertions(+), 21 deletions(-) diff --git a/kronolith/ajax.php b/kronolith/ajax.php index 3b41c3c91..078d1836c 100644 --- a/kronolith/ajax.php +++ b/kronolith/ajax.php @@ -348,6 +348,27 @@ try { } break; + case 'GetTask': + if (!$registry->hasMethod('tasks/getTask')) { + break; + } + if (is_null($id = Horde_Util::getFormData('id')) || + is_null($list = Horde_Util::getFormData('list'))) { + break; + } + $task = $registry->tasks->getTask($list, $id); + if (is_a($task, 'PEAR_Error')) { + $notification->push($task, 'horde.error'); + break; + } + if (!$task) { + $notification->push(_("The requested task was not found."), 'horde.error'); + break; + } + $result = new stdClass; + $result->task = $task->toJson(true, $prefs->getValue('twentyFour') ? 'H:i' : 'h:i A'); + break; + case 'ToggleCompletion': if (!$registry->hasMethod('tasks/toggleCompletion')) { break; diff --git a/kronolith/js/kronolith.js b/kronolith/js/kronolith.js index 3ca1daa3e..c939d414a 100644 --- a/kronolith/js/kronolith.js +++ b/kronolith/js/kronolith.js @@ -1657,27 +1657,82 @@ KronolithCore = { RedBox.onDisplay = null; }; - //this.updateTasklistDropDown(); - if (false && id) { + this.updateTasklistDropDown(); + if (id) { RedBox.loading(); this.doAction('GetTask', { 'list': tasklist, 'id': id }, this._editTask.bind(this)); } else { - /* - $('kronolithTaskId').value = ''; - $('kronolithTaskList').value = Kronolith.conf.default_tasklist; + $('kronolithTaskId').clear(); + $('kronolithTaskList').setValue(Kronolith.conf.default_tasklist); $('kronolithTaskDelete').hide(); - $('kronolithTaskStartDate').value = d.toString(Kronolith.conf.date_format); - $('kronolithTaskStartTime').value = d.toString(Kronolith.conf.time_format); - d.add(1).hour(); - $('kronolithTaskEndDate').value = d.toString(Kronolith.conf.date_format); - $('kronolithTaskEndTime').value = d.toString(Kronolith.conf.time_format); - */ + $('kronolithTaskDueDate').setValue(d.toString(Kronolith.conf.date_format)); + $('kronolithTaskDueTime').setValue(d.toString(Kronolith.conf.time_format)); RedBox.showHtml($('kronolithTaskDialog').show()); this.taskForm = RedBox.getWindowContents(); } }, /** + * Callback method for showing task forms. + * + * @param object r The ajax response object. + */ + _editTask: function(r) + { + if (!r.response.task) { + RedBox.close(); + window.history.back(); + return; + } + + var task = r.response.task; + + /* Basic information */ + $('kronolithTaskId').setValue(task.id); + $('kronolithTaskList').setValue(task.l); + $('kronolithTaskTitle').setValue(task.n); + //$('kronolithTaskLocation').setValue(task.l); + $('kronolithTaskDueDate').setValue(task.dd); + $('kronolithTaskDueTime').setValue(task.dt); + $('kronolithTaskDescription').setValue(task.de); + $('kronolithTaskPriority').setValue(task.pr); + + /* Alarm */ + if (task.a) { + $('kronolithTaskAlarmOn').setValue(true); + [10080, 1440, 60, 1].each(function(unit) { + if (task.a % unit == 0) { + $('kronolithTaskAlarmValue').setValue(task.a / unit); + $('kronolithTaskAlarmUnit').setValue(unit); + throw $break; + } + }); + } else { + $('kronolithEventAlarmOff').setValue(true); + } + + RedBox.showHtml($('kronolithTaskDialog').show()); + this.eventForm = RedBox.getWindowContents(); + }, + + /** + * Propagates a SELECT drop down list with the editable task lists. + * + * @param string id The id of the SELECT element. + */ + updateTasklistDropDown: function() + { + $('kronolithTaskList').update(); + $H(Kronolith.conf.calendars.tasklists).each(function(cal) { + if (cal.value.edit) { + $('kronolithTaskList').insert(new Element('OPTION', { 'value': 'tasks|' + cal.key }) + .setStyle({ 'backgroundColor': cal.value.bg, 'color': cal.value.fg }) + .update(cal.value.name.escapeHTML())); + } + }); + }, + + /** * Parses a date attribute string into a Date object. * * For other strings use Date.parse(). diff --git a/kronolith/templates/index/task.inc b/kronolith/templates/index/task.inc index 490a7d3a0..61fdb3c19 100644 --- a/kronolith/templates/index/task.inc +++ b/kronolith/templates/index/task.inc @@ -49,16 +49,16 @@
- +