{% extends "misago/admin/generic/list.html" %}
{% load i18n misago_capture misago_forms %}


{% block page-actions %}
<div class="page-actions">
  <a href="{% url 'misago:admin:users:agreements:new' %}" class="btn btn-success">
    <span class="fa fa-plus-circle"></span>
    {% trans "New agreement" %}
  </a>
</div>
{% endblock %}


{% block table-header %}
<th>{% trans "Title" %}</th>
<th style="width: 1%;">&nbsp;</th>
<th style="width: 180px;">{% trans "Type" %}</th>
<th style="width: 250px;">{% trans "Created" %}</th>
<th style="width: 250px;">{% trans "Modified" %}</th>
<th style="width: 1%;">&nbsp;</th>
<th style="width: 1%;">&nbsp;</th>
<th style="width: 1%;">&nbsp;</th>
{% endblock table-header %}


{% block table-row %}
<td class="item-name">
  {{ item.get_final_title }}
</td>
<td class="lead text-muted">
  {% if item.is_active %}
    <span class="fa fa-check-square tooltip-top" title="{% blocktrans trimmed with type=item.get_type_display.lower %}Active {{ type }}{% endblocktrans %}"></span>
  {% else %}
    &nbsp;
  {% endif %}
</td>
<td>
  {{ item.get_type_display }}
</td>
<td>
  {% capture trimmed as created_on %}
    <abbr class="moment" data-iso="{{ item.created_on.isoformat }}" data-format="LL"></abbr>
  {% endcapture %}
  {% capture trimmed as created_by %}
    {% if item.created_by %}
      <a href="{{ item.created_by.get_absolute_url }}" class="item-title">{{ item.created_by }}</a>
    {% else %}
      <span class="item-title">{{ item.created_by_name }}</span>
    {% endif %}
  {% endcapture %}
  {% blocktrans trimmed with created_on=created_on|safe created_by=created_by|safe %}
    {{ created_on }} by {{ created_by }}
  {% endblocktrans %}
</td>
<td>
  {% if item.last_modified_on %}
    {% capture trimmed as last_modified_on %}
      <abbr class="moment" data-iso="{{ item.last_modified_on.isoformat }}" data-format="LL"></abbr>
    {% endcapture %}
    {% capture trimmed as last_modified_by %}
      {% if item.last_modified_by %}
        <a href="{{ item.last_modified_by.get_absolute_url }}" class="item-title">{{ item.last_modified_by }}</a>
      {% else %}
        <span class="item-title">{{ item.last_modified_by }}</span>
      {% endif %}
    {% endcapture %}
    {% blocktrans trimmed with last_modified_on=last_modified_on|safe last_modified_by=last_modified_by|safe %}
      {{ last_modified_on }} by {{ last_modified_by }}
    {% endblocktrans %}
  {% else %}
    <em>{% trans "never" %}</em>
  {% endif %}
</td>
<td class="row-action">
  {% if not item.is_active %}
    <form action="{% url 'misago:admin:users:agreements:set-as-active' pk=item.pk %}" method="post" class="set-as-active-prompt">
      <button class="btn btn-primary tooltip-top" title="{% trans "Set as active" %}">
        {% csrf_token %}
        <span class="fa fa-check-square"></span>
      </button>
    </form>
  {% else %}
    &nbsp;
  {% endif %}
</td>
<td class="row-action">
  <a href="{% url 'misago:admin:users:agreements:edit' pk=item.pk %}" class="btn btn-primary tooltip-top" title="{% trans "Edit" %}">
    <span class="fa fa-pencil"></span>
  </a>
</td>
<td class="row-action">
  <form action="{% url 'misago:admin:users:agreements:delete' pk=item.pk %}" method="post" class="delete-prompt">
    <button class="btn btn-danger tooltip-top" title="{% trans "Remove" %}">
      {% csrf_token %}
      <span class="fa fa-times"></span>
    </button>
  </form>
</td>
{% endblock %}


{% block emptylist %}
<td colspan="9">
  {% if active_filters %}
  <p>{% trans "No agreements matching search criteria have been found" %}</p>
  {% else %}
  <p>{% trans "No agreements are currently set." %}</p>
  {% endif %}
</td>
{% endblock emptylist %}


{% block javascripts %}
{{ block.super }}
<script type="text/javascript">
  $(function() {
    $('.set-as-active-prompt').submit(function() {
      var decision = confirm("{% trans 'Are you sure you want to set this agreement as active for its type?' %}");
      return decision;
    });

    $('.delete-prompt').submit(function() {
      var decision = confirm("{% trans 'Are you sure you want to delete this agreement?' %}");
      return decision;
    });
  });
</script>
{% endblock %}


{% block modal-title %}
{% trans "Search bans" %}
{% endblock modal-title %}


{% block modal-body %}
<div class="row">
  <div class="col-md-12">
    {% form_row search_form.type %}
  </div>
</div>
<div class="row">
  <div class="col-md-12">
    {% form_row search_form.content %}
  </div>
</div>
{% endblock modal-body %}
