userOrgSelector: fix initial value and add email with single select

This commit is contained in:
Felix Niklas 2016-04-25 16:13:40 +02:00
parent 5cb02e5961
commit 190924cf4f

View file

@ -85,12 +85,16 @@ class App.UserOrganizationAutocompletion extends App.Controller
return if !userId return if !userId
return if !App.User.exists(userId) return if !App.User.exists(userId)
name = App.User.find(userId).displayName() user = App.User.find(userId)
name = user.displayName()
if @attribute.multiple if @attribute.multiple
# create token # create token
@createToken name, userId @createToken name, userId
else else
if user.email
name += " <#{user.email}>"
@userSelect.val(name) @userSelect.val(name)
if @callback if @callback
@ -228,13 +232,18 @@ class App.UserOrganizationAutocompletion extends App.Controller
App.view('generic/user_search/new_user')() App.view('generic/user_search/new_user')()
build: => build: =>
if @attribute.multiple tokens = ''
name = ''
value = ''
if @attribute.multiple && @attribute.value
# fallback for if the value is not an array
if typeof @attribute.value is not 'object' if typeof @attribute.value is not 'object'
@attribute.value = [@attribute.value] @attribute.value = [@attribute.value]
value = @attribute.value.join ',' value = @attribute.value.join ','
tokens = ''
name = '' # create tokens
for userId in @attribute.value for userId in @attribute.value
if App.User.exists userId if App.User.exists userId
tokens += App.view('generic/token')( tokens += App.view('generic/token')(
@ -245,7 +254,6 @@ class App.UserOrganizationAutocompletion extends App.Controller
@log 'userId doesn\'t exist', userId @log 'userId doesn\'t exist', userId
else else
value = @attribute.value value = @attribute.value
tokens = ''
if value if value
if App.User.exists value if App.User.exists value
name = App.User.find(value).displayName() name = App.User.find(value).displayName()