From 9c1dff28ecb3957cad0c6f985f78d28e8321dc5c Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Wed, 10 Sep 2014 14:06:21 +0200 Subject: [PATCH] Simplify tgColorizeTags directive. --- app/coffee/modules/common/tags.coffee | 37 ++++++++++++--------------- 1 file changed, 17 insertions(+), 20 deletions(-) diff --git a/app/coffee/modules/common/tags.coffee b/app/coffee/modules/common/tags.coffee index c7df2a15..70702633 100644 --- a/app/coffee/modules/common/tags.coffee +++ b/app/coffee/modules/common/tags.coffee @@ -21,6 +21,7 @@ taiga = @.taiga trim = @.taiga.trim +bindOnce = @.taiga.bindOnce module = angular.module("taigaCommon") @@ -53,38 +54,34 @@ module.directive("tgTags", TagsDirective) ColorizeTagsDirective = -> templates = { backlog: _.template(""" - <% _.each(tags, function(tag) { %> - <%- tag.name %> - <% }) %> + <% _.each(tags, function(tag) { %> + <%- tag.name %> + <% }) %> """) kanban: _.template(""" - <% _.each(tags, function(tag) { %> - - <% }) %> + <% _.each(tags, function(tag) { %> + + <% }) %> """) taskboard: _.template(""" - <% _.each(tags, function(tag) { %> - - <% }) %> + <% _.each(tags, function(tag) { %> + + <% }) %> """) } + 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}