tgCheckPermission directive
tg-class-permission="{'xx': 'modify_us'}" the directive add 'xx' if the user has the modify_us permisssionstable
parent
5edc4d76f3
commit
d7579b052b
|
@ -60,6 +60,42 @@ CheckPermissionDirective = ->
|
||||||
|
|
||||||
module.directive("tgCheckPermission", CheckPermissionDirective)
|
module.directive("tgCheckPermission", CheckPermissionDirective)
|
||||||
|
|
||||||
|
#############################################################################
|
||||||
|
## Add class based on permissions
|
||||||
|
#############################################################################
|
||||||
|
|
||||||
|
ClassPermissionDirective = ->
|
||||||
|
name = "tgClassPermission"
|
||||||
|
|
||||||
|
link = ($scope, $el, $attrs) ->
|
||||||
|
checkPermissions = (project, className, permission) ->
|
||||||
|
negation = permission[0] == "!"
|
||||||
|
|
||||||
|
permission = permission.slice(1) if negation
|
||||||
|
|
||||||
|
if negation && project.my_permissions.indexOf(permission) == -1
|
||||||
|
$el.addClass(className)
|
||||||
|
else if project.my_permissions.indexOf(permission) != -1
|
||||||
|
$el.addClass(className)
|
||||||
|
else
|
||||||
|
$el.removeClass(className)
|
||||||
|
|
||||||
|
tgClassPermissionWatchAction = (project) ->
|
||||||
|
if project
|
||||||
|
unbindWatcher()
|
||||||
|
|
||||||
|
classes = $scope.$eval($attrs[name])
|
||||||
|
|
||||||
|
for className, permission of classes
|
||||||
|
checkPermissions(project, className, permission)
|
||||||
|
|
||||||
|
|
||||||
|
unbindWatcher = $scope.$watch "project", tgClassPermissionWatchAction
|
||||||
|
|
||||||
|
return {link:link}
|
||||||
|
|
||||||
|
module.directive("tgClassPermission", ClassPermissionDirective)
|
||||||
|
|
||||||
#############################################################################
|
#############################################################################
|
||||||
## Animation frame service, apply css changes in the next render frame
|
## Animation frame service, apply css changes in the next render frame
|
||||||
#############################################################################
|
#############################################################################
|
||||||
|
|
Loading…
Reference in New Issue