Use constants for the different views.
authorJan Schneider <jan@horde.org>
Wed, 5 Aug 2009 16:14:55 +0000 (18:14 +0200)
committerJan Schneider <jan@horde.org>
Wed, 5 Aug 2009 16:14:55 +0000 (18:14 +0200)
Use strings in the nag api for the different views.

kronolith/ajax.php
kronolith/js/kronolith.js
nag/config/prefs.php.dist
nag/lib/Api.php
nag/lib/Driver/Kolab.php
nag/lib/Driver/Sql.php
nag/lib/Forms/task.php
nag/lib/Nag.php
nag/list.php

index 166bf8a..2b953b0 100644 (file)
@@ -131,7 +131,7 @@ try {
         }
 
         $taskList = Horde_Util::getFormData('list');
-        $taskType = (int)Horde_Util::getFormData('taskType');
+        $taskType = Horde_Util::getFormData('taskType');
         $tasks = $registry->call('tasks/listTasks',
                                  array(null, null, null, $taskList, $taskType, true));
         if (is_a($tasks, 'PEAR_Error')) {
@@ -339,7 +339,7 @@ try {
             break;
         }
         $taskList = Horde_Util::getFormData('taskList');
-        $taskType = (int)Horde_Util::getFormData('taskType');
+        $taskType = Horde_Util::getFormData('taskType');
         $taskId = Horde_Util::getFormData('taskId');
         $saved = $registry->call('tasks/toggleCompletion',
                                  array($taskId, $taskList));
index 0201581..cde84e5 100644 (file)
@@ -26,7 +26,7 @@ KronolithCore = {
     eventsLoading: $H(),
     loading: 0,
     date: new Date(),
-    taskType: 1, //Default to all tasks view
+    taskType: 'all',
 
     doActionOpts: {
         onException: function(r, e) { KronolitCore.debug('onException', e); },
@@ -1280,11 +1280,9 @@ KronolithCore = {
     /**
      * Loads tasks, either from cache or from the server.
      *
-     * @param integer taskType  The tasks type, (1 = all tasks,
-     *                          0 = incomplete tasks, 2 = complete tasks,
-     *                          3 = future tasks, 4 = future and incomplete
-     *                          tasks)
-     * @param Array tasksLists  The lists from where to obtain the tasks
+     * @param integer taskType  The tasks type (all, incomplete, complete,
+     *                          future or future_incomplete).
+     * @param Array tasksLists  The lists from where to obtain the tasks.
      */
     _loadTasks: function(taskType, taskLists)
     {
@@ -1338,11 +1336,9 @@ KronolithCore = {
     /**
      * Reads tasks from the cache and inserts them into the view.
      *
-     * @param integer taskType  The tasks type, (1 = all tasks,
-     *                          0 = incomplete tasks, 2 = complete tasks,
-     *                          3 = future tasks, 4 = future and incomplete
-     *                          tasks)
-     * @param string tasksList  The task list to be drawn
+     * @param integer taskType  The tasks type (all, incomplete, complete,
+     *                          future or future_incomplete).
+     * @param string tasksList  The task list to be drawn.
      */
     _insertTasks: function(taskType, taskList)
     {
index 65968d4..9565566 100644 (file)
@@ -203,9 +203,10 @@ $_prefs['show_completed'] = array(
     'locked' => false,
     'shared' => false,
     'type' => 'enum',
-    'enum' => array(1 => _("All tasks"),
-                    0 => _("Incomplete tasks"),
-                    2 => _("Complete tasks")),
+    'enum' => array(Nag::VIEW_ALL => _("All tasks"),
+                    Nag::VIEW_INCOMPLETE => _("Incomplete tasks"),
+                    Nag::VIEW_COMPLETE => _("Complete tasks"),
+                    Nag::VIEW_FUTURE => _("Future tasks")),
     'desc' => _("Show complete, incomplete, or all tasks in the task list?"),
 );
 
index aaa5f1a..5788a75 100644 (file)
@@ -90,7 +90,7 @@ class Nag_Api extends Horde_Registry_Api
                 'sortdir' => 'int',
                 'altsortby' => 'string',
                 'tasklists' => '{urn:horde}stringArray',
-                'completed' => 'int',
+                'completed' => 'string',
                 'json' => 'boolean'
             ),
             'type' => '{urn:horde}stringArray',
@@ -348,25 +348,30 @@ class Nag_Api extends Horde_Registry_Api
      * @param string $sortby        The field by which to sort
      *                              (NAG_SORT_PRIORITY, NAG_SORT_NAME
      *                              NAG_SORT_DUE, NAG_SORT_COMPLETION).
-     * @param integer $sortdir      The direction by which to sort
+     * @param integer $sortdir      The direction by which to sort.
      * @param string $altsortby     The secondary sort field.
      * @param array $tasklists      An array of tasklist to display or
      *                              null/empty to display taskslists
      *                              $GLOBALS['display_tasklists'].
-     * @param integer $completed    Which tasks to retrieve (1 = all tasks,
-     *                              0 = incomplete tasks, 2 = complete tasks,
-     *                              3 = future tasks, 4 = future and incomplete
-     *                              tasks).
+     * @param string $completed     Which tasks to retrieve (all, incomplete,
+     *                              complete, future or future_incomplete).
      * @param boolean $json         Retrieve the results of the tasks in
-     *                              'json format'
+     *                              'json format'.
      *
      * @return Nag_Task  A list of the requested tasks.
      */
-    public function listTasks($sortby = null, $sortdir = null, $altsortby = null,
-        $tasklists = null, $completed = null, $json = false)
+    public function listTasks($sortby = null, $sortdir = null,
+                              $altsortby = null, $tasklists = null,
+                              $completed = null, $json = false)
     {
         require_once dirname(__FILE__) . '/base.php';
 
+        $completedArray = array('incomplete' => Nag::VIEW_INCOMPLETE,
+                                'all' => Nag::VIEW_ALL,
+                                'complete' => Nag::VIEW_COMPLETE,
+                                'future' => Nag::VIEW_FUTURE,
+                                'future_incomplete' => Nag::VIEW_FUTURE_INCOMPLETE);
+
         if (!isset($sortby)) {
             $sortby = $GLOBALS['prefs']->getValue('sortby');
         }
@@ -379,8 +384,10 @@ class Nag_Api extends Horde_Registry_Api
         if (is_null($tasklists)) {
             $tasklists = $GLOBALS['display_tasklists'];
         }
-        if (is_null($completed)) {
+        if (is_null($completed) || !isset($completedArray[$completed]) {
             $completed = $GLOBALS['prefs']->getValue('show_completed');
+        } else {
+            $completed = $completedArray[$completed];
         }
 
         $tasks = Nag::listTasks($sortby, $sortdir, $altsortby, $tasklists);
index c6d4ab4..e3f46ee 100644 (file)
@@ -533,7 +533,7 @@ class Nag_Driver_kolab_wrapper_old extends Nag_Driver_kolab_wrapper {
      *
      * @return mixed  True on success, PEAR_Error on failure.
      */
-    function retrieve($completed = 1)
+    function retrieve($completed = Nag::VIEW_ALL)
     {
         $tasks = array();
 
@@ -553,11 +553,11 @@ class Nag_Driver_kolab_wrapper_old extends Nag_Driver_kolab_wrapper {
             }
             $complete = Kolab::percentageToBoolean($this->_kolab->getVal('completed'));
             $start_date = Kolab::decodeDateOrDateTime($this->_kolab->getVal('start-date'));
-            if (($completed == 0 && ($complete || $start_date > time())) ||
-                ($completed == 2 && !$complete) ||
-                ($completed == 3 &&
+            if (($completed == Nag::VIEW_INCOMPLETE && ($complete || $start_date > time())) ||
+                ($completed == Nag::VIEW_COMPLETE && !$complete) ||
+                ($completed == Nag::VIEW_FUTURE &&
                  ($complete || $start_date == 0 || $start_date < time())) ||
-                ($completed == 4 && $complete)) {
+                ($completed == Nag::VIEW_FUTURE_INCOMPLETE && $complete)) {
                 continue;
             }
             $tasks[$this->_kolab->getUID()] = new Nag_Task($this->_buildTask());
@@ -969,11 +969,11 @@ class Nag_Driver_kolab_wrapper_new extends Nag_Driver_kolab_wrapper {
                 $start = $t->start;
             }
 
-            if (($completed == 0 && ($complete || $start > time())) ||
-                ($completed == 2 && !$complete) ||
-                ($completed == 3 &&
+            if (($completed == Nag::VIEW_INCOMPLETE && ($complete || $start > time())) ||
+                ($completed == Nag::VIEW_COMPLETE && !$complete) ||
+                ($completed == Nag::VIEW_FUTURE &&
                  ($complete || $start == 0 || $start < time())) ||
-                ($completed == 4 && $complete)) {
+                ($completed == Nag::VIEW_FUTURE_INCOMPLETE && $complete)) {
                 continue;
             }
             if (empty($t->parent_id)) {
index 1600313..f2ac012 100644 (file)
@@ -375,25 +375,25 @@ class Nag_Driver_Sql extends Nag_Driver {
      *
      * @return mixed  True on success, PEAR_Error on failure.
      */
-    function retrieve($completed = 1)
+    function retrieve($completed = Nag::VIEW_ALL)
     {
         /* Build the SQL query. */
         $query = sprintf('SELECT * FROM %s WHERE task_owner = ?',
                          $this->_params['table']);
         $values = array($this->_tasklist);
         switch ($completed) {
-        case 0:
+        case Nag::VIEW_INCOMPLETE:
             $query .= ' AND task_completed = 0 AND (task_start IS NULL OR task_start = 0 OR task_start < ?)';
             $values[] = time();
             break;
-        case 2:
+        case Nag::VIEW_COMPLETE:
             $query .= ' AND task_completed = 1';
             break;
-        case 3:
+        case Nag::VIEW_FUTURE:
             $query .= ' AND task_completed = 0 AND task_start > ?';
             $values[] = time();
             break;
-        case 4:
+        case Nag::VIEW_FUTURE_INCOMPLETE:
             $query .= ' AND task_completed = 0';
             break;
         }
index 32784d0..4719569 100644 (file)
@@ -37,7 +37,7 @@ class Nag_TaskForm extends Horde_Form {
             reset($tasklists);
             $tasklist = key($tasklists);
         }
-        $tasks = Nag::listTasks(null, null, null, array($tasklist), 4);
+        $tasks = Nag::listTasks(null, null, null, array($tasklist), Nag::VIEW_FUTURE_INCOMPLETE);
         $task_enums = array('' => _("No parent task"));
         $tasks->reset();
         while ($task = $tasks->each()) {
index fb3c76c..d1052dd 100644 (file)
@@ -62,6 +62,31 @@ class Nag
      */
     const SORT_DESCEND = 1;
 
+    /**
+     * Incomplete tasks
+     */
+    const VIEW_INCOMPLETE = 0;
+
+    /**
+     * All tasks
+     */
+    const VIEW_ALL = 1;
+
+    /**
+     * Complete tasks
+     */
+    const VIEW_COMPLETE = 2;
+
+    /**
+     * Future tasks
+     */
+    const VIEW_FUTURE = 3;
+
+    /**
+     * Future and incompleted tasks
+     */
+    const VIEW_FUTURE_INCOMPLETE = 4;
+
     public static function secondsToString($seconds)
     {
         $hours = floor($seconds / 3600);
index 52c796f..a929861 100644 (file)
@@ -103,10 +103,10 @@ if ($print_view) {
     if (!$prefs->isLocked('show_completed')) {
         $listurl = Horde::applicationUrl('list.php');
         $tabs = new Horde_UI_Tabs('show_completed', $vars);
-        $tabs->addTab(_("_All tasks"), $listurl, 1);
-        $tabs->addTab(_("Incom_plete tasks"), $listurl, 0);
-        $tabs->addTab(_("_Future tasks"), $listurl, 3);
-        $tabs->addTab(_("_Completed tasks"), $listurl, 2);
+        $tabs->addTab(_("_All tasks"), $listurl, Nag::VIEW_ALL);
+        $tabs->addTab(_("Incom_plete tasks"), $listurl, Nag::VIEW_INCOMPLETE);
+        $tabs->addTab(_("_Future tasks"), $listurl, Nag::VIEW_FUTURE);
+        $tabs->addTab(_("_Completed tasks"), $listurl, Nag::VIEW_COMPLETE);
         echo $tabs->render($vars->get('show_completed'));
     }
 }