From 190924cf4f63a3f2d11fd38e9cb31385fa416bd8 Mon Sep 17 00:00:00 2001 From: Felix Niklas Date: Mon, 25 Apr 2016 16:13:40 +0200 Subject: [PATCH] userOrgSelector: fix initial value and add email with single select --- .../user_organization_autocompletion.coffee | 20 +++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/app/assets/javascripts/app/lib/app_post/user_organization_autocompletion.coffee b/app/assets/javascripts/app/lib/app_post/user_organization_autocompletion.coffee index 7ddf9a760..7072ae023 100644 --- a/app/assets/javascripts/app/lib/app_post/user_organization_autocompletion.coffee +++ b/app/assets/javascripts/app/lib/app_post/user_organization_autocompletion.coffee @@ -85,12 +85,16 @@ class App.UserOrganizationAutocompletion extends App.Controller return if !userId return if !App.User.exists(userId) - name = App.User.find(userId).displayName() + user = App.User.find(userId) + name = user.displayName() if @attribute.multiple # create token @createToken name, userId else + if user.email + name += " <#{user.email}>" + @userSelect.val(name) if @callback @@ -228,13 +232,18 @@ class App.UserOrganizationAutocompletion extends App.Controller App.view('generic/user_search/new_user')() 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' @attribute.value = [@attribute.value] - + value = @attribute.value.join ',' - tokens = '' - name = '' + + # create tokens for userId in @attribute.value if App.User.exists userId tokens += App.view('generic/token')( @@ -245,7 +254,6 @@ class App.UserOrganizationAutocompletion extends App.Controller @log 'userId doesn\'t exist', userId else value = @attribute.value - tokens = '' if value if App.User.exists value name = App.User.find(value).displayName()