Blob Blame Raw
{% extends "repo_master.html" %}
{% from "_formhelper.html" import render_field_in_row, show_comment, render_bootstrap_field %}

{% block title %}
  {%- if pull_request -%}
    PR#{{ requestid }}: {{ pull_request.title }} - {{ repo.name }}
  {% elif form and (repo_admin or remote_git) %}
    Create new Pull Request for {{ branch_to }} - {{ repo.name }}
  {%- else -%}
    Diff from {{ branch_from }} to {{ branch_to }} - {{ repo.name }}
  {%- endif -%}
{% endblock %}

{% set tag = "home" %}

{% block header %}
<link href="{{ url_for('static', filename='fontawesome/font-awesome.min.css') }}"
  rel="stylesheet" />
<link href="{{ url_for('static', filename='emoji/emojione.sprites.css') }}"
  rel="stylesheet" />
  <link href="{{ url_for('static', filename='selectize.bootstrap3.css') }}"
  rel="stylesheet" />
{% endblock %}

{% block repo %}
<div class="row">
  <div class="{% if pull_request %}col-md-8{% elif form and (repo_admin or remote_git) %}col-md-12{%endif%}">
{% if pull_request %}
<h2><span class="label label-default">PR#{{requestid}}</span> {{ pull_request.title | noJS(ignore="img") | safe
  }}{% if authenticated and (g.fas_user.username == pull_request.user.username
    or repo_admin) and pull_request.status == 'Open'
  %}
     <span class="pull-xs-right">
    <a class="btn btn-sm btn-primary"
       href="{{ url_for('request_pull_edit', username=username,
            repo=repo.name, requestid=requestid) }}"
      title="Update title">edit</a>

    {% if pull_request.status == 'Open' and authenticated and
        (repo_admin or g.fas_user.username == pull_request.user.username) %}
      <span><form style="display:inline;" action="{{ url_for('cancel_request_pull', username=username,
          repo=repo.name, requestid=requestid) }}" method="POST">
        {{ mergeform.csrf_token }}
        <button type="submit" value="Close" id="cancel_pr" class="btn btn-danger btn-sm">close</button>
      </form></span>
    {% endif %}
      </span>
      {% endif %}
</h2>

  <h5 class="text-muted">
    Proposed <a href="#" data-toggle="tooltip" title="{{ pull_request.date_created.strftime('%b %d %Y %H:%M:%S') }}">{{ pull_request.date_created |humanize }}</a>
    by {{ pull_request.user.user | avatar(16) | safe }} {{ pull_request.user.user }}
  </h5>

  From
    <span class="pr-toplabel">{{ pull_request.project_from.fullname or pull_request.remote_git}}</span> <span class="pr-toplabel">
    <span class="oi" data-glyph="random"> </span>{{ pull_request.branch_from }}</span>
  into
    <span class="pr-toplabel">{{ pull_request.project.fullname }}</span>
    <span class="pr-toplabel"><span class="oi" data-glyph="random"></span> {{ pull_request.branch }}</span>

<div class="header">
  <div class="btn-group" role="group" >
    {% if pull_request.status != 'Open' %}
     <span class="btn btn-default">{{ pull_request.status }} by
        <a href="{{ url_for('view_user', username=pull_request.closed_by.user)}} ">
          {{ pull_request.closed_by.user if pull_request.closed_by else ''}}
        </a>
     </span>
    {% endif %}
     {#<span class="btn btn-default">
      <a class="button patch" href="{{ url_for('request_pull_patch', username=username,
            repo=repo.name, requestid=requestid) }}">
        <button type="submit" class="btn btn-info">Patch View</button>
      </a>
     </span>#}
  </div>
</div>
{% elif form and (repo_admin or remote_git) %}
<h2>Create pull request</h2>
{% else %}
<h2>Diff
      (<a href="{{ url_for('view_tree', username=username,
               repo=repo.name, identifier=commitid) }}"
      >tree</a>)</h2>
{% endif %}

