Simplify tgColorizeTags directive.

stable
Andrey Antukh 2014-09-10 14:06:21 +02:00
parent c08282fade
commit 9c1dff28ec
1 changed files with 17 additions and 20 deletions

View File

@ -21,6 +21,7 @@
taiga = @.taiga
trim = @.taiga.trim
bindOnce = @.taiga.bindOnce
module = angular.module("taigaCommon")
@ -68,23 +69,19 @@ ColorizeTagsDirective = ->
<% }) %>
""")
}
link = ($scope, $el, $attrs, $ctrl) ->
render = (srcTags) ->
template = templates[$attrs.tgColorizeTagsType]
tags = []
for tag in srcTags
tags = _.map srcTags, (tag) ->
color = $scope.project.tags_colors[tag]
tags.push({name: tag, color: color})
$el.html template({tags: tags})
return {name: tag, color: color}
$scope.$watch $attrs.tgColorizeTags, ->
tags = $scope.$eval($attrs.tgColorizeTags)
if tags?
render(tags)
html = template({tags: tags})
$el.html(html)
tags = $scope.$eval($attrs.tgColorizeTags)
if tags?
render(tags)
$scope.$watch $attrs.tgColorizeTags, (tags) ->
render(tags) if tags?
return {link: link}