<div class="project_r_h">
  <h2 class="project_h2"><%=l(:label_document_plural)%></h2>
</div>
<div class="contextual">
  <!--Moved by young-->
  <%= l(:label_documents_sort) %>
  <%= link_to l(:field_category), {:sort_by => 'category'}, :class => (@sort_by == 'category' ? 'selected' :nil) %>
  <%= link_to l(:label_date), {:sort_by => 'date'}, :class => (@sort_by == 'date' ? 'selected' :nil) %>
  <%= link_to l(:field_title), {:sort_by => 'title'}, :class => (@sort_by == 'title' ? 'selected' :nil) %>
  <%= link_to l(:field_author), {:sort_by => 'author'}, :class => (@sort_by == 'author' ? 'selected' :nil) %>
  |
  <!--Ended by young-->
  <%= link_to l(:label_document_new), new_project_document_path(@project), :class => 'icon icon-add',
              :onclick => 'showAndScrollTo("add-document", "document_title"); return false;' if User.current.allowed_to?(:add_documents, @project) %>
</div>

<div id="add-document" style="display:none;">
  <h3>
    <%=l(:label_document_new)%>
  </h3>
  <%= labelled_form_for @document, :url => project_documents_path(@project), :html => {:multipart => true} do |f| %>
      <%= render :partial => 'form', :locals => {:f => f} %>
      <p>
        <%= submit_tag l(:button_create) %>
        <%= link_to l(:button_cancel), "#", :onclick => '$("#add-document").hide(); return false;' %>
      </p>
  <% end %>
</div>

<% if @grouped.empty? %>
    <p class="nodata" style="margin-top: 30px;">
      <%= l(:label_no_data) %>
    </p>
<% end %>

<% if @grouped.has_key? nil %>
    <% @grouped.keys.each do |group| %>
        <%= render :partial => 'documents/document', :collection => @grouped[group] %>
    <% end %>
<% else %>
    <% @grouped.keys.sort.each do |group| %>
        <%= render :partial => 'documents/document', :collection => @grouped[group] %>
    <% end %>
<% end %>

<% html_title(l(:label_document_plural)) -%>
