<% title _("Filters") %>

<% title_actions link_to_if_authorized(_("New filter"), hash_for_new_filter_path(:role_id => @role)),
                 documentation_button('4.1.2RolesandPermissions') %>

<table class="table table-bordered table-striped">
  <thead>
    <tr>
      <% unless params[:role_id] %>
        <th><%= sort :role, :as => _("Role") %></th>
      <% end %>
      <th><%= sort :resource, :as => s_("Filter|Resource") %></th>
      <th><%= s_("Filter|Permissions") %></th>
      <th><%= sort :search, :as => s_("Filter|Unlimited") %></th>
      <th><%= sort :search, :as => s_("Filter|Search") %></th>
      <th></th>
    </tr>
  </thead>
  <tbody>
    <% @filters.each do |filter| %>
      <tr>
        <% unless params[:role_id] %>
          <td>
            <%= content_tag('span', link_to_if_authorized(filter.role.name, hash_for_roles_path(:search => "name = #{filter.role.name}").
                  merge(:auth_object => filter.role, :authorizer => @roles_authorizer))) %>
          </td>
        <% end %>
        <td><%= _(filter.resource_class.try(:humanize_class_name) || filter.resource_type || '(Miscellaneous)') %></td>
        <td><%= filter.permissions.map(&:name).join(', ') %></td>
        <td><%= checked_icon filter.unlimited? %></td>
        <td>
          <%= content_tag('span', link_to_if_authorized(filter.search || _('none'),
                                                      hash_for_edit_filter_path(:id => filter, :role_id => @role).
                                                              merge(:auth_object => filter, :authorizer => authorizer))) %>
        </td>
        <td>
          <%= action_buttons(
                    display_link_if_authorized(_("Edit"), hash_for_edit_filter_path(:id => filter, :role_id => @role).
                            merge(:auth_object => filter, :authorizer => authorizer)),
                    display_delete_if_authorized(hash_for_filter_path(:id => filter, :role_id => @role).
                                                         merge(:auth_object => filter, :authorizer => authorizer),
                                                         :data => { :confirm => (_("Delete filter?")) } )
            )
        %>
        </td>
      </tr>
    <% end %>
  </tbody>
</table>
<%= will_paginate_with_info @filters %>
