Browse Source

disable add permission if necessary

tags/0.1.0
Robin Thoni 9 years ago
parent
commit
104c8bae0e
1 changed files with 20 additions and 4 deletions
  1. 20
    4
      src/lupermissionsedit.js

+ 20
- 4
src/lupermissionsedit.js View File

15
 
15
 
16
                     $scope.permissions = [];
16
                     $scope.permissions = [];
17
                     $scope.allPermissions = [];
17
                     $scope.allPermissions = [];
18
+                    $scope.allPermissionsCleared = [];
18
                     $scope.tmpPermission = {
19
                     $scope.tmpPermission = {
19
                         Name: "",
20
                         Name: "",
20
                         Value: true
21
                         Value: true
69
                         luModel.getGetAllPromise(null, null, promiseLoadPermissions)
70
                         luModel.getGetAllPromise(null, null, promiseLoadPermissions)
70
                             .then(function (permissions) {
71
                             .then(function (permissions) {
71
                                 $scope.permissions = permissions.Data;
72
                                 $scope.permissions = permissions.Data;
73
+                                $scope.allPermissionsCleared = [];
74
+                                for (var i = 0; i < $scope.allPermissions.length; ++i) {
75
+                                    var p = $scope.allPermissions[i];
76
+                                    if ($scope.permissions.find(function(p2)
77
+                                        {
78
+                                            return p.Name == p2.Name;
79
+                                        }) == null) {
80
+                                        $scope.allPermissionsCleared.push(p);
81
+                                    }
82
+                                }
83
+                                if ($scope.allPermissionsCleared.length > 0) {
84
+                                    $scope.tmpPermission.Name = $scope.allPermissionsCleared[0].Name;
85
+                                }
86
+                                else {
87
+                                    $scope.tmpPermission.Name = "";
88
+                                }
72
                             }, luticateDialogErrorHelper.errorDialog);
89
                             }, luticateDialogErrorHelper.errorDialog);
73
                     };
90
                     };
74
 
91
 
81
                         luticateAuthPermissions.getAll(null, promiseLoadAllPermissions)
98
                         luticateAuthPermissions.getAll(null, promiseLoadAllPermissions)
82
                             .then(function (permissions) {
99
                             .then(function (permissions) {
83
                                 $scope.allPermissions = permissions.Data;
100
                                 $scope.allPermissions = permissions.Data;
84
-                                $scope.tmpPermission.Name = $scope.allPermissions[0].Name;
101
+                                $scope.loadPermissions();
85
                             }, luticateDialogErrorHelper.errorDialog);
102
                             }, luticateDialogErrorHelper.errorDialog);
86
                     };
103
                     };
87
 
104
 
88
-                    $scope.loadPermissions();
89
                     $scope.loadAllPermissions();
105
                     $scope.loadAllPermissions();
90
                 }
106
                 }
91
             };
107
             };
122
 '    {{ tmpPermission.Name }} <span class="caret"></span>' +
138
 '    {{ tmpPermission.Name }} <span class="caret"></span>' +
123
 '    </a>' +
139
 '    </a>' +
124
 '    <ul class="dropdown-menu">' +
140
 '    <ul class="dropdown-menu">' +
125
-'    <li ng-repeat="permission in allPermissions">' +
141
+'    <li ng-repeat="permission in allPermissionsCleared">' +
126
 '    <a href="" ng-click="tmpPermission.Name = permission.Name">{{ permission.Name}}</a>' +
142
 '    <a href="" ng-click="tmpPermission.Name = permission.Name">{{ permission.Name}}</a>' +
127
 '</li>' +
143
 '</li>' +
128
 '</ul>' +
144
 '</ul>' +
136
 '<li><a href="" ng-click="tmpPermission.Value = true">Allow</a></li>' +
152
 '<li><a href="" ng-click="tmpPermission.Value = true">Allow</a></li>' +
137
 '</ul>' +
153
 '</ul>' +
138
 '</div>' +
154
 '</div>' +
139
-'<button type="button" class="btn btn-default" ng-click="addPermission(tmpPermission)">' +
155
+'<button type="button" class="btn btn-default" ng-click="addPermission(tmpPermission)" ng-disabled="allPermissionsCleared.length == 0">' +
140
 '    <span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Add' +
156
 '    <span class="glyphicon glyphicon-plus" aria-hidden="true"></span> Add' +
141
 '    </button>' +
157
 '    </button>' +
142
 '    </div>' +
158
 '    </div>' +

Loading…
Cancel
Save