<%
  doc_manage_perm = !document.active_record_restricted?(User.current, :manage)
  modul_uniq_id ||= [controller_name, action_name, dom_id(document)].join('_')
  h3_heading = @easy_page_modules_data.nil? || controller_name == 'projects' ? document.title : (document.project.to_s + ' &#187; ' + document.title).html_safe

  box_options = {
      icon: 'icon-file',
      heading_tag: 'h5',
      class: {heading: 'doc-subgroup-heading'}
  }
%>

<%= render_module_easy_box(modul_uniq_id, h3_heading, box_options) do |m| %>
  <% m.heading_links do %>
    <%= link_to(new_attachment_for_entity_path(entity_type: document.class.name, entity_id: document.id), class: 'icon icon-add', remote: true) do %>
      <span class="tooltip"><%= l(:label_attachment_new) %></span>
    <% end if authorize_for('documents', 'add_attachment', document.project) -%>
    <%= link_to(edit_document_path(document), {class: 'icon icon-edit', esskey: accesskey(:edit)}) do %>
      <span class="tooltip"><%= l(:button_edit) %></span>
    <% end if authorize_for('documents', 'edit', document.project) -%>
    <%= link_to(document, data: {confirm: l(:text_are_you_sure)}, method: :delete, class: 'icon icon-del') do %>
      <span class="tooltip"><%= l(:button_delete) %></span>
    <% end if authorize_for('documents', 'destroy', document.project) -%>
  <% end if @easy_page_modules_data.nil? && doc_manage_perm %>

  <div class="doc-detail" id="<%= dom_id(document) -%>">
    <% if document.custom_values.any? %>
      <div class="document-custom-values-container">
        <%= render :partial => 'documents/custom_field_values', :locals => {:custom_field_values => document.visible_custom_field_values} %>
      </div>
    <% end -%>
    <% unless document.description.blank? %>
      <div class="doc-description wiki">
        <%= content_tag :div, truncate_html(textilizable(document.description, {:headings => false}), 400, link_to_function(l(:label_more), "EASY.utils.switchElements($(this).parents('.truncated-text'),$('#document_#{document.id}').find('.original-text'))")).html_safe, :class => 'truncated-text' -%>
        <%= content_tag :div, textilizable(document.description || '') + link_to_function(l(:label_less), "EASY.utils.switchElements($(this).parents('.original-text'),$('#document_#{document.id}').find('.truncated-text'))").html_safe, :class => 'original-text', :style => 'display:none' -%>
      </div>
    <% end %>
    <div class="doc-index-attachments">
      <%= link_to_attachments document, {:author => true, :enable_toggling => false, :do_not_show_header => true, :default_button_state => !@project.nil?} %>
    </div>
  </div>

<% end %>
