<form id="user_edit_form" method="post" action="<%= ApplicationController.root_context -%>/users/update">
<fieldset>
      <div class="modal-head">
        <h2>Edit user: <%= h @user.login() -%></h2>
      </div>
      <div class="modal-body">
        <div class="modal-error"></div>
        <div class="modal-field">
          <input type="hidden" value="<%= @user.login() %>" name="user[login]" id="user_login"/>
        </div>
        <div class="modal-field">
          <label for="user[]">Name<em class="mandatory">*</em></label>
          <input type="text" value="<%= @user.name() %>" size="30" name="user[name]" maxlength="200" id="user_name"/>
        </div>
        <div class="modal-field">
          <label for="user[]">Email</label>
          <input type="text" value="<%= @user.email() %>" size="30" name="user[email]" maxlength="100" id="user_email">
        </div>
        <div class="modal-field">
          <label for="user[scm_accounts]">SCM accounts</label>
          <table>
            <% scmAccounts = @user.scmAccounts().to_a %>
            <% if scmAccounts.empty? %>
              <tr class="scm_account">
                <td>
                  <input id="user_scm_accounts" type="text" size="30" name="user[scm_accounts][]"/>
                </td>
              </tr>
            <% else %>
              <tr class="scm_account">
                <td>
                  <input id="user_scm_accounts" value="<%= scmAccounts.first() %>" type="text" size="30" name="user[scm_accounts][]"/>
                </td>
              </tr>
              <%
                 scmAccounts.shift
                 scmAccounts.each do |scmAccount| %>
                <tr class="scm_account">
                  <td>
                    <input id="user_scm_accounts" value="<%= scmAccount %>" type="text" size="30" name="user[scm_accounts][]"/>
                    <a href="#" class="delete link-action"><%= message('delete') -%></a>
                  </td>
                </tr>
              <% end %>
            <% end %>
            <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">
        <input type="submit" value="Save" name="commit">
        <a class="action" href="#" onclick="return closeModalWindow()"><%= h message('cancel') -%></a>
      </div>
  </fieldset>
</form>

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

  $j('#user_edit_form .delete').click(function () {
    $j(this).parents('.scm_account').remove();
    return false;
  });

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