2017-05-25 09:48:10 +00:00
|
|
|
import {module} from '../module';
|
|
|
|
|
|
|
|
function vnAcl(aclService, $compile) {
|
|
|
|
return {
|
|
|
|
restrict: 'A',
|
2017-05-25 12:23:19 +00:00
|
|
|
link: function($scope, $element, $attrs) {
|
|
|
|
let acls = $attrs.vnAcl.split(',');
|
|
|
|
let action = $attrs.vnAclAction || 'disabled';
|
2017-05-25 09:48:10 +00:00
|
|
|
if (!aclService.aclPermission(acls)) {
|
|
|
|
if (action === 'disabled') {
|
2017-05-25 12:23:19 +00:00
|
|
|
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);
|
|
|
|
}
|
2017-05-25 09:48:10 +00:00
|
|
|
} else {
|
2017-05-25 12:23:19 +00:00
|
|
|
$element.remove();
|
2017-05-25 09:48:10 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
vnAcl.$inject = ['aclService', '$compile'];
|
|
|
|
|
|
|
|
module.directive('vnAcl', vnAcl);
|