{% load bob %}
{% load i18n %}

{% if attachment_parent %}
  <h5>{% trans "Attachments:" %}

  {% if attachment_parent.attachments.all|length > 5 %}
  <div class='pull-right btn btn-info toggle-child-display'
    data-alt-msg='{% trans "Show last 5" %}'
    data-trgt='attachments-rows'
  >
    {% trans "Show all" %}
  </div>
  {% endif %}
  </h5>

  <table class="table table-striped table-bordered details-history">
      <thead><tr>
        <td style='text-align:center' colspan='4'>
          <a class='btn'
            href="{% url add_attachment parent=parent_name %}?select={{attachment_parent.id}}">
            {% trans "Add attachment" %}
          </a>
        </td>
        </tr>
        <tr>
          <th>{% trans "Date" %}</th>
          <th>{% trans "Author" %}</th>
          <th>{% trans "Original file name" %}</th>
          <th>{% trans "Actions" %}</th>
      </tr></thead>
      <tbody id='attachments-rows'>
      {% for file in attachment_parent.latest_attachments %}
      <tr class='{% if forloop.counter > 5 %}hide{% endif %} '>
          <td>{{ file.created|timesince_limited }}</td>
          <td>{{ file.uploaded_by|default:'' }}</td>
          <td>
            <a href="{{MEDIA_URL}}{{file.file.name}}">
            {{ file.original_filename }}
            </a>
          </td>
          <td>
            <div class="btn-group">
              <a class="btn dropdown-toggle" data-toggle="dropdown" href="#">
                Action
                <span class="caret"></span>
              </a>
              <ul class="dropdown-menu pull-right">
                <li>
                  <span class='btn btn-link delete-attachment'
                    data-form-id='delete-attachment-{{file.id}}'
                    data-delete-type='from_one'
                  >
                    {% blocktrans %} Delete from THIS {{parent_name}} {% endblocktrans %}
                  </span>
                  <li class="divider"></li>
                  <span class='btn btn-link delete-attachment'
                    data-form-id='delete-attachment-{{file.id}}'
                    data-delete-type='from_all'
                  >
                    {% blocktrans %} Delete from ALL {{parent_name}}s {% endblocktrans %}
                  </span>
                </li>
              </ul>
            </div>
          </td>
        </tr>
      {% endfor %}
      </tbody>
  </table>

{% endif %}
