{% extends 'GeekhubResourceBundle::layout.html.twig' %}

{% block content %}

    {{ include('GeekhubDreamBundle:includes:homePageSlider.html.twig', {completedDreams: completedDreams}) }}

    <div>
        <div id="added_success"></div>

        <div id="dreams"></div>
    </div>

{% endblock %}
{% block javascript %}
    {{ parent() }}
    <script>
        var loadDreams = function (startIndex) {
            var path = Routing.generate('api_v1_get_dreams');
            $.get(path, {offset: startIndex, statuses: ['collecting-resources', 'implementing', 'success'], orderBy: 'createdAt' })
                    .done(function (response) {
                        $(response).appendTo($('#dreams')).hide().fadeIn(300);
                    })
                    .error(function (msg) {
                        console.log(msg);
                    }
            );
        };

        $(document).ready(function() {
            var startIndex = 0;
            loadDreams(startIndex);

            $(window).scroll(function() {
                if($(window).height() + $(window).scrollTop() >= $(document).height()) {
                    startIndex += 8;
                    loadDreams(startIndex);
                    console.log('end document scrolled');
                }
            });
        });

    </script>

{% endblock %}

{% extends 'GeekhubResourceBundle::layout.html.twig' %}

{% block content %}

    {{ include('GeekhubDreamBundle:includes:homePageSlider.html.twig', {completedDreams: completedDreams}) }}

    <div>
        <div id="added_success"></div>

        <div id="dreams"></div>
    </div>

{% endblock %}
{% block javascript %}
    {{ parent() }}
    <script>
        var loadDreams = function (startIndex) {
            var path = Routing.generate('api_v1_get_dreams');
            $.get(path, {offset: startIndex, statuses: ['collecting-resources', 'implementing', 'success'], orderBy: 'favoritesCount' })
                    .done(function (response) {
                        $(response).appendTo($('#dreams')).hide().fadeIn(300);
                    })
                    .error(function (msg) {
                        console.log(msg);
                    }
            );
        };

        $(document).ready(function() {
            var startIndex = 0;
            loadDreams(startIndex);

            $(window).scroll(function() {
                if($(window).height() + $(window).scrollTop() >= $(document).height()) {
                    startIndex += 8;
                    loadDreams(startIndex);
                    console.log('end document scrolled');
                }
            });
        });

    </script>

{% endblock %}

Sort dreams at homepage by favoriteCout
Sort dreams at homepage by favoriteCout
