47 lines
1.4 KiB
JavaScript
47 lines
1.4 KiB
JavaScript
import ngModule from '../module';
|
|
import FormInput from '../components/form-input';
|
|
|
|
function vnAcl(aclService) {
|
|
let acls = [];
|
|
|
|
return {
|
|
restrict: 'A',
|
|
priority: -1,
|
|
link: function(_, $element, $attrs) {
|
|
acls = $attrs.vnAcl.split(',').map(i => i.trim());
|
|
if (acls[0] == '') return;
|
|
|
|
let action = $attrs.vnAclAction || 'disable';
|
|
|
|
if ($attrs.vnAclModel) {
|
|
console.log($attrs.vnAclModel, $attrs.vnAclProperty, $attrs.vnAclAccessType);
|
|
let hasAcl = aclService.hasAnyACL($attrs.vnAclModel, $attrs.vnAclProperty, $attrs.vnAclAccessType);
|
|
if (hasAcl) return;
|
|
}
|
|
|
|
if (aclService.hasAny(acls)) return;
|
|
|
|
if (action === 'disable') {
|
|
let element = $element[0];
|
|
let elementToDisable = element.$ctrl;
|
|
|
|
if (!(elementToDisable instanceof FormInput)) {
|
|
let selector = 'input, textarea, button, submit';
|
|
|
|
if (!element.matches(selector))
|
|
element = element.querySelector(selector);
|
|
|
|
elementToDisable = element;
|
|
}
|
|
|
|
if (elementToDisable)
|
|
elementToDisable.disabled = true;
|
|
} else
|
|
$element.remove();
|
|
}
|
|
};
|
|
}
|
|
vnAcl.$inject = ['aclService'];
|
|
|
|
ngModule.directive('vnAcl', vnAcl);
|