Restricting number of tags for tag rules to one

This commit is contained in:
Rob Harrington
2016-05-27 16:22:11 +10:00
parent 6dd05ca4da
commit 12e685bd92
10 changed files with 80 additions and 39 deletions

View File

@@ -7,10 +7,15 @@ angular.module("admin.utils").directive "tagsWithTranslation", ($timeout) ->
tagListAttr: "@?"
findTags: "&"
form: '=?'
onTagAdded: "&"
onTagRemoved: "&"
max: "="
link: (scope, element, attrs) ->
scope.findTags = undefined unless attrs.hasOwnProperty("findTags")
scope.limitReached = false
compileTagList = ->
scope.limitReached = scope.object[scope.tagsAttr].length >= scope.max if scope.max != undefined
scope.object[scope.tagListAttr] = (tag.text for tag in scope.object[scope.tagsAttr]).join(",")
$timeout ->
@@ -21,10 +26,12 @@ angular.module("admin.utils").directive "tagsWithTranslation", ($timeout) ->
compileTagList()
scope.tagAdded = ->
scope.onTagAdded()
compileTagList()
scope.tagRemoved = ->
# For some reason the tags input doesn't mark the form
# as dirty when a tag is removed, which breaks the save bar
scope.form.$setDirty(true) if typeof scope.form isnt 'undefined'
scope.onTagRemoved()
compileTagList()