{% if form and (repo_admin or remote_git) %}
<section class="new_project">
  {% if remote_git %}
  <form action="{{ url_for('.new_remote_request_pull', username=username,
    repo=repo.name, confirm=True) }}" method="post">
    <input type="hidden" value="{{ branch_from }}" name="branch_from" />
    <input type="hidden" value="{{ remote_git }}" name="git_repo" />
  {% else %}
  <form action="{{ url_for('.new_request_pull', username=username,
    repo=repo.name, commitid=commitid, branch_from=branch_from,
    branch_to=branch_to) }}" method="post">
  {% endif %}
  <div class="p-b-1">
  Pull from
    <span class="pr-toplabel">{%
      if remote_git -%}{{ remote_git }}{%-
      else -%}
        <span class="oi" data-glyph="fork"></span> {{ repo.fullname }} {%-
      endif -%}
    </span>
    <span class="pr-toplabel">
      <span class="oi" data-glyph="random">
    </span> {{ branch_from }} </span>
  into
<span class="pr-toplabel">{% if repo.is_fork -%}{{ repo.parent.fullname }}{% else %}{{ repo.fullname }}{% endif %}</span>
          <select class="pr-toplabel-select" id="branch_select" name="branch_to">
              <option value="{{ branch_to }}">{{ branch_to }}</option>
            {% for branch in branches |reverse %}
              {% if branch != branch_to %}
              <option value="{{ branch }}">{{ branch }}</option>
              {% endif %}
            {% endfor %}
          </select>
    </div>
      {{ render_bootstrap_field(form.title) }}
    <p class="buttons indent">
      <input type="submit" class="btn btn-primary" value="Create">
      {{ form.csrf_token }}
      <a class="btn btn-secondary" href="{{ url_for('view_repo', username=username, repo=repo.name)}}">
        Cancel
      </a>
    </p>
  </form>
</section>
{% endif %}

<ul class="nav nav-tabs nav-small" role="tablist" id="pr-tabs">
  {% if pull_request %}
    <li class="nav-item"><a class="nav-link active" data-toggle="tab" role="tab" href="#comments">Comments</a></li>
  {%endif%}
  <li class="nav-item">
    <a class="nav-link {% if not pull_request %}active{% endif %}" data-toggle="tab" role="tab" href="#request_diff">
      <span class="hidden-sm-down">Files Changed&nbsp;</span>
      <span class="label label-default label-pill hidden-sm-down">
        {{ diff|length if diff else 0}}
      </span>
    </a>
  </li>
  <li class="nav-item">
    <a class="nav-link" data-toggle="tab" role="tab" href="#commit_list">
      <span class="hidden-sm-down">Commits&nbsp;</span>
      <span class="label label-default label-pill hidden-sm-down">
        {{ diff_commits|length }}
      </span>
    </a>
  </li>
</ul>

