{% extends 'layout.twig' %}

{% block body %}
	<script> 
		{% if post.erreurValid or post.erreurValid != '' %}
			activePopupErreur("{{ path('Ajax.Erreur.popupErreurValid') }}", "{{ errorMessage }}", "{{ erreurValid | raw }}");
		{% endif %}
	</script>

    <!-- Modal content -->
    <div id="myModal" class="modal" tabindex="-1" role="dialog">

        <div class="modal-dialog" style="width:auto;height:auto;{% if application != 'Mobility' %}min-width:500px{% endif %}" role="document">
            <div id="modal-content" class="modal-content" style="z-index:99999;{% if application != 'Mobility' %}min-width: 600px;{% endif %}">
                <div class="modal-header">
                    <span class="modal-close">&times;</span>
                    <h3 id="modal-title"></h3>
                </div>
                <div id="modal-body" style="padding: 15px;z-index:99999">
                </div>
            </div>
        </div>
    </div>
    <div class="contenu clearfix" id="nouvelle-categorie">
        <h1>{{ title }}</h1>

        {{ ariane() }}

        <form method="post" name="new_group" id="new_group" class="box-form clearfix">
            <div class="full single">
                <div class="row">						
                    {{ inputAdvance('TEXT', {
                        'titre' : 'Libellé du nouveau groupe' | trad ~ ' :',
                        'name' : 'GROUPE',
                        'value' : GROUPE,
                        'pathValidator' : path('Ajax.validator.isStringAvecEspace'),
                        'paramsValidator' : "{'sizeMin' : '1', 'sizeMax' : '30'}",
                        'obligatoire' : true,
                    }) }}
                </div>
            </div>
			<div class="button_right full validation_modal">
				<button type="submit" class="button principal button_right" >{{'Valider' | trad}}</button>
                <a class="button secondaire" href="{{ path('Evaluation.GroupOfRaters.index', {mode: mode, id: id}) }}">{{ 'Annuler' | trad }}</a>
            </div>
        </form>
    </div>
    <script>
        $('#new_group').on('submit', function(e){
            e.preventDefault();
            var data = $('#new_group').serialize();
            activeLoader();
            $.ajax({
                url         : {{ path('Evaluation.GroupOfRaters.validate', {mode: mode, id: id, group: group }) | json }},
                type        : 'POST',
                dataType    : 'JSON',
                data        : data,
                success     : function (data) {
                    if (data.statut == 'O') {
                        desactiveLoader(); 
                        redirectJSWithPost(data.path);
                    } else {
                        desactiveLoader();
                        activePopupErreur('{{ path('Ajax.Erreur.popupErreurValid') }}', '',  data.erreur);
                    }
                }
            });
        })
    </script>

{% endblock %}
