{% load translations %}
{% load i18n %}
{% load crispy_forms_tags %}
{% load permissions %}

{% can_edit_flags user project as user_can_edit_flags %}
{% can_edit_priority user project as user_can_edit_priority %}

<div class="row">
<div class="col-lg-6">
<table class="table table-condensed table-striped">
<thead>
<tr>
<th>{% trans "Language" %}</th>
<th>{% trans "Status" %}</th>
<th>{% trans "Checks" %}</th>
<th>{% trans "Edit" %}</th>
</tr>
</thead>
<tbody>
{% for unit in units %}
<tr>
<th>{{ unit.translation.language }}</th>
<td>{% get_state_flags unit %}</td>
<td>{% show_checks unit.translation.subproject.project unit.checks user %}</td>
<td><a href="{{ unit.get_absolute_url }}" class="button small-button">{% trans "Edit" %}</a></td>
</tr>
{% endfor %}
</tbody>
</table>
</div>

<div class="col-lg-6">
<table class="table table-condensed">
{% if user_can_edit_flags %}
<tr>
<td>
<div class="btn-group pull-right flip">
  <button type="button" class="btn btn-default btn-xs dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
    {% trans "Add" %} <span class="caret"></span>
  </button>
  <ul class="dropdown-menu" role="menu">
    {% for flag in extra_flags %}
    <li><a href="#" data-flag="{{ flag.0 }}">{{ flag.1 }}</a></li>
    {% endfor %}
    <li class="divider"></li>
    {% for flag in check_flags %}
    <li><a href="#" data-flag="{{ flag.0 }}">{% blocktrans with flag.1 as check %}Ignore: {{ check }}{% endblocktrans %}</a></li>
    {% endfor %}
  </ul>
</div>
<form method="POST" action="{% url 'edit_check_flags' pk=source.pk %}">
{% csrf_token %}
<input type="hidden" name="next" value="{{ next }}" />
{{ check_flags_form|crispy }}

<input type="submit" value="{% trans "Save" %}" class="btn btn-default" />
</form>
</td>
</tr>
{% endif %}
{% if user_can_edit_priority %}
<tr>
<td>
<form method="POST" action="{% url 'edit_priority' pk=source.pk %}">
{% csrf_token %}
<input type="hidden" name="next" value="{{ next }}" />
{{ priority_form|crispy }}
<input type="submit" value="{% trans "Save" %}" class="btn btn-default" />
</form>
</td>
</tr>
{% endif %}
{% with units.0 as unit %}
{% include "unit-details.html" %}
{% with unit.get_source_comments as comments %}
{% if comments %}
<tr>
<th>{% trans "User comments" %}</th>
</tr>
<tr>
<td>
{% with next as next_url %}
{% include "list-comments.html" %}
{% endwith %}
</td>
</tr>
{% endif %}
{% endwith %}
{% endwith %}
</table>
</div>

</div>
