Fixup the mailbox edit logic
This commit is contained in:
@@ -158,7 +158,7 @@ angular.module('Application').controller('EmailController', ['$scope', '$locatio
|
||||
if (error) return console.error(error);
|
||||
|
||||
$scope.mailboxes.mailboxes = mailboxes.map(function (m) {
|
||||
m.aliases = aliases.filter(function (a) { return a.ownerId === m.id; }).map(function (a) { return a.name; }).join(',');
|
||||
m.aliases = aliases.filter(function (a) { return a.aliasTarget === m.name; }).map(function (a) { return a.name; }).join(',');
|
||||
m.owner = $scope.users.find(function (u) { return u.id === m.ownerId; });
|
||||
|
||||
m.orig = {};
|
||||
@@ -171,21 +171,21 @@ angular.module('Application').controller('EmailController', ['$scope', '$locatio
|
||||
});
|
||||
},
|
||||
|
||||
submit: function (user) {
|
||||
user.busy = true;
|
||||
user.error ='';
|
||||
submit: function (mailbox) {
|
||||
mailbox.busy = true;
|
||||
mailbox.error ='';
|
||||
|
||||
var aliases = user.aliases.split(',').map(function (a) { return a.trim(); }).filter(function (a) { return !!a; });
|
||||
var aliases = mailbox.aliases.split(',').map(function (a) { return a.trim(); }).filter(function (a) { return !!a; });
|
||||
|
||||
function done(error) {
|
||||
user.busy = false;
|
||||
mailbox.busy = false;
|
||||
|
||||
if (error && error.statusCode === 409) {
|
||||
var alias = error.message.match(RegExp('\'(.*)-' + $scope.selectedDomain.domain + '\''))[1];
|
||||
user.error = alias + '@' + $scope.selectedDomain.domain + ' already exists';
|
||||
mailbox.error = alias + '@' + $scope.selectedDomain.domain + ' already exists';
|
||||
return;
|
||||
} else if (error && error.statusCode === 400) {
|
||||
user.error = error.message;
|
||||
mailbox.error = error.message;
|
||||
return;
|
||||
} else if (error) {
|
||||
console.error('Unable to configure mailbox.', error);
|
||||
@@ -193,16 +193,14 @@ angular.module('Application').controller('EmailController', ['$scope', '$locatio
|
||||
}
|
||||
|
||||
// reset the dirty state
|
||||
user.orig.mailboxEnabled = user.mailboxEnabled;
|
||||
user.orig.aliases = user.aliases;
|
||||
mailbox.orig.aliases = mailbox.aliases;
|
||||
mailbox.orig.owner = mailbox.owner;
|
||||
}
|
||||
|
||||
var func = user.mailboxEnabled ? Client.enableUserMailbox : Client.disableUserMailbox;
|
||||
func($scope.selectedDomain.domain, user.id, function (error) {
|
||||
Client.updateMailbox($scope.selectedDomain.domain, mailbox.name, mailbox.owner.id, function (error) {
|
||||
if (error) return done(error);
|
||||
|
||||
if (user.mailboxEnabled) Client.setAliases($scope.selectedDomain.domain, user.id, aliases, done);
|
||||
else done();
|
||||
Client.setAliases($scope.selectedDomain.domain, mailbox.name, aliases, done);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user