diff --git a/dashboard/src/views/email.html b/dashboard/src/views/email.html index 99c366236..4077efb45 100644 --- a/dashboard/src/views/email.html +++ b/dashboard/src/views/email.html @@ -11,7 +11,7 @@ @@ -110,35 +110,50 @@
- Enable mailboxes for users on this domain. Each user will get an email address of username@{{ selectedDomain.domain }} + Each mailboxes has an owner, who is able to access the mailbox.

- - - + + + - - - - - - + + + + + + + + + + + +
 UserAliasesNameOwnerAliases Action
- - - {{ user.username }} - -

{{ user.error }}

- -
- -
+ {{ mailbox.name }} + + + +

{{ mailbox.error }}

+ +
+ + +
+ + + + +   + + +
diff --git a/dashboard/src/views/email.js b/dashboard/src/views/email.js index 84323b3f3..1ae45ff0f 100644 --- a/dashboard/src/views/email.js +++ b/dashboard/src/views/email.js @@ -129,7 +129,47 @@ angular.module('Application').controller('EmailController', ['$scope', '$locatio }; $scope.mailboxes = { - users: [], + mailboxes: [], + add: { + busy: false, + name: '', + owner: null, + + submit: function () { + $scope.mailboxes.add.busy = true; + + Client.addMailbox($scope.selectedDomain.domain, $scope.mailboxes.add.name, $scope.mailboxes.add.owner.id, function (error) { + $scope.mailboxes.add.busy = false; + if (error) return console.error(error); + + $scope.mailboxes.add.name = ''; + $scope.mailboxes.add.owner = null; + + $scope.mailboxes.refresh(); + }); + } + }, + + refresh: function () { + Client.getMailboxes($scope.selectedDomain.domain, function (error, mailboxes) { + if (error) return console.error(error); + + Client.listAliases($scope.selectedDomain.domain, function (error, aliases) { + 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.owner = $scope.users.find(function (u) { return u.id === m.ownerId; }); + + m.orig = {}; + m.orig.owner = m.owner; + m.orig.aliases = m.aliases; + + return m; + }); + }); + }); + }, submit: function (user) { user.busy = true; @@ -363,26 +403,7 @@ angular.module('Application').controller('EmailController', ['$scope', '$locatio $scope.selectedDomain.mailConfig = mailConfig; $scope.selectedDomain.mailStatus = {}; - // mailboxes - Client.getMailboxes($scope.selectedDomain.domain, function (error, mailboxes) { - if (error) return console.error(error); - - Client.listAliases($scope.selectedDomain.domain, function (error, aliases) { - if (error) return console.error(error); - - var enabledUsers = mailboxes.map(function (m) { return m.name; }); - $scope.mailboxes.users = $scope.users.filter(function (u) { return !!u.username; }).map(function (u) { - u.mailboxEnabled = (enabledUsers.indexOf(u.username) !== -1); - u.aliases = aliases.filter(function (a) { return a.ownerId === u.id; }).map(function (a) { return a.name; }).join(','); - - u.orig = {}; - u.orig.mailboxEnabled = u.mailboxEnabled; - u.orig.aliases = u.aliases; - - return u; - }); - }); - }); + $scope.mailboxes.refresh(); // mailinglists/groups Client.getGroups(function (error, groups) { @@ -434,7 +455,11 @@ angular.module('Application').controller('EmailController', ['$scope', '$locatio Client.getUsers(function (error, users) { if (error) return console.error('Unable to get user listing.', error); - $scope.users = users; + // ensure we have a display value available + $scope.users = users.map(function (u) { + u.display = u.username || u.email; + return u; + }); Client.getDomains(function (error, domains) { if (error) return console.error('Unable to get domain listing.', error);