2016-04-10 20:03:12 +02:00
|
|
|
define(function () {
|
2016-06-14 00:40:39 +02:00
|
|
|
app.registerController('UsersCtrl', ['$scope', '$http', '$uibModal', '$rootScope', function ($scope, $http, $modal, $rootScope) {
|
2016-04-10 20:03:12 +02:00
|
|
|
$http.get('/users').success(function (users) {
|
|
|
|
$scope.users = users;
|
|
|
|
});
|
|
|
|
|
|
|
|
$scope.addUser = function () {
|
2016-06-14 00:40:39 +02:00
|
|
|
var scope = $rootScope.$new();
|
|
|
|
scope.user = {}
|
|
|
|
|
2016-04-10 20:03:12 +02:00
|
|
|
$modal.open({
|
2016-06-14 00:40:39 +02:00
|
|
|
templateUrl: '/tpl/users/add.html',
|
|
|
|
scope: scope
|
2016-04-10 20:03:12 +02:00
|
|
|
}).result.then(function (_user) {
|
|
|
|
$http.post('/users', _user).success(function (user) {
|
|
|
|
$scope.users.push(user);
|
|
|
|
|
|
|
|
$http.post('/users/' + user.id + '/password', {
|
|
|
|
password: _user.password
|
|
|
|
}).error(function (_, status) {
|
|
|
|
swal('Error', 'Setting password failed, API responded with HTTP ' + status, 'error');
|
|
|
|
});
|
|
|
|
}).error(function (_, status) {
|
|
|
|
swal('Error', 'API responded with HTTP ' + status, 'error');
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}]);
|
|
|
|
});
|