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

{% block breadcrumbs %}
<li><a href="{% url 'profile' %}">{% trans "Your profile" %}</a></li>
{% endblock %}

{% block content %}

{% if form.errors or userform.errors or subscriptionform.errors %}
{% trans "Please fix errors in the form." as msg %}
{% show_message "error" msg %}
{% endif %}

<form method="post" action="{% url 'profile' %}">
{% csrf_token %}
<input type="hidden" id="form-activetab" name="activetab" value="" />

<ul class="nav nav-pills">
<li class="active"><a data-toggle="tab" href="#languages">{% trans "Languages" %}</a></li>
<li><a data-toggle="tab" href="#preferences">{% trans "Preferences" %}</a></li>
<li><a data-toggle="tab" href="#subscriptions">{% trans "Subscriptions" %}</a></li>
<li><a data-toggle="tab" href="#account">{% trans "Account" %}</a></li>
<li><a data-toggle="tab" href="#auth">{% trans "Authentication" %}</a></li>
<li><a data-toggle="tab" href="#profile">{% trans "Profile" %}</a></li>
<li><a data-toggle="tab" href="#licenses">{% trans "Licenses" %}</a></li>
<li><a data-toggle="tab" href="#audit">{% trans "Audit log" %}</a></li>
<li><a data-toggle="tab" href="#api">{% trans "API access" %}</a></li>
{% if user.billing %}
<li><a data-toggle="tab" href="#billing">{% trans "Billing" %}</a></li>
{% endif %}
</ul>

<div class="tab-content">
<div class="tab-pane active" id="languages">
<div class="row">
<div class="col-lg-6">
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% trans "Languages" %}</h4></div>
  <div class="panel-body">
    {{ form|crispy }}
  </div>
  <div class="panel-footer">
    <input type="submit" value="{% trans "Save" %}" class="btn btn-default" />
  </div>
</div>
</div>
<div class="col-lg-6 hidden-xs">
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% trans "Description" %}</h4></div>
  <div class="panel-body">
    <p>
      {% blocktrans %}Choose which languages you prefer to translate. These will be offered to you on the dashboard to have easier access to chosen translations.{% endblocktrans %}
    </p>
    <p>
      {% blocktrans %}The secondary languages are shown next to the source string when translating.{% endblocktrans %}
    </p>
    <p>
      {% blocktrans %}Only languages which are currently being translated are listed. If you want to translate to another language, please request it first on the project you want to translate.{% endblocktrans %}
    </p>
  </div>
  <div class="panel-footer">
  <a class="btn btn-default" href="{% documentation 'user/profile' 'languages' %}">{% trans "Documentation" %}</a>
  </div>
</div>
</div>
</div>
</div>
<div class="tab-pane" id="preferences">
<div class="row">
<div class="col-lg-6">
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% trans "Preferences" %}</h4></div>
  <div class="panel-body">
    {{ usersettingsform|crispy }}
    {{ dashboardsettingsform|crispy }}
  </div>
  <div class="panel-footer">
    <input type="submit" value="{% trans "Save" %}" class="btn btn-default" />
  </div>
</div>
</div>
<div class="col-lg-6 hidden-xs">
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% trans "Description" %}</h4></div>
  <div class="panel-body">
    <p>
      {% blocktrans %}Customize Weblate behavior to match your personal preferences.{% endblocktrans %}
    </p>
  </div>
  <div class="panel-footer">
  <a class="btn btn-default" href="{% documentation 'user/profile' 'preferences' %}">{% trans "Documentation" %}</a>
  </div>
</div>
</div>
</div>
</div>
<div class="tab-pane" id="subscriptions">
<div class="row">
<div class="col-lg-6">
{% if managed_projects %}
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% trans "Managed projects" %}</h4></div>
  <div class="panel-body">
    <div class="list-group">
{% for project in managed_projects %}
      <a class="list-group-item" href="{{ project.get_absolute_url }}">{{ project }}</a>
{% endfor %}
    </div>
    <p class="helptext">{% trans "You will automatically receive important notifications on managed projects." %}</p>
  </div>
