{% extends "base.html" %}

{% load i18n %}
{% load crispy_forms_filters %}

{% block content %}
    <div class="card">
        <div class="card-header text-center">
            <h3>{% trans "Authorize" %} {{ application.name }} ?</h3>
        </div>
        {% if not error %}
            <form id="authorizationForm" method="post">
                <div class="card-body">
                    <p>{% trans "Application requires following permissions:" %}</p>

                    <ul>
                        {% for scope in scopes_descriptions %}
                            <li>{{ scope }}</li>
                        {% endfor %}
                    </ul>

                    {% csrf_token %}
                    {{ form|crispy }}
                </div>
                <div class="card-footer text-center">
                    <div class="control-group">
                        <div class="controls">
                            <input type="submit" class="btn btn-large btn-danger" value="{% trans "Cancel" %}"/>
                            <input type="submit" class="btn btn-large btn-primary" name="allow" value="{% trans "Authorize" %}"/>
                        </div>
                    </div>
                </div>
            </form>
        {% else %}
            <div class="card-body">
                <h2>{% trans "Error:" %} {{ error.error }}</h2>
                <p>{{ error.description }}</p>
            </div>
        {% endif %}
    </div>
{% endblock %}

{% block extrajavascript %}
    <script>
        {# Small hack to have the remove the allow checkbox and replace it with the button #}
        {# Django oauth toolkit does simply not render the wdiget since it is not hidden, and create directly the button #}
        document.getElementById('div_id_allow').parentElement.remove()
    </script>
{% endblock %}
