|
@@ -3,8 +3,8 @@
|
3
|
3
|
*/
|
4
|
4
|
|
5
|
5
|
angular.module('luticate')
|
6
|
|
- .controller('UserEditController', ['$scope', 'luticateAuthUsers', 'data',
|
7
|
|
- function($scope, luticateAuthUsers, data) {
|
|
6
|
+ .controller('UserEditController', ['$scope', 'luticateAuthUsers', 'data', '$q',
|
|
7
|
+ function($scope, luticateAuthUsers, data, $q) {
|
8
|
8
|
if (data != null) {
|
9
|
9
|
$scope.user = data;
|
10
|
10
|
}
|
|
@@ -13,24 +13,64 @@ angular.module('luticate')
|
13
|
13
|
Username: "",
|
14
|
14
|
Email: "",
|
15
|
15
|
Firstname: "",
|
16
|
|
- Lastname: "",
|
17
|
|
- Password: ""
|
|
16
|
+ Lastname: ""
|
18
|
17
|
};
|
19
|
18
|
}
|
|
19
|
+ $scope.userPassword = {
|
|
20
|
+ value: "",
|
|
21
|
+ confirm: ""
|
|
22
|
+ };
|
|
23
|
+ $scope.passwordValidation = {
|
|
24
|
+ length: '$value.length >= 5 || $value.length == 0'
|
|
25
|
+ };
|
|
26
|
+ $scope.password2Validation = {
|
|
27
|
+ same_passwords: 'userPassword.value==$value'
|
|
28
|
+ };
|
|
29
|
+
|
20
|
30
|
var promiseEditUser = {
|
21
|
31
|
id: "promiseEditUser",
|
22
|
32
|
loaderGroups: ["modal"]
|
23
|
33
|
};
|
|
34
|
+ var promiseAddUser = {
|
|
35
|
+ id: "promiseAddUser",
|
|
36
|
+ loaderGroups: ["modal"]
|
|
37
|
+ };
|
|
38
|
+ var promiseSetPassword = {
|
|
39
|
+ id: "promiseSetPassword",
|
|
40
|
+ loaderGroups: ["modal"]
|
|
41
|
+ };
|
|
42
|
+
|
|
43
|
+ $scope.onCanceled = function()
|
|
44
|
+ {
|
|
45
|
+ console.log($scope.userPassword);
|
|
46
|
+ };
|
24
|
47
|
|
25
|
48
|
$scope.submitForm = function()
|
26
|
49
|
{
|
|
50
|
+ console.log($scope.userPassword);
|
27
|
51
|
if ($scope.user.Id != null) {
|
28
|
|
- return luticateAuthUsers.edit({
|
|
52
|
+ var defer = $q.defer();
|
|
53
|
+ luticateAuthUsers.edit({
|
29
|
54
|
user_id: $scope.user.Id,
|
30
|
55
|
email: $scope.user.Email,
|
31
|
56
|
firstname: $scope.user.Firstname,
|
32
|
57
|
lastname: $scope.user.Lastname
|
33
|
|
- }, promiseEditUser);
|
|
58
|
+ }, promiseEditUser)
|
|
59
|
+ .then(function(data)
|
|
60
|
+ {
|
|
61
|
+ console.log($scope.userPassword);
|
|
62
|
+ if ($scope.userPassword.value != "") {
|
|
63
|
+ luticateAuthUsers.setPassword({
|
|
64
|
+ user_id: $scope.user.Id,
|
|
65
|
+ password: $scope.userPassword.value
|
|
66
|
+ }, promiseSetPassword)
|
|
67
|
+ .then(defer.resolve, defer.reject);
|
|
68
|
+ }
|
|
69
|
+ else {
|
|
70
|
+ defer.resolve(data);
|
|
71
|
+ }
|
|
72
|
+ }, defer.reject);
|
|
73
|
+ return defer.promise;
|
34
|
74
|
}
|
35
|
75
|
else {
|
36
|
76
|
var user = {
|
|
@@ -38,11 +78,9 @@ angular.module('luticate')
|
38
|
78
|
email: $scope.user.Email,
|
39
|
79
|
firstname: $scope.user.Firstname,
|
40
|
80
|
lastname: $scope.user.Lastname,
|
41
|
|
- password: $scope.user.Password
|
|
81
|
+ password: $scope.userPassword.value
|
42
|
82
|
};
|
43
|
|
- console.log(user);
|
44
|
|
- return;
|
45
|
|
- return luticateAuthUsers.add(user, promiseEditUser);
|
|
83
|
+ return luticateAuthUsers.add(user, promiseAddUser);
|
46
|
84
|
}
|
47
|
85
|
};
|
48
|
86
|
}]);
|