Simplify the tg-check-permission directive.
parent
cc04ee80a6
commit
bf732f7a17
|
@ -28,19 +28,15 @@ module = angular.module("taigaCommon", [])
|
||||||
#############################################################################
|
#############################################################################
|
||||||
|
|
||||||
CheckPermissionDirective = ->
|
CheckPermissionDirective = ->
|
||||||
showElementIfPermission = (element, permission, project) ->
|
render = ($el, project, permission) ->
|
||||||
element.show() if project.my_permissions.indexOf(permission) > -1
|
$el.show() if project.my_permissions.indexOf(permission) > -1
|
||||||
|
|
||||||
link = ($scope, $el, $attrs) ->
|
link = ($scope, $el, $attrs) ->
|
||||||
$el.hide()
|
$el.hide()
|
||||||
permission = $attrs.tgCheckPermission
|
permission = $attrs.tgCheckPermission
|
||||||
|
|
||||||
#Sometimes this directive from a self included html template
|
$scope.$watch "project", (project) ->
|
||||||
if $scope.project?
|
render($el, project, permission) if project?
|
||||||
showElementIfPermission($el, permission, $scope.project)
|
|
||||||
|
|
||||||
$scope.$on "project:loaded", (ctx, project) ->
|
|
||||||
showElementIfPermission($el, permission, project)
|
|
||||||
|
|
||||||
$scope.$on "$destroy", ->
|
$scope.$on "$destroy", ->
|
||||||
$el.off()
|
$el.off()
|
||||||
|
|
Loading…
Reference in New Issue