您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

luhaspermission.js 2.1KB

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