This repository was archived by the owner on Sep 17, 2019. It is now read-only.
Repository navigation
Expand file tree
/
Copy pathusers.js
More file actions
246 lines (236 loc) · 6.62 KB
/
Copy pathusers.js
File metadata and controls
246 lines (236 loc) · 6.62 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
'use strict';
angular.module('ModuleAB.users', ['ngRoute'])
.config(['$routeProvider', function($routeProvider) {
$routeProvider.when('/users', {
templateUrl: 'users/users.html',
controller: 'users'
});
}])
.controller('users', ['$scope', '$http', '$uibModal', '$rootScope',
function($scope, $http, $uibModal, $rootScope) {
$scope.usersGet = function() {
$http({
method: "GET",
url: "/api/v1/users"
}).then(function(response) {
$scope.users = response.data;
}, function(response) {});
};
$scope.usersGet();
$scope.userEdit = function(type, user) {
var modal = $uibModal.open({
templateUrl: 'userModal.html',
controller: 'userModal',
resolve: {
type: function() {
return type;
},
user: function() {
return user;
}
}
});
modal.result.then(function(d) {
$scope.usersGet();
});
};
$scope.delete = function(user) {
var modal = $uibModal.open({
templateUrl: 'common/deleteModal.html',
controller: 'deleteUserModal',
resolve: {
user: function() {
return user;
}
}
});
modal.result.then(function(d) {
$http({
method: "DELETE",
url: "/api/v1/users/" + user.loginname
}).then(function(response) {
$scope.usersGet();
}, function(response) {
$rootScope.alertType = 'alert-warning';
$rootScope.fadein = 'fadein-opacity';
switch (response.status) {
case 401:
window.location.href = "/login";
break;
case 403:
$rootScope.failMessage = "没有权限";
break;
case 404:
$rootScope.failMessage = "无此用户";
break;
case 500:
$rootScope.failMessage = "服务器错误,见控制台输出";
console.log(response.data);
break;
default:
$rootScope.failMessage = "通讯故障";
break;
}
});
});
};
}
])
.controller('deleteUserModal', function($scope, $uibModalInstance, user) {
$scope.cancel = function() {
$uibModalInstance.dismiss('cancel');
};
$scope.doDelete = function() {
$uibModalInstance.close('delete');
}
$scope.modalDeleteObjName = user.name;
})
.controller('userModal', function($scope, $http, $uibModalInstance, type,
user) {
if (user === undefined) {
user = {
loginname: "",
password: "",
name: "",
Roles: [],
removable: true
};
}
$scope.user = user
$scope.password2 = user.password;
$http({
method: "GET",
url: "/api/v1/roles"
}).then(function(response) {
$scope.roles = response.data;
}, function(response) {
// do nothing.
});
$scope.selectedRoles = [];
$scope.$watch('user.Roles', function(s) {
if (!s) {
return;
}
angular.forEach(s, function(v) {
$scope.selectedRoles.push(v.id.toString());
});
});
switch (type) {
case 'new':
$scope.type = "新增";
$scope.jobType = "fa-plus";
$scope.job = "新增"
$scope.isModifyMode = false;
break;
case 'modify':
$scope.type = "修改";
$scope.jobType = "fa-pencil";
$scope.job = "修改";
$scope.isModifyMode = true;
break;
}
$scope.modalInfoFadein = "";
$scope.doJob = function() {
if ($scope.user.loginname == '') {
$scope.modalInfoFadein = "fadein-opacity";
$scope.modalInfoMsg = "登录名不能为空";
return;
}
if ($scope.user.name == '') {
$scope.modalInfoFadein = "fadein-opacity";
$scope.modalInfoMsg = "显示名不能为空";
return;
}
if (!$scope.user.password.match(/.{8,32}/)) {
$scope.modalInfoFadein = "fadein-opacity";
$scope.modalInfoMsg = "密码长度为8-32位!";
return;
}
if ($scope.user.password != $scope.password2) {
$scope.modalInfoFadein = "fadein-opacity";
$scope.modalInfoMsg = "两次输入的密码不一致!";
return;
}
$scope.user.Roles = [];
angular.forEach($scope.selectedRoles, function(s0) {
angular.forEach($scope.roles, function(s1) {
if (s1.id == s0) {
$scope.user.Roles.push(s1);
}
});
});
if ($scope.user.Roles.length == 0) {
$scope.modalInfoFadein = "fadein-opacity";
$scope.modalInfoMsg = "请指定至少一个用户角色";
return;
}
switch (type) {
case 'new':
$http({
method: "POST",
url: "/api/v1/users",
data: $scope.user
}).then(function(response) {
$uibModalInstance.close(response.data.id);
}, function(response) {
$scope.modalInfoFadein = "fadein-opacity";
switch (response.status) {
case 400:
$scope.modalInfoMsg = "数据错误";
break;
case 401:
$scope.modalInfoMsg = "未登录";
window.location.href = "/login";
break;
case 403:
$scope.modalInfoMsg = "访问被拒绝";
break;
case 500:
$scope.modalInfoMsg = "服务器错误,见控制台输出";
console.log(response.data);
break;
default:
$scope.modalInfoMsg = "通讯故障";
break;
}
});
break;
case 'modify':
$http({
method: "PUT",
url: "/api/v1/users/" + $scope.user.loginname,
data: $scope.user
}).then(function(response) {
$uibModalInstance.close(response.status);
}, function(response) {
$scope.modalInfoFadein = "fadein-opacity";
switch (response.status) {
case 400:
$scope.modalInfoMsg = "数据错误";
break;
case 401:
$scope.modalInfoMsg = "未登录";
window.location.href = "/login";
break;
case 403:
$scope.modalInfoMsg = "访问被拒绝";
break;
case 404:
$scope.modalInfoMsg = "无此用户";
break;
case 500:
$scope.modalInfoMsg = "服务器错误,见控制台输出";
console.log(response.data);
break;
default:
$scope.modalInfoMsg = "通讯故障";
break;
}
});
break;
}
}
$scope.cancel = function() {
$uibModalInstance.dismiss('cancel');
}
});