## -*- coding: utf-8 -*-

<%def name="pullrequest_overview(pullrequests)">

%if not len(pullrequests):
    <div class="text-muted">${_('No entries')}</div>
    <% return %>
%endif

<div>
  <table class="table">
    <thead>
      <tr>
        <th>${_('Vote')}</th>
        <th>${_('Title')}</th>
        <th>${_('Owner')}</th>
        <th>${_('Age')}</th>
        <th>${_('From')}</th>
        <th>${_('To')}</th>
        <th>${_('Delete')}</th>
      </tr>
    </thead>
% for pr in pullrequests:
    <tr class="${'pr-closed' if pr.is_closed() else ''}">
      <td>
        <% status = pr.user_review_status(request.authuser.user_id) %>
        %if status:
          <i class="icon-circle changeset-status-${status}" title="${_('You voted: %s') % h.changeset_status_lbl(status)}"></i>
        %else:
          <i class="icon-circle changeset-status-not_reviewed" title="${_('You didn\'t vote')}"></i>
        %endif
      </td>
      <td>
        <a href="${pr.url()}">
        ${h.urlify_text(pr.title or _("(no title)"), pr.org_repo.repo_name, pr.url())}
        %if pr.is_closed():
          <span class="pr-closed-tag">${_('Closed')}</span>
        %endif
        </a>
      </td>
      <td>
        ${pr.owner.full_name_and_username}
      </td>
      <td>
        <span data-toggle="tooltip" title="${h.fmt_date(pr.created_on)}">
          ${h.age(pr.created_on)}
        </span>
      </td>
      <td>
        <% org_ref_name=pr.org_ref.rsplit(':', 2)[-2] %>
        <a href="${h.url('summary_home', repo_name=pr.org_repo.repo_name, anchor=org_ref_name)}">
          ${pr.org_repo.repo_name}#${org_ref_name}
        </a>
      </td>
      <td>
        <% other_ref_name=pr.other_ref.rsplit(':', 2)[-2] %>
        <a href="${h.url('summary_home', repo_name=pr.other_repo.repo_name, anchor=other_ref_name)}">
          ${pr.other_repo.repo_name}#${other_ref_name}
        </a>
      </td>
      <td>
        %if pr.owner_id == request.authuser.user_id:
          ${h.form(url('pullrequest_delete', repo_name=pr.other_repo.repo_name, pull_request_id=pr.pull_request_id))}
          <button type="submit" class="btn btn-link btn-xs"
                  id="remove_${pr.pull_request_id}"
                  name="remove_${pr.pull_request_id}"
                  title="${_('Delete Pull Request')}"
                  onclick="return confirm('${_('Confirm to delete this pull request')}')
                      && ((${len(pr.comments)} == 0) ||
                          confirm('${_('Confirm again to delete this pull request with %s comments') % len(pr.comments)}'))
                      ">
            <i class="icon-trashcan"></i>
          </button>
          ${h.end_form()}
        %endif
      </td>
    </tr>
% endfor
  </table>
</div>

%if hasattr(pullrequests, 'pager'):
    ${pullrequests.pager()}
%endif

</%def>
