|
@@ -1,99 +1,49 @@
|
1
|
1
|
angular.module('luticate')
|
2
|
|
- .controller('UsersController', ['$scope', '$state', 'luticateAuthUsers', 'dialogs', '$q', 'luticateDialogErrorHelper',
|
3
|
|
- function($scope, $state, luticateAuthUsers, dialogs, $q, luticateDialogErrorHelper) {
|
4
|
|
- $scope.page = 0;
|
5
|
|
- $scope.perPage = 15;
|
6
|
|
- $scope.users = [];
|
7
|
|
- $scope.pages = [];
|
8
|
|
- $scope.selectedUsers = [];
|
9
|
|
-
|
10
|
|
- var promiseLoadUsers = {
|
11
|
|
- id: "promiseLoadUsers",
|
12
|
|
- groups: ['userList']
|
13
|
|
- };
|
14
|
|
- var promiseDelUsers = {
|
15
|
|
- id: "promiseDelUsers",
|
16
|
|
- loadGroups: ['userList']
|
17
|
|
- };
|
18
|
|
-
|
19
|
|
- $scope.loadPage = function(page)
|
20
|
|
- {
|
21
|
|
- luticateAuthUsers.getAll({page: page, perPage: $scope.perPage}, promiseLoadUsers)
|
22
|
|
- .then(function(users)
|
23
|
|
- {
|
24
|
|
- $scope.page = page;
|
25
|
|
- $scope.users = users;
|
26
|
|
- $scope.pages = [];
|
27
|
|
- var start = Math.max(0, $scope.page - 5);
|
28
|
|
- var end = Math.min(start + 10, (users.Count / $scope.perPage) + (users.Count % $scope.perPage == 0 ? -1 : 0));
|
29
|
|
- for (var i = start; i < end; ++i) {
|
30
|
|
- $scope.pages.push(i);
|
31
|
|
- }
|
32
|
|
- }, function(error)
|
33
|
|
- {
|
34
|
|
- });
|
35
|
|
- };
|
36
|
|
-
|
37
|
|
- $scope.displayUser = function(user)
|
38
|
|
- {
|
39
|
|
- dialogs.create('views/modals/useredit.html', 'UserEditController', user)
|
40
|
|
- .result.then(function (data) {
|
41
|
|
- $scope.loadPage($scope.page);
|
42
|
|
- });
|
43
|
|
- };
|
44
|
|
-
|
45
|
|
- $scope.removeUsers = function()
|
46
|
|
- {
|
47
|
|
- if ($scope.selectedUsers.length == 0) {
|
48
|
|
- $scope.loadPage($scope.page);
|
49
|
|
- return;
|
|
2
|
+ .controller('UsersController', ['$scope', 'luticateAuthUsers',
|
|
3
|
+ function($scope, luticateAuthUsers) {
|
|
4
|
+
|
|
5
|
+ $scope.columns = [
|
|
6
|
+ {
|
|
7
|
+ name: "Username",
|
|
8
|
+ width: 3,
|
|
9
|
+ getValue: function(item) {
|
|
10
|
+ return item.Username;
|
|
11
|
+ }
|
|
12
|
+ }, {
|
|
13
|
+ name: "Email",
|
|
14
|
+ width: 3,
|
|
15
|
+ getValue: function(item) {
|
|
16
|
+ return item.Email;
|
|
17
|
+ }
|
|
18
|
+ }, {
|
|
19
|
+ name: "Firstname",
|
|
20
|
+ width: 3,
|
|
21
|
+ getValue: function(item) {
|
|
22
|
+ return item.Firstname;
|
|
23
|
+ }
|
|
24
|
+ }, {
|
|
25
|
+ name: "Lastname",
|
|
26
|
+ width: 3,
|
|
27
|
+ getValue: function(item) {
|
|
28
|
+ return item.Lastname;
|
|
29
|
+ }
|
50
|
30
|
}
|
51
|
|
- luticateAuthUsers.del({user_id: $scope.selectedUsers[0]}, promiseDelUsers)
|
52
|
|
- .then(function(data)
|
53
|
|
- {
|
54
|
|
- $scope.selectedUsers.splice(0, 1);
|
55
|
|
- $scope.removeUsers();
|
56
|
|
- }, function(error)
|
57
|
|
- {
|
58
|
|
- luticateDialogErrorHelper.errorDialog(error)
|
59
|
|
- .result.then(function(data)
|
60
|
|
- {
|
61
|
|
- $scope.loadPage($scope.page);
|
62
|
|
- }, function(error) {});
|
63
|
|
- });
|
64
|
|
- };
|
|
31
|
+ ];
|
65
|
32
|
|
66
|
|
- $scope.addUser = function()
|
|
33
|
+ $scope.getLoadPagePromise = function(page, perPage, promise)
|
67
|
34
|
{
|
68
|
|
- dialogs.create('views/modals/useredit.html', 'UserEditController', null)
|
69
|
|
- .result.then(function (data) {
|
70
|
|
- $scope.loadPage($scope.page);
|
71
|
|
- });
|
|
35
|
+ return luticateAuthUsers.getAll({page: page, perPage: perPage}, promise);
|
72
|
36
|
};
|
73
|
37
|
|
74
|
|
- $scope.toggleSelectedUser = function(id)
|
|
38
|
+ $scope.getDelPromise = function(id, promise)
|
75
|
39
|
{
|
76
|
|
- var idx = $scope.selectedUsers.indexOf(id);
|
77
|
|
- if (idx > -1) {
|
78
|
|
- $scope.selectedUsers.splice(idx, 1);
|
79
|
|
- }
|
80
|
|
- else {
|
81
|
|
- $scope.selectedUsers.push(id);
|
82
|
|
- }
|
|
40
|
+ return luticateAuthUsers.del({user_id: id}, promise);
|
83
|
41
|
};
|
84
|
42
|
|
85
|
|
- $scope.toggleSelectAll = function()
|
|
43
|
+ $scope.getEditController = function()
|
86
|
44
|
{
|
87
|
|
- if ($scope.selectedUsers.length == $scope.users.Data.length) {
|
88
|
|
- $scope.selectedUsers = [];
|
89
|
|
- }
|
90
|
|
- else {
|
91
|
|
- $scope.selectedUsers = [];
|
92
|
|
- for (var i = 0; i < $scope.users.Data.length; ++i) {
|
93
|
|
- $scope.selectedUsers.push($scope.users.Data[i].Id);
|
94
|
|
- }
|
95
|
|
- }
|
|
45
|
+ return "UserEdit";
|
96
|
46
|
};
|
97
|
47
|
|
98
|
|
- $scope.loadPage($scope.page);
|
|
48
|
+
|
99
|
49
|
}]);
|