Implement task viewing.
authorJan Schneider <jan@horde.org>
Thu, 12 Nov 2009 23:15:28 +0000 (00:15 +0100)
committerJan Schneider <jan@horde.org>
Thu, 12 Nov 2009 23:16:11 +0000 (00:16 +0100)
kronolith/ajax.php
kronolith/js/kronolith.js
kronolith/templates/index/task.inc
nag/lib/Api.php
nag/lib/Task.php

index 3b41c3c..078d183 100644 (file)
@@ -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;
index 3ca1daa..c939d41 100644 (file)
@@ -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().
index 490a7d3..61fdb3c 100644 (file)
 <br class="clear" />
 
 <div id="kronolithTaskTabDescription" class="kronolithTabsOption">
-  <textarea name="desc" id="taskDescription" rows="5" cols="40" class="kronolithLongField"></textarea>
+  <textarea name="desc" id="kronolithTaskDescription" rows="5" cols="40" class="kronolithLongField"></textarea>
 </div>
 
 <div id="kronolithTaskTabReminder" class="kronolithTabsOption" style="display:none">
-   <label><input type="radio" name="nag_alarm[on]" value="0" checked="checked" /> <?php echo _("don't set") ?></label>
+   <label><input type="radio" name="nag_alarm[on]" id="kronolithTaskAlarmOff" value="0" checked="checked" /> <?php echo _("don't set") ?></label>
    <?php echo _("or") ?>
-   <label><input type="radio" name="nag_alarm[on]" value="1" /> <?php echo _("set") ?></label>
+   <label><input type="radio" name="nag_alarm[on]" id="kronolithTaskAlarmOn" value="1" /> <?php echo _("set") ?></label>
    <label>
-     <input type="text" name="nag_alarm[value]" size="3" value="15" class="kronolithEventValue" />
-     <select name="nag_alarm[unit]">
+     <input type="text" name="nag_alarm[value]" id="kronolithTaskAlarmValue" size="3" value="15" class="kronolithEventValue" />
+     <select name="nag_alarm[unit]" id="kronolithTaskAlarmUnit">
        <option value="1"><?php echo _("minutes") ?></option>
        <option value="60"><?php echo _("hours") ?></option>
        <option value="1440"><?php echo _("days") ?></option>
index 2a62e3e..0788a85 100644 (file)
@@ -934,6 +934,21 @@ class Nag_Api extends Horde_Registry_Api
     }
 
     /**
+     * Returns a task object.
+     *
+     * @param string $tasklist  A tasklist id.
+     * @param string $id        A task id.
+     *
+     * @return Nag_Task  The matching task object.
+     */
+    public function getTask($tasklist, $id)
+    {
+        require_once dirname(__FILE__) . '/base.php';
+        $storage = Nag_Driver::singleton($tasklist);
+        return $storage->get($id);
+    }
+
+    /**
      * Exports a tasklist in the requested content type.
      *
      * @param string $tasklist     The tasklist to export.
index 666b2b3..110340e 100644 (file)
@@ -653,11 +653,12 @@ class Nag_Task {
      * Returns a simple object suitable for json transport representing this
      * task.
      *
-     * @param boolean $full  Whether to return all event details.
+     * @param boolean $full        Whether to return all event details.
+     * @param string $time_format  The date() format to use for time formatting.
      *
      * @return object  A simple object.
      */
-    function toJson($full = false)
+    function toJson($full = false, $time_format = 'H:i')
     {
         $json = new stdClass;
         $json->l = $this->tasklist;
@@ -682,11 +683,15 @@ class Nag_Task {
             // @todo: do we really need all this?
             $json->id = $this->id;
             $json->de = $this->desc;
-            $json->ui = $this->uid;
+            if ($this->due) {
+                $date = new Horde_Date($this->due);
+                $json->dd = $date->strftime('%x');
+                $json->dt = $date->format($time_format);
+            }
+            /*
             $json->p = $this->parent_id;
             $json->o = $this->owner;
             $json->as = $this->assignee;
-            $json->ct = $this->category;
             if ($this->estimate) {
                 $date = new Horde_Date($this->estimate);
                 $json->e = $date->toJson();
@@ -695,9 +700,10 @@ class Nag_Task {
                 $date = new Horde_Date($this->completed_date);
                 $json->cd = $date->toJson();
             }
+            */
             $json->a = $this->alarm;
             $json->m = $this->methods;
-            $json->pv = (boolean)$this->private;
+            //$json->pv = (boolean)$this->private;
         }
 
         return $json;