<div class="tab-content">

  <div class="tab-pane" role="tabpanel" id="commit_list">
    <div class="list-group">
          {% for commit in diff_commits %}

              {% if pull_request and pull_request.status and pull_request.project_from.is_fork %}
              <a class="list-group-item" href="{{ url_for('view_commit', username=pull_request.project_from.user.user,
                        repo=pull_request.project_from.name, commitid=commit.oid.hex)}}">
              {% elif pull_request and pull_request.remote %}
              <a>
              {% else %}
              <a class="list-group-item" href="{{ url_for('view_commit', username=username,
                            repo=repo.name, commitid=commit.oid.hex)}}">
              {% endif %}

              <h5>
                <strong>{{ commit.message.strip().split('\n')[0] }}</strong>
                <div class="pull-xs-right">
                  <span class="commitdate" title="{{ commit.commit_time|format_ts }}">
                    {{ commit.commit_time|humanize }}
                  </span>
                </div>
              </h5>
              {{ commit.author | author2avatar(20) | safe }} {{ commit.author.name }}
              <div class="pull-xs-right">
                <span class="label label-default">{{ commit.hex|short }}</span>
              </div>
            </a>
          {% else %}
          <p class="error"> No commits found </p>
          {% endfor %}
      </div>
  </div>

  <div class="tab-pane {% if not pull_request %}active{% endif %}" role="tabpanel" id="request_diff">
    {% if authenticated and pull_request %}
    <form action="{{ url_for('.pull_request_drop_comment', username=username,
        repo=repo.name, requestid=requestid) }}" method="post" class="icon"
        onsubmit="return try_async_comment(this, null)" >
    {% endif %}

    {% if diff %}
      {% for patch in diff %}
        {% if patch |hasattr('new_id') %}
          {% set patch_new_id = patch.new_id %}
        {% elif patch |hasattr('delta') %}
          {% set patch_new_id = patch.delta.new_file.id %}
        {% else %}
          {% set patch_new_id = patch.new_oid %}
        {% endif %}

        {% if patch | hasattr('new_file_path') %}
          {% set patch_new_file_path = patch.new_file_path -%}
          {% if patch.new_file_path != patch.old_file_path %}
            {% set patch_old_file_path = patch.old_file_path %}
          {%- endif -%}
        {%- elif patch | hasattr('delta') -%}
          {% set patch_new_file_path = patch.delta.new_file.path -%}
          {%- if patch.delta.new_file.path != patch.delta.old_file.path -%}
            {% set patch_old_file_path = patch.delta.old_file.path %}
          {%- endif -%}
        {%- endif -%}

      <section class="commit_diff">
      <div class="card clearfix">
        <div class="card-header">
            <h5>
              {%- if patch_new_file_path == patch_old_file_path -%}
                {{ patch_new_file_path }} (Renamed from "{{ patch_old_file_path }}")
              {%- else -%}
                {{ patch_new_file_path }}
              {%- endif -%}

              {% if pull_request %}
              <a class="button small view headerlink pull-xs-right" href="{{
                  url_for(
                      'view_file',
                      username=pull_request.project_from.user.username
                          if pull_request.project_from.is_fork else None,
                      repo=pull_request.project_from.name,
                      identifier=pull_request.branch_from,
                      filename=patch_new_file_path) }}"
              {% else %}
              <a class="button small view headerlink pull-xs-right" href="{{
                  url_for(
                      'view_file',
                      username=username,
                      repo=repo.name,
                      identifier=branch_from,
                      filename=patch_new_file_path) }}"
              {% endif %}
              title="View file as of {{ patch_new_id|short }}">View</a>
            </h5>
        </div>

      {% autoescape false %}
          {{ patch | patch_to_diff | html_diff | format_loc(
                  filename=patch_new_file_path,
                  commit=patch_new_id,
                  prequest=pull_request,
                  index=loop.index)}}
      {% endautoescape %}

      </div>
      </section>
      {% endfor %}
      {% endif %}

    {% if authenticated and pull_request %}
    {{ mergeform.csrf_token }}
    </form>
    {% endif %}
  </div>
  {% if pull_request %}
  <div class="tab-pane active" role="tabpanel" id="comments">
    <section class="request_comment" id="request_comment">
    {% if pull_request.comments %}
      <form action="{{ url_for('.pull_request_drop_comment', username=username,
          repo=repo.name, requestid=requestid) }}" method="post"
          onsubmit="return try_async_comment(this, null)">

      {% for comment in pull_request.comments %}
        {% if not comment.commit_id %}
          {{ show_comment(comment, comment.id, repo, username,
                          requestid, form, repo_admin) }}
        {% else %}
          <div class="card">
            <div class="card-header">
              <div>
                {{comment.user.user}} commented on line <a href="#c-{{comment.commit_id}}-{{comment.line}}" onclick="showTab()">{{comment.line}} of {{comment.filename}}</a>
                <div class="pull-xs-right text-muted"><span title="{{comment.date_created.strftime('%Y-%m-%d %H:%M:%S')}}">{{ comment.date_created | humanize}}</span></div>
              </div>
            </div>
          </div>
        {% endif %}
      {% endfor %}
      {{ mergeform.csrf_token }}
      </form>
    {% endif %}
    </section>

    {% if authenticated and mergeform and pull_request %}
    <div class="card">
      <div class="card-header">

        <section class="request_comment add_comment">

          {% if authenticated %}
            <form action="{{ url_for(
                'pull_request_add_comment', username=username, repo=repo.name,
                requestid=requestid) }}"
                method="post" onsubmit="return try_async_comment(this, false)">
              {{ mergeform.csrf_token }}

              <fieldset class="form-group">
                <label for="comment"><strong>Add new comment</strong></label>
                <small class="text-muted pull-xs-right">
                  <span class="btn btn-sm btn-secondary inactive"
                    aria-pressed="false" id="previewinmarkdown">Preview
                  </span>
                </small>
                <textarea class="form-control" rows=8 id="comment" name="comment"
                placeholder="Enter your comment here"></textarea>
                <div id="preview">
                </div>
              </fieldset>

              <div>
                <input type="submit" class="btn btn-primary" value="Update Issue">
                <input type="button" class="btn btn-secondary" value="Clear" id="clear_comment" />
              </div>
            </form>
          {% else %}
            <p><a href="{{ url_for('auth_login', next=request.url) }}">Login</a> to comment on this ticket.</p>
          {% endif %}
        </section>
      </div>
    </div>
    {% endif %}
  </div>
  {% endif %}
