 
             if event.keyCode == 13
                 saveInputTag()
+            else if event.keyCode == 27
+                $el.find('.save').hide()
+                $el.find("input").hide()
+                $el.find("input").val('')
+                $el.find('.add-tag').show()
             else if target.val().length
                 $el.find('.save').show()
             else

        </span>
    <% }); %>""")

    renderTags = ($el, tags, editable, tagsColors) ->
        ctx = {
            tags: _.map(tags, (t) -> {name: t, color: tagsColors[t]})
            editable: editable
        }
        html = templateTags(ctx)
        $el.find("div.tags-container").html(html)

    normalizeTags = (tags) ->
        tags = _.map(tags, trim)
        tags = _.map(tags, (x) -> x.toLowerCase())
        return _.uniq(tags)

    link = ($scope, $el, $attrs, $model) ->
        editable = false

        $el.addClass("tags-block")

        addValue = (value) ->
            value = trim(value)

                    promise.then null, ->
                        $confirm.notify("error")

        $scope.$watch $attrs.ngModel, (val) ->
            tags_colors = if $scope.project?.tags_colors? then $scope.project.tags_colors else []
            renderTags($el, val, editable, tags_colors)

            if val? and val.length > 0
                $el.find("span.add-tag-text").hide()
            else
                $el.find("span.add-tag-text").show()

        $scope.$on "$destroy", ->
            $el.off()

    return {
        link:link,
        require:"ngModel"
