<%= title [l(:label_user_plural), users_path], l(:label_user_new) %>

<%= labelled_form_for @user, :url => { :action => 'create' }, :html => { :class => 'form-box', :autocomplete => 'off' } do |f| %>
  <%= render :partial => 'users/form', :locals => { :f => f } %>
  <div class="form-actions">
    <label class="inline"><%= check_box_tag 'send_information', 1, true %> <%= l(:label_send_information) %></label><br/>
    <%= submit_tag l(:button_create), :class => 'button-positive' %>
    <%= submit_tag l(:button_create_and_continue), :name => 'continue', :class => 'button' %>
  </div>
<% end %>

<% if @auth_sources.present? && @auth_sources.any?(&:searchable?) %>
  <script type="text/javascript">
    observeAutocompleteField('user_login', '<%= j autocomplete_for_new_user_auth_sources_path %>', {
      select: function(event, ui) {
        $('input#user_firstname').val(ui.item.firstname);
        $('input#user_lastname').val(ui.item.lastname);
        $('input#user_mail').val(ui.item.mail);
        $('select#user_auth_source_id option').each(function(){
          if ($(this).attr('value') == ui.item.auth_source_id) {
            $(this).prop('selected', true);
            $('select#user_auth_source_id').trigger('change');
          }
        });
      }
    });
  </script>
<% end %>
