Add expand_all/collapse_all treelist methods (#6860)

* add expand_all()/collapse_all() treelist methods
* prevent possible race condition in rcmail.folder_collapsed()
pull/6894/head
johndoh 5 years ago committed by Aleksander Machniak
parent e88e0c16c9
commit 3a40f6cd91

@ -1776,6 +1776,9 @@ function rcube_webmail()
this.folder_collapsed = function(node) this.folder_collapsed = function(node)
{ {
if (this.folder_collapsed_timer)
clearTimeout(this.folder_collapsed_timer);
var prefname = this.env.task == 'addressbook' ? 'collapsed_abooks' : 'collapsed_folders', var prefname = this.env.task == 'addressbook' ? 'collapsed_abooks' : 'collapsed_folders',
old = this.env[prefname]; old = this.env[prefname];
@ -1794,7 +1797,7 @@ function rcube_webmail()
if (!this.drag_active) { if (!this.drag_active) {
if (old !== this.env[prefname]) if (old !== this.env[prefname])
this.command('save-pref', { name: prefname, value: this.env[prefname] }); this.folder_collapsed_timer = setTimeout(function(){ ref.command('save-pref', { name: prefname, value: ref.env[prefname] }); }, 10)
if (this.env.unread_counts) if (this.env.unread_counts)
this.set_unread_count_display(node.id, false); this.set_unread_count_display(node.id, false);

@ -81,6 +81,8 @@ function rcube_treelist_widget(node, p)
this.container = container; this.container = container;
this.expand = expand; this.expand = expand;
this.collapse = collapse; this.collapse = collapse;
this.expand_all = expand_all;
this.collapse_all = collapse_all;
this.select = select; this.select = select;
this.render = render; this.render = render;
this.reset = reset; this.reset = reset;
@ -210,10 +212,8 @@ function rcube_treelist_widget(node, p)
}); });
} }
/////// private methods
/** /**
* Collaps a the node with the given ID * Collapse a the node with the given ID
*/ */
function collapse(id, recursive, set) function collapse(id, recursive, set)
{ {
@ -253,6 +253,30 @@ function rcube_treelist_widget(node, p)
} }
} }
/**
* Collapse all expanded nodes
*/
function collapse_all()
{
$.each(indexbyid, function(id, data) {
if (data.children.length > 0 && !data.collapsed) {
collapse(id);
}
});
}
/**
* Expand all collapsed nodes
*/
function expand_all()
{
$.each(indexbyid, function(id, data) {
if (data.children.length > 0 && data.collapsed) {
collapse(id, false, false);
}
});
}
/** /**
* Select a tree node by it's ID * Select a tree node by it's ID
*/ */

Loading…
Cancel
Save