{% extends '@CadolesCore/base.html.twig' %}

{% block pagewrapper %}
{{ form_start(form) }}
    <h1 class="page-header">
    {% if mode=="update" %}
    Modification Article de Blog
    {% elseif mode=="submit" %}
    Création Article de Blog
    {% endif %}
    </h1>

    {{ form_widget(form.submit) }}
    {% if mode=="update" %}
    <a class="btn btn-default" href='{{ path('cadoles_portal_'~access~'_blogarticle_view',{'id':entity.id}) }}'>Annuler</a>
    {% elseif mode=="submit" %}
        {% set blogid=0 %}
        {%if entity.blog.id is defined %}
            {% set blogid=entity.blog.id %}
        {%endif%}
    
        {% if pageid is empty %}
            <a class="btn btn-default" href='{{ path('cadoles_portal_'~access~'_blog_view',{'id':blogid})}}'>Annuler</a>
        {% else %}
            <a class="btn btn-default" href="{{path('cadoles_core_home',{id:pageid})}}" target="_top">Annuler</a>
        {% endif %}
    {% endif %}

    {% if mode=="update" %}
    <a href={{ path('cadoles_portal_'~access~'_blogarticle_delete',{'id':entity.id}) }}
        class="btn btn-danger pull-right"
        data-method="delete" data-csrf="_token:{{ 'csrf' }}"
        data-confirm="Êtes-vous sûr de vouloir supprimer cet article ?">
          Supprimer
    </a>
    {% endif %}

    <br><br>

    {% 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="form-group row clearfix">
        <div class="col-md-8">
            {{ form_row(form.name) }}
            {{ form_row(form.blog) }}
            {{ form_row(form.fgcomment) }}
            {{ form_row(form.description) }}
        </div>
        
        <div class="col-md-4">
            <div style="margin:10px auto;">
            <a class="btn btn-info" style="width:100%" data-toggle="modal" data-target="#mymodal" onClick="ModalLoad('mymodal','Image à la une','{{ path('cadoles_portal_'~access~'_blogarticle_image') }}');" title='Ajouter un Header'>Téléchargez une image à la une</a>
            <img id="blogarticle_image_img" src="/{{ alias }}/{{ entity.image }}" style="width:100%;margin:auto;display:block;">
            {{ form_widget(form.image) }}
            </div>     
        </div>
    </div>

  
{{ form_end(form) }}
{% endblock %}

{% block localjavascript %}
    $('#mymodal').on('hidden.bs.modal', function () {
        var imgSrc = $("#blogarticle_image_img").attr('src');
        $("#blogarticle_image_img").attr('src',imgSrc);
    }); 
{% endblock %}
