From 3a40f6cd9181afe487563575187f731277c79701 Mon Sep 17 00:00:00 2001 From: johndoh Date: Sat, 10 Aug 2019 07:46:33 +0100 Subject: [PATCH] Add expand_all/collapse_all treelist methods (#6860) * add expand_all()/collapse_all() treelist methods * prevent possible race condition in rcmail.folder_collapsed() --- program/js/app.js | 5 ++++- program/js/treelist.js | 30 +++++++++++++++++++++++++++--- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/program/js/app.js b/program/js/app.js index f5f506129..b2f82c578 100644 --- a/program/js/app.js +++ b/program/js/app.js @@ -1776,6 +1776,9 @@ function rcube_webmail() 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', old = this.env[prefname]; @@ -1794,7 +1797,7 @@ function rcube_webmail() if (!this.drag_active) { 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) this.set_unread_count_display(node.id, false); diff --git a/program/js/treelist.js b/program/js/treelist.js index 96610a14c..c120e4a29 100644 --- a/program/js/treelist.js +++ b/program/js/treelist.js @@ -81,6 +81,8 @@ function rcube_treelist_widget(node, p) this.container = container; this.expand = expand; this.collapse = collapse; + this.expand_all = expand_all; + this.collapse_all = collapse_all; this.select = select; this.render = render; 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) { @@ -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 */