{% extends 'Admin/layout.html.twig' %}

{% block javascripts %}
    <script>
        $(function() {
            $('.fancybox').fancybox({
                'maxHeight': '90%',
                'padding': 0
            });

            function changePosition (type, liste) {
                $.ajax({
                    type: "POST",
                    url: "{{ path('module_ordering')}}",
                    data: {
                        type: type,
                        list: liste
                    },
                    cache: false
                });
            }

            $("#sortableLevel1").sortable({
                axis: "y",
                update: function(event, ui) {
                    var listlevel1 = new Array(),
                            classelement = ui.item.context.className,
                            iselement = classelement.indexOf('containerLevel1');

                    $('.level1').each(function () {
                        listlevel1.push($(this).attr('data-elementid'));
                    });

                    if (listlevel1.length!=0 && iselement!= -1) {
                        changePosition('Module', listlevel1);
                    }
                }
            });

            $("#sortableLevel1").disableSelection();
        });
    </script>
{% endblock %}

{% block body %}
    {{ knp_menu_render('actions_modules') }}

    {# Formulaire de recherche #}
    <form action="{{ path(app.request.attributes.get('_route'), app.request.attributes.get('_route_params')) }}" class="search-admin" method="get">
        <fieldset>
            <div class="search-fields">
                <p>
                    <label for="form_search_title">Titre</label>
                    <input id="form_search_title" name="title" type="text" value="{{ search_title }}">
                </p>
                {% if type == "all" %}
                <p>
                    <label for="form_search_type">{{ 'form.module.default.type.label'|trans([], 'form') }}</label>
                    <select id="form_search_type" name="mtype">
                        <option value="">- {{ 'form.module.default.type.all'|trans([], 'form') }} -</option>
                        {% for typename in types %}
                            <option value="{{ typename }}"{% if search_type == typename %} selected="selected"{% endif %}>
                                {{ ('word.module.' ~ typename)|trans([], 'word') }}
                            </option>
                        {% endfor %}
                    </select>
                </p>
                {% endif %}
                <p>
                    <label for="form_search_position">{{ 'form.module.default.position.label'|trans([], 'form') }}</label>
                    <select id="form_search_position" name="position">
                        <option value="">- {{ 'form.module.default.position.all'|trans([], 'form') }} -</option>
                        {% for position in positions %}
                            <option value="{{ position }}"{% if search_position == position %} selected="selected"{% endif %}>
                                {{ ('form.module.default.position.' ~ position)|trans([], 'form') }}
                            </option>
                        {% endfor %}
                    </select>
                </p>
            </div>
        </fieldset>
        <p>
            <input class="btn" type="submit" value="{{ 'action.search'|trans({}, 'action') }}" />
        </p>
    </form>

    <div class="listDomaines"{% if 'all' == type and search_title is empty and search_type is empty and search_position is empty %} id="sortableLevel1"{% endif %}>
        {% for module in modules %}
            <div class="containerLevel1 delete-element-container">
                <div class="level1 element {{ module.type }}" data-elementid="{{ module.id|raw }}">
                    <div>
                        <a href="{{ path('admin_module_edit', {'id':module.id}) }}">
                            {{ module.title }}
                            | <strong>{{ ('word.module.' ~ module.type)|trans([], 'word') }}</strong>
                            | <em>{{ ('form.module.default.position.' ~ module.position)|trans([], 'form') }}</em>
                        </a>
                    </div>
                    <ul class="element-actions">
                        <li>
                            <a class="edit" href="{{ path('admin_module_edit', {'id':module.id}) }}">
                                <span>{{ 'action.edit.label'|trans({}, 'action') }}</span>
                            </a>
                        </li>
                        <li>
                            <input
                                {% if module.isactive %} checked="checked"{% endif %}
                                class="input-active"
                                data-url="{{ path('admin_module_actif')}}"
                                type="checkbox"
                                value="{{ module.id }}"
                            />
                            <span class="checkbox"></span>
                        </li>
                            <li>
                                <a class="delete-element" href="{{ path('admin_module_delete', {'id':module.id}) }}">
                                    <span>{{ 'action.delete.label'|trans({}, 'action') }}</span>
                                </a>
                            </li>
                    </ul>
                </div>
            </div>
        {% endfor %}
    </div>

    {{ include('Admin/Paginator/pagination.html.twig', {pages:nb_pages}) }}
{% endblock %}
