mirror of
https://github.com/taobataoma/meanTorrent.git
synced 2026-01-17 12:52:22 +01:00
51 lines
1.1 KiB
JavaScript
51 lines
1.1 KiB
JavaScript
(function () {
|
|
'use strict';
|
|
|
|
angular
|
|
.module('users.admin')
|
|
.controller('UserController', UserController);
|
|
|
|
UserController.$inject = ['$scope', '$state', 'Authentication', 'userResolve'];
|
|
|
|
function UserController($scope, $state, Authentication, user) {
|
|
var vm = this;
|
|
|
|
vm.authentication = Authentication;
|
|
vm.user = user;
|
|
vm.remove = remove;
|
|
vm.update = update;
|
|
|
|
function remove(user) {
|
|
if (confirm('Are you sure you want to delete this user?')) {
|
|
if (user) {
|
|
user.$remove();
|
|
|
|
vm.users.splice(vm.users.indexOf(user), 1);
|
|
} else {
|
|
vm.user.$remove(function () {
|
|
$state.go('admin.users');
|
|
});
|
|
}
|
|
}
|
|
}
|
|
|
|
function update(isValid) {
|
|
if (!isValid) {
|
|
$scope.$broadcast('show-errors-check-validity', 'vm.userForm');
|
|
|
|
return false;
|
|
}
|
|
|
|
var user = vm.user;
|
|
|
|
user.$update(function () {
|
|
$state.go('admin.user', {
|
|
userId: user._id
|
|
});
|
|
}, function (errorResponse) {
|
|
vm.error = errorResponse.data.message;
|
|
});
|
|
}
|
|
}
|
|
}());
|