{% extends "account/base.html.twig" %}

{% block title %}
    {% trans "Granted third party applications" %}
{% endblock %}

{% set selected = "applications" %}

{% block content_account %}
    <div class="row-fluid">
        <div class="span6">
            <div id="content-apps">
                <h3>{% trans "Vous avez autorise ces applications a acceder a votre compte" %}</h3>
                {% if applications|length > 0 %}
                    <ul class="unstyled app-list">
                        {% for application in applications %}
                            <li id="app_{{ application.get_id() }}">
                                <div>
                                    {% set account = application.get_user_account(app["authentication"].getUser()) %}
                                    <a href="{{ path("grant_app_access", {"application_id" : application.get_id()}) }}" class="revoke app-btn btn btn-small pull-right {% if account.is_revoked() %}hidden{% endif %}" value="{{application.get_id()}}">{% trans "Revoquer l\'access" %}</a>
                                    <a href="{{ path("grant_app_access", {"application_id" : application.get_id()}) }}"  class="authorize app-btn btn btn-small pull-right {% if not account.is_revoked() %}hidden{% endif %}" value="{{application.get_id()}}">{% trans "Authoriser l\'access" %}</a>
                                    <p class="app-row">
                                        <a href="{{ application.get_website() }}" target="_blank">
                                            <strong>{{ application.get_name() }}</strong>
                                        </a>
                                        {% if application.get_creator() is not none %}
                                            <small>
                                                {% set user_name = application.get_creator().get_display_name() %}
                                                {% trans %}
                                                    par {{ user_name }}
                                                {% endtrans %}
                                            </small>
                                        {% endif%}
                                    </p>
                                    <p class="app-row">
                                        <span class="status text-error {% if account.is_revoked() == false %}hidden{% endif %}">{% trans "Not Allowed"%}</span>
                                        <span class="status text-success {% if account.is_revoked() == true %}hidden{% endif %}">{% trans "Allowed"%}</span>
                                    </p>
                                    <p class="app-row">{{ application.get_description()|truncate(120, true, "...") }}</p>
                                </div>
                            </li>
                        {%endfor%}
                    </ul>
                 {% else %}
                    <div>
                        {% trans "Aucune application n\'a accés à vos données." %}
                    </div>
                 {% endif %}
            </div>
        </div>
        <div class="span6">
            <div class="well well-small">
                <h3>{% trans "Third-party applications" %}</h3>
                <p>
                  {% trans "A third-party application is a product developed apart from Phraseanet and that would access Phraseanet data." %}
                </p>
            </div>

            <div class="well well-small">
                <h3>{% trans "Developpeurs" %}</h3>
                <p>
                    {% trans "Les developpeurs peuvent editer l\'enregistrement de leurs application grace a l\'onglet 'developpeurs' ci-dessus" %}
                </p>
            </div>
        </div>
    </div>
{% endblock %}
