2017-05-25 09:48:10 +00:00
|
|
|
import {module} from '../module';
|
|
|
|
|
2017-09-21 08:23:51 +00:00
|
|
|
function vnAcl(aclService, $timeout) {
|
2017-11-23 13:53:37 +00:00
|
|
|
function getMaterialType(className) {
|
|
|
|
let type = '';
|
|
|
|
if (className) {
|
|
|
|
type = className.replace('mdl-', '').replace('__input', '');
|
|
|
|
type = type.charAt(0).toUpperCase() + type.slice(1);
|
|
|
|
}
|
|
|
|
return type;
|
|
|
|
}
|
|
|
|
function udateMaterial(input) {
|
|
|
|
if (input && input.className) {
|
|
|
|
let find = input.className.match(/mdl-[\w]+input/g);
|
|
|
|
if (find.length && find[0]) {
|
|
|
|
let type = getMaterialType(find[0]);
|
|
|
|
if (type && input.parentNode[`Material${type}`] && input.parentNode[`Material${type}`].updateClasses_) {
|
|
|
|
input.parentNode[`Material${type}`].updateClasses_();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2017-05-25 09:48:10 +00:00
|
|
|
return {
|
|
|
|
restrict: 'A',
|
2017-09-21 08:23:51 +00:00
|
|
|
priority: -1,
|
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) {
|
2017-09-21 08:23:51 +00:00
|
|
|
$timeout(() => {
|
|
|
|
input.setAttribute("disabled", "true");
|
2017-11-23 13:53:37 +00:00
|
|
|
udateMaterial(input);
|
2017-09-21 08:23:51 +00:00
|
|
|
});
|
2017-10-19 17:11:49 +00:00
|
|
|
$element[0].querySelectorAll('i, vn-drop-down').forEach(element => {
|
|
|
|
element.parentNode.removeChild(element);
|
2017-09-21 08:23:51 +00:00
|
|
|
});
|
2017-05-25 12:23:19 +00:00
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
2017-09-21 08:23:51 +00:00
|
|
|
vnAcl.$inject = ['aclService', '$timeout'];
|
2017-05-25 09:48:10 +00:00
|
|
|
|
|
|
|
module.directive('vnAcl', vnAcl);
|