{% extends 'layout.twig' %}

{% block body %}

	<div class="contenu clearfix"  id="Consultation">
	
		{% include '@Consultation/SaisieReponses/block_entete.twig' %}
		
    	<div style="display:flex; margin-top:10px;">
    	
    		<div id="divTreeview" class="colonne3" style="min-width:450px;">
                <div id="treeview" class="treeview">
                </div>
    		</div>
    	

	    	<div id="questionnaire" class="colonneComplement">
                <div class="panel panel-default">
                    <div class="panel-body">
                        <div class="slide-container">
                            <div class="list-group listGroupV2" id="mg-multisidetabs">
                            	{% for theme in listeTheme %}
                            		{{ buildTreeFormQuestionnaire(theme,idFrs, idRep, typeFG, CV, trad, canEdit) }}
                            	{% endfor %}
                            </div><!-- ./ end list-group -->
                        </div><!-- ./ end slide-container -->
                    </div><!-- ./ end panel-body -->
                </div><!-- ./ end panel panel-default-->

        	</div>
    	
    	</div>
    	<script>
        	$('#treeview').jstree({
        		'core' : {
        			"themes":{
        				"theme" : "default",
        				"dots" : false,
        				"icons":false,
        				"variant" : "large"
        			},
        			'data' :  {{ tree | json }}
        		},
        	}).bind("loaded.jstree", function(event, data) {$(this).jstree("open_all");});
        	
			var erreurFormulaire = 0;
        	function updateReponse(params, modeErreur)
        	{	
				if(modeErreur==true){return '';}
        		/*if(modeErreur==true){ 
					$('#validerButton').attr('onclick', "popupConfirmation('{{ path('Ajax.Erreur.popupInformation') }}', '', '', '{{ 'Vous devez résoudre les erreurs dans le questionnaire.' |trad }}');");

					if ($('#input_'+codeChps).data('error') != 1) {
						erreurFormulaire++;
						$('#input_'+codeChps).data('error', 1);
					}
					return '';
				} else {
					$('#input_'+codeChps).data('error', 0);
					erreurFormulaire--;
				}
				
				if (erreurFormulaire == 0 ) {
					$('#validerButton').attr('onclick', "popupConfirmation('{{ path('Ajax.Erreur.popupConfirmationSuppresion') }}', '', '{{ path('Consultation.SaisieReponses.validateReponse', {idAO: idAO, typeFG:typeFG, idFrs:idFrs, idRep:idRep, CV:CV}) }}', '{{ 'Une fois validée, la réponse ne sera plus modifiable. Voulez-vous confirmer la validation de la réponse ?' | trad }}', 'redirect')");
				}*/

                var inputId = params.name + '-' + params.theme + '-' + params.question;
        		
        		if(inputId.indexOf('NAPPL')===0) {
        			if($('#input_'+inputId).is(':checked')){
        				var value = 1;
        			} else {
        				var value = 0;
        			}
        		} else {
        			var value = $('#input_'+inputId).val();        		
        		}
    			
    			activeLoader();
                $.ajax({
                    dataType : 'html',
                    url: '{{ path('Consultation.SaisieReponsesQst.ajaxUpdateValue', {idAO:idAO, typeFG:typeFG, idFrs:idFrs, idRep:idRep,CV:CV}) }}',
                    data: {chps:params, value:value},
                    type: "POST",
                    success: function(result){
                        desactiveLoader();
                    }
    			});
        	}
        	
            $(document).on('click', '#treeview .jstree-anchor', function(e) {
        
                var anchorId = $(this).parent().attr('id');
                var id = 'zone'+anchorId.replace('_anchor', '');
				
                $(window).scrollTop($('#'+id).offset().top);
            });

    	</script>
	</div>
	
	<style>	
		#questionnaire .list-group-item {
			border: 0px !important;
		}
		
		#questionnaire label{
			width:89%;
		}
	</style>
{% endblock %}