<%= render :partial => 'easy_queries/easy_query_index', :locals => {:query => @query, :easy_query_name =>  l(:label_document_global), :free_search_options => {:free_search_element_to_update => 'easy_documents', :free_search_url => documents_path}} %>

<div id="easy_documents">
  <%= render :partial => 'easy_documents/easy_documents' %>
</div>
<span class="pagination"><%= pagination_links_full @entity_pages, @entity_count %></span>

<% content_for :easy_page_layout_service_box do %>
  <% if User.current.allowed_to?(:add_documents, @project, :global => true) %>
    <%= link_to(l(:label_document_new), {:controller => 'easy_documents', :action => 'new'}, :class => 'button-positive icon icon-add') -%>
  <% end %>
<% end -%>

<% content_for :sidebar do %>
  <div id="documents-sidebar-order-box" class="box">
    <%= content_tag :h3, l(:label_group_by, ''), :class => 'icon icon-reorder' -%>
    <%= form_tag({:controller => 'easy_documents', :action => 'index'}, :method => :get) do %>
      <div class="order">
        <label><%= radio_button_tag 'sort_by', 'category', (@sort_by == 'category'), :onclick => 'this.form.submit();' %> <%= l(:field_category) %></label>
        <label><%= radio_button_tag 'sort_by', 'date', (@sort_by == 'date'), :onclick => 'this.form.submit();' %> <%= l(:label_date) %></label>
        <label><%= radio_button_tag 'sort_by', 'title', (@sort_by == 'title'), :onclick => 'this.form.submit();' %> <%= l(:field_title) %></label>
        <label><%= radio_button_tag 'sort_by', 'author', (@sort_by == 'author'), :onclick => 'this.form.submit();' %> <%= l(:field_author) %></label>
        <label><%= radio_button_tag 'sort_by', 'project', (@sort_by == 'project'), :onclick => 'this.form.submit();' %> <%= l(:field_project) %></label>
      </div>
    <% end %>
  </div>
  <%= render :partial => 'sidebar/saved_easyqueries_by_type', :locals => {:query_class => @query.class, :project => @project} %>
<% end -%>

<% include_attachment_tags %>

<script type="text/javascript">
  $(document).on('easy-query:after-search', function(e) {
    $("#easy-query-heading-count").remove();
  });
</script>