Initial commit
This commit is contained in:
commit
880e39de2e
511 files changed
+38363
No files matched your search
@@ -0,0 +1,32 @@
|
||||
(function() {
|
||||
'use strict';
|
||||
|
||||
angular.module('portal.common.directives.permissions', ['ui.router'])
|
||||
.directive('hasPermission', function(permissions){
|
||||
return {
|
||||
link: function(scope, element, attrs) {
|
||||
if (!_.isString(attrs.hasPermission)){
|
||||
throw 'hasPermission value must be a string';
|
||||
}
|
||||
var value = attrs.hasPermission.trim();
|
||||
var notPermissionFlag = value[0] === '!';
|
||||
if (notPermissionFlag) {
|
||||
value = value.slice(1).trim();
|
||||
}
|
||||
|
||||
function toggleVisibility() {
|
||||
permissions.canView({permission: value}).then(function(allowed){
|
||||
if ((allowed && !notPermissionFlag) || (!allowed && notPermissionFlag)) {
|
||||
element.css('display', 'block');
|
||||
} else {
|
||||
element.css('display', 'none');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
toggleVisibility();
|
||||
scope.$on('permissionsChanged', toggleVisibility);
|
||||
}
|
||||
};
|
||||
});
|
||||
})();
|
||||
Reference in new issue
Block a user