add.ctp 3.33 KB

<div class="formules form">
    <?= $this->Form->create($formule) ?>
    <fieldset>
		<h2>
			<i class="icon-plus"></i> Ajouter une formule
		</h2>
      
	  
	  <?php
echo $this->Form->control('nommesure', [
    'label' => 'Nom mesure',
    'required' => 'required'
]);

echo $this->Form->control('symbole', [
    'label' => 'Symbole'
]);

echo $this->Form->control('unite', [
    'label' => 'Unité',
    'required' => 'required'
]);

echo $this->Form->control('nbVariable', [
    'label' => 'Nombre de variable(5 max.)',
    'default' => 1,
    'empty' => 1,
    'required' => 'required'
]);
?>
	  <div id="variable" style="display: none" required></div>
		<div id="derive" style="display: none" required></div>

	</fieldset>
    <?= $this->Form->submit(__('Valider')) ?>
    <?= $this->Form->end() ?>
</div>

<div class="actions">
	<?php
echo $this->element('menu');
echo $this->element('menu_form', [
    'pluralHumanName' => 'Formules'
]);
?>
</div>

<script type="text/javascript">



$(document).ready(function () {
		variable();
		$("#nbvariable").bind("focusout", function (event) {
				variable();
				});
			});

function sin(i){
			document.getElementById("derive"+i).value +="sin";
			document.getElementById("derive"+i).focus();
			}

function cos(i){
			document.getElementById("derive"+i).value +="cos";
			document.getElementById("derive"+i).focus();
			}
		
function variable(){
			var nbVariable = $("#nbvariable").val();
			
			if(nbVariable >=1 && nbVariable<=5){
			$("#variable").show();
			$("#derive").show();
			document.getElementById("derive").innerHTML="";
			document.getElementById("variable").innerHTML ="<table><tr><td> Variables </td><td>Symbole grandeur physique</td><td>Symbole unite mesure</td><td>nom Grandeur physique</td><td>Domaine de definition</td></tr></table>";
			for(var i=1;i<=nbVariable;i++){
			document.getElementById("variable").innerHTML +="<table><tr><td>X"+i+"</td><td><input type=\"control\" name=\"variables["+i+"][symbolegrandeurphysique]\" required></td><td><input type=\"control\" name=\"variables["+i+"][symboleunitemesure]\" required></td><td><input type=\"control\" name=\"variables["+i+"][nomgrandeurphysique]\" required></td><td><input type=\"control\" name=\"variables["+i+"][domainedef]\" placeholder=\"ex:[X;X[\" required></td></tr></table>";
			document.getElementById("derive").innerHTML += "<div class=\"button\"><input id=\"sin"+i+"\" onclick=\"sin("+i+")\" type=\"button\" value=\"sin\" style=\"width: 100px;\"><input id=\"cos"+i+"\" onclick=\"cos("+i+")\" type=\"button\" value=\"cos\" style=\"width: 100px;\"></div>";
			document.getElementById("derive").innerHTML += "<div class=\"input text required\"><label>Ecrire la dérivé partielle de F par rapport a la variable X"+i+"</label><input id=\"derive"+i+"\" type=\"control\" name=\"variables["+i+"][derivepartielle]\" required></div>";
			}
			i++;
			document.getElementById("derive").innerHTML += "<div class=\"button\"><input id=\"sin"+i+"\" onclick=\"sin("+i+")\" type=\"button\" value=\"sin\" style=\"width: 100px;\"><input id=\"cos"+i+"\" onclick=\"cos("+i+")\" type=\"button\" value=\"cos\" style=\"width: 100px;\"></div>";
			document.getElementById("derive").innerHTML += "<div class=\"input text required\"><label>Formule</label><input type=\"text\" name=\"formule\" id=\"derive"+i+"\" required></div>";
			}else{
			alert("erreur");
			
			
			}
				
		}

	

</script>