salix/front/core/directives/acl.js

42 lines
1.1 KiB
JavaScript
Raw Normal View History

2018-02-10 15:18:01 +00:00
import ngModule from '../module';
2019-10-18 19:36:30 +00:00
import FormInput from '../components/form-input';
2019-10-18 19:36:30 +00:00
function vnAcl(aclService) {
let acls = [];
return {
restrict: 'A',
2017-09-21 08:23:51 +00:00
priority: -1,
2019-10-18 19:36:30 +00:00
link: function(_, $element, $attrs) {
2019-01-24 09:57:43 +00:00
acls = $attrs.vnAcl.split(',').map(i => i.trim());
2019-03-12 14:04:09 +00:00
if (acls[0] == '') return;
2019-10-18 19:36:30 +00:00
let action = $attrs.vnAclAction || 'disable';
if (aclService.hasAny(acls)) return;
2019-03-12 14:04:09 +00:00
2019-10-18 19:36:30 +00:00
if (action === 'disable') {
let element = $element[0];
let elementToDisable = element.$ctrl;
2019-10-18 19:36:30 +00:00
if (!(elementToDisable instanceof FormInput)) {
let selector = 'input, textarea, button, submit';
2019-10-18 19:36:30 +00:00
if (!element.matches(selector))
element = element.querySelector(selector);
elementToDisable = element;
}
if (elementToDisable)
elementToDisable.disabled = true;
} else
$element.remove();
}
};
}
2019-10-18 19:36:30 +00:00
vnAcl.$inject = ['aclService'];
2018-02-10 15:18:01 +00:00
ngModule.directive('vnAcl', vnAcl);