From 7a4dbcb36485ccdf1e95aecc1770f26c2847479b Mon Sep 17 00:00:00 2001 From: Francis Lachapelle Date: Wed, 22 Feb 2017 23:07:26 -0500 Subject: [PATCH] (js) Update children paths when renaming a mailbox Fixes #4046 --- .../js/Mailer/Mailbox.service.js | 20 ++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) diff --git a/UI/WebServerResources/js/Mailer/Mailbox.service.js b/UI/WebServerResources/js/Mailer/Mailbox.service.js index 83c9b3237..fca58f9d7 100644 --- a/UI/WebServerResources/js/Mailer/Mailbox.service.js +++ b/UI/WebServerResources/js/Mailer/Mailbox.service.js @@ -157,7 +157,7 @@ */ Mailbox.prototype.init = function(data) { var _this = this; - if (angular.isUndefined(this.$messages)) { + if (data.headers) { this.$isLoading = true; this.$messages = []; this.uidsMap = {}; @@ -525,9 +525,8 @@ i = _.indexOf(_.map(children, 'id'), this.id); return this.$save().then(function(data) { - var sibling; - angular.extend(_this, data); // update the path attribute - _this.id = _this.$id(); + var sibling, oldPath = _this.path; + _this.init(data); // update the path and id // Move mailbox among its siblings according to its new name children.splice(i, 1); @@ -542,6 +541,17 @@ i = children.length; } children.splice(i, 0, _this); + + // Update the path and id of children + var pathRE = new RegExp('^' + oldPath); + var _updateChildren = function(mailbox) { + _.forEach(mailbox.children, function(child) { + child.path = child.path.replace(pathRE, _this.path); + child.id = child.$id(); + _updateChildren(child); + }); + }; + _updateChildren(_this); }); }; @@ -869,7 +879,7 @@ _this.init(data); if (_this.uids) { - Mailbox.$log.debug('unwrapping ' + data.uids.length + ' messages'); + Mailbox.$log.debug('unwrapping ' + _this.uids.length + ' messages'); // First entry of 'headers' are keys headers = _.invokeMap(_this.headers[0], 'toLowerCase');