Add group edit ui to select mailing lists

This commit is contained in:
Johannes Zellner
2018-01-26 11:31:43 +01:00
parent 8af587b6d9
commit 9d57c81505
2 changed files with 115 additions and 4 deletions

View File

@@ -363,6 +363,85 @@ angular.module('Application').controller('UsersController', ['$scope', '$locatio
setupLink: ''
};
$scope.groupEdit = {
busy: false,
busyFetching: false,
error: {},
group: null,
lists: [],
availableLists: [],
show: function (group) {
$scope.groupEdit.busy = false;
$scope.groupEdit.busyFetching = true;
$scope.groupEdit.error = {};
$scope.groupEdit.availableLists = $scope.emailDomains.map(function (domain) { return { domain: domain, address: group.name + '@' + domain.domain }; });
$scope.groupEdit.selectedLists = [];
$scope.groupEdit.currentLists = [];
$scope.groupEdit.group = angular.copy(group);
var tmp = [];
asyncForEach($scope.emailDomains, function (domain, callback) {
Client.getMailingList(domain.domain, $scope.groupEdit.group.id, function (error) {
if (error) return callback(error);
var list = $scope.groupEdit.availableLists.find(function (list) { return list.domain.domain === domain.domain; });
tmp.push(list);
$scope.groupEdit.currentLists.push(list);
callback();
});
}, function (error) {
$scope.groupEdit.busyFetching = false;
if (error) return console.error('Unable to get mailing lists.', error);
$scope.groupEdit.selectedLists = tmp;
});
$scope.groupEditForm.$setUntouched();
$scope.groupEditForm.$setPristine();
$('#groupEditModal').modal('show');
},
submit: function () {
$scope.groupEdit.busy = true;
var addedLists = $scope.groupEdit.selectedLists.filter(function (s) {
return !$scope.groupEdit.currentLists.find(function (c) {
return c.domain.domain === s.domain.domain;
});
});
var removedLists = $scope.groupEdit.currentLists.filter(function (c) {
return !$scope.groupEdit.selectedLists.find(function (s) {
return s.domain.domain === c.domain.domain;
});
});
asyncForEach(addedLists, function (list, callback) {
Client.addMailingList(list.domain.domain, $scope.groupEdit.group.id, callback);
}, function (error) {
if (error) {
$scope.groupEdit.busy = false;
return console.error('Failed to add group to mailinglists.', error);
}
asyncForEach(removedLists, function (list, callback) {
Client.removeMailingList(list.domain.domain, $scope.groupEdit.group.id, callback);
}, function (error) {
$scope.groupEdit.busy = false;
if (error) {
return console.error('Failed to remove group to mailinglists.', error);
}
$('#groupEditModal').modal('hide');
});
});
}
};
$scope.groupRemove = {
busy: false,
error: {},