<%= render :partial => 'action_menu' %>

<h2><%= issue_heading(@issue) %></h2>

<div class="<%= @issue.css_classes %> details">
  <% if @prev_issue_id || @next_issue_id %>
    <div class="next-prev-links contextual">
      <%= link_to_if @prev_issue_id,
                     "\xc2\xab #{l(:label_previous)}",
                     (@prev_issue_id ? issue_path(@prev_issue_id) : nil),
                     :title => "##{@prev_issue_id}" %> |
      <% if @issue_position && @issue_count %>
        <span class="position"><%= l(:label_item_position, :position => @issue_position, :count => @issue_count) %></span> |
      <% end %>
      <%= link_to_if @next_issue_id,
                     "#{l(:label_next)} \xc2\xbb",
                     (@next_issue_id ? issue_path(@next_issue_id) : nil),
                     :title => "##{@next_issue_id}" %>
    </div>
  <% end %>

  <%= avatar(@issue.author, :size => "50") %>

<div class="subject">
<%= render_issue_subject_with_tree(@issue) %>
</div>
        <p class="author">
        <%= authoring @issue.created_on, @issue.author %>.
        <% if @issue.created_on != @issue.updated_on %>
        <%= l(:label_updated_time, time_tag(@issue.updated_on)).html_safe %>.
        <% end %>
        </p>

<table class="attributes">
<%= issue_fields_rows do |rows|
  rows.left l(:field_status), h(@issue.status.name), :class => 'status'
  rows.left l(:field_priority), h(@issue.priority.name), :class => 'priority'

  unless @issue.disabled_core_fields.include?('assigned_to_id')
    rows.left l(:field_assigned_to), avatar(@issue.assigned_to, :size => "14").to_s.html_safe + (@issue.assigned_to ? link_to_user(@issue.assigned_to) : "-"), :class => 'assigned-to'
  end
  unless @issue.disabled_core_fields.include?('category_id')
    rows.left l(:field_category), h(@issue.category ? @issue.category.name : "-"), :class => 'category'
  end
  unless @issue.disabled_core_fields.include?('fixed_version_id')
    rows.left l(:field_fixed_version), (@issue.fixed_version ? link_to_version(@issue.fixed_version) : "-"), :class => 'fixed-version'
  end

  unless @issue.disabled_core_fields.include?('start_date')
    rows.right l(:field_start_date), format_date(@issue.start_date), :class => 'start-date'
  end
  unless @issue.disabled_core_fields.include?('due_date')
    rows.right l(:field_due_date), format_date(@issue.due_date), :class => 'due-date'
  end
  unless @issue.disabled_core_fields.include?('done_ratio')
    rows.right l(:field_done_ratio), progress_bar(@issue.done_ratio, :width => '80px', :legend => "#{@issue.done_ratio}%"), :class => 'progress'
  end
  unless @issue.disabled_core_fields.include?('estimated_hours')
    unless @issue.estimated_hours.nil?
      rows.right l(:field_estimated_hours), l_hours(@issue.estimated_hours), :class => 'estimated-hours'
    end
  end
  if User.current.allowed_to?(:view_time_entries, @project)
    rows.right l(:label_spent_time), (@issue.total_spent_hours > 0 ? link_to(l_hours(@issue.total_spent_hours), project_issue_time_entries_path(@project, @issue)) : "-"), :class => 'spent-time'
  end
end %>
<%= render_custom_fields_rows(@issue) %>
<%= call_hook(:view_issues_show_details_bottom, :issue => @issue) %>
</table>

<% if @issue.description? || @issue.attachments.any? -%>
<hr />
<% if @issue.description? %>
<div class="description">
  <div class="contextual">
  <%= link_to l(:button_quote), quoted_issue_path(@issue), :remote => true, :method => 'post', :class => 'icon icon-comment' if authorize_for('issues', 'edit') %>
  </div>

  <p><strong><%=l(:field_description)%></strong></p>
  <div class="wiki">
  <%= textilizable @issue, :description, :attachments => @issue.attachments %>
  </div>
</div>
<% end %>
<%= link_to_attachments @issue, :thumbnails => true %>
<% end -%>

<%= call_hook(:view_issues_show_description_bottom, :issue => @issue) %>

<% if !@issue.leaf? || User.current.allowed_to?(:manage_subtasks, @project) %>
<hr />
<div id="issue_tree">
<div class="contextual">
  <%= link_to_new_subtask(@issue) if User.current.allowed_to?(:manage_subtasks, @project) %>
</div>
<p><strong><%=l(:label_subtask_plural)%></strong></p>
<%= render_descendants_tree(@issue) unless @issue.leaf? %>
</div>
<% end %>

<% if @relations.present? || User.current.allowed_to?(:manage_issue_relations, @project) %>
<hr />
<div id="relations">
<%= render :partial => 'relations' %>
</div>
<% end %>

</div>

<% if @changesets.present? %>
<div id="issue-changesets">
<h3><%=l(:label_associated_revisions)%></h3>
<%= render :partial => 'changesets', :locals => { :changesets => @changesets} %>
</div>
<% end %>

<% if @journals.present? %>
<div id="history">
<h3><%=l(:label_history)%></h3>
<%= render :partial => 'history', :locals => { :issue => @issue, :journals => @journals } %>
</div>
<% end %>


<div style="clear: both;"></div>
<%= render :partial => 'action_menu' %>

<div style="clear: both;"></div>
<% if @issue.editable? %>
  <div id="update" style="display:none;">
  <h3><%= l(:button_update) %></h3>
  <%= render :partial => 'edit' %>
  </div>
<% end %>

<% other_formats_links do |f| %>
  <%= f.link_to 'Atom', :url => {:key => User.current.rss_key} %>
  <%= f.link_to 'PDF' %>
<% end %>

<% html_title "#{@issue.tracker.name} ##{@issue.id}: #{@issue.subject}" %>

<% content_for :sidebar do %>
  <%= render :partial => 'issues/sidebar' %>

  <% if User.current.allowed_to?(:add_issue_watchers, @project) ||
    (@issue.watchers.present? && User.current.allowed_to?(:view_issue_watchers, @project)) %>
    <div id="watchers">
      <%= render :partial => 'watchers/watchers', :locals => {:watched => @issue} %>
    </div>
  <% end %>
<% end %>

<% content_for :header_tags do %>
    <%= auto_discovery_link_tag(:atom, {:format => 'atom', :key => User.current.rss_key}, :title => "#{@issue.project} - #{@issue.tracker} ##{@issue.id}: #{@issue.subject}") %>
<% end %>

<%= context_menu issues_context_menu_path %>