</div> <!-- tab content-->

</div>


  <div class="col-md-4">
  {% if pull_request %}
    <section class="pr_info">
      <div id="merge-alert" class="alert text-xs-center" style="display:none;" role="alert">
      {% if pull_request.status == 'Open' and repo_admin %}
       <div>
        <form action="{{ url_for('merge_request_pull', username=username,
            repo=repo.name, requestid=requestid) }}" method="POST">
          {{ mergeform.csrf_token }}
          <button id="merge_btn" type="submit" class="btn btn-block">Merge</button>
        </form>
       </div>
      {% endif %}
        <small id="merge-alert-message"></small>
      </div>

    {% if pull_request.flags %}
    <div class="card" id="pr_flags">
      <ul class="list-group list-group-flush">
            {% for flag in pull_request.flags %}
              <li class="list-group-item">
                <div>
                  <span><a href="{{ flag.url }}">{{ flag.username }}</a></span>
                  <div class="pull-xs-right"><span class="label {%if flag.percent <= 10%}label-danger{%elif flag.percent <= 90%}label-warning{%else%}label-success{%endif%}">{{ flag.percent }}%</label></div>
                </div>
                <small><div class="clearfix">
                    <span>{{ flag.comment }}</span>
                    <div title="{{ flag.date_created }}" class="pull-xs-right">
                    {{ flag.date_created | humanize }}</div>
                </div>
                </small>
              </li>
            {% endfor %}
      </ul>
    </div>
    {% endif %}

    {#
    <div class="card">
      <div class="card-block">
        <table class="table table-hover table-striped m-b-0">
          <thead></thead>
          <tfoot></tfoot>
          <tbody>
          <tr>
            <th>Assignee</th>
            <td>
              {% if authenticated and mergeform and pull_request.status == True %}
              <form method="POST" action="{{ url_for('.set_assignee_requests',
                  username=username, repo=repo.name, requestid=requestid) }}">
                <input value="{{ pull_request.assignee.username or '' }}"
                  name="user" id="assignee" placeholder="username" >
                {{ mergeform.csrf_token }}
                <input type="submit" class="submit positive button" value="Update">
              </form>
              {% else %}
              {{ pull_request.assignee.username or '' }}
              {% endif %}
            </td>
          </tr>
        </table>
      </div>
    </div>
    #}
    </section>
  {% endif %}
  {% if diff and pull_request%}
    <div class="card clearfix">
      <div class="card-header">
        <h5><strong>Changes summary</strong></h5>
      </div>
    <div class="list-group list-group-flush">
    {% for patch in diff %}
        <div class="list-group-item">
          <span>
            {%- if patch | hasattr('new_file_path') -%}
              {%- if patch.new_file_path == patch.old_file_path -%}
              {{ patch.new_file_path }}
              {%- else -%}
              {{ patch.new_file_path }} (Renamed from "{{ patch.old_file_path }}")
              {%- endif -%}
            {%- elif patch | hasattr('delta') -%}
              {%- if patch.delta.new_file.path == patch.delta.old_file.path -%}
              {{ patch.delta.new_file.path }}
              {%- else -%}
              {{ patch.delta.new_file.path }} (Renamed from "{{ patch.delta.old_file.path }}")
              {%- endif -%}
            {%- endif -%}
          </span>
          <div class="pull-right">
            {% if patch | hasattr('additions') %}
            {# Version of pygit2 -0.21.4 -- F21/EL7 #}
            {% if (patch.additions + patch.deletions) %}
              <span style="width: {{ (100.0 * patch.additions / (patch.additions + patch.deletions))|round|int }}%">
                {% if patch.additions > 0 %}+{{ patch.additions }}{% endif %}
                {% if patch.deletions > 0 %}-{{ patch.deletions }}{% endif %}
              </span>
            {% endif %}
            {% else %}
            {# Version of pygit2 -0.23.0 -- F23 #}
            {% if (patch.line_stats[1] + patch.line_stats[2]) %}
              <span style="width: {{ (100.0 * patch.line_stats[1] / (patch.line_stats[1] + patch.line_stats[2]))|round|int }}%">
                {% if patch.line_stats[1] > 0 %}+{{ patch.line_stats[1] }}{% endif %}
                {% if patch.line_stats[2] > 0 %}-{{ patch.line_stats[2] }}{% endif %}
              </span>
            {% endif %}
            {% endif %}
          </div>
        </div>
    {% endfor %}
      </div>
    </div>
  {% endif %}
  </div>

</div>
{% endblock %}

{% block jscripts %}
{{ super() }}
<script type="text/javascript"
    src="{{ url_for('static', filename='emoji/jquery.textcomplete.min.js') }}">
</script>
<script type="text/javascript"
    src="{{ url_for('static', filename='emoji/emojione.min.js') }}">
</script>
<script src="{{ url_for('static', filename='selectize.min.js') }}" type="text/javascript"> </script>

<script type="text/javascript">
function cancel_edit_btn() {
  $(".cancel").unbind();
  $( ".cancel" ).click(
    function() {
      item = $(this).closest('section');
      $(item.parent().find('.issue_comment')).show();
      $(item.parent().find('.issue_actions')).show();
      $(item.parent().closest('.pr_comment_form')).remove();
      return false;
    }
  );
};

function setup_edit_btns() {
  $(".edit_btn").unbind();
  $(".edit_btn").click(function() {
    var commentid = $( this ).attr('data-comment');
    var _url = '{{ request.base_url }}' + '/comment/' + commentid + '/edit';
    $.ajax({
        url: _url + '?js=1',
        type: 'GET',
        dataType: 'html',
        success: function(res) {
          var el = $('#comment-' + commentid);
          var sec = el.parent().find('.issue_comment');
          $(sec).hide();
          el.parent().find('.issue_actions').hide();
          $(sec).after(res);
          cancel_edit_btn();
        },
        error: function() {
          alert('Could not make edit work');
        }
    });
    return false;
  });
};

function setup_reply_btns() {
  $(".reply").unbind();
  $( ".reply" ).click(
    function() {
      var _section = $(this).closest('.card-block');
      var _comment = _section.find('.comment_body');
      var _text = _comment.text().split("\n");
      var _output = new Array();
      for (var cnt=0; cnt < _text.length; cnt++) {
          _output[cnt] = '> ' + _text[cnt];
      }
      $( "#comment" ).val(_output.join("\n"));
    }
  );
};


  function showTab(){
   $('#pr-tabs a[href="#request_diff"]').tab('show')
  }


 $(document).ready(function() {

  $( ".commit_msg_txt" ).hide();
  $( ".commit_msg_btn" ).click(function() {
    var msgid = $( this ).attr('data-id');
    $( '#commit_msg_' + msgid).toggle();
  });

  var folder = '{{url_for("static", filename="emoji/png/") }}';
  var json_url = '{{ url_for("static", filename="emoji/emoji_strategy.json") }}';


  var branchselect = $('#branch_select').selectize({
    create: false,
    sortField: 'text',
    allowEmptyOption: false,
    onChange:     function(value) {
      if (value != ""){
        var sel = $('#branch_select');
        var final_url = "{{ url_for('.new_request_pull', username=username,
          repo=repo.name, branch_from=branch_from,
          branch_to='--') }}";
        final_url = final_url.replace('--', sel.val());
        window.location.href = final_url;
      }
    }
  });

{% if pull_request %}
{# These lines are only for existing pull-requests, not new ones #}

  emoji_complete(json_url, folder);

  $('#cancel_pr').click(function(){
    return window.confirm("Are you sure you want to close this requested pull?");
  });

  $( ".code_table tr" ).hover(
    function() {
      $( this ).find( ".prc_img" ).show().width(13);
    }, function() {
      $( this ).find( ".prc_img" ).hide();
    }
  );

  $( ".prc" ).click(
    function() {
      var row = $( this ).attr('data-row');
      var commit = $( this ).attr('data-commit');
      var filename = $( this ).attr('data-filename');
      var url = "{{ url_for(
        'pull_request_add_comment', username=username, repo=repo.name,
        requestid=requestid, commit='', filename='', row='') }}".slice(0, -2);
      url = url + commit + '/' + filename + '/' + row;
      var rowid = $(this).prev().find('a').attr('id');
      var table = $( this ).parent().parent();
      var nextid = rowid.replace('_' + row, '_' + (Number(row) + 1));
      var next_row = table.find('#' + nextid).parent().parent();
      {# If we're at the last row, we won't be able to find the next_row
         therefore we need to add it manually #}
      if (next_row.length == 0) {
        table.find("tr:last").after(
            '<tr><td><a id="' + nextid + '"></a></td></tr>');
        next_row = table.find('#' + nextid).parent().parent();
      }
      if (next_row.prev().find('.pr_comment_form').length == 0){
        $.get( url , function( data ) {
          next_row.before(
            '<tr><td></td><td colspan="2" class="pr_comment_form"> \
            <div class="card m-x-1"><div class="card-block">'
            + data + '</div></div></td></tr>' );
          cancel_edit_btn();
          emoji_complete(json_url, folder);
        });
      } else {
        next_row.prev().find('.pr_comment_form').parent().remove();
      }
    }
  );

  $( "#clear_comment").click(
    function() {
      $( "#comment" ).val("");
    }
  );

  $( "#preview" ).hide();
  $( "#previewinmarkdown" ).click(
    function(event, ui) {
        if ($( "#previewinmarkdown" ).hasClass("inactive")){
          var _text = $( "#comment" ).val();
          var _url = "{{ url_for('markdown_preview') }}";
            $.ajax({
                url: _url ,
                type: 'POST',
                data: {
                  content: _text,
                  csrf_token: "{{ mergeform.csrf_token.current_token }}",
                },
                dataType: 'html',
                success: function(res) {
                    $( "#preview" ).html(res);
                    $( "#previewinmarkdown" ).removeClass("inactive");
                    $( "#previewinmarkdown" ).addClass("active");
                    $( "#comment" ).hide();
                    $( "#preview" ).show();
                },
                error: function() {
                    alert('Unable to generate preview!');
                }
            });
            return false;
          } else if ($( "#previewinmarkdown" ).hasClass("active")){
            $( "#previewinmarkdown" ).addClass("inactive");
            $( "#previewinmarkdown" ).removeClass("active");
            $( "#comment" ).show();
            $( "#preview" ).hide();
          }
    }
  );

  setup_edit_btns();
  setup_reply_btns();

  var cur_hash = null;

  highlight_comment = function() {
    var _hash = window.location.hash;
    console.log(_hash);
    if (_hash == '#commit_list' || _hash == '#request_diff') {
        return false;
    }
    if (_hash != cur_hash) {
      $( cur_hash ).css(
        "background", "linear-gradient(to bottom, #ededed 0%, #fff 100%)"
      );
    };
    cur_hash = _hash;
    if ( _hash ) {
      $( _hash ).css(
        "background", "linear-gradient(to bottom, #eded98 0%, #fff 100%)"
      );
    };
    return false;
  };

  $(window.onload=highlight_comment());
  $(window).on('hashchange', highlight_comment);

  $(".comment_body").each(function(ind, obj) {
    var source = $(obj).html();
    var preview = emojione.toImage(source);
    $(obj).html(preview);
  });
  $(".pr_comment").each(function(ind, obj) {
    var source = $(obj).html();
    var preview = emojione.toImage(source);
    $(obj).html(preview);
  });

  {% if pull_request.status == 'Open' %}
  $(function(){
    $.ajax({
      url: '{{ url_for("internal_ns.mergeable_request_pull") }}' ,
      type: 'POST',
      data: {
        requestid: "{{ pull_request.uid }}",
        csrf_token: "{{ mergeform.csrf_token.current_token }}",
      },
      dataType: 'json',
      success: function(res) {
        if (res.code == 'FFORWARD'){
          $('#merge_btn').addClass("btn-success");
          $('#merge-alert').addClass("alert-success");
          $('#merge-alert-message').append(res.message);
          $('#merge-alert').show();
        }
        else if (res.code == 'MERGE') {
          $('#merge_btn').addClass("btn-warning");
          $('#merge-alert').addClass("alert-warning");
          $('#merge-alert-message').append(res.message);
          $('#merge-alert').show();
        }
        else if (res.code == 'CONFLICTS') {
          $('#merge_btn').hide();
          $('#merge-alert').addClass("alert-danger");
          $('#merge-alert-message').append(res.message);
          $('#merge-alert').show();
        }
        else if (res.code == 'NO_CHANGE') {
          $('#merge_btn').hide();
          $('#merge-alert').addClass("alert-info");
          $('#merge-alert-message').append(res.message);
          $('#merge-alert').show();
        }
      },
      error: function(res) {
        var _obj = $('#pr_flags').find('tbody');
        if (res.responseJSON.message) {
          _obj.append(
            $('<tr><th>PR Status:</th><td><span class="'+ res.responseJSON.code +'" title="'
            + res.responseJSON.message +'"></span>'+ res.responseJSON.message +'</td></tr>'));
        } else {
          _obj.append(
            $('<tr><th>PR Status:</th><td><span class="'+ res.responseJSON.code +'"></span>'
              + res.responseJSON.message +'</td></tr>'));
        }
        $('#merge_btn').attr("disabled", "disabled");
      }
    });
    return false;
  });
  {% endif %}

