{% extends "MuzichHomeBundle::layout.html.twig" %}

{% if login is not defined %}
  {% set login = false %}
{% endif %}

{% block title %}{{ 'title.home'|trans({}, 'userui') }}{% endblock %}
{% block mainbox_classes %}mainbox_margintop mainbox_nopadding{% endblock %}

{% block content %}

  {% include 'MuzichCoreBundle:Component:element_add_buttons.html.twig' %}
  {% include 'MuzichHomeBundle:Component:filter_menu.html.twig' %}
  
  {% include 'MuzichCoreBundle:Component:element_add_box.html.twig' with {
    'box_title': 'home.add_element_box.title'|trans({}, 'navigationui')
  } %}

  {% if app.user %}
    {% if app.user.wantSeeHelp('home') %}
      {% include 'MuzichCoreBundle:HelpTour:home.html.twig' with {'start' : true} %}
    {% endif %}
  {% else %}
    {% include 'MuzichCoreBundle:HelpTour:home.html.twig' with {'start' : false} %}
  {% endif %}

  {# TODO: Cette partie de javascript ne devra plus exister après la réecriture du code javascript #}
  {% if from_url is defined %}
  {% if from_url %}
    <script type="text/javascript">
      $(document).ready(function(){
        $('#element_add_box').slideDown("slow");
        $('#element_add_link').hide();
        $('form[name="search"]').slideUp();
        $('img#form_add_loader').show();
        $('input#element_add_url').val("{{ from_url }}");
        $('form[name="add"]').submit();
      });
    </script>
  {% endif %}
  {% endif %}
    
  {% if login %}
    <script type="text/javascript">
      $(document).ready(function(){
        {% if not email_token %}
          open_connection_or_subscription_window(true);
        {% else %}
          open_connection_or_subscription_window(true, {"email_confirmation_token":"{{ email_token }}"});
        {% endif %}
      });
    </script>
  {% endif %}

  <div class="top_tools">
  
    <div class="search_tools">
      <form name="{{ search_form_name }}" action="{{ path('search_elements', {'context':'home'}) }}" method="post" {{ form_enctype(search_form) }}>
        
        {% include "MuzichCoreBundle:SearchElement:form.html.twig" with { 
          'form_name'               : search_form_name,
          'search_tags'             : search_tags_id,
          'display_help_notags'     : true
        } %}
        
        <input class="main button" type="submit" value="{{ 'filter.submit'|trans({}, 'userui') }}"/>
        
      </form>
    </div>
  
  </div>

  <div id="elements_list">
  {% include "MuzichCoreBundle:SearchElement:default.html.twig" with {
    'noelements_filter'    : true,
    'display_new_elements' : true,
    'display_autoplay'     : true,
    'autoplay_context'     : 'home'
  }%}
  </div>
  
  {% if elements|length %}
    {% include "MuzichCoreBundle:SearchElement:more_button.html.twig" with {
      'more_path'           : path('search_elements', {'context':'home'})
    }%}
  {% endif %}
  
{% endblock %}