{% extends "SsoBackendBundle:WsApplication:base.html.twig" %}
{% block title %}{{ parent() }} - Show{% endblock %}

{% block body %}
    <h2>Application View</h2>
    <ul class="list-group">
        <li class="list-group-item">
            <div class="labelview">Id</div>
            {{ entity.id }}&nbsp;
        </li>
        <li class="list-group-item">
            <div class="labelview">Name</div>
            {{ entity.Name }}&nbsp;
        </li>
        <li class="list-group-item">
            <div class="labelview">Description</div>
            {{ entity.Description }}&nbsp;
        </li>
    </ul>
    <div class="clearfix">
        <div class="pull-right">
            {% if not showUsers %}
                <a class="btn btn-success show-users" data-toggle="button" data-hide-text="Hide Users"
                   href="{{ path('_admin_backend_webservice_user_application_user_show', { 'applicationId': entity.id }) }}">
                    Show Users
                </a>
            {% endif %}
            <a class="btn btn-default" href="{{ path('_admin_backend_webservice_application') }}">
                Back to the list
            </a>
        </div>

        <a class="btn btn-primary"
           href="{{ path('_admin_backend_webservice_application_edit', { 'applicationId': entity.id }) }}">
            Edit Application
        </a>

        {% include '@SsoBackend/WsApplication/delete-form-btn.html.twig' %}
    </div>

    <h3 style="clear:both">Application Roles</h3>
    {% if entity.Roles|length > 0 %}
        <ul class="list-group">
            {% for role in entity.Roles %}
                <li class="list-group-item">
                    {{ role.Name }}
                </li>
            {% endfor %}
        </ul>
    {% else %}
        <p>No roles defined yet.</p>
    {% endif %}

    <h3>Application Attributes</h3>
    {% if entity.Attributes|length > 0 %}
        <ul class="list-group">
            {% for attribute in entity.Attributes %}
                <li class="list-group-item">
                    {{ attribute.Name }}
                </li>
            {% endfor %}
        </ul>
    {% else %}
        <p>No attributes defined yet.</p>
    {% endif %}

    <div style="clear:both" id="userContainer"
         data-url="{{ path('_admin_backend_webservice_user_application_user_show', { 'applicationId': entity.id }) }}">
        {% if showUsers %}
            {{ render(controller('SsoBackendBundle:WsUserApplication:userShow', { 'applicationId': entity.id })) }}
        {% endif %}
    </div>

    <script>
        $(function () {
            $(".show-users").click(function () {
                var me = $(this),
                    container = $("#userContainer");
                if (me.hasClass("btn-pressed")) {
                    me.removeClass("btn-pressed").button("reset");
                    container.slideUp("slow", function () {
                        container.empty();
                    });
                } else {
                    me.addClass("btn-pressed").button("hide");
                    container.load(me.attr("href"), function () {
                        container.slideDown();
                    });
                }
                return false;
            });
            $("body").prepend($('<div id="messageContainer" />'));
        });
    </script>
{% endblock %}

{% block javascripts %}
    {{ parent() }}
    {% include '@SsoBackend/WsApplication/delete-form-js.html.twig' %}
{% endblock %}
