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

{% perm 'source.edit' project as user_can_edit_source %}
{% perm 'screenshot.add' project as user_can_add_screenshot %}
{% perm 'screenshot.edit' 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 project unit.checks user %}</td>
<td><a href="{{ unit.get_absolute_url }}" class="btn btn-primary">{% trans "Edit" %}</a></td>
</tr>
{% endfor %}
</tbody>
</table>
</div>

<div class="col-lg-6">
<table class="table table-condensed">
{% if user_can_edit_source %}
<tr>
<td>
<div class="btn-group pull-right flip">
  <button type="button" class="btn btn-primary 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 %}
    {% for flag in param_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-primary" />
</form>
</td>
</tr>
<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-primary" />
</form>
</td>
</tr>
<tr>
<td>
<form method="POST" action="{% url 'edit_context' pk=source.pk %}">
{% csrf_token %}
<input type="hidden" name="next" value="{{ next }}" />
{{ context_form|crispy }}
<input type="submit" value="{% trans "Save" %}" class="btn btn-primary" />
</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.component.project.slug component=source.component.slug %}" class="btn btn-primary"><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.component.project.slug component=source.component.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-primary" 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" with object=unit.translation %}
{% endwith %}
</td>
</tr>
{% endif %}
{% endwith %}
{% endwith %}
</table>
</div>

</div>
