%h3
  = "Merge Request ##{@merge_request.id}:"
  &nbsp;
  %span.pretty_label.branch= @merge_request.source_branch
  &rarr;
  %span.pretty_label.branch= @merge_request.target_branch

  %span.right
    - if can?(current_user, :modify_merge_request, @merge_request)
      - if @merge_request.open?
        = link_to 'Close', project_merge_request_path(@project, @merge_request, :merge_request => {:closed => true }, :status_only => true), :method => :put, :class => "btn small padded", :title => "Close merge request"
        = link_to edit_project_merge_request_path(@project, @merge_request), :class => "btn small padded" do 
          Edit

    %br
    - if @merge_request.upvotes > 0
      .upvotes#upvotes= "+#{pluralize @merge_request.upvotes, 'upvote'}"

= render "merge_requests/how_to_merge"
.back_link
  = link_to project_merge_requests_path(@project) do 
    &larr; To merge requests

.main_box
  .top_box_content
    %h4
      - if @merge_request.closed
        .alert-message.error.status_info Closed
      - else 
        .alert-message.success.status_info Open
      = @merge_request.title

  .middle_box_content
    %div
      %cite.cgray Created at #{@merge_request.created_at.stamp("Aug 21, 2011")} by 
      = image_tag gravatar_icon(@merge_request.author_email), :width => 16, :class => "lil_av"
      %strong.author= link_to_merge_request_author(@merge_request)

      %cite.cgray and currently assigned to 
      = image_tag gravatar_icon(@merge_request.assignee_email), :width => 16, :class => "lil_av"
      %strong.author= link_to_merge_request_assignee(@merge_request)


  - if @merge_request.closed
    .bottom_box_content
      - if @merge_request.merged?
        %span
          Merged by #{@merge_request.merge_event.author_name} 
          %small #{time_ago_in_words(@merge_request.merge_event.created_at)} ago.
      - elsif @merge_request.closed_event
        %span
          Closed by #{@merge_request.closed_event.author_name} 
          %small #{time_ago_in_words(@merge_request.closed_event.created_at)} ago.


- if @merge_request.open? && @commits.any? && can?(current_user, :accept_mr, @project)
  .automerge_widget.can_be_merged{:style => "display:none"}
    .ui-box.padded
      %p 
        You can accept this request automatically. If you still want to do it manually - #{link_to "click here", "#", :class => "how_to_merge_link vlink", :title => "How To Merge"} for instructions
      = link_to "Accept Merge Request", automerge_project_merge_request_path(@project, @merge_request), :class => "btn small info accept_merge_request", :remote => true
      &nbsp;
      
  .automerge_widget.cannot_be_merged{:style => "display:none"}
    .alert-message
      %p
        %strong This request cant be merged with GitLab. You should do it manually &nbsp;
        = link_to "Show how to merge", "#", :class => "how_to_merge_link btn small padded", :title => "How To Merge"
  
  .automerge_widget.unchecked
    .alert-message
      %p
        %strong Checking for ability to automatically merge… 
  
  .automerge_widget.already_cannot_be_merged{:style => "display:none"}
    .alert-message
      %p
        %strong This merge request already can not be merged




= render "merge_requests/commits"

- unless @commits.empty?
  .nav.nav-tabs
    %li.active
      = link_to "#notes", :class => "merge-notes-tab tab" do 
        Notes
    %li
      = link_to "#diffs", "data-url" => diffs_project_merge_request_path(@project, @merge_request), :class => "merge-diffs-tab tab" do
        Diff


.merge_request_notes#notes= render "notes/notes", :tid => @merge_request.id, :tt => "merge_request"

.merge-request-diffs
.status

:javascript
  $(function(){
    MergeRequest.init({
      url_to_automerge_check: "#{automerge_check_project_merge_request_path(@project, @merge_request)}",
      check_enable: #{@merge_request.state == MergeRequest::UNCHECKED ? "true" : "false"},
      current_state: "#{@merge_request.human_state}"
    });

    $(".accept_merge_request").live("ajax:beforeSend", function() {
      $(this).replaceWith('#{image_tag "ajax_loader.gif"}');
    })
  })

= render "notes/per_line_form"

:javascript
  $(document).ready(function(){
    $(".line_note_link, .line_note_reply_link").live("click", function(e) { 
      var form = $(".per_line_form");
      $(this).parent().parent().after(form);
      form.find("#note_line_code").val($(this).attr("line_code"));
      form.show();  
      return false;
    });
  });
