Fix hierarchical task list rendering; fix count updates; also assign all child tasks to the new list when parent is moved
This commit is contained in:
parent
3fce0577c6
commit
2cc6a00acf
2 changed files with 81 additions and 22 deletions
|
@ -415,9 +415,14 @@ function rcube_tasklist_ui(settings)
|
||||||
loadstate.filter = response.filter;
|
loadstate.filter = response.filter;
|
||||||
loadstate.search = response.search;
|
loadstate.search = response.search;
|
||||||
|
|
||||||
for (var i=0; i < response.data.length; i++) {
|
for (var id, i=0; i < response.data.length; i++) {
|
||||||
listdata[response.data[i].id] = response.data[i];
|
id = response.data[i].id;
|
||||||
listindex.push(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();
|
render_tasklist();
|
||||||
|
@ -486,6 +491,7 @@ function rcube_tasklist_ui(settings)
|
||||||
$('#taskselector a').each(function(i, elem){
|
$('#taskselector a').each(function(i, elem){
|
||||||
var link = $(elem),
|
var link = $(elem),
|
||||||
f = link.parent().attr('class').replace(/\s\w+/, '');
|
f = link.parent().attr('class').replace(/\s\w+/, '');
|
||||||
|
if (f != 'all')
|
||||||
link.children('span').html(taskcounts[f] || '')[(taskcounts[f] ? 'show' : 'hide')]();
|
link.children('span').html(taskcounts[f] || '')[(taskcounts[f] ? 'show' : 'hide')]();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -498,9 +504,16 @@ function rcube_tasklist_ui(settings)
|
||||||
*/
|
*/
|
||||||
function update_taskitem(rec)
|
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,
|
var id = rec.id,
|
||||||
oldid = rec.tempid || id;
|
oldid = rec.tempid || id,
|
||||||
oldindex = listindex.indexOf(oldid);
|
oldindex = listindex.indexOf(oldid),
|
||||||
|
list = me.tasklists[rec.list];
|
||||||
|
|
||||||
if (oldindex >= 0)
|
if (oldindex >= 0)
|
||||||
listindex[oldindex] = id;
|
listindex[oldindex] = id;
|
||||||
|
@ -509,7 +522,11 @@ function rcube_tasklist_ui(settings)
|
||||||
|
|
||||||
listdata[id] = rec;
|
listdata[id] = rec;
|
||||||
|
|
||||||
|
if (list.active)
|
||||||
render_task(rec, oldid);
|
render_task(rec, oldid);
|
||||||
|
else
|
||||||
|
$('li[rel="'+id+'"]', rcmail.gui_objects.resultlist).remove();
|
||||||
|
|
||||||
append_tags(rec.tags || []);
|
append_tags(rec.tags || []);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -683,6 +700,21 @@ function rcube_tasklist_ui(settings)
|
||||||
return d;
|
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 */
|
/* Helper functions for drag & drop functionality */
|
||||||
|
|
||||||
|
@ -752,7 +784,11 @@ function rcube_tasklist_ui(settings)
|
||||||
// dropped on another list -> move
|
// dropped on another list -> move
|
||||||
if ($(this).data('type') == 'tasklist') {
|
if ($(this).data('type') == 'tasklist') {
|
||||||
if (rec) {
|
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;
|
rec.list = drop_id;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -180,8 +180,16 @@ class tasklist extends rcube_plugin
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 'move':
|
case 'move':
|
||||||
if ($success = $this->driver->move_task($rec)) {
|
$recs = array();
|
||||||
$refresh = $this->driver->get_task($rec);
|
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;
|
break;
|
||||||
|
|
||||||
|
@ -207,6 +215,7 @@ class tasklist extends rcube_plugin
|
||||||
$this->rc->output->command('plugin.unlock_saving');
|
$this->rc->output->command('plugin.unlock_saving');
|
||||||
|
|
||||||
if ($refresh) {
|
if ($refresh) {
|
||||||
|
if ($refresh['id'])
|
||||||
$this->encode_task($refresh);
|
$this->encode_task($refresh);
|
||||||
$this->rc->output->command('plugin.refresh_task', $refresh);
|
$this->rc->output->command('plugin.refresh_task', $refresh);
|
||||||
}
|
}
|
||||||
|
@ -405,7 +414,15 @@ class tasklist extends rcube_plugin
|
||||||
*/
|
*/
|
||||||
public function fetch_counts()
|
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);
|
$counts = $this->driver->count_tasks($lists);
|
||||||
$this->rc->output->command('plugin.update_counts', $counts);
|
$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
|
// 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'));
|
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))));
|
$this->rc->output->command('plugin.data_ready', array('filter' => $f, 'lists' => $lists, 'search' => $search, 'data' => $data, 'tags' => array_values(array_unique($tags))));
|
||||||
|
@ -526,7 +544,15 @@ class tasklist extends rcube_plugin
|
||||||
$rec['attachments'][$k]['classname'] = rcmail_filetype2classname($attachment['mimetype'], $attachment['name']);
|
$rec['attachments'][$k]['classname'] = rcmail_filetype2classname($attachment['mimetype'], $attachment['name']);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!isset($rec['_depth'])) {
|
$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;
|
$rec['_depth'] = 0;
|
||||||
$parent_id = $this->task_tree[$rec['id']];
|
$parent_id = $this->task_tree[$rec['id']];
|
||||||
while ($parent_id) {
|
while ($parent_id) {
|
||||||
|
@ -536,9 +562,6 @@ class tasklist extends rcube_plugin
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->task_titles[$rec['id']] = $rec['title'];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Compare function for task list sorting.
|
* Compare function for task list sorting.
|
||||||
* Nested tasks need to be sorted to the end.
|
* Nested tasks need to be sorted to the end.
|
||||||
|
|
Loading…
Add table
Reference in a new issue