</div>
{% endif %}
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% trans "Watched projects" %}</h4></div>
  <div class="panel-body">
{% crispy subscriptionform %}
  </div>
  <div class="panel-footer">
    <input type="submit" value="{% trans "Save" %}" class="btn btn-default" />
  </div>
</div>
</div>
<div class="col-lg-6 hidden-xs">
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% trans "Description" %}</h4></div>
  <div class="panel-body">
    <p>{% trans "You will receive chosen notifications via email for all your languages." %}</p>
    <p>{% trans "Watched projects are also shown on dashboard, so choose all projects you want to translate." %}</p>
  </div>
  <div class="panel-footer">
  <a class="btn btn-default" href="{% documentation 'user/profile' 'subscriptions' %}">{% trans "Documentation" %}</a>
  </div>
</div>
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% trans "Subscription settings" %}</h4></div>
  <div class="panel-body">
{% crispy subscriptionsettingsform %}
  </div>
  <div class="panel-footer">
    <input type="submit" value="{% trans "Save" %}" class="btn btn-default" />
  </div>
</div>
</div>
</div>
</div>
<div class="tab-pane" id="account">
<div class="row">
<div class="col-lg-6">
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% trans "Account" %}</h4></div>
  <div class="panel-body">
{{ userform|crispy }}
  </div>
  <div class="panel-footer">
    <input type="submit" value="{% trans "Save" %}" class="btn btn-default" />
  </div>
</div>
</div>
<div class="col-lg-6 hidden-xs">
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% trans "Description" %}</h4></div>
  <div class="panel-body">
    <p>{% trans "Your name and email will appear as author on the commits." %}</p>
  </div>
  <div class="panel-footer">
  <a class="btn btn-default" href="{% documentation 'user/profile' %}">{% trans "Documentation" %}</a>
  </div>
</div>
</div>
</div>
</div>
<div class="tab-pane" id="auth">
<div class="row">
<div class="col-lg-6">
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% trans "Current user identities" %}</h4></div>
<table class="table">
<thead>
<tr>
<th>{% trans "Identity" %}</th>
<th>{% trans "User ID" %}</th>
<th>{% trans "Action" %}</th>
</tr>
<tbody>
<tr>
<th>{% trans "Password" %}</th>
<td>{{ request.user.username }}</td>
<td>
<a href="{% url 'password' %}" class="btn btn-default">{% if request.user.has_usable_password %}{% trans "Change password" %}{% else %}{% trans "Set password" %}{% endif %}</a>
</td>
</tr>
{% for assoc in associated %}
<tr>
<th>{% auth_name assoc.provider '' ' ' %}</th>
<td>{{ assoc.uid }}</td>
<td>
{% if associated.count > 1 %}
<a href="{% url 'social:disconnect_individual' assoc.provider assoc.id %}?next={% url 'profile' %}%23auth" class="disconnect btn btn-danger"><i class="fa fa-trash"></i> {% trans "Disconnect" %}</a>
{% endif %}
</td>

</tr>
{% endfor %}
</tbody>
</table>
</div>

{% if new_backends %}
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% trans "Add new association" %}</h4></div>
  <div class="panel-body">
{% for name in new_backends %}
  <a class="btn btn-link link-post" href="{% url 'social:begin' name %}?next={% url 'profile' %}%23auth">{% auth_name name %}</a>
{% endfor %}
</div>
</div>
{% endif %}


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

    <p>{% trans "Removal of the account deletes all your private data." %}</p>
   </div>
   <div class="panel-footer">
    <a class="btn btn-danger" href="{% url 'remove' %}"><i class="fa fa-trash"></i> {% trans "Remove my account" %}</a>
   </div>
</div>

