userOrgSelector: initially render tokens/name

This commit is contained in:
Felix Niklas 2016-04-25 15:59:38 +02:00
parent e0324b7e35
commit 5cb02e5961
2 changed files with 35 additions and 8 deletions

View file

@ -32,12 +32,8 @@ class App.UserOrganizationAutocompletion extends App.Controller
@build() @build()
# set current value # set current value
if @attribute.value if @attribute.value and @callback
if @attribute.multiple and typeof value is 'object' @callback(@attribute.value)
for value in @attribute.value
@selectUser value, false
else
@selectUser @attribute.value, false
element: => element: =>
@el @el
@ -232,9 +228,37 @@ 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
if typeof @attribute.value is not 'object'
@attribute.value = [@attribute.value]
value = @attribute.value.join ','
tokens = ''
name = ''
for userId in @attribute.value
if App.User.exists userId
tokens += App.view('generic/token')(
name: App.User.find(userId).displayName()
value: userId
)
else
@log 'userId doesn\'t exist', userId
else
value = @attribute.value
tokens = ''
if value
if App.User.exists value
name = App.User.find(value).displayName()
else
@log 'userId doesn\'t exist', value
@html App.view('generic/user_search/input')( @html App.view('generic/user_search/input')(
attribute: @attribute attribute: @attribute
value: value
tokens: tokens
name: name
) )
if !@attribute.disableCreateUser if !@attribute.disableCreateUser
@recipientList.append(@buildUserNew()) @recipientList.append(@buildUserNew())

View file

@ -1,6 +1,9 @@
<div class="tokenfield form-control u-positionOrigin"> <div class="tokenfield form-control u-positionOrigin">
<input class="js-userId" type="hidden" name="<%- @attribute.name %>" tabindex="-1"> <input class="js-userId" type="hidden" value="<%= @value %>" name="<%- @attribute.name %>" tabindex="-1">
<input name="<%- @attribute.name %>_completion" class="user-select token-input js-userSelect" autocapitalize="off" placeholder="<%- @attribute.placeholder %>" autocomplete="off" role="textbox" aria-autocomplete="list" aria-haspopup="true"> <% if @attribute.multiple: %>
<%- @tokens %>
<% end %>
<input name="<%- @attribute.name %>_completion" class="user-select token-input js-userSelect" autocapitalize="off" placeholder="<%- @attribute.placeholder %>" autocomplete="off" role="textbox" aria-autocomplete="list" value="<%= @name %>" aria-haspopup="true">
<%- @Icon('arrow-down', 'dropdown-arrow') %> <%- @Icon('arrow-down', 'dropdown-arrow') %>
</div> </div>