{% extends "base.html" %}
{% load i18n %}
{% load translations %}
{% load permissions %}
{% 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='svg' color='badge' extension='svg' %}" />
</a>
{% endblock %}

{% block content %}

{% whiteboard_messages project=object %}

{% can_see_repository_status user object as user_can_see_repository_status %}
{% can_commit_translation user object as user_can_commit_translation %}
{% can_manage_acl user object as user_can_manage_acl %}
{% can_edit_project user object as user_can_edit_project %}

<ul class="nav nav-pills">
  <li class="active"><a href="#components" data-toggle="tab">{% trans "Components" %}</a></li>
  <li><a href="#languages" data-toggle="tab">{% trans "Languages" %}</a></li>
  <li><a href="#information" data-toggle="tab">{% trans "Information" %}</a></li>
  <li><a href="#glossaries" data-toggle="tab">{% trans "Glossaries" %}</a></li>
  <li><a href="#history" data-toggle="tab">{% trans "History" %}</a></li>
  <li><a href="#activity" data-toggle="tab" data-load="activity" data-yearly="{% url 'yearly_activity' project=object.slug %}" data-monthly="{% url 'monthly_activity' 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>
      <li><a href="{% url 'export_stats' project=object.slug %}?format=csv">{% trans "Download statistics (CSV)" %}</a></li>
      <li><a href="{% url 'export_stats' project=object.slug %}?format=json">{% trans "Download statistics (JSON)" %}</a></li>
      {% if user_can_commit_translation %}
      <li><a href="{{ object.get_commit_url }}" class="link-post">{% trans "Commit" %}</a></li>
      {% endif %}
      {% if user_can_see_repository_status %}
      <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 user_can_manage_acl %}
      <li><a href="#acl" data-toggle="tab">{% trans "Manage users" %}</a></li>
      {% endif %}
      {% if user_can_edit_project %}
      <li><a href="#settings" data-toggle="tab">{% trans "Settings" %}</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="{% url 'engage' project=object.slug %}">{% trans "Engage page" %}</a></li>
      <li><a href="{{ widgets_url }}">{% trans "Status widgets" %}</a></li>
{% endwith %}
    </ul>
  </li>
{% endif %}
{% with object as project %}
{% include "watch-dropdown.html" %}
{% endwith %}
</ul>

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

<table class="sort table">
<thead>
<tr>
<th>{% trans "Component" %}</th>
<th colspan="2">{% trans "Translated" %}</th>
<th colspan="2">{% trans "Words" %}</th>
</tr>
<tbody>
{% for prj in object.subproject_set.select_related %}
<tr>
<th><a href="{{ prj.get_absolute_url }}">{{ prj.name }}</a></th>
<td class="progress-cell">{% translation_progress prj %}</td>
<td class="percent">{{ prj.get_translated_percent }}%</td>
<td class="progress-cell">{% generic_progress prj.get_words_percent %}</td>
<td class="percent">{{ prj.get_words_percent }}%</td>
</tr>
{% endfor %}
</tbody>
</table>

{% include "legend.html" %}

</div>

<div class="tab-pane" id="information">

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

</div>
<div class="tab-pane" id="languages">

<table class="sort table">
<thead>
<tr>
<th>{% trans "Language" %}</th>
<th colspan="2">{% trans "Translated" %}</th>
<th colspan="2">{% trans "Words" %}</th>
</tr>
</thead>
<tbody>
{% for language in language_stats %}
<tr>
<th><a href="{% url 'project-language' lang=language.0.code project=object.slug %}">{{ language.0 }}</a></th>
<td class="progress-cell">{% generic_progress language.1 %}</td>
<td class="percent">{{ language.1 }}%</td>
<td class="progress-cell">{% generic_progress language.2 %}</td>
<td class="percent">{{ language.2 }}%</td>
</tr>
{% endfor %}
</tbody>
</table>

</div>

<div class="tab-pane" id="glossaries">

{% 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 %}

<a class="btn btn-default" href="{% url 'show_dictionaries' project=object.slug %}">{% trans "Manage all glossaries" %}</a>

</div>

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

{% include "activity-tab.html" %}

{% if user_can_see_repository_status %}
<div class="tab-pane" id="repository">
<p>{% trans "Loading…" %}</p>
</div>
{% endif %}

{% if user_can_manage_acl %}
<div class="tab-pane" id="acl">
<div class="container-fluid">
<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>
{% with object.owners.count as owner_count %}
  {% for user in object.owners.all %}
  <tr>
  <td>{{ user.username }} <span class="badge">{% trans "Owner" %}</span></td>
  <td>{{ user.first_name }}</td>
  <td>{{ user.email }}</td>
  <td>
{% if owner_count > 1 %}
{% if object.enable_acl %}
<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>
{% endif %}
<form action="{% url "revoke-owner" project=object.slug %}" method="post">
{% csrf_token %}
<input type="hidden" name="name" value="{{ user.username }}" />
<button type="submit" class="btn btn-warning btn-xs">
<i class="fa fa-user-times"></i>
{% trans "Revoke ownership" %}
</button>
</form>
{% endif %}
  </td>
  </tr>
  {% endfor %}
{% endwith %}
{% if object.enable_acl %}
  {% 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>
<form action="{% url "make-owner" project=object.slug %}" method="post">
{% csrf_token %}
<input type="hidden" name="name" value="{{ user.username }}" />
<button type="submit" class="btn btn-success btn-xs">
<i class="fa fa-user-plus"></i>
{% trans "Make owner" %}
</button>
</form>
  </td>
  </tr>
  {% endfor %}
{% endif %}
  </tbody>
  </table>
  </div>
</div>

</div>

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

{% if object.enable_acl %}
<form action="{% url "add-user" project=object.slug %}" method="post">
{% else %}
<form action="{% url "make-owner" project=object.slug %}" method="post">
{% endif %}
{% csrf_token %}
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">
{% if object.enable_acl %}
  {% trans "Add new user" %}
{% else %}
  {% trans "Add new owner" %}
{% endif %}
  </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>
</div>
{% endif %}

{% if user_can_edit_project %}
<div class="tab-pane" id="settings">
<form action="{% url 'project' project=object.slug %}#settings" method="post" enctype="multipart/form-data">
{% csrf_token %}
<div class="panel panel-primary">
<div class="panel-heading">
{% doc_url 'admin/projects' 'project' as settings_doc_url %}
<h4 class="panel-title">
<a class="pull-right flip" href="{{ settings_doc_url }}"><i class="fa fa-question-circle" aria-hidden="true"></i></a>
{% trans "Settings" %}
</h4>
</div>
<div class="panel-body">
{% crispy settings_form %}
</div>
<div class="panel-footer">
<input type="submit" value="{% trans "Save" %}" class="btn btn-default" />
</div>
</div>
</div>
</div>
</form>
</div>
{% endif %}

</div>

{% endblock %}
