Add business logic for group adding

This commit is contained in:
Johannes Zellner
2016-02-10 16:37:58 +01:00
parent 9ba4d52fb7
commit a8001995c8
2 changed files with 43 additions and 17 deletions

View File

@@ -38,7 +38,43 @@ angular.module('Application').controller('UsersController', ['$scope', '$locatio
$scope.groupadd = {
busy: false,
error: {},
name: ''
name: '',
reset: function () {
$scope.groupadd.busy = false;
$scope.groupadd.error = {};
$scope.groupadd.name = '';
$scope.groupAddForm.$setUntouched();
$scope.groupAddForm.$setPristine();
},
show: function () {
$scope.groupadd.reset();
$('#groupAddModal').modal('show');
},
submit: function () {
$scope.groupadd.busy = true;
$scope.groupadd.error.name = null;
Client.createGroup($scope.groupadd.name, function (error) {
if (error && error.statusCode === 409) {
$scope.groupadd.error.name = 'Name already taken';
$scope.groupAddForm.name.$setPristine();
$('#groupAddName').focus();
return;
}
if (error) return console.error('Unable to create group.', error.statusCode, error.message);
$('#groupAddModal').modal('hide');
refresh();
$scope.groupadd.reset();
});
}
};
$scope.isMe = function (user) {
@@ -65,16 +101,6 @@ angular.module('Application').controller('UsersController', ['$scope', '$locatio
});
};
$scope.showGroupAdd = function () {
$scope.groupadd.error = {};
$scope.groupadd.name = '';
$scope.groupAddForm.$setUntouched();
$scope.groupAddForm.$setPristine();
$('#groupAddModal').modal('show');
};
$scope.showUserAdd = function () {
$scope.useradd.error = {};
$scope.useradd.username = '';