|
@@ -2,58 +2,59 @@
|
2
|
2
|
* Created by robin on 11/5/15.
|
3
|
3
|
*/
|
4
|
4
|
|
5
|
|
-angular.module('luticateUtils')
|
6
|
|
- .directive('luShowPermission', ['luticateAuthCache',
|
7
|
|
- function(luticateAuthCache) {
|
8
|
|
- return {
|
9
|
|
- restrict: 'A',
|
10
|
|
- link: function ($scope, element, attrs) {
|
|
5
|
+(function()
|
|
6
|
+{
|
|
7
|
+ function checkPermissions(permissions, luticateAuthCache)
|
|
8
|
+ {
|
|
9
|
+ var perms = permissions.split(',');
|
|
10
|
+ for (var i = 0; i < perms.length; ++i) {
|
|
11
|
+ if (!luticateAuthCache.hasEffectivePermission(perms[i])) {
|
|
12
|
+ return false;
|
|
13
|
+ }
|
|
14
|
+ }
|
|
15
|
+ return true;
|
|
16
|
+ }
|
11
|
17
|
|
12
|
|
- $scope.$watch(function()
|
13
|
|
- {
|
14
|
|
- var permissions = luticateAuthCache.getEffectivePermissions();
|
15
|
|
- if (permissions == null) {
|
16
|
|
- return null;
|
17
|
|
- }
|
18
|
|
- var permission_name = attrs.luShowPermission;
|
19
|
|
- if ($scope[permission_name] != null) {
|
20
|
|
- permission_name = $scope[permission_name];
|
21
|
|
- }
|
|
18
|
+ angular.module('luticateUtils')
|
|
19
|
+ .directive('luShowPermission', ['luticateAuthCache',
|
|
20
|
+ function(luticateAuthCache) {
|
|
21
|
+ return {
|
|
22
|
+ restrict: 'A',
|
|
23
|
+ link: function ($scope, element, attrs) {
|
22
|
24
|
|
23
|
|
- var value = permissions[permission_name];
|
24
|
|
- return value == null ? null : value;
|
25
|
|
- }, function(newValue, oldValue)
|
26
|
|
- {
|
27
|
|
- if (newValue == true) {
|
28
|
|
- element.show();
|
29
|
|
- }
|
30
|
|
- else {
|
31
|
|
- element.hide();
|
32
|
|
- }
|
33
|
|
- })
|
34
|
|
- }
|
35
|
|
- };
|
36
|
|
- }])
|
37
|
|
- .directive('luEnablePermission', ['luticateAuthCache',
|
38
|
|
- function(luticateAuthCache) {
|
39
|
|
- return {
|
40
|
|
- restrict: 'A',
|
41
|
|
- scope: {
|
42
|
|
- luEnablePermission: '@'
|
43
|
|
- },
|
44
|
|
- link: function ($scope, element, attrs) {
|
|
25
|
+ $scope.$watch(function()
|
|
26
|
+ {
|
|
27
|
+ return checkPermissions(attrs.luShowPermission, luticateAuthCache);
|
|
28
|
+ }, function(newValue)
|
|
29
|
+ {
|
|
30
|
+ if (newValue == true) {
|
|
31
|
+ element.show();
|
|
32
|
+ }
|
|
33
|
+ else {
|
|
34
|
+ element.hide();
|
|
35
|
+ }
|
|
36
|
+ })
|
|
37
|
+ }
|
|
38
|
+ };
|
|
39
|
+ }])
|
|
40
|
+ .directive('luEnablePermission', ['luticateAuthCache',
|
|
41
|
+ function(luticateAuthCache) {
|
|
42
|
+ return {
|
|
43
|
+ restrict: 'A',
|
|
44
|
+ link: function ($scope, element, attrs) {
|
45
|
45
|
|
46
|
|
- $scope.$watch(function() {
|
47
|
|
- return luticateAuthCache.hasEffectivePermissions($scope.luEnablePermission);
|
48
|
|
- }, function(newValue)
|
49
|
|
- {
|
50
|
|
- if (newValue == true) {
|
51
|
|
- element.removeAttr("disabled");
|
52
|
|
- }
|
53
|
|
- else {
|
54
|
|
- element.attr("disabled", "disabled");
|
55
|
|
- }
|
56
|
|
- })
|
57
|
|
- }
|
58
|
|
- };
|
59
|
|
- }]);
|
|
46
|
+ $scope.$watch(function() {
|
|
47
|
+ return checkPermissions(attrs.luEnablePermission, luticateAuthCache);
|
|
48
|
+ }, function(newValue)
|
|
49
|
+ {
|
|
50
|
+ if (newValue == true) {
|
|
51
|
+ element.removeAttr("disabled");
|
|
52
|
+ }
|
|
53
|
+ else {
|
|
54
|
+ element.attr("disabled", "disabled");
|
|
55
|
+ }
|
|
56
|
+ })
|
|
57
|
+ }
|
|
58
|
+ };
|
|
59
|
+ }]);
|
|
60
|
+})()
|