</div>
<div class="col-lg-6 hidden-xs">
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% trans "Description" %}</h4></div>
  <div class="panel-body">
    <p>{% trans "You can manage identities which are associated to this account and which can be used to log in." %}</p>
    <p>{% trans "You can configure how you will log in on this site." %}</p>
  </div>
  <div class="panel-footer">
  <a class="btn btn-default" href="{% documentation 'user/profile' 'authentication' %}">{% trans "Documentation" %}</a>
  </div>
</div>
</div>
</div>

</div>
<div class="tab-pane" id="profile">
<div class="row">
<div class="col-lg-6">
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% trans "Your summary" %}</h4></div>
<table class="table">
{% with request.user as user %}
{% include 'user-activity.html' %}
{% endwith %}
<tr>
{% url 'user_page' user=request.user.username as user_page%}
<th>{% trans "Your public profile" %}</th>
<td><a href="{{ user_page }}">{{ user_page }}</a></td>
</tr>
</table>
</div>

{% if enable_avatars %}
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% trans "Your avatar" %}</h4></div>
  <div class="panel-body">
<p class="border"><img src="{% url 'user_avatar' user=request.user.username size=128 %}" /></p>
<p><a href="https://www.libravatar.org/">{% trans "Avatars are provided using libravatar." %}</a></p>
</div>
</div>
{% endif %}

</div>

<div class="col-lg-6 hidden-xs">
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% trans "Description" %}</h4></div>
  <div class="panel-body">
    <p>{% trans "Your public appearance on this site." %}</p>
  </div>
  <div class="panel-footer">
  <a class="btn btn-default" href="{% documentation 'user/profile' 'avatar' %}">{% trans "Documentation" %}</a>
  </div>
</div>
</div>

</div>

</div>

<div class="tab-pane" id="audit">
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% trans "Description" %}</h4></div>
  <div class="panel-body">
    <p>{% blocktrans %}Audit log shows important changes on your account. In case you see something suspicious don't hesitate to contact us.{% endblocktrans %}</p>
  </div>
</div>

<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% trans "Audit log" %}</h4></div>
<table class="table">
<thead>
<tr>
<th>{% trans "When" %}</th>
<th>{% trans "Account activity" %}</th>
<th>{% trans "IP address" %}</th>
<th>{% trans "User agent" %}</th>
</tr>
</thead>
<tbody>
{% for log in auditlog %}
<tr>
<td>{{ log.timestamp|naturaltime }}</td>
<td>{{ log.get_message }}</td>
{% if not demo_server or user.username not in demo_accounts %}
<td>{{ log.address }}</td>
<td>{{ log.user_agent }}</td>
{% else %}
<td>{% trans "Hidden" %}</td>
<td>{% trans "Hidden" %}</td>
{% endif %}
</td>
<td>
</tr>
{% empty %}
<tr><td colspan="3">{% trans "No recent activity found!" %}</td></tr>
{% endfor %}
</tbody>
</table>
  <div class="panel-footer">
    <a href="{% url 'contact' %}?t=account" class="btn btn-warning">{% trans "Report suspicious activity" %}</a>
  </div>
</div>

</div>

<div class="tab-pane" id="api">
<div class="row">
<div class="col-lg-6">
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% trans "API access" %}</h4></div>
<table class="table">
<tr>
<th>{% trans "Your personal API key:" %}</th>
<td>
    {{ user.auth_token.key }} 
</td>
</tr>
<tr>
<td colspan="2">
    <a class="pull-right flip btn btn-default link-post" href="{% url 'reset-api-key' %}">{% trans "Regenerate API key" %}</a>
</td>
</tr>
<tr>
<th>{% trans "API root URL:" %}</th>
<td><a href="{{ site_url }}{% url 'api:api-root' %}">{{ site_url }}{% url 'api:api-root' %}</a></td>
</tr>
<tr>
<th colspan="2">{% trans "API usage example:" %}</th>
</tr>
<tr>
<td colspan="2">
<pre>
curl \
    -H "Authorization: Token {{ user.auth_token.key }}" \
    {{ site_url }}{% url 'api:api-root' %}
