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

<div class="page">
  <header class="page-header">
    <h1 class="page-title"><%= message('project_links.page') -%></h1>
    <div class="page-actions">
      <div class="button-group">
        <%= link_to message('projects_role.apply_template'),
                    {:controller => :roles, :action => :apply_template_form, :components => [@project.key], :names => @project.name, :results_count => 1},
                    :id => "apply-template-#{u @project.kee}", :class => 'open-modal link-action button' %>
      </div>
    </div>
    <p class="page-description"><%= message('project_links.page.description') -%></p>
  </header>

  <table class="data width100">
    <thead>
      <tr>
        <th>&nbsp;</th>
        <th>
          <%= message('projects_role.user') -%><br/>
          <span class="small gray" style="font-size: 11px; font-weight: normal;"><%= message('projects_role.user.desc') -%></span>
        </th>
        <th>
          <%= message('projects_role.admin') -%><br/>
          <span class="small gray" style="font-size: 11px; font-weight: normal;"><%= message('projects_role.admin.desc') -%></span>
        </th>
        <th>
          <%= message('projects_role.issueadmin') -%><br/>
          <span class="small gray" style="font-size: 11px; font-weight: normal;"><%= message('projects_role.issueadmin.desc') -%></span>
        </th>
        <th>
          <%= message('projects_role.codeviewer') -%><br/>
          <span class="small gray" style="font-size: 11px; font-weight: normal;"><%= message('projects_role.codeviewer.desc') -%></span>
        </th>
      </tr>
    </thead>
    <tbody>
      <tr class="even">
        <td valign="top"><b>Users</b></td>
        <% ['user', 'admin', 'issueadmin', 'codeviewer'].each do |permission| -%>
        <td valign="top">
          <span id="<%= permission -%>-role-users"><%= users(permission, @project.id).map(&:name).join(', ') %></span>
          (<%= link_to_edit_roles_permission_form(message('select'), permission, @project.id, "select-#{permission}-edit-users") %>)<br/>
        </td>
        <% end %>
      </tr>
      <tr class="odd">
        <td valign="top"><b>Groups</b></td>
        <% ['user', 'admin', 'issueadmin', 'codeviewer'].each do |permission| -%>
        <td valign="top">
          <span id="<%= permission -%>-role-groups"><%= groups(permission, @project.id).map{|g| group_name(g)}.join(', ') %></span>
          (<%= link_to_edit_groups_permission_form(message('select'), permission, @project.id, "select-#{permission}-edit-groups") %>)<br/>
        </td>
        <% end %>
      </tr>
    </tbody>
  </table>
</div>
