mirror of
https://github.com/taobataoma/meanTorrent.git
synced 2026-01-15 03:42:23 +01:00
Added visual notification for user/article updates angular-ui-notification config added to core client config Notification idea from #369
59 lines
1.7 KiB
JavaScript
59 lines
1.7 KiB
JavaScript
(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;
|
|
}
|
|
}
|
|
}());
|