</pre>
</td>
</tr>
<tr>
<th colspan="2">{% trans "CLI usage example:" %}</th>
</tr>
<tr>
<td colspan="2">
<pre>
wlc \
    --key {{ user.auth_token.key }} \
    --url {{ site_url }}{% url 'api:api-root' %} \
    list-projects
</pre>
</td>
</tr>
</table>
</div>

</div>

<div class="col-lg-6 hidden-xs">
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% trans "Description" %}</h4></div>
  <div class="panel-body">
    <p>{% blocktrans %}You can control Weblate using HTTP REST API and API key is used to authenticate to it.{% endblocktrans %}</p>
    <p>{% blocktrans %}The API key is also used to authenticate to automatically exported Git repositories.{% endblocktrans %}</p>
  </div>
  <div class="panel-footer">
  <a class="btn btn-default" href="{% documentation 'api' %}">{% trans "API documentation" %}</a>
  <a class="btn btn-default" href="{% documentation 'admin/optionals' 'git-exporter' %}">{% trans "Git export documentation" %}</a>
  </div>
</div>
</div>

</div>

</div>
<div class="tab-pane" id="licenses">
<div class="row">
<div class="col-lg-6">
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% trans "Licenses" %}</h4></div>
  <div class="panel-body">
<p>
{% trans "By registering you agree to use your name and email in the commits and provide your contribution under license defined by each translated project." %}
</p>

{% if licenses %}
<p>{% trans "Following translations have explicitly specified their licensing and copyright conditions:" %}</p>
<table class="table">
<thead>
<tr><th>{% trans "Project" %}</th><th>{% trans "License" %}</th></tr>
</thead>
<tbody>
{% for component in licenses %}
<tr>
<th><a href="{{ component.get_absolute_url }}">{{ component }}</a></th>
<td>
{% if component.license_url %}
<a href="{{ component.license_url }}">{{ component.license }}</a></p>
{% else %}
{{ component.license }}
{% endif %}
</td>
</tr>
{% endfor %}
</tbody>
</table>
{% endif %}
</div>
</div>

</div>

<div class="col-lg-6 hidden-xs">
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% trans "Description" %}</h4></div>
  <div class="panel-body">
    <p>{% trans "Please pay attention to the licensing information as these specify how others are allowed to use your translations." %}</p>
  </div>
</div>
</div>

</div>

</div>

{% if user.billing %}
{% with user.billing as billing %}
<div class="tab-pane" id="billing">
<div class="row">


<div class="col-lg-6">
{% include "billing/detail.html" %}
</div>

<div class="col-lg-6">
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% trans "Invoices" %}</h4></div>
<table class="table table-striped">
<thead>
<tr>
<th>{% trans "Invoice period" %}</th>
<th>{% trans "Invoice amount" %}</th>
<th>{% trans "Download invoice" %}</th>
</tr>
</thead>
<tbody>
{% for invoice in billing.invoice_set.all %}
<tr>
<td>{{ invoice.start|date:"SHORT_DATE_FORMAT" }} - {{ invoice.end|date:"SHORT_DATE_FORMAT" }}</td>
<td>{{ invoice.payment }} {{ invoice.get_currency_display }}</td>
<td>
{% if invoice.ref %}
<a href="{% url 'invoice-download' pk=invoice.pk %}">{{ invoice.filename }}</a>
{% else %}
{% trans "Not available" %}
{% endif %}
</td>
</tr>
{% empty %}
<tr><td colspan="3">{% trans "No invoices found!" %}</td/></tr>
{% endfor %}
</tbody>
</table>
</div>
</div>

</div>

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

</div>


</form>
<form method="post" action="" id="disconnect-form">{% csrf_token %}</form>

{% endblock %}
