<div class="contextual">
<% if User.current.allowed_to?(:manage_issue_relations, @project) %>
  <%= toggle_link l(:button_add), 'new-relation-form', {:focus => 'relation_issue_to_id'} %>
<% end %>
</div>

<p><strong><%=l(:label_related_issues)%></strong></p>

<% if @relations.present? %>
<form>
<table class="list issues">
<% @relations.each do |relation| %>
<tr class="issue hascontextmenu">
<td class="checkbox"><%= check_box_tag("ids[]", relation.other_issue(@issue).id, false, :id => nil) %></td>
<td class="subject"><%= l(relation.label_for(@issue)) %> <%= "(#{l('datetime.distance_in_words.x_days', :count => relation.delay)})" if relation.delay && relation.delay != 0 %>
    <%= h(relation.other_issue(@issue).project) + ' - ' if Setting.cross_project_issue_relations? %>
    <%= link_to_issue(relation.other_issue(@issue), :truncate => 60) %>
</td>
<td class="status"><%= relation.other_issue(@issue).status.name %></td>
<td class="start_date"><%= format_date(relation.other_issue(@issue).start_date) %></td>
<td class="due_date"><%= format_date(relation.other_issue(@issue).due_date) %></td>
<td class="buttons"><%= link_to_remote(image_tag('link_break.png'), { :url => {:controller => 'issue_relations', :action => 'destroy', :issue_id => @issue, :id => relation},                                              
                                                  :method => :post
                                                }, :title => l(:label_relation_delete)) if authorize_for('issue_relations', 'destroy') %></td>
</tr>
<% end %>
</table>
</form>
<% end %>

<% remote_form_for(:relation, @relation, 
                 :url => {:controller => 'issue_relations', :action => 'new', :issue_id => @issue},
                 :method => :post,
                 :complete => "Form.Element.focus('relation_issue_to_id');",
                 :html => {:id => 'new-relation-form', :style => (@relation ? '' : 'display: none;')}) do |f| %>
<%= render :partial => 'issue_relations/form', :locals => {:f => f}%>
<% end %>
