Skip to content

Commit

Permalink
fix(mail(js)): create new object instances in popup from parent's data
Browse files Browse the repository at this point in the history
  • Loading branch information
cgx committed Nov 24, 2021
1 parent cb6b729 commit a98b46a
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
20 changes: 15 additions & 5 deletions UI/WebServerResources/js/Mailer/Account.service.js
Expand Up @@ -8,7 +8,8 @@
* @constructor
* @param {object} futureAccountData
*/
function Account(futureAccountData) {
function Account(futureAccountData) {
var _this = this;
// Data is immediately available
if (typeof futureAccountData.then !== 'function') {
angular.extend(this, futureAccountData);
Expand All @@ -24,7 +25,9 @@
identity.textSignature = _.map(element.contents(), 'textContent').join(' ').trim();
}
});
Account.$log.debug('Account: ' + JSON.stringify(futureAccountData, undefined, 2));
_.forEach(this.$mailboxes, function(mailboxData, i, mailboxes) {
mailboxes[i] = new Account.$Mailbox(_this, mailboxData);
});
}
else {
// The promise will be unwrapped first
Expand Down Expand Up @@ -339,7 +342,7 @@
* @function $getMailboxByPath
* @memberof Account.prototype
* @desc Recursively find a mailbox using its path
* @returns a promise of the HTTP operation
* @returns the Mailbox instance or null if not found
*/
Account.prototype.$getMailboxByPath = function(path) {
var mailbox = null,
Expand Down Expand Up @@ -551,15 +554,22 @@
* @desc Return a sanitized object used to send to the server.
* @return an object literal copy of the Account instance
*/
Account.prototype.$omit = function () {
var account = {}, identities = [], defaultIdentity = false;
Account.prototype.$omit = function (deep) {
var account = {}, identities = [], mailboxes = [], defaultIdentity = false;

angular.forEach(this, function(value, key) {
if (key != 'constructor' && key !='identities' && key[0] != '$') {
account[key] = angular.copy(value);
}
});

if (deep) {
_.forEach(this.$mailboxes, function(mailbox) {
mailboxes.push(mailbox.$omit());
});
account.$mailboxes = mailboxes;
}

_.forEach(this.identities, function (identity) {
if (!identity.isReadOnly)
identities.push(_.pick(identity, ['email', 'fullName', 'replyTo', 'signature', 'isDefault']));
Expand Down
26 changes: 19 additions & 7 deletions UI/WebServerResources/js/Mailer/Mailer.popup.js
Expand Up @@ -130,13 +130,24 @@
/**
* @ngInject
*/
stateAccount.$inject = ['$q', '$stateParams', 'stateAccounts'];
function stateAccount($q, $stateParams, stateAccounts) {
var account;
stateAccount.$inject = ['$q', '$window', '$stateParams', 'Account', 'stateAccounts'];
function stateAccount($q, $window, $stateParams, Account, stateAccounts) {
var account = null;

account = _.find(stateAccounts, function(account) {
return account.id == $stateParams.accountId;
});
if ($window.opener) {
if ('$mailboxController' in $window.opener &&
'account' in $window.opener.$mailboxController &&
$window.opener.$mailboxController.account.id == $stateParams.accountId) {
// The message account is selected in the parent window
account = new Account($window.opener.$mailboxController.account.$omit(true));
}
}

if (!account) {
account = _.find(stateAccounts, function(account) {
return account.id == $stateParams.accountId;
});
}
if (account) {
return $q.when(account);
}
Expand All @@ -163,7 +174,8 @@
$window.opener.$mailboxController.account.id == stateAccount.id &&
$window.opener.$mailboxController.selectedFolder.path == mailboxId) {
// The message mailbox is opened in the parent window
mailbox = $window.opener.$mailboxController.selectedFolder;
mailbox = new Mailbox(stateAccount,
$window.opener.$mailboxController.selectedFolder.$omit());
}
}

Expand Down

0 comments on commit a98b46a

Please sign in to comment.