From 7c4b1b36cfd6a9213879585a7a310f661eb8be20 Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Thu, 26 May 2016 11:18:36 -0400 Subject: [PATCH] (js) Fix restore of mailboxes expansion states --- NEWS | 1 + .../js/Mailer/Account.service.js | 22 +++++++++++++------ 2 files changed, 16 insertions(+), 7 deletions(-) diff --git a/NEWS b/NEWS index 3829d0454..7ed5b2b85 100644 --- a/NEWS +++ b/NEWS @@ -14,6 +14,7 @@ Bug fixes - [web] fixed event classification icon (private/confidential) in day/week/multicolumn views - [web] fixed display of mailboxes list on mobiles (#3654) - [web] restored Catalan and Slovak translations (#3687) + - [web] fixed restore of mailboxes expansion state when multiple IMAP accounts are configured 3.1.0 (2016-05-18) ------------------ diff --git a/UI/WebServerResources/js/Mailer/Account.service.js b/UI/WebServerResources/js/Mailer/Account.service.js index 2b699c861..4dcabb179 100644 --- a/UI/WebServerResources/js/Mailer/Account.service.js +++ b/UI/WebServerResources/js/Mailer/Account.service.js @@ -86,6 +86,8 @@ o.id = i; collection[i] = new Account(o); }); + Account.$accounts = collection; + return collection; }; @@ -139,7 +141,10 @@ * @function $flattenMailboxes * @memberof Account.prototype * @desc Get a flatten array of the mailboxes. - * @param {object} [options] - force a reload + * @param {object} [options] - the following boolean attributes are available: + * - reload: rebuild the flatten array of mailboxes from the original tree representation (this.$mailboxes) + * - all: return all mailboxes, ignoring their expanstion state + * - saveState: save expansion state of mailboxes to the server * @returns an array of Mailbox instances */ Account.prototype.$flattenMailboxes = function(options) { @@ -163,12 +168,15 @@ if (!options || !options.all) { _this.$$flattenMailboxes = allMailboxes; if (options && options.saveState) { - _.reduce(allMailboxes, function(expandedFolders, mailbox) { - if (mailbox.$expanded) { - expandedFolders.push('/' + mailbox.id); - } - return expandedFolders; - }, expandedMailboxes); + // Save expansion state of mailboxes to the server + _.forEach(Account.$accounts, function(account) { + _.reduce(account.$$flattenMailboxes, function(expandedFolders, mailbox) { + if (mailbox.$expanded) { + expandedFolders.push('/' + mailbox.id); + } + return expandedFolders; + }, expandedMailboxes); + }); Account.$$resource.post(null, 'saveFoldersState', expandedMailboxes); } }