2 commits - plugins/tasklist

Thomas Brüderli bruederli at kolabsys.com
Wed Sep 19 13:22:26 CEST 2012


 plugins/tasklist/tasklist.js  |   54 +++++++++++++++++++++++++++++++------
 plugins/tasklist/tasklist.php |   60 +++++++++++++++++++++++++++++-------------
 2 files changed, 87 insertions(+), 27 deletions(-)

New commits:
commit c7614649e4312a2f079c5b771316a0fa3a4da821
Author: Thomas Bruederli <thomas at roundcube.net>
Date:   Wed Sep 19 13:20:14 2012 +0200

    Fix date picker format and quick-filter assigments

diff --git a/plugins/tasklist/tasklist.js b/plugins/tasklist/tasklist.js
index 1605c49..49c8b36 100644
--- a/plugins/tasklist/tasklist.js
+++ b/plugins/tasklist/tasklist.js
@@ -69,7 +69,7 @@ function rcube_tasklist_ui(settings)
     // general datepicker settings
     var datepicker_settings = {
       // translate from PHP format to datepicker format
-      dateFormat: settings['date_format'].replace(/m/, 'mm').replace(/n/g, 'm').replace(/F/, 'MM').replace(/l/, 'DD').replace(/dd/, 'D').replace(/d/, 'dd').replace(/j/, 'd').replace(/Y/g, 'yy'),
+      dateFormat: settings['date_format'].replace(/M/g, 'm').replace(/mmmmm/, 'MM').replace(/mmm/, 'M').replace(/dddd/, 'DD').replace(/ddd/, 'D').replace(/yy/g, 'y'),
       firstDay : settings['first_day'],
 //      dayNamesMin: settings['days_short'],
 //      monthNames: settings['months'],
diff --git a/plugins/tasklist/tasklist.php b/plugins/tasklist/tasklist.php
index 88eed94..8c584fc 100644
--- a/plugins/tasklist/tasklist.php
+++ b/plugins/tasklist/tasklist.php
@@ -595,6 +595,7 @@ class tasklist extends rcube_plugin
 
         $mask = 0;
         $start = $rec['startdate'] ?: '1900-00-00';
+        $duedate = $rec['date'] ?: '3000-00-00';
 
         if ($rec['flagged'])
             $mask |= self::FILTER_MASK_FLAGGED;
@@ -606,13 +607,13 @@ class tasklist extends rcube_plugin
         else if ($rec['date'] < $today)
             $mask |= self::FILTER_MASK_OVERDUE;
 
-        if ($rec['date'] >= $today && $start <= $today)
+        if ($duedate <= $today || ($rec['startdate'] && $start <= $today))
             $mask |= self::FILTER_MASK_TODAY;
-        if ($rec['date'] >= $tomorrow && $start <= $tomorrow)
+        if ($duedate <= $tomorrow || ($rec['startdate'] && $start <= $tomorrow))
             $mask |= self::FILTER_MASK_TOMORROW;
-        if (($start > $tomorrow || $rec['date'] > $tomorrow) && $rec['date'] <= $weeklimit)
+        if (($start > $tomorrow || $duedate > $tomorrow) && $duedate <= $weeklimit)
             $mask |= self::FILTER_MASK_WEEK;
-        if ($start > $weeklimit || $rec['date'] > $weeklimit)
+        if ($start > $weeklimit || $duedate > $weeklimit)
             $mask |= self::FILTER_MASK_LATER;
 
         return $mask;


commit 2cc6a00acf132800bc491660e76ad4a9dc487c3b
Author: Thomas Bruederli <thomas at roundcube.net>
Date:   Wed Sep 19 13:01:12 2012 +0200

    Fix hierarchical task list rendering; fix count updates; also assign all child tasks to the new list when parent is moved

diff --git a/plugins/tasklist/tasklist.js b/plugins/tasklist/tasklist.js
index 99c93de..1605c49 100644
--- a/plugins/tasklist/tasklist.js
+++ b/plugins/tasklist/tasklist.js
@@ -415,9 +415,14 @@ function rcube_tasklist_ui(settings)
         loadstate.filter = response.filter;
         loadstate.search = response.search;
 
-        for (var i=0; i < response.data.length; i++) {
-            listdata[response.data[i].id] = response.data[i];
-            listindex.push(response.data[i].id);
+        for (var id, i=0; i < response.data.length; i++) {
+            id = response.data[i].id;
+            listindex.push(id);
+            listdata[id] = response.data[i];
+            listdata[id].children = [];
+            // register a forward-pointer to child tasks
+            if (listdata[id].parent_id && listdata[listdata[id].parent_id])
+                listdata[listdata[id].parent_id].children.push(id);
         }
 
         render_tasklist();
@@ -486,7 +491,8 @@ function rcube_tasklist_ui(settings)
         $('#taskselector a').each(function(i, elem){
             var link = $(elem),
                 f = link.parent().attr('class').replace(/\s\w+/, '');
-            link.children('span').html(taskcounts[f] || '')[(taskcounts[f] ? 'show' : 'hide')]();
+            if (f != 'all')
+                link.children('span').html(taskcounts[f] || '')[(taskcounts[f] ? 'show' : 'hide')]();
         });
 
         // spacial case: overdue
@@ -498,9 +504,16 @@ function rcube_tasklist_ui(settings)
      */
     function update_taskitem(rec)
     {
+        // handle a list of task records
+        if ($.isArray(rec)) {
+            $.each(rec, function(i,r){ update_taskitem(r); });
+            return;
+        }
+
         var id = rec.id,
-            oldid = rec.tempid || id;
-            oldindex = listindex.indexOf(oldid);
+            oldid = rec.tempid || id,
+            oldindex = listindex.indexOf(oldid),
+            list = me.tasklists[rec.list];
 
         if (oldindex >= 0)
             listindex[oldindex] = id;
@@ -509,7 +522,11 @@ function rcube_tasklist_ui(settings)
 
         listdata[id] = rec;
 
-        render_task(rec, oldid);
+        if (list.active)
+            render_task(rec, oldid);
+        else
+            $('li[rel="'+id+'"]', rcmail.gui_objects.resultlist).remove();
+
         append_tags(rec.tags || []);
     }
 
@@ -683,6 +700,21 @@ function rcube_tasklist_ui(settings)
         return d;
     }
 
+    /**
+     *
+     */
+    function get_all_childs(id)
+    {
+        var cid, childs = [];
+        for (var i=0; listdata[id].children && i < listdata[id].children.length; i++) {
+            cid = listdata[id].children[i];
+            childs.push(cid);
+            childs = childs.concat(get_all_childs(cid));
+        }
+
+        return childs;
+    }
+
 
     /*  Helper functions for drag & drop functionality  */
     
@@ -752,7 +784,11 @@ function rcube_tasklist_ui(settings)
         // dropped on another list -> move
         if ($(this).data('type') == 'tasklist') {
             if (rec) {
-                save_task({ id:rec.id, list:drop_id, _fromlist:rec.list }, 'move');
+                var ids = [ rec.id ],
+                    childs = get_all_childs(rec.id);
+                if (childs.length)
+                    ids = ids.concat(childs);
+                save_task({ id:ids, list:drop_id, _fromlist:rec.list }, 'move');
                 rec.list = drop_id;
             }
         }
diff --git a/plugins/tasklist/tasklist.php b/plugins/tasklist/tasklist.php
index 88f87fa..88eed94 100644
--- a/plugins/tasklist/tasklist.php
+++ b/plugins/tasklist/tasklist.php
@@ -180,8 +180,16 @@ class tasklist extends rcube_plugin
             break;
 
           case 'move':
-              if ($success = $this->driver->move_task($rec)) {
-                  $refresh = $this->driver->get_task($rec);
+              $recs = array();
+              foreach ((array)$rec['id'] as $id) {
+                  $r = $rec;
+                  $r['id'] = $id;
+                  if ($this->driver->move_task($r)) {
+                      $r = $this->driver->get_task($r);
+                      $this->encode_task($r);
+                      $refresh[] = $r;
+                      $success = true;
+                  }
               }
               break;
 
@@ -207,7 +215,8 @@ class tasklist extends rcube_plugin
         $this->rc->output->command('plugin.unlock_saving');
 
         if ($refresh) {
-            $this->encode_task($refresh);
+            if ($refresh['id'])
+                $this->encode_task($refresh);
             $this->rc->output->command('plugin.refresh_task', $refresh);
         }
     }
@@ -405,7 +414,15 @@ class tasklist extends rcube_plugin
      */
     public function fetch_counts()
     {
-        $lists = get_input_value('lists', RCUBE_INPUT_GPC);;
+        if (isset($_REQUEST['lists'])) {
+            $lists = get_input_value('lists', RCUBE_INPUT_GPC);
+        }
+        else {
+            foreach ($this->driver->get_lists() as $list) {
+                if ($list['active'])
+                    $lists[] = $list['id'];
+            }
+        }
         $counts = $this->driver->count_tasks($lists);
         $this->rc->output->command('plugin.update_counts', $counts);
     }
@@ -477,6 +494,7 @@ class tasklist extends rcube_plugin
         }
 
         // sort tasks according to their hierarchy level and due date
