
{% extends '@ajax-layout/layout.twig' %}

{% block body %}
<script>

function disableFieldByCheckbox ()
{
	  if($('#autorisation').is(':checked'))
	  {
		  $('#input_MNTPREMIN').removeAttr("disabled");
		  $('#input_MNTPREMAX').removeAttr("disabled");
		  $('#typecontrole').removeAttr("disabled");
		
	  }
	  else
	  {
		  $('#input_MNTPREMIN').attr("disabled", "disabled");
		  $('#input_MNTPREMAX').attr("disabled", "disabled");
		  $('#typecontrole').attr("disabled", "disabled");
		  
	  }
}
{% if findSocieteAutorise (marche, societes.CODESOC) != 1 %} 
	$('#input_MNTPREMIN').attr("disabled", "disabled");
	$('#input_MNTPREMAX').attr("disabled", "disabled");
	$('#typecontrole').attr("disabled", "disabled");
{% endif %} 

$("#send").click(function(e) {

	var MNTPREMIN = '', MNTPREMAX = '', typecontrole = '', i = 0, autorise = '' ;
	
    if(!$('#input_MNTPREMIN').is(':disabled'))
    {
        i++;
    	MNTPREMIN = $('#input_MNTPREMIN').val();
    }

    if(!$('#input_MNTPREMAX').is(':disabled'))
    {
        i++;
    	MNTPREMAX = $('#input_MNTPREMAX').val();
    }

    if(!$('#typecontrole').is(':disabled'))
    {
        i++;
    	typecontrole = $('#typecontrole').val();
    }

    //sendForm = $('#sendForm').val();
    
    if(i==0)
    	autorise = '0';
    else
    	autorise = '1';

	i = 0;

	if ($('#input_autorisation').is(":checked"))
    {
 		autorise = 1;
    }
    else
    {
       	autorise = 0;
    }
	
    $.ajax({
    	url : '{{ path('Contrat.societe.modifierSociete', {'codemarch' : marche,'codeste' : codeste }) }}',
        type: 'POST',
	  	dataType : 'HTML',
        data: {autorise : autorise, MNTPREMIN : MNTPREMIN, MNTPREMAX : MNTPREMAX , typecontrole : typecontrole},
        success: function (data) {
			
			if(data =='')
			{
			    $.ajax({
			        url: '{{ path('Contrat.societe.index', {'id' : marche}) }}',
			        type: 'POST',
			        dataType: 'html',
			        success: function (htmlData) {
			            var result = $('<div />').append(htmlData).find('#societes_autorisees').html();
			            $('#societes_autorisees').html(result);
			            desactivePopup(); 
			        }
			    });
		            
				desactivePopup();
			}
			else
			{

/* 				$('#message_erreur_popup p').html(data);
				$('#message_erreur_popup').show(); */
			}
				
			
        }
    });
});


</script>
<div id="message_erreur_popup" class="error displayNone clearfix" >
	<p></p>
</div>
 
<div class="modal-body clearfix">
    <form method="post" name="sendform" id="sendform" class="bg_form padding_form border_form">

    	<div class="colonne2">
        	<div class="row">
        	{% if findSocieteAutorise (marche, societes.CODESOC) == 1 %}
			 	 {{ inputSwitch('Autorisé ?' | trad,'autorisation', 1) }}
			{% endif %}
			{% if findSocieteAutorise (marche, societes.CODESOC) == 0 %}
				{{ inputSwitch('Autorisé ?' | trad,'autorisation', 0) }}
			{% endif %}
        	</div>
        	<div class="row">
        		<label>{{'Type de contrôle' | trad}} :</label>

        		<select name="typecontrole" id="typecontrole" class="form-control">
        			<option > {{ post.MNTPREMIN }}</option>
        			<option value=" "{% if societes.TYPCTRBUD == ' ' %} selected {% endif %}>{{'Pas de contrôle' | trad }}</option>
        			<option value="B"{% if societes.TYPCTRBUD == 'B' %} selected {% endif %}>{{'Bloquant' | trad }}</option>
        			<option value="N"{% if societes.TYPCTRBUD == 'N' %} selected {% endif %}>{{'Non Bloquant' | trad }}</option>
        		</select>

    		</div>
    	</div>
    	<div class="colonne2 last">
        	<div class="row">
        		<label>{{'Montant min' | trad }} :</label>
        		{{ inputText('', 'MNTPREMIN',  societes.MNTPREMIN | prix, '', path('Ajax.validator.integer'), "{'sizeMin' : '0', 'sizeMax' : '12'}" )}} 
        		<span class="input-group-addon"> {{'EUR' | trad }}</span>
    		</div>
        	<div class="row">
        		<label>{{'Montant max' | trad }} :</label>
        		{{ inputText('', 'MNTPREMAX',  societes.MNTPREMAX | prix , '', path('Ajax.validator.integer'), "{'sizeMin' : '0', 'sizeMax' : '12'}" )}} 
        		<span class="input-group-addon"> {{'EUR' | trad }}</span>
    		</div>
		</div>

    
    <div class="modal-footer clearfix">
			
         <button type="button" id="send" class="button principal button_right" >{{'Valider' | trad}}</button>
         <button type="button" class="button secondaire button_right" onClick ='desactivePopup()' data-dismiss="modal">{{'Annuler' | trad }}</button>
         
    </div>
    </form>
</div>

{% endblock %}