<% form_for :user, @user, :url => {:id => @user.id, :action => 'create'}, :html => {:id => 'user_create_form', :method => @user.id.nil? ? :post : :put} do |f| %>
  <fieldset>
    <div class="modal-head">
      <h2>Add new user</h2>
    </div>
    <div class="modal-body">
      <div class="modal-error"/>
      <div class="modal-field"><label for="user[login]">Login <em class="mandatory">*</em></label>
        <%= f.text_field :login, :size => 30, :maxLength => 255 %>
      </div>
      <div class="modal-field">
        <label for="user[]">Name <em class="mandatory">*</em></label>
        <%= f.text_field :name, :size => 30, :maxLength => 200 %></div>
      <div class="modal-field">
        <label for="user[]">Email</label>
        <%= f.text_field :email, :size => 30, :maxLength => 100 %></div>
      <div class="modal-field">
        <label for="user[password]">Password <em class="mandatory">*</em></label><%= f.password_field :password, :size => 30, :maxLength => 50, :autocomplete => 'off' %></div>
      <div class="modal-field"><label for="user[password_confirmation]">Confirm password
        <em class="mandatory">*</em></label><%= f.password_field :password_confirmation, :size => 30, :maxLength => 50, :autocomplete => 'off' %></div>

      <div class="modal-field">
        <label for="user[scm_accounts]">SCM accounts</label>
        <table>
          <tr class="scm_account">
            <td>
              <input id="user_scm_accounts" type="text" size="30" name="user[scm_accounts][]"/>
            </td>
          </tr>
          <tr class="scm_account template" style="display:none">
            <td>
              <input id="user_scm_accounts" type="text" size="30" name="user[scm_accounts][]"/>
              <a href="#" class="delete link-action"><%= message('delete') -%></a>
              <br/>
            </td>
          </tr>
        </table>
        <div class="note marginbottom10">Note that login and email are automatically considered as SCM accounts</div>
        <button class="add_value"><%= message('user.add_scm_account') -%></button>
      </div>

    </div>
    <div class="modal-foot">
      <%= submit_tag 'Create' %>
      <%= link_to 'Cancel', {:controller => 'users', :action => 'index'}, {:class => 'action'} %><br/>
    </div>
  </fieldset>
<% end %>

<script>
  $j("#user_create_form").modalForm();

  $j('#user_create_form').on('click', '.delete', function () {
    $j(this).closest('.scm_account').remove();
    return false;
  });

  $j('#user_create_form .add_value').click(function () {
    var template = $j(this).parents('#user_create_form').find('.template').last();
    template.clone().insertBefore(template).show();
    return false;
  });
</script>
