{% block toolbar %}
    <span class="dropdownButton">
        <div class="btn-group">
            <button id="selectCase" class="default_action btn btn-inverse answer_selector" data-action-name="select-toggle" data-state="default">&nbsp;</button>
            <button class="trigger btn btn-inverse dropdown-toggle" data-toggle="dropdown"><span class="caret"></span>
            </button>
            <ul class="dropdown-menu">
                <li>
                    <a class="answer_selector all_selector" data-action-name="select-all" data-state="default">
                        {{ 'reponses:: selectionner tout' | trans }}
                    </a>
                </li>
                <li class="divider"></li>
                <li>
                    <a class="answer_selector none_selector" data-action-name="unselect-all" data-state="true">
                        {{ 'reponses:: selectionner rien' | trans }}
                    </a>
                </li>
                <li class="divider"></li>
                <li>
                    <a class="answer_selector image_selector" data-action-name="select-type" data-state="default" data-type=".type-image">
                        {{ 'phraseanet::type:: images' | trans }}
                    </a>
                </li>
                <li class="divider"></li>
                <li>
                    <a class="answer_selector document_selector" data-action-name="select-type" data-state="default" data-type=".type-document">
                        {{ 'phraseanet::type:: documents' | trans }}
                    </a>
                </li>
                <li class="divider"></li>
                <li>
                    <a class="answer_selector video_selector" data-action-name="select-type" data-state="default" data-type=".type-video">
                        {{ 'phraseanet::type:: videos' | trans }}
                    </a>
                </li>
                <li class="divider"></li>
                <li>
                    <a class="answer_selector audio_selector" data-action-name="select-type" data-state="default" data-type=".type-audio">
                        {{ 'phraseanet::type:: audios' | trans }}
                    </a>
                </li>
            </ul>
        </div>
    </span>

    {% set menus = {
        'export': [
            {
                'class':'TOOL_disktt_btn',
                'icon':'/assets/common/images/icons/disktt_history.png',
                'label':'action : exporter' | trans },
            {
                'class':'TOOL_print_btn',
                'icon':'/assets/common/images/icons/print_history.png',
                'label':'action : print' | trans }
        ],
        'edit': [],
        'push': [],
        'tools': [],
        'delete': []
    } %}

    {# menu "edit" #}
    {% set m = [] %}
    {% if acl.has_right(constant('\\ACL::CANMODIFRECORD')) %}
        {% set m = m|merge([
            {
                'class':'TOOL_ppen_btn',
                'icon':'/assets/common/images/icons/ppen_history.png',
                'label':'action : editer' | trans },
            {
                'class':'TOOL_videoeditor_btn',
                'icon':'/assets/common/images/icons/icon-video-editor.png',
                'label':'prod::toolbar : video editor' | trans }
        ]) %}
    {% endif %}
    {% if acl.has_right(constant('\\\ACL::CHGSTATUS')) %}
        {% set m = m|merge([
            {
                'class':'TOOL_chgstatus_btn',
                'icon':'/assets/common/images/icons/chgstatus_history.png',
                'label':'action : status' | trans }
        ]) %}
    {% endif %}
    {% if acl.has_right(constant('\\ACL::CANDELETERECORD')) and acl.has_right(constant('\\ACL::CANADDRECORD')) %}
        {% set m = m|merge([
            {
                'class':'TOOL_chgcoll_btn',
                'icon':'/assets/common/images/icons/chgcoll_history.png',
                'label':'action : collection' | trans }
        ]) %}
    {% endif %}
    {% set menus = menus|merge({'edit' : m}) %}

    {# menu "push" #}
    {% set m = [] %}
    {% if acl.has_right(constant('\\ACL::CANPUSH')) %}
        {% set m = m|merge([
            {
                'class':'TOOL_pushdoc_btn',
                'icon':'/assets/common/images/icons/push16.png',
                'label':'action : push' | trans },
            {
                'class':'TOOL_feedback_btn',
                'icon':'/assets/common/images/icons/feedback16.png',
                'label':'Feedback' | trans }
        ]) %}
    {% endif %}
    {% if acl.has_right(constant('\\ACL::BAS_CHUPUB')) %}
        {% set m = m|merge([
            {
                'class':'TOOL_publish_btn',
                'icon':'/assets/common/images/icons/rss16.png',
                'label':'action : publier' | trans }
        ]) %}
    {% endif %}
    {% set menus = menus|merge({'push' : m}) %}

    {# menu "tools" #}
    {% if acl.has_right(constant('\\ACL::IMGTOOLS')) %}
        {% set menus = menus|merge({'tools' : [
            {
                'class':'TOOL_imgtools_btn',
                'icon':'/assets/common/images/icons/imgtools_history.png',
                'label':'action : outils' | trans }
        ]}) %}
    {% endif %}

    {# menu "delete" #}
    {% if acl.has_right(constant('\\ACL::CANDELETERECORD')) %}
        {% set menus = menus|merge({'delete' : [
            {
                'class':'TOOL_trash_btn',
                'icon':'/assets/common/images/icons/delete.png',
                'label':'action : supprimer' | trans }
        ]}) %}
    {% endif %}

    {# add plugins entries #}
    {% if plugins.actionbar is not empty %}
        {% for plugin in plugins.actionbar %}
            {% for k, menu in plugin.getActionBar() %}
                {% if k != '_context_' %}
                    {% set m = menus[k]|default([]) %}
                    {% for action in menu %}
                        {% set m = m|merge([{
                            'class':action.classes|default(''),
                            'icon':plugin_asset(plugin.PluginName, action.icon),
                            'label':action.label|trans({}, plugin.PluginLocale) }])
                        %}
                    {% endfor %}
                    {% set menus = menus|merge({(k) : m}) %}
                {% endif %}
            {% endfor %}
        {% endfor %}
    {% endif %}

    {# print #}
    {% for menu_entries in menus %}
        {% if menu_entries|length > 0 %}
            <span class="dropdownButton">
                <div class="btn-group">
            {% set menu_entry = menu_entries[0] %}
                    <button class="results_window btn btn-inverse {{ menu_entry.class }}" data-selection-source="search-result">
                        <img src="{{ menu_entry.icon }}"  class="btn-image"/>
                        {{ menu_entry.label }}
                    </button>
            {% set menu_entries = menu_entries|slice(1) %}
                    {% if menu_entries|length > 0 %}
                    <button class="trigger btn btn-inverse dropdown-toggle" data-toggle="dropdown"><span
                                    class="caret"></span></button>
                    <ul class="dropdown-menu">
                        {% for menu_entry in menu_entries %}
                        <li>
                            <a class="results_window {{ menu_entry.class }}" data-selection-source="search-result">
                                <img src="{{ menu_entry.icon }}" class="btn-image"/>
                                {{ menu_entry.label }}
                            </a>
                        </li>
                        {% endfor %}
                    </ul>
                    {% endif %}
                </div>
            </span>
        {% endif %}
    {% endfor %}

{% endblock %}

{% block toolbarJS %}
    {% if plugins.actionbar is not empty %}
        {% for pluginId, plugin in plugins.actionbar %}
            {% if plugin.getActionBarTemplate is defined %}
                {% set template = plugin.getActionBarTemplate() %}
                {% if template %}
                    {% include template with {'app': app, 'plugin_id': pluginId, 'plugin': plugin} only %}
                {% endif %}
            {% endif %}
        {% endfor %}
    {% endif %}
{% endblock %}