{% extends 'base.html.twig' %}

{% block pagewrapper %}
{{ form_start(form) }}
    <h1 class="page-title">
        Nouvelle Page
    </h1>
    
    <p>
        {{ form_widget(form.submit) }}
        {% if access=="config" %}
            <a class="btn btn-secondary" href="{{ path('app_portal_config_page') }}">Annuler</a>
        {% else %}
            <a class="btn btn-secondary" href="{{ path('app_core_home') }}">Annuler</a>
        {% endif %}
    </p>

    {% if app.session.flashbag.has('error') %}
        <div class='alert alert-danger' style='margin: 5px 0px'>
            <strong>Erreur</strong><br>
            {% for flashMessage in app.session.flashbag.get('error') %}
                {{ flashMessage }}<br>
            {% endfor %}
        </div>
    {% endif %}

    {% if app.session.flashbag.has('notice') %}
        <div class='alert alert-info' style='margin: 5px 0px'>
            <strong>Information</strong><br>
            {% for flashMessage in app.session.flashbag.get('notice') %}
                {{ flashMessage }}<br>
            {% endfor %}
        </div>
    {% endif %}

    <div class="card">
        <div class="card-header">
            <i class="fa fa-pencil-alt fa-fw"></i> Informations
        </div>

        <div class="card-body">
            {{ form_row(form.name) }}
            {{ form_row(form.pagecategory) }}
            {{ form_row(form.usage) }}
            {% if form.user is defined %}
                {{ form_row(form.user) }}
            {% endif %}

            <div id="pagegroup">{{ form_row(form.page) }}</div>
            <div id="groupworkgroup">{{ form_row(form.groups) }}</div>
            {{ form_row(form.roworder) }}
            {{ form_row(form.fonticon) }}
            {{ form_row(form.maxwidth) }}
        </div>
    </div>
{{ form_end(form) }}
{% endblock %}

{% block localjavascript %}
    $('document').ready(function(){
        hideshow();
    });

    $(document.body).on("change","#page_submit_pagecategory",function(){
        hideshow();
    });

    $(document.body).on("change","#page_submit_usage",function(){
        hideshow();
    });

    function hideshow() {
        if($("#page_submit_pagecategory").val()==2)
            $("#pagegroup").show();
        else {
            $("#pagegroup").hide();
        }

        if($("#page_submit_usage").val()=="group")
            $("#groupworkgroup").show();
        else {
            $("#groupworkgroup").hide();
        }        
    }       

{% endblock %}