tgCheckPermission directive

tg-class-permission="{'xx': 'modify_us'}" the directive add 'xx' if the user has the modify_us permisssion
stable
Juanfran 2015-03-13 08:42:08 +01:00 committed by David Barragán Merino
parent 5edc4d76f3
commit d7579b052b
1 changed files with 36 additions and 0 deletions

View File

@ -60,6 +60,42 @@ 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
#############################################################################