Fixup the mailinglist crud ui
This commit is contained in:
@@ -62,42 +62,94 @@ angular.module('Application').controller('EmailController', ['$scope', '$locatio
|
||||
|
||||
$scope.mailinglists = {
|
||||
busy: false,
|
||||
groups: [], // current model in the ui by name
|
||||
availableGroups: [], // all available groups by name
|
||||
availableGroupsFull: [], // all available groups full objects
|
||||
currentGroups: [], // currently set groups in the backend for new/removed detection
|
||||
availableMailboxNames: [],
|
||||
mailinglists: [],
|
||||
|
||||
submit: function () {
|
||||
$scope.mailinglists.busy = true;
|
||||
add: {
|
||||
busy: false,
|
||||
error: '',
|
||||
name: '',
|
||||
members: [],
|
||||
|
||||
var removedGroups = $scope.mailinglists.currentGroups.filter(function (g) { return $scope.mailinglists.groups.indexOf(g) === -1; })
|
||||
.map(function (groupName) {
|
||||
return $scope.mailinglists.availableGroupsFull.find(function (g) { return g.name === groupName; });
|
||||
submit: function () {
|
||||
$scope.mailinglists.add.busy = true;
|
||||
|
||||
Client.addMailingList($scope.selectedDomain.domain, $scope.mailinglists.add.name, $scope.mailinglists.add.members, function (error) {
|
||||
$scope.mailinglists.add.busy = false;
|
||||
|
||||
if (error) {
|
||||
$scope.mailinglists.add.error = error.message;
|
||||
console.error(error);
|
||||
return;
|
||||
}
|
||||
|
||||
$scope.mailinglists.add.error = '';
|
||||
$scope.mailinglists.add.name = '';
|
||||
$scope.mailinglists.add.members = [];
|
||||
|
||||
$scope.mailinglists.refresh();
|
||||
});
|
||||
var newGroups = $scope.mailinglists.groups.filter(function (g) { return $scope.mailinglists.currentGroups.indexOf(g) === -1; })
|
||||
.map(function (groupName) {
|
||||
return $scope.mailinglists.availableGroupsFull.find(function (g) { return g.name === groupName; });
|
||||
}
|
||||
},
|
||||
|
||||
remove: {
|
||||
busy: false,
|
||||
list: null,
|
||||
|
||||
show: function (list) {
|
||||
$scope.mailinglists.remove.list = list;
|
||||
|
||||
$('#mailinglistRemoveModal').modal('show');
|
||||
},
|
||||
|
||||
submit: function () {
|
||||
$scope.mailinglists.remove.busy = true;
|
||||
|
||||
Client.removeMailingList($scope.selectedDomain.domain, $scope.mailinglists.remove.list.name, function (error) {
|
||||
$scope.mailinglists.remove.busy = false;
|
||||
|
||||
if (error) return console.error(error);
|
||||
|
||||
$scope.mailinglists.remove.list = null;
|
||||
$scope.mailinglists.refresh();
|
||||
|
||||
$('#mailinglistRemoveModal').modal('hide');
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
asyncForEach(removedGroups, function (group, callback) {
|
||||
if (!group) return callback();
|
||||
refresh: function () {
|
||||
Client.getMailboxes($scope.selectedDomain.domain, function (error, result) {
|
||||
if (error) return console.error(error);
|
||||
|
||||
Client.removeMailingList($scope.selectedDomain.domain, group.id, callback);
|
||||
}, function (error) {
|
||||
if (error) console.error('Unable to remove mailinglists.', error);
|
||||
console.log('mailboxes', result);
|
||||
|
||||
asyncForEach(newGroups, function (group, callback) {
|
||||
if (!group) return callback();
|
||||
$scope.mailinglists.availableMailboxNames = result.map(function (m) { return m.name; });
|
||||
|
||||
Client.addMailingList($scope.selectedDomain.domain, group.id, callback);
|
||||
}, function (error) {
|
||||
if (error) console.error('Unable to remove mailinglists.', error);
|
||||
Client.listMailingLists($scope.selectedDomain.domain, function (error, result) {
|
||||
if (error) return console.error(error);
|
||||
|
||||
// reset the state
|
||||
$scope.mailinglists.currentGroups = $scope.mailinglists.groups.slice();
|
||||
$scope.mailinglists.busy = false;
|
||||
console.log('lists', result);
|
||||
|
||||
$scope.mailinglists.mailinglists = result.map(function (m) {
|
||||
m.orig = {};
|
||||
m.orig.members = m.members;
|
||||
|
||||
return m;
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
|
||||
submit: function (list) {
|
||||
list.busy = true;
|
||||
|
||||
Client.updateMailingList($scope.selectedDomain.domain, list.name, list.members, function (error) {
|
||||
if (error) console.error(error);
|
||||
|
||||
list.orig.members = list.members;
|
||||
list.busy = false;
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
@@ -427,21 +479,7 @@ angular.module('Application').controller('EmailController', ['$scope', '$locatio
|
||||
$scope.selectedDomain.mailStatus = {};
|
||||
|
||||
$scope.mailboxes.refresh();
|
||||
|
||||
// mailinglists/groups
|
||||
Client.getGroups(function (error, groups) {
|
||||
if (error) return console.error(error);
|
||||
|
||||
$scope.mailinglists.availableGroupsFull = groups.slice();
|
||||
$scope.mailinglists.availableGroups = groups.map(function (u) { return u.name; });
|
||||
|
||||
Client.listMailingLists($scope.selectedDomain.domain, function (error, lists) {
|
||||
if (error) return console.error(error);
|
||||
|
||||
$scope.mailinglists.groups = lists.map(function (u) { return u.name; });
|
||||
$scope.mailinglists.currentGroups = lists.map(function (u) { return u.name; });
|
||||
});
|
||||
});
|
||||
$scope.mailinglists.refresh();
|
||||
|
||||
// we will fetch the status without blocking the ui
|
||||
Client.getMailStatusForDomain($scope.selectedDomain.domain, function (error, mailStatus) {
|
||||
|
||||
Reference in New Issue
Block a user