{#

This file is part of the Sonata package.

(c) Thomas Rabaix <thomas.rabaix@sonata-project.org>

For the full copyright and license information, please view the LICENSE
file that was distributed with this source code.

#}

{% extends sonata_block.templates.block_base %}

{% block block %}

    <table class="table table-condensed sonata-ba-list">

        {% for group in groups %}
            {% set display = (group.roles is empty or is_granted('ROLE_SUPER_ADMIN') ) %}
            {% for role in group.roles if not display %}
                {% set display = is_granted(role)%}
            {% endfor %}

            {% if display %}
                <tr>
                    <td colspan="3" style="background: none repeat scroll 0 0 #F7F7F7;"><strong>{{ group.label|trans({}, group.label_catalogue) }}</strong></td>
                </tr>

                {% for admin in group.items %}
                    {% if admin.hasroute('create') and admin.isGranted('CREATE') or admin.hasroute('list') and admin.isGranted('LIST') %}
                        <tr>
                            <td class="sonata-ba-list-label">
                                {{ admin.label|trans({}, admin.translationdomain) }}
                            </td>
                            <td>
                                <div class="btn-group">
                                    {% if admin.hasroute('create') and admin.isGranted('CREATE') %}
                                        {% if admin.subClasses is empty %}
                                            <a class="btn btn-link" href="{{ admin.generateUrl('create')}}">
                                                <i class="icon-plus"></i>
                                                {% trans from 'SonataAdminBundle' %}link_add{% endtrans %}
                                            </a>
                                        {% else %}
                                            <a class="btn btn-link dropdown-toggle" data-toggle="dropdown" href="#">
                                                <i class="icon-plus"></i>
                                                {% trans from 'SonataAdminBundle' %}link_add{% endtrans %}
                                                <span class="caret"></span>
                                            </a>
                                            <ul class="dropdown-menu">
                                                {% for subclass in admin.subclasses|keys %}
                                                    <li>
                                                        <a href="{{ admin.generateUrl('create', {'subclass': subclass}) }}">{{ subclass }}</a>
                                                    </li>
                                                {% endfor %}
                                            </ul>
                                        {% endif %}
                                    {% endif %}
                                    {% if admin.hasroute('list') and admin.isGranted('LIST') %}
                                        <a class="btn btn-link" href="{{ admin.generateUrl('list')}}">
                                            <i class="icon-list"></i>
                                            {% trans from 'SonataAdminBundle' %}link_list{% endtrans -%}
                                        </a>
                                    {% endif %}
                                </div>
                            </td>
                        </tr>
                    {% endif %}
                {% endfor %}

            {% endif %}
        {% endfor %}
    </table>
{% endblock %}
