<div class="contextual">
<%= link_to l(:label_document_new), new_project_document_path(@project), :class => 'icon icon-add',
      :onclick => 'Element.show("add-document"); Form.Element.focus("document_title"); return false;' if User.current.allowed_to?(:manage_documents, @project) %>
</div>

<div id="add-document" style="display:none;">
<h2><%=l(:label_document_new)%></h2>
<% 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 => 'Element.hide("add-document")' %>
</p>
<% end %>
</div>

<h2><%=l(:label_document_plural)%></h2>

<% if @grouped.empty? %><p class="nodata"><%= l(:label_no_data) %></p><% end %>

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

<% content_for :sidebar do %>
    <h3><%= l(:label_sort_by, '') %></h3>
    <% form_tag({}, :method => :get) do %>
    <label><%= radio_button_tag 'sort_by', 'category', (@sort_by == 'category'), :onclick => 'this.form.submit();' %> <%= l(:field_category) %></label><br />
    <label><%= radio_button_tag 'sort_by', 'date', (@sort_by == 'date'), :onclick => 'this.form.submit();' %> <%= l(:label_date) %></label><br />
    <label><%= radio_button_tag 'sort_by', 'title', (@sort_by == 'title'), :onclick => 'this.form.submit();' %> <%= l(:field_title) %></label><br />
    <label><%= radio_button_tag 'sort_by', 'author', (@sort_by == 'author'), :onclick => 'this.form.submit();' %> <%= l(:field_author) %></label>
    <% end %>
<% end %>

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