{% 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 'show_dictionaries' project=project.slug %}">{% trans "glossaries" %}</a></li>
<li><a href="{% url 'show_dictionary' project=project.slug lang=language.code %}">{{ language }}</a></li>
{% endblock %}

{% block content %}

{% perm 'glossary.delete' project as user_can_delete_dictionary %}
{% perm 'glossary.edit' project as user_can_change_dictionary %}
{% perm 'glossary.upload' project as user_can_upload_dictionary %}
{% perm 'glossary.add' project as user_can_add_dictionary %}

<ul class="nav nav-pills">
<li class="active"><a href="#browse" data-toggle="tab">{% trans "Browse" %}</a></li>
{% if user_can_add_dictionary %}
<li><a href="#add" data-toggle="tab">{% trans "Add new word" %}</a></li>
{% endif %}
{% if user_can_upload_dictionary %}
<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">
<li><a href="{% url 'download_dictionary' project=project.slug lang=language.code %}?format=csv">{% trans "Comma separated values (CSV)" %}</a></li>
<li><a href="{% url 'download_dictionary' project=project.slug lang=language.code %}?format=po">{% trans "Gettext (PO)" %}</a></li>
<li><a href="{% url 'download_dictionary' project=project.slug lang=language.code %}?format=xliff">{% trans "XML Localization Interchange File Format (XLIFF)" %}</a></li>
<li><a href="{% url 'download_dictionary' project=project.slug lang=language.code %}?format=tbx">{% trans "TermBase eXchange (TBX)" %}</a></li>
</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">
{% include "paginator.html" %}

<form class="autosubmit paginatoraddon 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></th>
</tr>
</thead>
<tbody>
{% for word in page_obj.object_list %}
<tr>
<td>{% format_translation word.source project.source_language simple=True %}</td>
<td>{% format_translation word.target language simple=True %}</td>
<td>
{% if user_can_change_dictionary %}
<form action="{% url 'edit_dictionary' project=project.slug lang=language.code pk=word.id %}" method="get" class="inlineform">
<button type="submit" class="btn btn-xs btn-info"><i class="fa fa-pencil"></i> {% trans "Edit" %}</button>
</form>
{% endif %}
{% if user_can_delete_dictionary %}
<form action="{% url 'delete_dictionary' project=project.slug lang=language.code pk=word.id %}" method="post" class="inlineform">
{% csrf_token %}
<input type="hidden" name="letter" value="{{ letter }}" />
<input type="hidden" name="limit" value="{{ page_obj.paginator.per_page }}" />
<input type="hidden" name="page" value="{{ page_obj.number }}" />
<button type="submit" class="btn btn-xs btn-danger"><i class="fa fa-trash"></i> {% trans "Delete" %}</button>
</form>
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% else %}
<p>{% trans "No words found!" %}</p>
{% endif %}
</div>

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

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

</div>
{% endif %}

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

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

</div>
{% endif %}

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

</div>

{% endblock %}
