Make mail list members a textarea

Also, fix the error handling
This commit is contained in:
Girish Ramakrishnan
2019-09-11 14:09:53 -07:00
parent 758b32a61c
commit 9e2ac31a08
2 changed files with 37 additions and 30 deletions

View File

@@ -70,15 +70,15 @@ angular.module('Application').controller('EmailController', ['$scope', '$locatio
add: {
busy: false,
error: null,
error: {},
name: '',
members: [],
membersTxt: '',
reset: function () {
$scope.mailinglists.add.busy = false;
$scope.mailinglists.add.error = null;
$scope.mailinglists.add.error = {};
$scope.mailinglists.add.name = '';
$scope.mailinglists.add.members = [];
$scope.mailinglists.add.membersTxt = '';
},
show: function () {
@@ -89,12 +89,21 @@ angular.module('Application').controller('EmailController', ['$scope', '$locatio
submit: function () {
$scope.mailinglists.add.busy = true;
var members = $scope.mailinglists.add.members.map(function (m) { return m.name; });
var members = $scope.mailinglists.add.membersTxt
.split(/[\n,]/)
.map(function (m) { return m.trim(); })
.filter(function (m) { return m.length !== 0; });
Client.addMailingList($scope.selectedDomain.domain, $scope.mailinglists.add.name, members, function (error) {
$scope.mailinglists.add.busy = false;
$scope.mailinglists.add.error = {};
if (error) {
$scope.mailinglists.add.busy = false;
$scope.mailinglists.add.error = error;
if (error.statusCode === 400 && error.message.indexOf('member') !== -1) {
$scope.mailinglists.add.error.members = error.message;
} else {
$scope.mailinglists.add.error.name = error.message;
}
return;
}
@@ -108,18 +117,13 @@ angular.module('Application').controller('EmailController', ['$scope', '$locatio
edit: {
busy: false,
error: null,
error: {},
name: '',
members: [],
membersTxt: '',
show: function (list) {
$scope.mailinglists.edit.name = list.name;
var members = list.members.map(function (name) {
return $scope.mailboxes.mailboxes.find(function (m) { return m.name === name; });
});
// A mailinglist may contain mailbox names, which do not exist, so remove them here
$scope.mailinglists.edit.members = members.filter(function (m) { return !!m; });
$scope.mailinglists.edit.membersTxt = list.members.sort().join('\n');
$('#mailinglistEditModal').modal('show');
},
@@ -127,12 +131,18 @@ angular.module('Application').controller('EmailController', ['$scope', '$locatio
submit: function () {
$scope.mailinglists.edit.busy = true;
var members = $scope.mailinglists.edit.members.map(function (m) { return m.name; });
var members = $scope.mailinglists.edit.membersTxt.split(/[\n,]/)
.map(function (m) { return m.trim(); })
.filter(function (m) { return m.length !== 0; });
Client.updateMailingList($scope.selectedDomain.domain, $scope.mailinglists.edit.name, members, function (error) {
$scope.mailinglists.edit.busy = false;
$scope.mailinglists.edit.error = {};
if (error) return console.error(error);
if (error) {
$scope.mailinglists.edit.error.members = error.message;
return;
}
$scope.mailinglists.refresh();
@@ -722,7 +732,7 @@ angular.module('Application').controller('EmailController', ['$scope', '$locatio
// setup all the dialog focus handling
['testEmailModal', 'mailboxAddModal', 'mailboxEditModal', 'mailinglistEditModal', 'mailinglistAddModal'].forEach(function (id) {
$('#' + id).on('shown.bs.modal', function () {
$(this).find("[autofocus]:first").focus();
$(this).find('[autofocus]:first').focus();
});
});