forked from meanjs/mean
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser.client.controller.js
More file actions
58 lines (47 loc) · 1.68 KB
/
Copy pathuser.client.controller.js
File metadata and controls
58 lines (47 loc) · 1.68 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
(function () {
'use strict';
angular
.module('users.admin')
.controller('UserController', UserController);
UserController.$inject = ['$scope', '$state', '$window', 'Authentication', 'userResolve', 'Notification'];
function UserController($scope, $state, $window, Authentication, user, Notification) {
var vm = this;
vm.authentication = Authentication;
vm.user = user;
vm.remove = remove;
vm.update = update;
vm.isContextUserSelf = isContextUserSelf;
function remove(user) {
if ($window.confirm('Are you sure you want to delete this user?')) {
if (user) {
user.$remove();
vm.users.splice(vm.users.indexOf(user), 1);
Notification.success('User deleted successfully!');
} else {
vm.user.$remove(function () {
$state.go('admin.users');
Notification.success({ message: '<i class="glyphicon glyphicon-ok"></i> User deleted successfully!' });
});
}
}
}
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
});
Notification.success({ message: '<i class="glyphicon glyphicon-ok"></i> User saved successfully!' });
}, function (errorResponse) {
Notification.error({ message: errorResponse.data.message, title: '<i class="glyphicon glyphicon-remove"></i> User update error!' });
});
}
function isContextUserSelf() {
return vm.user.username === vm.authentication.user.username;
}
}
}());