{% extends 'layout.twig' %}
     
{% block body %}

	<div class="contenu clearfix"  id="fournisseurs">
    	<h1>
        	{{ 'Paramétrage portail fournisseur' | trad }}
        </h1>
    
        {{ ariane() }}
        
        <div class="tab-content clearfix" style="margin-top:15px;">

        	{{ arianeSub() }}

        	<div class="padding15">
            	<form method="post" name="form_fournisseur" id="form_fournisseur" class="bg_form padding_form border_form clearfix" >
            
                    <fieldset class="scheduler-border" >
                    		<legend class="scheduler-border">{{ 'Demande de référencement' | trad }}</legend>
                    		<div class="colonne2">
                    			<div class="row">
                        			{{ inputAdvance('SWITCH',{
                        			    'titre' : 'Activer le captcha ?' | trad,
                        			    'name' : 'CAPTCHA_ACTIF',
                        			    'value' : post['CAPTCHA_ACTIF']??true,
                        			}) }}
                    			</div>
                			</div>
                    </fieldset>
                
                    <fieldset class="scheduler-border" >
                		<legend class="scheduler-border">{{ 'Création Fournisseur' | trad }}</legend>
                		
                		<div class="clearfix">

							<div class="row" style="display: flex;">
								<span class="title" style="width:20%;margin-top:0px;">{{ 'Initialisation' | trad }}</span>
    							{% for key, ligne in liste_PROSPECT_REFERENCE %}
    								<div style="width:20%;">
    									{{ inputAdvance('RADIO', {
    										'name' : 'PROSPECT_REFERENCE',
    										'value' : key,
    										'titre' : ligne,
    										'checked' : post.PROSPECT_REFERENCE == key ? 1 : 0,
    									}) }}
                            		</div style="width:20%;">
                              	{% endfor %}
							</div>
                        	<h4>{{ 'Visibilité des champs de la fiche fournisseur' | trad }}</h4>
                            <table class="table">
                              	<thead>
                                  	<tr>
                                  		<th>{{ 'Champs' | trad }}</th>
                                  		<th width="75px">{{ 'Visible ?' | trad }}</th>
                              		    <th width="90px">{{ 'Obligatoire ?' | trad }}</th>
                              		</tr>
                              	</thead>
                              	<tbody>
                              		{% for key,ChpsFrs in listeChpsFrs %}
                              			{% if key|slice(0, 6) == 'SPLIT_' %}
                              				{% set splitTR = key %}
                              				<tr class="recherche">
                              					<td><h4 style="margin-left:15px;">{{ ChpsFrs | trad }}</h4></td>
                              					<td>
                              						{% if regleAffichage[key]['VISI']=='O' %}
                                  						<input type="checkbox" name="{{ key }}" id="{{ key }}" onclick="checkoutVisible('{{ key }}', '{{ key }}');" class="form-control visible checkbox" {% if chpsVisibile[key]!='O' %}checked{% endif %} />
                          							{% endif %}
                          						</td>
                              					<td></td>
                              				</tr>
                              			{% else %}
                                  			<tr>
                                  				<td>{{ ChpsFrs | trad }}</td>
                                  				<td>
													{% if regleAffichage[key]['VISI']=='O' %}                            				
                                                        <input type="checkbox" name="{{ key }}" id="{{ key }}" onchange="lockInputObligatoire('{{ key }}');"class="form-control checkbox visible {{ splitTR }}" {% if chpsVisibile[key]!='O' %}checked{% endif %} />
                                  					{% endif %}
                                  				</td>
                                  				<td>
                                      				{% if regleAffichage[key]['OBLI']=='O' %}  
                                                        <input type="checkbox" name="obli_{{ key }}" id="obli_{{ key }}" class="form-control checkbox obli obli_{{ splitTR }}" {% if chpsObligatoire['obli_'~key]=='O' %}checked{% endif %} {% if chpsVisibile[key]=='O' %}disabled{% endif %}/>
                                  					{% endif %}
                                  				</td>
                                  			</tr>
                              			{% endif %}
                              		{% endfor %}
                              		{% if regleAffichage['SPLIT_ListChampsSup']['VISI']=='O' %}
                              			{% for cs in listeCS %}
                              				{% set key = 'CS_'~cs.NUM_FIX %}
                              				<tr>
                              					<td>{{ cs.NOM | trad }}</td>
                                  				<td>                            				
                                                    <input type="checkbox" name="{{ key }}" id="{{ key }}" onchange="lockInputObligatoire('{{ key }}');"class="form-control checkbox visible {{ splitTR }}" {% if cs.OXALINK_VIS| boolSql %}checked{% endif %} />
                                  				</td>
                                  				<td>
                                                    <input type="checkbox" name="obli_{{ key }}" id="obli_{{ key }}" class="form-control checkbox obli obli_CS" {% if cs.OXALINK_OBLIG | boolSql %}checked{% endif %} {% if cs.OXALINK_VIS | boolSql %}{% else %}disabled{% endif %}/>
                                  				</td>
                              				</tr>
                              			{% endfor %}
                              		{% endif %}
                              	</tbody>
                        	</table>
                    	</div>
                	</fieldset>
            	
            		<button class="button principal button_right" type="button" onClick="sendFormParametrage('{{ path('Parametrage.ParametrageOxalink.fournisseur') }}');">{{ 'Enregistrer' | trad }}</button>
            	
            	</form>
        	</div>
        	
        	<div id="theDiv">
        	</div>
        	
        </div>
        
    </div>
	<script>
		function sendFormParametrage(path)
		{			
			activeLoader();
			$.ajax({
				url: path,
				type: 'POST',
				dataType: 'html',
				data: $('#form_fournisseur').serialize(),
				success: function(result){
					desactiveLoader();
					alert("{{ 'Vos modifications sont prises en compte.' | trad }}");
				},
		        error: function (data){
					$("#modal-content").removeClass('modal_large modal_small').addClass('modal_small');
					$("#modal-body").html(data.responseText);
					activePopup ();
					desactiveLoader();
		        }
			});
		}

		function lockInputObligatoire(id)
		{

			if( $('input[name="'+id+'"]').is(':checked') )
			{
				$('input[name="obli_'+id+'"]').attr("disabled", false);
			} 
			else 
			{
				$('input[name="obli_'+id+'"]').attr("disabled", true);
				$('input[name="obli_'+id+'"]').attr("checked", false);
			}
		}

 		function checkoutObli(id, idBox)
		{
			idVisible = id.substr();

			$("."+id).each(function() 
			{
				idVisible = this.id.substr(5);

				if( $('input[name="'+idVisible+'"]').is(':checked') || this.id.substr(0,10)=='all2SPLIT_')
				{
					if ($("#"+idBox).is(':checked')) {
						$(this).prop('checked', true);
					}
					else
					{
						$(this).prop('checked', false);
						$(this).attr("disabled", false);
					}
				}
			});				
		}
	
		function checkoutVisible(id, idBox)
		{
			if ($("#"+idBox).is(':checked')) {
				$("."+id).prop('checked', true);
				$("."+id).change();
				$("."+id).attr("disabled", false);
			}
			else
			{
				$("."+id).prop('checked', false);
				$("."+id).change();
				$("."+id).attr("disabled", true);
			}
		}
    </script>
{% endblock %}