Semaphore/public/js/controllers/users.js
Matej Kramny 2ab74b1768 Fix new user modal
- Fixes #124
2016-06-13 15:40:39 -07:00

30 lines
873 B
JavaScript

define(function () {
app.registerController('UsersCtrl', ['$scope', '$http', '$uibModal', '$rootScope', function ($scope, $http, $modal, $rootScope) {
$http.get('/users').success(function (users) {
$scope.users = users;
});
$scope.addUser = function () {
var scope = $rootScope.$new();
scope.user = {}
$modal.open({
templateUrl: '/tpl/users/add.html',
scope: scope
}).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');
});
});
}
}]);
});