{% 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 %}
{% can_add_screenshot user project as user_can_add_screenshot %}
{% can_change_screenshot user project as user_can_change_screenshot %}

<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="btn btn-info">{% 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 %}
<tr>
<th>{% trans "Screenshot context" %}</th>
</tr>
<tr>
<td>
{% for screenshot in source.screenshots.all %}
{% include "screenshots/screenshot_show.html" %}
{% empty %}
{% trans "No screenshot currently associated!" %}
{% endfor %}
{% if user_can_change_screenshot %}
<a href="{% url 'screenshots' project=source.subproject.project.slug subproject=source.subproject.slug %}" class="btn btn-default"><i class="fa fa-picture-o"></i> {% trans "Manage screenshots" %}</a>
{% endif %}
</td>
</tr>
{% if user_can_add_screenshot %}
<tr>
<td>
<form action="{% url 'screenshots' project=source.subproject.project.slug subproject=source.subproject.slug %}" method="POST" enctype="multipart/form-data">
{% csrf_token %}
<div class="panel panel-primary">
<div class="panel-heading"><h4 class="panel-title">{% trans "Add new screenshot" %}</h4></div>
  <div class="panel-body">
<input type="hidden" name="source" value="{{ source.pk }}" />
{{ screenshot_form|crispy }}
  </div>
  <div class="panel-footer">
  <input type="submit" class="btn btn-success" value="{% trans "Upload" %}" />
  </div>
</div>
</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>
