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';
|
2017-05-25 09:48:10 +00:00
|
|
|
|
2019-10-18 19:36:30 +00:00
|
|
|
function vnAcl(aclService) {
|
2018-03-01 09:54:02 +00:00
|
|
|
let acls = [];
|
|
|
|
|
2017-05-25 09:48:10 +00:00
|
|
|
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;
|
2018-03-01 09:54:02 +00:00
|
|
|
|
2019-10-18 19:36:30 +00:00
|
|
|
if (!(elementToDisable instanceof FormInput)) {
|
|
|
|
let selector = 'input, textarea, button, submit';
|
2018-03-01 09:54:02 +00:00
|
|
|
|
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();
|
2017-05-25 09:48:10 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2019-10-18 19:36:30 +00:00
|
|
|
vnAcl.$inject = ['aclService'];
|
2017-05-25 09:48:10 +00:00
|
|
|
|
2018-02-10 15:18:01 +00:00
|
|
|
ngModule.directive('vnAcl', vnAcl);
|