{% 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>
</ul>

<div class="tab-content">

<div class="tab-pane active" id="languages">
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% documentation_icon 'user/profile' 'languages' right=True %}{% trans "Languages" %}</h4></div>
  <div class="panel-body">
    {% crispy languagesform %}
    <p class="help-block">
      {% 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">
    <input type="submit" value="{% trans "Save" %}" class="btn btn-default" />
  </div>
</div>
</div>

<div class="tab-pane" id="preferences">
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% documentation_icon 'user/profile' 'preferences' right=True %}{% 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="tab-pane" id="subscriptions">
{% 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">{% documentation_icon 'user/profile' 'subscriptions' right=True %}{% trans "Watched projects" %}</h4></div>
  <div class="panel-body">
{% crispy subscriptionform %}
    <p class="help-block">{% trans "Watched projects are also shown on dashboard, so choose all projects you want to translate." %}</p>
  </div>
  <div class="panel-footer">
    <input type="submit" value="{% trans "Save" %}" class="btn btn-default" />
  </div>
</div>

<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% documentation_icon 'user/profile' 'subscriptions' right=True %}{% trans "Subscription settings" %}</h4></div>
  <div class="panel-body">
{% crispy subscriptionsettingsform %}
    <p class="help-block">{% trans "You will receive chosen notifications via email for all your languages." %}</p>
  </div>
  <div class="panel-footer">
    <input type="submit" value="{% trans "Save" %}" class="btn btn-default" />
  </div>
</div>
</div>

<div class="tab-pane" id="account">
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% documentation_icon 'user/profile' right=True %}{% trans "Account" %}</h4></div>
  <div class="panel-body">
{% crispy userform %}
    <p class="help-block">{% trans "Your name and email will appear as author on the commits." %}</p>
  </div>
  <div class="panel-footer">
    <input type="submit" value="{% trans "Save" %}" class="btn btn-default" />
  </div>
</div>
</div>

<div class="tab-pane" id="auth">
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% documentation_icon 'user/profile' 'authentication' right=True %}{% 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><i class="fa fa-lg fa-wl-social fa-key" aria-hidden="true"></i> {% 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="tab-pane" id="profile">
<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 class="panel-footer">
    <p class="help-block">{% trans "Your public appearance on this site." %}</p>
</div>
</div>

{% if enable_avatars %}
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% documentation_icon 'user/profile' 'avatar' right=True %}{% 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.gravatar.com/">{% trans "Avatars are provided using Gravatar." %}</a></p>
</div>
</div>
{% endif %}

</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 user.is_demo %}
<td>{{ log.address }}</td>
<td>{{ log.user_agent }}</td>
{% else %}
<td>{% trans "Hidden" %}</td>
<td>{% trans "Hidden" %}</td>
{% endif %}
</tr>
{% empty %}
<tr><td colspan="4">{% 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="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% documentation_icon 'api' right=True %}{% trans "API access" %}</h4></div>
<table class="table">
<tr><td colspan="2">
    <p>{% blocktrans %}You can control Weblate using HTTP REST API and API key is used to authenticate to it.{% endblocktrans %}</p>
</td></tr>
<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>

{% if has_gitexport %}
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% documentation_icon 'admin/optionals' 'git-exporter' right=True %}{% trans "Accessing Git repositories" %}</h4></div>
  <div class="panel-body">
    <p>{% blocktrans %}The API key is also used to authenticate to automatically exported Git repositories.{% endblocktrans %}</p>
    <pre>
git clone 'https://{{ user.username }}:{{ user.auth_token.key }}@{{ site_domain }}/git/PROJECT/COMPONENT/'</pre>
  </div>
</div>
{% endif %}

</div>

<div class="tab-pane" id="licenses">
<div class="panel panel-primary">
  <div class="panel-heading"><h4 class="panel-title">{% trans "Licenses" %}</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>
<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 user.contributoragreement_set.all %}
<p>{% trans "You have agreed to the following as a contributor:" %}</p>
<ul>
{% for agreement in user.contributoragreement_set.all %}
<li><a href="{% url 'contributor-agreement' project=agreement.component.project.slug component=agreement.component.slug %}">{{ agreement.component }}</a></li>
{% endfor %}
</ul>
{% endif %}

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


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

{% endblock %}
