salix/client/core/src/directives/acl.js

31 lines
959 B
JavaScript
Raw Normal View History

import {module} from '../module';
function vnAcl(aclService, $compile) {
return {
restrict: 'A',
link: function($scope, $element, $attrs) {
let acls = $attrs.vnAcl.split(',');
let action = $attrs.vnAclAction || 'disabled';
if (!aclService.aclPermission(acls)) {
if (action === 'disabled') {
let input = $element[0];
let selector = 'input, textarea, button, submit';
if (!input.matches(selector))
input = input.querySelector(selector);
if (input) {
input.setAttribute("ng-disabled", "true");
$compile(input)($scope);
}
} else {
$element.remove();
}
}
}
};
}
vnAcl.$inject = ['aclService', '$compile'];
module.directive('vnAcl', vnAcl);