{#
/*
 * Spring Signage Ltd - http://www.springsignage.com
 * Copyright (C) 2015 Spring Signage Ltd
 * (${FILE_NAME})
 */

#}

{% extends "form-base.twig" %}
{% import "forms.twig" as forms %}

{% block formTitle %}
    {% trans "Edit Application" %}
{% endblock %}

{% block formButtons %}
    {% trans "Help" %}, XiboHelpRender("{{ help }}")
    {% trans "Cancel" %}, XiboDialogClose()
    {% trans "Save" %}, $("#applicationFormSubmit").submit()
{% endblock %}

{% block callBack %}copyFromSecretInput{% endblock %}

{% block formHtml %}
    <div class="row">
        <div class="col-md-12">
            <ul class="nav nav-tabs" role="tablist">
                <li class="active"><a href="#general" role="tab" data-toggle="tab"><span>{% trans "General" %}</span></a></li>
                <li><a href="#scopes" role="tab" data-toggle="tab"><span>{% trans "Permissions" %}</span></a></li>
            </ul>
            <form id="applicationFormSubmit" class="XiboForm form-horizontal" method="put" action="{{ urlFor("application.edit", {id: client.key}) }}">
                <div class="tab-content">
                    <div class="tab-pane active" id="general">
                        {% set title %}{% trans "Application Name" %}{% endset %}
                        {{ forms.input("name", title, client.name) }}

                        {% set title %}{% trans "Client Id" %}{% endset %}
                        {{ forms.disabled("clientId", title, client.key, "", "", "disabled") }}

                        {% set title %}{% trans "Client Secret" %}{% endset %}
                        {% set buttonTitle %}{% trans "Copy to Clipboard" %}{% endset %}
                        {{ forms.inputWithButton("clientSecret", title, client.secret, "", "", "readonly='readonly'", "", "copy-button", buttonTitle, "button", "") }}
                                                    
                        {% set title %}{% trans "Reset Secret?" %}{% endset %}
                        {% set helpText %}{% trans "Reset your client secret to prevent access from any existing application." %}{% endset %}
                        {{ forms.checkbox("resetKeys", title, 0, helpText) }}

                        {% set title %}{% trans "Authorization Code?" %}{% endset %}
                        {% set helpText %}{% trans "Allow the Authorization Code Grant for this Client?" %}{% endset %}
                        {{ forms.checkbox("authCode", title, client.authCode, helpText) }}

                        {% set title %}{% trans "Client Credentials?" %}{% endset %}
                        {% set helpText %}{% trans "Allow the Client Credentials Grant for this Client?" %}{% endset %}
                        {{ forms.checkbox("clientCredentials", title, client.clientCredentials, helpText) }}

                        {% set title %}{% trans "Redirect URI" %}{% endset %}
                        {% set helpText %}{% trans "White listed redirect URI's that will be allowed, only application for Authorization Code Grants" %}{% endset %}
                        {{ forms.input("redirectUri[]", title, "", helpText) }}
                    </div>
                    <div class="tab-pane" id="scopes">
                        {% set message %}{% trans "Select permissions to grant to this application (scopes)." %}{% endset %}
                        {{ forms.message(message) }}

                        {% for url in client.redirectUris %}
                            {% set title %}{% trans "Redirect URI" %}{% endset %}
                            {{ forms.input("redirectUri[]", title, url.redirectUri) }}
                        {% endfor %}

                        {% for scope in scopes %}
                            {% set title %}{{ scope.description }}{% endset %}
                            {% set id %}scope_{{ scope.id }}{% endset %}
                            {{ forms.checkbox(id, title, scope.selected) }}
                        {% endfor %}

                        {% set title %}{% trans "Owner" %}{% endset %}
                        {% set helpText %}{% trans "Set the owner of this Application. If you are not an admin you will not be able to reverse this action." %}{% endset %}
                        {% set users = [{userId: null, user: ""}]|merge(users) %}
                        {{ forms.dropdown("userId", "single", title, "", users, "userId", "userName", helpText) }}
                    </div>
                </div>
            </form>
        </div>
    </div>
{% endblock %}