Set the users when creating group

This commit is contained in:
Girish Ramakrishnan
2018-08-05 22:19:54 -07:00
parent a78c991330
commit 2f2c70d1df
2 changed files with 35 additions and 17 deletions

View File

@@ -16,7 +16,7 @@ angular.module('Application').controller('UsersController', ['$scope', '$locatio
$scope.userInfo = Client.getUserInfo();
$scope.groupMembers = function (group) {
return group.userIds.filter(function (uid) { return !!$scope.usersById[uid]; }).map(function (uid) { return $scope.usersById[uid].username || $scope.usersById[uid].email; }).join(', ');
return group.userIds.filter(function (uid) { return !!$scope.usersById[uid]; }).map(function (uid) { return $scope.usersById[uid].username || $scope.usersById[uid].email; }).join(' ');
};
$scope.userremove = {
@@ -238,6 +238,7 @@ angular.module('Application').controller('UsersController', ['$scope', '$locatio
busy: false,
error: {},
name: '',
selectedUsers: [],
show: function () {
$scope.groupAdd.busy = false;
@@ -255,25 +256,36 @@ angular.module('Application').controller('UsersController', ['$scope', '$locatio
$scope.groupAdd.busy = true;
$scope.groupAdd.error = {};
Client.createGroup($scope.groupAdd.name, function (error) {
$scope.groupAdd.busy = false;
Client.createGroup($scope.groupAdd.name, function (error, result) {
if (error) {
$scope.groupAdd.busy = false;
if (error && error.statusCode === 409) {
$scope.groupAdd.error.name = 'Name already taken';
$scope.groupAddForm.name.$setPristine();
$('#groupAddName').focus();
return;
if (error.statusCode === 409) {
$scope.groupAdd.error.name = 'Name already taken';
$scope.groupAddForm.name.$setPristine();
$('#groupAddName').focus();
return;
} else if (error.statusCode === 400) {
$scope.groupAdd.error.name = error.message;
$scope.groupAddForm.name.$setPristine();
$('#groupAddName').focus();
return;
} else {
return console.error('Unable to create group.', error.statusCode, error.message);
}
}
if (error && error.statusCode === 400) {
$scope.groupAdd.error.name = error.message;
$scope.groupAddForm.name.$setPristine();
$('#groupAddName').focus();
return;
}
if (error) return console.error('Unable to create group.', error.statusCode, error.message);
refresh();
$('#groupAddModal').modal('hide');
var userIds = $scope.groupAdd.selectedUsers.map(function (u) { return u.id; });
Client.setGroupMembers(result.id, userIds, function (error) {
$scope.groupAdd.busy = false;
if (error) return console.error('Unable to add memebers.', error.statusCode, error.message);
refresh();
$('#groupAddModal').modal('hide');
});
});
}
};