{% extends "base.html" %}
{% load i18n %}
{% load translations %}
{% load url from future %}
{% load crispy_forms_tags %}

{% block breadcrumbs %}
<li><a href="{{ object.get_absolute_url }}">{{ object }}</a></li>

<a class="pull-right flip" href="{{ object.get_widgets_url }}">
<img src="{% url 'widget-image' project=object.slug widget='shields' color='badge' extension='svg' %}" />
</a>
{% endblock %}

{% block content %}
<ul class="nav nav-pills">
  <li class="active"><a href="#overview" data-toggle="tab">{% trans "Overview" %}</a></li>
  <li><a href="#history" data-toggle="tab">{% trans "History" %}</a></li>
  <li><a href="#activity" data-toggle="tab" data-href="{% url 'view_activity_project' project=object.slug %}">{% trans "Activity" %}</a></li>
  <li class="dropdown">
    <a class="dropdown-toggle" data-toggle="dropdown" href="#">
      {% trans "Tools" %} <span class="caret"></span>
    </a>
    <ul class="dropdown-menu">
      <li><a href="{% url 'data_project' project=object.slug  %}">{% trans "Data exports" %}</a></li>
      {% if perms.trans.commit_translation or perms.trans.update_translation %}
      <li><a href="#repository" data-toggle="tab" data-href="{% url 'git_status_project' project=object.slug %}">{% trans "Repository maintenance" %}</a></li>
      {% endif %}
      <li><a href="{% url 'checks' %}?project={{ object.slug }}">{% trans "Failing checks" %}</a></li>
      <li><a href="{% url 'checks' %}?project={{ object.slug }}&amp;ignored=true">{% trans "Ignored checks" %}</a></li>
      {% if perms.trans.manage_acl and object.enable_acl %}
      <li><a href="#acl" data-toggle="tab">{% trans "Manage users" %}</a></li>
      {% endif %}
    </ul>
  </li>
{% if enable_sharing %}
  <li class="dropdown">
    <a class="dropdown-toggle" data-toggle="dropdown" href="#">
      {% trans "Share" %} <span class="caret"></span>
    </a>
    <ul class="dropdown-menu">
{% with object.get_share_url as share_url and object.get_widgets_url as widgets_url %}
      <li><a href="http://www.facebook.com/sharer.php?u={{ share_url }}">{% trans "Share on Facebook!" %}</a></li>
      <li><a href="https://twitter.com/share?text={% blocktrans %}Translate {{ object }} using %23Weblate at {{ share_url }}!{% endblocktrans %}">{% trans "Tweet this translation!" %}</a></li>
      <li><a href="{{ widgets_url }}">{% trans "Status widgets" %}</a></li>
{% endwith %}
    </ul>
  </li>
{% endif %}
</ul>

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

<div class="row">

<div class="col-lg-6">


<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% trans "Components" %}</h4></div>
  <div class="panel-body">

<table class="sort table">
<thead>
<tr>
<th>{% trans "Component" %}</th>
<th colspan="2">{% trans "Translated" %}</th>
</tr>
<tbody>
{% for prj in object.subproject_set.select_related %}
{% with prj.get_translated_percent as percent and prj.get_fuzzy_percent as fuzzy and prj.get_failing_checks_percent as check_percent %}
<tr>
<th><a href="{{ prj.get_absolute_url }}">{{ prj.name }}</a></th>
<td class="progress-cell">{% translation_progress prj %}</td>
<td class="percent">{{ percent }}%</td>
</tr>
{% endwith %}
{% endfor %}
</tbody>
</table>

{% include "legend.html" %}
</div>
</div>


</div>

<div class="col-lg-6">

<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% trans "Project Information" %}</h4></div>
  <div class="panel-body">

<table class="table">
{% include "project_info.html" %}
</table>
</div>
</div>

<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% trans "Glossaries" %}</h4></div>
  <div class="panel-body">
{% if dicts %}
<div class="list-group">
{% for dict in dicts %}
<a class="list-group-item" href="{% url 'show_dictionary' project=object.slug lang=dict.language.code %}"><span class="badge">{{ dict.count }}</span>{{ dict.language }}</a>
{% endfor %}
</div>
{% else %}
<p>{% trans "There are currently no glossaries defined for this project." %}</p>
{% endif %}
</div>
<div class="panel-footer">
<a class="btn btn-default" href="{% url 'show_dictionaries' project=object.slug %}">{% trans "Manage all glossaries" %}</a>
</div>
</div>


</div>
</div>

</div>

<div class="tab-pane" id="history">
{% include "last-changes.html" %}
</div>

<div class="tab-pane" id="activity">
<div class="panel panel-primary">
<div class="panel-heading"><h4 class="panel-title">{% trans "Activity" %}</h4></div>
<div class="panel-body">
<p>{% trans "Loading…" %}</p>
</div>

</div>
</div>

{% if perms.trans.commit_translation or perms.trans.update_translation %}
<div class="tab-pane" id="repository">
<p>{% trans "Loading…" %}</p>
</div>
{% endif %}

{% if perms.trans.manage_acl and object.enable_acl %}
<div class="tab-pane" id="acl">
<div class="row">
<div class="col-lg-6">

<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% trans "Users" %}</h4></div>
  <div class="panel-body">
  <table class="table table-striped">
  <thead>
  <tr>
  <th>{% trans "Username" %}</th>
  <th>{% trans "Full name" %}</th>
  <th>{% trans "E-mail" %}</th>
  </tr>
  </thead>
  <tbody>
  {% for user in object.all_users %}
  <tr>
  <td>{{ user.username }}</td>
  <td>{{ user.first_name }}</td>
  <td>{{ user.email }}</td>
  <td>
<form action="{% url "delete-user" project=object.slug %}" method="post">
{% csrf_token %}
<input type="hidden" name="name" value="{{ user.username }}" />
<button type="submit" class="btn btn-danger btn-xs">
<i class="fa fa-trash"></i>
{% trans "Remove" %}
</button>
</form>
  </td>
  </tr>
  {% endfor %}
  </tbody>
  </table>
  </div>
</div>

</div>

<div class="col-lg-6">

<form action="{% url "add-user" project=object.slug %}" method="post">
{% csrf_token %}
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% trans "Add new user" %}</h4></div>
  <div class="panel-body">
    {{ add_user_form|crispy }}
  </div>
  <div class="panel-footer">
  <input type="submit" class="btn btn-default" value="{% trans "Add" %}" />
  </div>
</div>
</form>

</div>

</div>
</div>
{% endif %}

</div>

{% endblock %}
