<div id="request-{{ request.id }}" class="card filterable mt-3"
  data-keywords="{{ request.common_name }}|" data-id="{{request.id}}">
  <div class="card-header">
    {% if certificate.server %}
      <i class="fa fa-server"></i>
    {% else %}
      <i class="fa fa-laptop"></i>
    {% endif %}
    {{ request.common_name }}
  </div>
  <div class="card-block">
    <p class="mb-1">
      Submitted
      <time class="timeago" datetime="{{ request.submitted }}">Request was submitted {{ request.submitted }}</time>
      from
      {% if request.hostname %}{{request.hostname}} ({{request.address}}){% else %}{{request.address}}{% endif %}
    </p>
    <div class="btn-group">
      <button type="button" class="btn btn-secondary" data-toggle="collapse" data-target="#details-{{ request.sha256sum }}"><i class="fa fa-list"></i> Details</button>
      <button type="button" class="btn btn-danger"
        data-loading-text="<i class='fa fa-circle-o-notch fa-spin'></i> Rejecting..."
        onclick="onRejectRequest(event, '{{ request.id }}', '{{ request.sha256sum }}');">
        <i class="fa fa-trash"></i> Reject</button>
      <button type="button" class="btn btn-success"
        data-loading-text="<i class='fa fa-circle-o-notch fa-spin'></i> Processing Order"
        onclick="onSignRequest(event, '{{ request.id }}', '{{ request.sha256sum }}');">
        <i class="fa fa-thumbs-up"></i> Approve</button>
      <button type="button" class="btn btn-success dropdown-toggle dropdown-toggle-split" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
        <span class="sr-only">Toggle Dropdown</span>
      </button>
      <div class="dropdown-menu">
        {% for p in authority.signature.profiles %}
          <a class="dropdown-item{% if not request.common_name.match(p.common_name) %} disabled{% endif %}"
            {% if not request.common_name.match(p.common_name) %} title="Common name doesn't match expression {{ p.common_name }}"{% endif %}
            href="#" onclick="javascript:$.ajax({url:'/api/request/id/{{request.id}}/?sha256sum={{ request.sha256sum }}&profile={{ p.key }}',type:'post'});">
            {{ p.key }}, expires in {{ p.lifetime }} days</a>
        {% endfor %}
      </div>
    </div>
    <div class="collapse" id="details-{{ request.sha256sum }}">
      <p>Use following to fetch the signing request:</p>
      <div class="bd-example">
        <pre><code class="language-sh" data-lang="sh">wget <a href="/api/request/{{ request.common_name }}/">http://{{ authority.namespace }}/api/request/{{ request.common_name }}/</a>
curl -L http://{{ authority.namespace }}/api/request/{{ request.common_name }}/ \
  | openssl req -text -noout</code></pre>
      </div>

      <div style="overflow: auto; max-width: 100%;">
        <table class="table" id="signed_certificates">
          <tbody>
            <tr><th>Common name</th><td>{{ request.common_name }}</td></tr>
            <tr><th>Submitted</th><td>{{ request.submitted | datetime }}
            {% if request.address %}from {{ request.address }}
            {% if request.hostname %} ({{ request.hostname }}){% endif %}{% endif %}</td></tr>
            <tr><th>MD5</th><td>{{ request.md5sum }}</td></tr>
            <tr><th>SHA1</th><td>{{ request.sha1sum }}</td></tr>
            <tr><th>SHA256</th><td>{{ request.sha256sum }}</td></tr>
          </tbody>
        </table>
      </div>

    </div>
  </div>
</div>
