{% extends 'Admin/layout.html.twig' %}
{%- import 'Admin/Form/macros.html.twig' as m -%}

{% block javascripts %}
    <script>
        $( function() {
            $("#form_search").autocomplete({
                source: "{{  path('admin_operation_pee_search_teacher') }}",
                minLength: 2,
                select: function( event, ui ) {
                    $('#form_id').val(ui.item.id);
                }
            });

            $("#form_search").on('keypress keyup', function() {
                $('#form_id').val('');
            });

            $('#form-operationpeeaddteacher').on('submit', function(){
                if ($('#form_id').val() == '') {
                    alert('Professeur inconnu');
                    return false;
                }
            });
        } );
    </script>
{% endblock javascripts %}

{% block body %}
    <header>
        <ul class="btns">
            <li class="btns-back">
                {{ m.step_back() }}
            </li>
        </ul>

        <h1>Ajouter un professeur à l'opération PEE <em>{{ ope.company }} {{ ope.site }}</em> {{
            ope.dateVisite is not null
            ? 'du ' ~ ope.dateVisite|date('d/m/Y')
            : 'sentence.date.operationPEE.missing'|trans({}, 'sentence')|lower
            }}</h1>
    </header>

        <div class="left" style="width:30%;">
            <h2>Professeur existant</h2>
            {{ form_start(formAdd, {'attr':{'id':'form-operationpeeaddteacher'}}) }}
            {{ form_row(formAdd.search) }}
            <br/>
                <button class="btn btn-save" form="form-operationpeeaddteacher">
                    {{ 'action.add.teacher.choose'|trans({}, 'action') }}
                </button>
            {{ form_end(formAdd) }}
        </div>

        <div class="left" style="width:50%;">
            {{ form_start(form, {'attr':{'id':'form-operationpeecreateteacher'}}) }}
                <h2>Nouveau professeur</h2>
                {{ form_row(form.lastname) }}
                {{ form_row(form.firstname) }}
                {{ form_row(form.email) }}
                {{ form_row(form.phone) }}
                <button class="btn btn-save" form="form-operationpeecreateteacher">
                    {{ 'action.add.teacher.save'|trans({}, 'action') }}
                </button>
            {{ form_end(form) }}
        </div>
{% endblock %}
