1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859 |
- /**
- * Created by robin on 11/5/15.
- */
-
- angular.module('luticateUtils')
- .directive('luShowPermission', ['luticateAuthCache',
- function(luticateAuthCache) {
- return {
- restrict: 'A',
- link: function ($scope, element, attrs) {
-
- $scope.$watch(function()
- {
- var permissions = luticateAuthCache.getEffectivePermissions();
- if (permissions == null) {
- return null;
- }
- var permission_name = attrs.luShowPermission;
- if ($scope[permission_name] != null) {
- permission_name = $scope[permission_name];
- }
-
- var value = permissions[permission_name];
- return value == null ? null : value;
- }, function(newValue, oldValue)
- {
- if (newValue == true) {
- element.show();
- }
- else {
- element.hide();
- }
- })
- }
- };
- }])
- .directive('luEnablePermission', ['luticateAuthCache',
- function(luticateAuthCache) {
- return {
- restrict: 'A',
- scope: {
- luEnablePermission: '@'
- },
- link: function ($scope, element, attrs) {
-
- $scope.$watch(function() {
- return luticateAuthCache.hasEffectivePermissions($scope.luEnablePermission);
- }, function(newValue)
- {
- if (newValue == true) {
- element.removeAttr("disabled");
- }
- else {
- element.attr("disabled", "disabled");
- }
- })
- }
- };
- }]);
|