You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

luhaspermission.js 2.0KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. /**
  2. * Created by robin on 11/5/15.
  3. */
  4. (function()
  5. {
  6. function checkPermissions(permissions, luticateAuthCache)
  7. {
  8. var perms = permissions.split(',');
  9. for (var i = 0; i < perms.length; ++i) {
  10. if (!luticateAuthCache.hasEffectivePermission(perms[i])) {
  11. return false;
  12. }
  13. }
  14. return true;
  15. }
  16. angular.module('luticateUtils')
  17. .directive('luShowPermission', ['luticateAuthCache',
  18. function(luticateAuthCache) {
  19. return {
  20. restrict: 'A',
  21. link: function ($scope, element, attrs) {
  22. $scope.$watch(function()
  23. {
  24. return checkPermissions(attrs.luShowPermission, luticateAuthCache);
  25. }, function(newValue)
  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. link: function ($scope, element, attrs) {
  42. $scope.$watch(function() {
  43. return checkPermissions(attrs.luEnablePermission, luticateAuthCache);
  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. }]);
  56. })()