{% extends "SsoBackendBundle:token:base.html.twig" %}
{% block title %}
    LifeStyle Object
{% endblock %}

{% block body %}
    <h2>Available Object</h2>
    <div class="row">
        <div class="col-md-12 col-ld-12">
            <a class="btn btn-primary dropdown-toggle pull-left" data-toggle="collapse" data-target="#filters">
                show filter
                <span class="caret"></span>
            </a>
            <a class="btn btn-danger pull-right" id="deleteAll"
               href="{{ path('_admin_backend_webservice_object_delete_all') }}">
                !!! delete all objects !!!
            </a>
            <script>
                $(document).ready(function () {
                    $("#deleteAll").on("click", function (e) {
                        var link = this;

                        e.preventDefault();

                        $("<div>Are you sure you want to continue?</div>").dialog({
                            buttons: {
                                "Ok": function () {
                                    window.location = link.href;
                                },
                                "Cancel": function () {
                                    $(this).dialog("close");
                                }
                            }
                        });
                    });
                });

            </script>
        </div>
        <div class="col-md-12 col-ld-12">
            <div id="filters" class="collapse">
                <form class="well" method="get" action="">
                    {{ form_rest(form) }}
                    <p>
                        <button class="btn btn-primary" type="submit" name="filter_action"
                                value="filter">{% trans %}btn.filter{% endtrans %}</button>
                        <button id="reset" class="btn btn-danger" type="submit" name="filter_action"
                                value="reset">{% trans %}btn.reset{% endtrans %}</button>
                    </p>
                </form>
            </div>
        </div>
    </div>
    <hr/>
    <div class="row">
        <div class="col-md-12 col-lg-12">
            <div style="font-size: 20px;margin-bottom: 20px;" class="pull-right">
                <span class="label label-success label-as-badge">count: {{ pagination.getTotalItemCount }}</span>
            </div>
            <table class="table table-striped table-bordered table-condensed">
                <thead>
                <tr>
                    <th {% if pagination.isSorted('a.guid') %} class="sorted"{% endif %}>{{ knp_pagination_sortable(pagination, 'Guid', 'a.guid') }}</th>
                    <th>Reference Id</th>
                    <th {% if pagination.isSorted('a.name') %} class="sorted"{% endif %}>{{ knp_pagination_sortable(pagination, 'Name', 'a.name') }}</th>
                    <th>Type</th>
                    <th>Parent</th>
                    <th>Attribute Groups</th>
                    <th>Actions</th>
                </tr>
                </thead>
                <tbody>
                {% for entity in pagination %}
                    <tr>
                        <td>
                            <a class="tt" data-toggle="tooltip" data-placement="top" title="{{ entity.guid }}" href="#"><span
                                        class="cutstring">{{ entity.guid }}</span></a>
                        </td>
                        <td>
                            {% if entity.referenceId is defined %}
                                {{ entity.referenceId }}
                            {% endif %}
                        </td>
                        <td>
                            {{ entity.name }}
                        </td>
                        <td>
                            <ul class="list-group" style="margin:0;">
                                <li class="list-group-item list-group-item-danger">
                                    {{ entity.type.name }}
                                </li>
                            </ul>
                        </td>
                        <td>
                            {% if entity.parent %}
                                <ul class="list-group">
                                    <li class="list-group-item list-group-item-warning">
                                        <div class="labelview">Name</div>
                                        {{ entity.parent.name }}&nbsp;
                                    </li>
                                    <li class="list-group-item list-group-item-warning">
                                        <div class="labelview">Type</div>
                                        {{ entity.parent.type.name }}
                                    </li>
                                </ul>
                            {% else %}
                                object has no parent
                            {% endif %}
                        </td>
                        <td>
                            <ul class="list-group" style="margin:0;">
                                {% for attributeGroup in entity.type.attributeGroups %}

                                    <li class="list-group-item list-group-item-info">
                                        {{ attributeGroup.name }}
                                    </li>

                                {% endfor %}
                            </ul>
                        </td>

                        <td>
                            <a class="btn btn-success btn-mini"
                               href="{{ path('_admin_backend_webservice_object_show', { 'objectId': entity.guid }) }}">
                                show
                            </a>&nbsp;
                            <a class="btn btn-danger"
                               href="{{ path('_admin_backend_webservice_object_edit', { 'objectId': entity.guid }) }}">
                                edit
                            </a>

                        </td>
                    </tr>
                {% endfor %}
                </tbody>
            </table>
        </div>

        <div class="col-md-12 col-ld-12">
            <div class="navigation">
                {{ knp_pagination_render(pagination) }}
            </div>
        </div>

        <div class="col-md-6 col-ld-6">
            <a class="btn btn-success likepaginator" href="{{ path('_admin_backend_webservice_object_new') }}">
                New Object
            </a>
        </div>

    </div>

    <script>
        $(function () {
            $(".tt").tooltip();
        });
    </script>
    <style>
        .labelview {
            float: left;
            font-weight: bold;
            margin-right: 15px;
            padding-left: 5px;
            text-align: right;
            width: 60px;
        }
    </style>
{% endblock %}