Robin Thoni 9 роки тому
джерело
коміт
5290d61d63

+ 2
- 1
bower.json Переглянути файл

@@ -15,6 +15,7 @@
15 15
     "luticate-utils": "https://git.rthoni.com/repos/luticate-front/utils.git",
16 16
     "luticate-auth": "https://git.rthoni.com/repos/luticate-front/auth.git",
17 17
     "angular-dialog-service": "~5.2.8",
18
-    "ngSanitize": "~0.0.2"
18
+    "ngSanitize": "~0.0.2",
19
+    "angular-ui-validate": "~1.2.1"
19 20
   }
20 21
 }

+ 2
- 1
luticate/app.js Переглянути файл

@@ -9,7 +9,8 @@ var luticate = angular.module('luticate', [
9 9
     'luticateAuth',
10 10
     'LocalStorageModule',
11 11
     'dialogs.main',
12
-    'ngSanitize'
12
+    'ngSanitize',
13
+    'ui.validate'
13 14
 ]);
14 15
 
15 16
 luticate.config(['$stateProvider', '$urlRouterProvider', '$httpProvider',

+ 4
- 2
luticate/controllers/directives/dialogokcancel.js Переглянути файл

@@ -14,6 +14,7 @@ angular.module('luticate')
14 14
                     $scope.title = attrs.title;
15 15
                     $scope.model = {};
16 16
                     $scope.pending = false;
17
+
17 18
                     $scope.__submit = function()
18 19
                     {
19 20
                         if ($scope.form.$valid) {
@@ -25,7 +26,7 @@ angular.module('luticate')
25 26
                                     if ($scope.onDone) {
26 27
                                         $scope.onDone(data);
27 28
                                     }
28
-                                    $scope.$dismiss();
29
+                                    $scope.$close(data);
29 30
                                     $scope.pending = false;
30 31
                                 })
31 32
                                     .catch(function(error)
@@ -37,11 +38,12 @@ angular.module('luticate')
37 38
                                     });
38 39
                             }
39 40
                             else {
40
-                                $scope.$dismiss();
41
+                                $scope.$close();
41 42
                                 $scope.pending = false;
42 43
                             }
43 44
                         }
44 45
                     };
46
+
45 47
                     $scope.__cancel = function()