{% endif %}

 });

{% if authenticated and pull_request %}
$('#assignee').selectize({
  valueField: 'user',
  labelField: 'user',
  searchField: 'user',
  maxItems: 1,
  create: false,
  load: function(query, callback) {
    if (!query.length) return callback();
    $.getJSON(
      "{{ url_for('api_ns.api_users') }}", {
        pattern: query.term
      },
      function( data ) {
        callback( data.users.map(function(x) { return { user: x }; }) );
      }
    );
  }
});

function try_async_comment(form, inline) {
  $(form).off('submit');
  var _data = $(form).serialize();
  var btn = $(document.activeElement);
  if (btn[0].name == 'drop_comment'){
    _data += '&drop_comment=' + btn[0].value;
    return true;
  }
  if (!sse) {
    console.log('no sse, submitting');
    form.submit();
    return false;
  }
  $.post( form.action + "?js=1", $(form).serialize() )
    .done(function(data) {
      if(data == 'ok') {
        $('#comment').val('');
        /* We have submitted the comment correctly */
        var item = $('.pr_comment_form').closest('tr');
        if (!$(item.parent().children()[1]).is(':visible')){
          $(item.parent().children()[1]).show()
        }
        item.remove();
      } else {
        // Make the browser submit the form sync
        form.submit();
      }
    })
    .fail(function() {
      // Make the browser submit the form sync
      form.submit();
    })
  $(form).on('submit');
  return false;
};
{% endif %}

</script>


{% if config['EVENTSOURCE_SOURCE'] and pull_request %}
<script type="text/javascript"
  src="{{ url_for('static', filename='request_ev.js') }}"></script>

<script type="text/javascript">
var source = null;
var sse = true;
if (!!window.EventSource) {
  source = new EventSource('{{ config["EVENTSOURCE_SOURCE"]
    + request.script_root + request.path }}');
  source.addEventListener('error', function(e) {
    sse = false;
  }, false);
}

window.onbeforeunload = function() {
    source.close()
};

source.addEventListener('message', function(e) {
  console.log(e.data);
  var data = $.parseJSON(e.data);
  process_event(data, "{{ request.uid }}");
  setup_edit_btns();
  setup_reply_btns();
  }, false);
</script>
{% endif %}

{% endblock %}