{% extends "base.html" %}
{% load i18n %}
{% load translations %}
{% load crispy_forms_tags %}
{% load permissions %}

{% block breadcrumbs %}
<li><a href="{{ project.get_absolute_url }}">{{ project }}</a></li>
<li><a href="{% url 'project-language' project=project.slug lang=language.code %}">{{ language }}</a></li>
<li><a href="{% url 'show_glossary' project=project.slug lang=language.code %}">{% trans "Glossary" %}</a></li>
{% endblock %}

{% block content %}

{% perm 'glossary.delete' project as user_can_delete_glossary %}
{% perm 'glossary.edit' project as user_can_change_glossary %}
{% perm 'glossary.upload' project as user_can_upload_glossary %}
{% perm 'glossary.add' project as user_can_add_glossary %}

<ul class="nav nav-pills">
<li class="active"><a href="#browse" data-toggle="tab">{% trans "Browse" %}</a></li>
{% if user_can_add_glossary %}
<li><a href="#add" data-toggle="tab">{% trans "Add new word" %}</a></li>
{% endif %}
{% if user_can_upload_glossary %}
<li><a href="#import" data-toggle="tab">{% trans "Import glossary" %}</a></li>
{% endif %}
<li>
    <a class="dropdown-toggle" data-toggle="dropdown" href="#">
      {% trans "Export glossary" %} <span class="caret"></span>
    </a>
    <ul class="dropdown-menu">
	{% for exporter in exporters %}
	<li><a href="{% url 'download_glossary' project=project.slug lang=language.code %}?format={{ exporter.name  }}">Export as {{ exporter.verbose  }}</a></li>
	{% endfor  %}
    </ul>
</li>
<li><a href="#changes" data-toggle="tab">{% trans "History" %}</a></li>
</ul>

<div class="tab-content">
<div class="tab-pane active" id="browse">

<form class="searchform result-page-form" action="{% url 'show_glossary' project=project.slug lang=language.code %}">
{% crispy searchform %}
</form>

{% include "paginator.html" %}

<form class="autosubmit form-inline pull-right flip">
{% crispy letterform %}
</form>

{% if page_obj.object_list %}
<table class="table table-condensed table-striped">
<thead>
<tr>
<th>{% trans "Source" %}</th>
<th>{% trans "Translation" %}</th>
<th>{% trans "Glossary" %}</th>
<th></th>
</tr>
</thead>
<tbody>
{% for word in page_obj.object_list %}
<tr>
<td>{% format_translation word.source word.glossary.source_language simple=True %}</td>
<td>{% format_translation word.target language simple=True %}</td>
<td>{% include "snippets/glossary-badge.html" with glossary=word.glossary %}</td>
<td>
{% if user_can_change_glossary %}
<form action="{% url 'edit_glossary' pk=word.id %}" method="get" class="inlineform">
<input type="hidden" name="next" value="{{ request.get_full_path }}" />
<button type="submit" class="btn btn-xs btn-primary">{% trans "Edit" %}</button>
</form>
{% endif %}
{% if user_can_delete_glossary %}
<form action="{% url 'delete_glossary' pk=word.id %}" method="post" class="inlineform">
{% csrf_token %}
<input type="hidden" name="next" value="{{ request.get_full_path }}" />
<button type="submit" class="btn btn-xs btn-danger">{% trans "Delete" %}</button>
</form>
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% include "paginator.html" %}
{% else %}
<p>{% trans "No words found!" %}</p>
{% endif %}
</div>

{% if user_can_add_glossary %}
<div class="tab-pane" id="add">

<form action="{% url 'show_glossary' project=project.slug lang=language.code %}" method="POST">
{% csrf_token %}
{{ form|crispy }}
<input type="submit" value="{% trans "Add" %}" class="btn btn-primary" />
</form>

</div>
{% endif %}

{% if user_can_upload_glossary %}
<div class="tab-pane" id="import">
<form action="{% url 'upload_glossary' project=project.slug lang=language.code %}" method="post" enctype="multipart/form-data">

{% csrf_token %}
{{ uploadform|crispy }}
<input type="submit" class="btn btn-primary" value="{% trans "Import" %}" />
</form>

</div>
{% endif %}

<div class="tab-pane" id="changes">
{% include "last-changes-content.html" %}
<a class="btn btn-primary" href="{% url 'changes' %}?{{ last_changes_url }}">{% trans "Browse all glossary changes" %}</a>
</div>

</div>

{% endblock %}
