<% content_for :script do %>
  <script>require(['common/select-list']);</script>
<% end %>

<div class="page">
  <header class="page-header">
    <h1 class="page-title"><%= message('users.page') -%></h1>
    <% if profiles_administrator? %>
      <div class="page-actions">
        <a id="create-link-user" href="<%= ApplicationController.root_context -%>/users/create_form" class="open-modal">
          Add new user
        </a>
      </div>
    <% end %>
    <p class="page-description"><%= message('users.page.description') -%> </p>
  </header>

  <table width="100%">
    <tr>
      <td valign="top">
        <table class="data width100 sortable" id="users">
          <thead>
          <tr>
            <th class="left"><a>Login</a></th>
            <th class="left sortfirstasc"><a>Name</a></th>
            <th class="left"><a>Email</a></th>
            <th class="left nosort"><a>Groups</a></th>
            <th class="right nosort" nowrap><a>Operations</a></th>
          </tr>
          </thead>
          <tbody>
          <% @users.each do |user| %>
            <tr id="user-<%= user.login.parameterize -%>">
              <td class="left" valign="top"><%= h user.login -%></td>
              <td class="left" valign="top"><%= h user.name -%></td>
              <td class="left" valign="top"><%= h user.email -%></td>
              <td class="left" valign="top">
                <%= h user.groups.sort.map(&:name).join(', ') %>
                (<%= link_to "select", {:action => 'select_group', :id => user.id}, {:id => "select-#{user.login.parameterize}", :class => 'open-modal link-action'} %>)
              </td>
              <td class="right" valign="top">
                <a id="edit-<%= user.login -%>" class="open-modal link-action" href="<%= ApplicationController.root_context -%>/users/edit_form/<%= u user.login -%>">Edit</a>
                &nbsp;
                <%= link_to 'Change password', {:id => user.id, :action => 'change_password_form'}, {:id => "change-password-#{user.login.parameterize}", :class => 'open-modal link-action'} -%>
                &nbsp;
                <%= link_to_action message('delete'), "#{ApplicationController.root_context}/users/delete/#{user.id}",
                                   :class => 'link-action link-red',
                                   :id => "delete-#{user.login}",
                                   :confirm_button => message('delete'),
                                   :confirm_title => 'Delete user: '+user.login,
                                   :confirm_msg => 'Warning : are you sure to delete the user "' + user.name+'"?',
                                   :confirm_msg_params => [user.name]
                -%>
              </td>
            </tr>
          <% end %>
          </tbody>
        </table>
        <script>jQuery('#users').sortable();</script>
      </td>
    </tr>
  </table>
</div>
