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

{% block javascripts %}
    <script>
        $(function() {
            function changePosition (type, liste)
            {
                $.ajax({
                    type: "POST",
                    url: "{{ path('element_position')}}",
                    data: {
                        type: type,
                        list: liste
                    },
                    cache: false
                });
            }


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

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

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

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

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

    <div class="listDomaines" id="sortableLevel1">
        {% for slider in sliders %}
            <div class="containerLevel1 delete-element-container">
                <div class="level1 element slide" data-elementid="{{ slider.id|raw }}">
                    <div>
                        <a href="{{ path('admin_slider_edit', {'id':slider.id}) }}">
                            {{ slider.title }}
                        </a>
                    </div>

                    <ul class="element-actions">
                        <li>
                            <a class="edit" href="{{ path('admin_slider_edit', {'id':slider.id}) }}">
                                <span>{{ 'action.edit.label'|trans({}, 'action') }}</span>
                            </a>
                        </li>
                        <li>
                            <input
                                {% if slider.isactive %} checked="checked"{% endif %}
                                class="input-active"
                                data-type="Slider"
                                data-url="{{ path('element_actif')}}"
                                type="checkbox"
                                value="{{ slider.id }}"
                            />
                            <span class="checkbox"></span>
                        </li>
                        <li>
                            <a class="delete-element" href="{{ path('admin_menu_delete', {'id':slider.id, 'type':'Slider'}) }}">
                                <span>{{ 'action.delete.label'|trans({}, 'action') }}</span>
                            </a>
                        </li>
                    </ul>
                </div>
            </div>
        {% endfor %}
    </div>
{% endblock %}
