<% user ||= @user
auth_sources ||= @auth_sources %>
<%= error_messages_for 'user' %>

<div id="user_form" class="splitcontent">
  <div class="splitcontentleft">
    <h3><%=l(:label_information_plural)%></h3>
    <div class="box tabular">
      <p>
        <%= f.text_field :login, :required => true, :size => 25  %>
      </p>
      <p>
        <%= f.text_field :firstname, :required => true %>
      </p>
      <p>
        <%= f.text_field :lastname, :required => true %>
      </p>
      <p>
        <%= f.text_field :mail, :required => true %> <%= additional_emails_link(@user) unless @user.new_record? %>
      </p>
      <% unless user.force_default_language? %>
        <p>
          <%= f.select :language, lang_options_for_select %>
        </p>
      <% end %>
      <% if Setting.openid? %>
        <p>
          <%= f.text_field :identity_url  %>
        </p>
      <% end %>
      <% if user.safe_attribute_names.include?('easy_user_type_id') %>
        <p>
          <%= f.select :easy_user_type_id, easy_user_type_options %>
        </p>
      <% end %>
      <% if false && user.safe_attribute_names.include?('tag_list') %>
        <p class="easy-tag-list-field">
          <%= label_tag 'user_tag_list', l(:label_easy_tags) %>
          <%= autocomplete_field_tag 'user[tag_list][]', autocomplete_easy_taggables_path(:format => :json), user.tag_list, {:id => 'user_tag_list', load_immediately: true} %>
        </p>
      <% end %>
      <% if user.safe_attribute_names.include?('easy_system_flag') %>
        <p>
          <%= f.check_box :easy_system_flag %><%= l(:label_easy_system_flag, appname: EasyExtensions::EasyProjectSettings.app_name) -%>
        </p>
      <% end %>

      <% user.custom_field_values.each do |value| %>
        <% unless (cf_tag = custom_field_tag_with_label :user, value).blank? %>
          <p>
            <%= cf_tag %>
          </p>
        <% end %>
      <% end %>

      <% if user.safe_attribute_names.include?('admin') %>
        <p>
          <%= f.check_box :admin, :disabled => (user == User.current) %>
        </p>
      <% end %>
      <%= call_hook(:view_users_form, :user => user, :form => f) %>
    </div>

    <h3><%=l(:label_authentication)%></h3>
    <div class="box tabular">
      <% unless auth_sources.empty? %>
        <p><%= f.select :auth_source_id, ([[l(:label_internal), '']] + auth_sources.collect { |a| [a.name, a.id] }), {}, :onchange => "$('#password_fields').toggle(this.value === '');" %></p>
      <% end %>
      <div id="password_fields" style="<%= 'display:none;' if user.auth_source %>">
        <p><%= f.password_field :password, :required => user.new_record?, :size => 25  %><br />
          <em><%= l(:text_caracters_minimum, :count => Setting.password_min_length) %></em></p>
        <p><%= f.password_field :password_confirmation, :required => user.new_record?, :size => 25  %></p>
        <p><%= f.check_box :generate_password %></p>
        <p><%= f.check_box :must_change_passwd %></p>
      </div>
    </div>
  </div>

  <div class="splitcontentright">
    <h3><%=l(:field_mail_notification)%></h3>
    <div class="box">
      <%= render :partial => 'users/mail_notifications', :locals => {:user => user} %>
    </div>

    <h3><%=l(:label_preferences)%></h3>
    <div class="box tabular">
      <%= render :partial => 'users/preferences', :locals => {:user => user} %>
      <%= call_hook(:view_users_form_preferences, :user => @user, :form => f) %>
      <%= call_hook(:view_my_account_preferences, :user => @user, :form => f) %>
    </div>

    <h3><%= l(:label_user_form_other_settings) -%></h3>
    <div class="box tabular">
      <%= render :partial => 'users/other_settings', :locals => {:user => user} %>
    </div>
  </div>

  <div style="clear:both;"></div>
</div>
<div style="clear:left;"></div>

<%= javascript_tag do %>
  $(document).ready(function(){
  $('#user_generate_password').change(function(){
  var passwd = $('#user_password, #user_password_confirmation');
  if ($(this).is(':checked')){
  passwd.val('').prop('disabled', true);
  }else{
  passwd.removeAttr('disabled');
  }
  }).trigger('change');
  });
<% end %>