46 48
                     {
47 49
                         if ($scope.onCanceled) {

+ 2
- 1
luticate/controllers/login.controller.js Переглянути файл

@@ -10,7 +10,8 @@ angular.module('luticate')
10 10
                 loaderGroups: ["loginForm"]
11 11
             };
12 12
 
13
-            if (luticateAuthCache.getUser() != null) {
13
+            var user = luticateAuthCache.getUser();
14
+            if (user != null) {
14 15
                 $state.go('home');
15 16
                 return;
16 17
             }

+ 32
- 7
luticate/controllers/modals/useredit.controller.js Переглянути файл

@@ -5,7 +5,18 @@
5 5
 angular.module('luticate')
6 6
     .controller('UserEditController', ['$scope', 'luticateAuthUsers', 'data',
7 7
         function($scope, luticateAuthUsers, data) {
8
-            $scope.user = data;
8
+            if (data != null) {
9
+                $scope.user = data;
10
+            }
11
+            else {
12
+                $scope.user = {
13
+                    Username: "",
14
+                    Email: "",
15
+                    Firstname: "",
16
+                    Lastname: "",
17
+                    Password: ""
18
+                };
19
+            }
9 20
             var promiseEditUser = {
10 21
                 id: "promiseEditUser",
11 22
                 loaderGroups: ["modal"]
@@ -13,11 +24,25 @@ angular.module('luticate')
13 24
 
14 25
             $scope.submitForm = function()
15 26
             {
16
-                return luticateAuthUsers.edit({
17
-                    user_id: $scope.user.Id,
18
-                    email: $scope.user.Email,
19
-                    firstname: $scope.user.Firstname,
20
-                    lastname: $scope.user.Lastname
21
-                }, promiseEditUser);
27
+                if ($scope.user.Id != null) {
28
+                    return luticateAuthUsers.edit({
29
+                        user_id: $scope.user.Id,
30
+                        email: $scope.user.Email,
31
+                        firstname: $scope.user.Firstname,
32
+                        lastname: $scope.user.Lastname
33
+                    }, promiseEditUser);
34
+                }
35
+                else {
36
+                    var user = {
37
+                        username: $scope.user.Username,
38
+                        email: $scope.user.Email,
39
+                        firstname: $scope.user.Firstname,
40
+                        lastname: $scope.user.Lastname,
41
+                        password: $scope.user.Password
42
+                    };
43
+                    console.log(user);
44
+                    return;
45
+                    return luticateAuthUsers.add(user, promiseEditUser);
46
+                }
22 47
             };
23 48
         }]);

+ 39
- 3
luticate/controllers/users.controller.js Переглянути файл

@@ -5,6 +5,7 @@ angular.module('luticate')
5 5
             $scope.perPage = 15;
6 6
             $scope.users = [];
7 7
             $scope.pages = [];
8
+            $scope.selectedUsers = [];
8 9
 
9 10
             var promiseUsers = {
10 11
                 id: "promiseUsers",
@@ -33,11 +34,46 @@ angular.module('luticate')
33 34
             {
34 35
                 dialogs.create('views/modals/useredit.html', 'UserEditController', user)
35 36
                     .result.then(function (data) {
36
-                        console.log(data);
37
-                    }, function (error) {
38
-                        console.log(error);
37
+                        $scope.loadPage($scope.page);
39 38
                     });
40 39
             };
41 40
 
41
+            $scope.removeUsers = function()
42
+            {
43
+                console.log($scope.selectedUsers);
44
+            };
45
+
46
+            $scope.addUser = function()
47
+            {
48
+                dialogs.create('views/modals/useredit.html', 'UserEditController', null)
49
+                    .result.then(function (data) {
50
+                        $scope.loadPage($scope.page);
51
+                    });
52
+            };
53
+
54
+            $scope.toggleSelectedUser = function(id)
55
+            {
56
+                var idx = $scope.selectedUsers.indexOf(id);
57
+                if (idx > -1) {
58
+                    $scope.selectedUsers.splice(idx, 1);
59
+                }
60
+                else {
61
+                    $scope.selectedUsers.push(id);
62
+                }
63
+            };
64
+
65
+            $scope.toggleSelectAll = function()
66
+            {
67
+                if ($scope.selectedUsers.length == $scope.users.Data.length) {
68
+                    $scope.selectedUsers = [];
69
+                }
70
+                else {
71
+                    $scope.selectedUsers = [];
72
+                    for (var i = 0; i < $scope.users.Data.length; ++i) {
73
+                        $scope.selectedUsers.push($scope.users.Data[i].Id);
74
+                    }
75
+                }
76
+            };
77
+
42 78
             $scope.loadPage($scope.page);
43 79
     }]);

+ 1
- 0
luticate/index.html Переглянути файл

@@ -16,6 +16,7 @@
16 16
     <script src="../bower_components/angular-bootstrap/ui-bootstrap.js"></script>
17 17
     <script src="../bower_components/angular-bootstrap/ui-bootstrap-tpls.min.js"></script>
18 18
     <script src="../bower_components/angular-local-storage/dist/angular-local-storage.js"></script>
19
+    <script src="../bower_components/angular-ui-validate/dist/validate.js"></script>
19 20
     <script src="../bower_components/bootstrap/js/collapse.js"></script>
20 21
     <script src="../bower_components/bootstrap/js/transition.js"></script>
21 22
     <script src="../bower_components/bootstrap/js/dropdown.js"></script>

+ 1
- 1
luticate/views/login.html Переглянути файл

@@ -9,7 +9,7 @@
9 9
                 <input id="login" ng-model="username" class="form-control" />
10 10
 
11 11
                 <label for="password">Password</label><br />
12
-                <input id="password" ng-model="password" class="form-control" />
12
+                <input id="password" ng-model="password" type="password" class="form-control" />
13 13
 
14 14
                 <br />
15 15
                 <div class="col-sm-12 center-block">

+ 29
- 5
luticate/views/modals/useredit.html Переглянути файл

@@ -1,18 +1,42 @@
1
-<dialog-ok-cancel title="Edit user {{ user.Username }}">
1
+<dialog-ok-cancel title="{{ user.Id == null ? 'Add' : 'Edit'}} user {{ user.Username }}">
2 2
     <div class="form-group">
3 3
         <label for="username" class="col-sm-2 control-label">Username</label>
4
-        <div class="col-sm-9"><input id="username" class="form-control" ng-model="user.Username" readonly/></div>
4
+        <div class="col-sm-9">
5
+            <input id="username" class="form-control" ng-model="user.Username" ng-readonly="user.Id != null" required/>
6
+        </div>
5 7
     </div>
6 8
     <div class="form-group">
7 9
         <label for="email" class="col-sm-2 control-label">Email</label>
8
-        <div class="col-sm-9"><input id="email" class="form-control" ng-model="user.Email" /></div>
10
+        <div class="col-sm-9">
11
+            <input id="email" class="form-control" ng-model="user.Email" />
12
+        </div>
9 13
     </div>
10 14
     <div class="form-group">
11 15
         <label for="firstname" class="col-sm-2 control-label">Firstname</label>
12
-        <div class="col-sm-9"><input id="firstname" class="form-control" ng-model="user.Firstname" /></div>
16
+        <div class="col-sm-9">
17
+            <input id="firstname" class="form-control" ng-model="user.Firstname" />
18
+        </div>
13 19
     </div>
14 20
     <div class="form-group">
15 21
         <label for="lastname" class="col-sm-2 control-label">Lastname</label>
16
-        <div class="col-sm-9"><input id="lastname" class="form-control" ng-model="user.Lastname" /></div>
22
+        <div class="col-sm-9">
23
+            <input id="lastname" class="form-control" ng-model="user.Lastname" />
24
+        </div>
25
+    </div>
26
+    <div class="form-group">
27
+        <label for="password" class="col-sm-2 control-label">Password</label>
28
+        <div class="col-sm-9">
29
+            <input id="password" class="form-control" type="password" ng-model="user.Password" />
30
+        </div>
31
+        <div class="clearfix"></div>
32
+        <label for="password" class="col-sm-2 control-label">Confirmation</label>
33
+        <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' }"/>
36
+        </div>
37
+        <div class="clearfix"></div>
38
+        <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
+        </div>
17 41
     </div>
18 42
 </dialog-ok-cancel>

+ 21
- 7
luticate/views/users.html Переглянути файл

@@ -4,18 +4,23 @@
4 4
         <table class="col-sm-12 table table-hover">
5 5
             <thead>
6 6
                 <tr>
7
-                    <th class="col-sm-1">Id</th>
8
-                    <th class="col-sm-4">Username</th>
9
-                    <th class="col-sm-5">Email</th>
10
-                    <th class="col-sm-2">Profile Id</th>
7
+                    <th class="col-sm-3">
8
+                        <input type="checkbox" ng-click="toggleSelectAll()"
9
+                               ng-checked="selectedUsers.length == users.Data.length && users.Data.length != 0">
10
+                        Username
11
+                    </th>
12
+                    <th class="col-sm-3">Email</th>
13
+                    <th class="col-sm-3">Firstname</th>
14
+                    <th class="col-sm-3">Lastname</th>
11 15
                 </tr>
12 16
             </thead>
13 17
             <tbody>
14 18
                 <tr ng-repeat="user in users.Data" style="cursor: pointer" ng-click="displayUser(user)">
15
-                    <td>{{ user.Id }}</td>
16
-                    <td>{{ user.Username }}</td>
19
+                    <td><input name="selectedUsers[]" type="checkbox" ng-checked="selectedUsers.indexOf(user.Id) > -1"
20
+                               ng-click="$event.stopPropagation();toggleSelectedUser(user.Id)" >&nbsp;{{ user.Username }}</td>
17 21
                     <td>{{ user.Email }}</td>
18
-                    <td>{{ user.ProfileId }}</td>
22
+                    <td>{{ user.Firstname }}</td>
23
+                    <td>{{ user.Lastname }}</td>
19 24
                 </tr>
20 25
             </tbody>
21 26
         </table>
@@ -23,5 +28,14 @@
23 28
         <div class="col-sm-12 text-center">
24 29
             <a class="{{ p == page ? 'pagination-current' : 'pagination-not-current'}}" href="" ng-repeat="p in pages" ng-click="loadPage(p)">{{ p + 1 }}&nbsp;</a>
25 30
         </div>
31
+
32
+        <div class="col-sm-12">
33
+            <button class="btn btn-default" type="button" ng-click="removeUsers()" ng-disabled="selectedUsers.length == 0">
34
+                <span class="glyphicon glyphicon-remove" aria-hidden="true"></span> Remove
35
+            </button>
36
+            <button class="btn btn-default" type="button" ng-click="addUser()">
37
+                <span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Add
38
+            </button>
39
+        </div>
26 40
     </div>
27 41
 </div>

Завантаження…
Відмінити
Зберегти