Robin Thoni 9 лет назад
Родитель
Сommit
8291340ad1

+ 10
- 0
luticate/controllers/directives/dialogokcancel.js Просмотреть файл

@@ -14,9 +14,13 @@ angular.module('luticate')
14 14
                     $scope.title = attrs.title;
15 15
                     $scope.model = {};
16 16
                     $scope.pending = false;
17
+                    $scope.submitted = false;
18
+                    $scope.errorString = "";
17 19
 
18 20
                     $scope.__submit = function()
19 21
                     {
22
+                        $scope.submitted = true;
23
+                        $scope.errorString = "";
20 24
                         if ($scope.form.$valid) {
21 25
                             $scope.pending = true;
22 26
                             $scope.promise = $scope.submitForm();
@@ -34,6 +38,12 @@ angular.module('luticate')
34 38
                                         if ($scope.onError) {
35 39
                                             $scope.onError(error);
36 40
                                         }
41
+                                        if (error.Data) {
42
+                                            $scope.errorString = error.Data;
43
+                                        }
44
+                                        else {
45
+                                            $scope.errorString = error;
46
+                                        }
37 47
                                         $scope.pending = false;
38 48
                                     });
39 49
                             }

+ 48
- 10
luticate/controllers/modals/useredit.controller.js Просмотреть файл

@@ -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
         }]);

+ 3
- 4
luticate/views/directives/dialogokcancel.html Просмотреть файл

@@ -6,14 +6,13 @@
6 6
                 <ng-transclude></ng-transclude>
7 7
             </div>
8 8
             <div class="clearfix"></div>
9
-            <!--<span class="error" ng-show="submitted">
10
-                <p class="error" ng-show="{{ e.show }}" ng-repeat="e in submittedErrors" ng-bind-template="{{ e.text | translate }}"></p>
9
+            <span class="error" ng-show="submitted">
10
+                <p class="error">{{ errorString }}</p>
11 11
             </span>
12
-            <p class="error" ng-show="{{ e.show }}" ng-repeat="e in alwaysErrors" ng-bind-template="{{ e.text | translate }}"></p>-->
13 12
         </div>
14 13
         <div class="modal-footer">
15 14
             <button type="button" class="btn btn-default" ng-click="__cancel()">Cancel</button>
16
-            <button type="submit" class="btn btn-default" ng-enabled="!pending" ng-click="submitted = true">OK</button>
15
+            <button type="submit" class="btn btn-default" ng-enabled="!pending">OK</button>
17 16
         </div>
18 17
     </form>
19 18
 </div>

+ 7
- 5
luticate/views/modals/useredit.html Просмотреть файл

@@ -26,17 +26,19 @@
26 26
     <div class="form-group">
27 27
         <label for="password" class="col-sm-2 control-label">Password</label>
28 28
         <div class="col-sm-9">
29
-            <input id="password" class="form-control" type="password" ng-model="user.Password" />
29
+            <input id="password" class="form-control" type="password" ng-model="userPassword.value"
30
+                   name="password" ui-validate="passwordValidation"/>
30 31
         </div>
31 32
         <div class="clearfix"></div>
32
-        <label for="password" class="col-sm-2 control-label">Confirmation</label>
33
+        <label for="password2" class="col-sm-2 control-label">Confirmation</label>
33 34
         <div class="col-sm-9">
34
-            <input id="password2" class="form-control" type="password" ng-model="password2"
35
-                   name="password2" ui-validate="{ same_passwords: '$value==user.Password' }"/>
35
+            <input id="password2" class="form-control" type="password" ng-model="userPassword.confirm"
36
+                   name="password2" ui-validate="password2Validation" ui-validate-watch="'userPassword.value'"/>
36 37
         </div>
37 38
         <div class="clearfix"></div>
38 39
         <div class="col-sm-offset-2 col-sm-9">
39
-            <p class="error" ng-show="form.password2.$error.same_passwords && user.Password != ''">Passwords do not match</p>
40
+            <p class="error" ng-show="form.password.$error.length">Passwords is too short</p>
41
+            <p class="error" ng-show="form.password2.$error.same_passwords">Passwords do not match</p>
40 42
         </div>
41 43
     </div>
42 44
 </dialog-ok-cancel>

Загрузка…
Отмена
Сохранить