+        array_walk($data, array($this, 'task_walk_tree'));
         usort($data, array($this, 'task_sort_cmp'));
 
         $this->rc->output->command('plugin.data_ready', array('filter' => $f, 'lists' => $lists, 'search' => $search, 'data' => $data, 'tags' => array_values(array_unique($tags))));
@@ -526,20 +544,25 @@ class tasklist extends rcube_plugin
             $rec['attachments'][$k]['classname'] = rcmail_filetype2classname($attachment['mimetype'], $attachment['name']);
         }
 
-        if (!isset($rec['_depth'])) {
-            $rec['_depth'] = 0;
-            $parent_id = $this->task_tree[$rec['id']];
-            while ($parent_id) {
-                $rec['_depth']++;
-                $rec['parent_title'] = $this->task_titles[$parent_id];
-                $parent_id = $this->task_tree[$parent_id];
-            }
-        }
-
         $this->task_titles[$rec['id']] = $rec['title'];
     }
 
     /**
+     * Callback function for array_walk over all tasks.
+     * Sets tree depth and parent titles
+     */
+    private function task_walk_tree(&$rec)
+    {
+        $rec['_depth'] = 0;
+        $parent_id = $this->task_tree[$rec['id']];
+        while ($parent_id) {
+            $rec['_depth']++;
+            $rec['parent_title'] = $this->task_titles[$parent_id];
+            $parent_id = $this->task_tree[$parent_id];
+        }
+    }
+
+    /**
      * Compare function for task list sorting.
      * Nested tasks need to be sorted to the end.
      */





More information about the commits mailing list