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

<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-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>
      {% if user_can_commit_translation %}
      <li><a href="{{ object.get_commit_url }}">{% 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 %}
    </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 %}
</ul>

<div class="tab-content">
<div class="tab-pane active" id="overview">
<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 "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 %}
<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>
</tr>
{% 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>

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

</div>

{% endblock %}
