Commit 0da7988e authored by Raulin's avatar Raulin
parents 4f4db46f 2e5567c1
File added
...@@ -15,10 +15,12 @@ ...@@ -15,10 +15,12 @@
<div style="margin-right:100px"> <div style="margin-right:100px">
<table id="table_aliments" class="dataTable" style="color : #212529; "> <table id="table_aliments" class="dataTable" style="color : #212529; ">
<thead> <thead>
<tr> <tr>
<th>Aliment</th> <th>Aliment</th>
<th>Type</th> <th>Type</th>
<th>AjoutAuJournal</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
......
var selectedRow = null var selectedRow = null
function onFormSubmit() { function onFormSubmit() {
var formData = readFormData(); var formData = readFormData();
if (selectedRow == null) if (selectedRow == null)
...@@ -25,7 +26,9 @@ function insertNewRecord(data) { ...@@ -25,7 +26,9 @@ function insertNewRecord(data) {
cell2 = newRow.insertCell(1); cell2 = newRow.insertCell(1);
cell2.innerHTML = data.type; cell2.innerHTML = data.type;
cell3 = newRow.insertCell(2); cell3 = newRow.insertCell(2);
cell3.innerHTML = `<a onClick="onEdit(this)">Edit</a> cell3.innerHTML = `<a onClick="onAdd(this)" href="index.php?page=journal">Add</a>`;
cell4 = newRow.insertCell(3);
cell4.innerHTML = `<a onClick="onEdit(this)">Edit</a>
<a onClick="onDelete(this)">Delete</a>`; <a onClick="onDelete(this)">Delete</a>`;
} }
...@@ -35,6 +38,17 @@ function resetForm() { ...@@ -35,6 +38,17 @@ function resetForm() {
selectedRow = null; selectedRow = null;
} }
function onAdd(td){
selectedRow=td.parentElement.parentElement;
var table1 = document.getElementById("table_conso").getElementsByTagName('tbody')[0];
var newRow1 = table1.insertRow(table1.length);
cell1 = newRow1.insertCell(0);
cell1.innerHTML = selectedRow.cells[0].innerHTML;
cell2 = newRow1.insertCell(1);
cell2.innerHTML = selectedRow.cells[1].innerHTML;
}
function onEdit(td) { function onEdit(td) {
selectedRow = td.parentElement.parentElement; selectedRow = td.parentElement.parentElement;
document.getElementById("aliment").value = selectedRow.cells[0].innerHTML; document.getElementById("aliment").value = selectedRow.cells[0].innerHTML;
......
<head>
<meta charset="utf-8">
<script src="https://code.jquery.com/jquery-3.4.1.js" integrity="sha256-WpOohJOqMqqyKL9FccASB9O0KwACQJpFTUBLTYOVvVU=" crossorigin="anonymous"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.20/css/jquery.dataTables.css">
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.20/js/jquery.dataTables.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#table_conso').DataTable();
} );
</script>
</head>
<section id="journal" style="display : flex; flex-direction : row; ">
<div style="margin-right:100px">
<table id="table_conso" class="dataTable" style="color : #212529; ">
<thead>
<tr>
<th>Aliment</th>
<th>Type</th>
<th>Date</th>
</tr>
</thead>
<tbody id="t">
</tbody>
</table>
<script src="crud.js"></script>
</div>
\ No newline at end of file
<head>
<meta charset="utf-8">
<script src="https://code.jquery.com/jquery-3.4.1.js" integrity="sha256-WpOohJOqMqqyKL9FccASB9O0KwACQJpFTUBLTYOVvVU=" crossorigin="anonymous"></script>
<link rel="stylesheet" type="text/css" href="https://cdn.datatables.net/1.10.20/css/jquery.dataTables.css">
<script type="text/javascript" charset="utf8" src="https://cdn.datatables.net/1.10.20/js/jquery.dataTables.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$('#table_récap').DataTable();
} );
</script>
</head>
<section> <section>
<form id="info_form" action=".php" method="GET"> <table>
<tr>
<td>
<table id="table_récap" class="dataTable" style="color : #212529; ">
<thead>
<tr>
<th>Login</th>
<th>Âge</th>
<th>Poids</th>
<th>Taille(m)</th>
<th>Sexe</th>
<th>Niveau de sport</th>
<th>Besoins journaliers en calories</th>
<th>CRUD</th>
</tr>
</thead>
<tbody>
</tbody>
</table>
</td>
<td>
<form onsubmit="event.preventDefault();onFormSubmit();" autocomplete="off">
<table> <table>
<tr> <tr>
<th>Login :</th> <th>Login :</th>
<td><input type="text" name="login"></td> <td><input type="text" name="login" id="login"></td>
</tr> </tr>
<tr> <tr>
<th>Tranche d'âge :</th> <th>Âge :</th>
<td> <td>
<label> Moins de 40 ans <input type="text" name="age" id="age">
<input type="radio" name="radioAge" value="<40"> </td>
</label><br> </tr>
<label> Moins de 50 ans <tr>
<input type="radio" name="radioAge" value="<60"> <th>Poids(kg) :</th>
</label><br> <td>
<label> 60 ans et plus <input type="text" name="poids" id="poids">
<input type="radio" name="radioAge" value="60+"> </td>
</label> </tr>
<tr>
<th>Taille(m):</th>
<td>
<input type="text" name="taille" id="taille">
</td> </td>
</tr> </tr>
<tr> <tr>
<th>Sexe :</th> <th>Sexe :</th>
<td> <td>
<label> Homme <label> Homme
<input type="radio" name="radioSexe" value="<40"> <input type="radio" name="sex" id="M">
</label><br> </label><br>
<label> Femme <label> Femme
<input type="radio" name="radioSexe" value="<60"> <input type="radio" name="sex" id="F">
</label></td> </label></td>
</tr> </tr>
<tr> <tr>
<th>Niveau de pratique sportive :</th> <th>Niveau de pratique sportive :</th>
<td> <td>
<label> Bas <label> Bas
<input type="radio" name="radioSport" value="<40"> <input type="radio" name="sport" id="bas">
</label><br> </label><br>
<label> Moyen <label> Moyen
<input type="radio" name="radioSport" value="<60"> <input type="radio" name="sport" id="moyen">
</label><br> </label><br>
<label> Elevé <label> Elevé
<input type="radio" name="radioSport" value="60+"> <input type="radio" name="sport" id="eleve">
</label> </label>
</td> </td>
</tr> </tr>
<tr> <tr>
<td><input class="btn btn-primary" href="#" data-dismiss="modal" type="submit" name="Valider"></td> <td><input type="submit" name="Valider"></td>
</tr> </tr>
</table> </table>
</form> </form>
</td>
</tr>
</table>
<script src="scriptcalcul.js"></script>
<h2> Nom </h2> <h2> Nom </h2>
<img src="logo.png" alt="" height="90px" width="150px"/> <img src="logo.png" alt="" height="90px" width="150px"/>
......
var selectedRow = null
function onFormSubmit() {
var formData = readFormData();
if (selectedRow == null)
insertNewRecord(formData);
else
updateRecord(formData);
resetForm();
}
function readFormData() {
var formData = {};
formData["login"] = document.getElementById("login").value;
formData["age"] = document.getElementById("age").value;
formData["poids"] = document.getElementById("poids").value;
formData["taille"] = document.getElementById("taille").value;
formData["M"] = document.getElementById("M").checked;
formData["F"] = document.getElementById("F").checked;
formData["bas"] = document.getElementById("bas").checked;
formData["moyen"] = document.getElementById("moyen").checked;
formData["eleve"] = document.getElementById("eleve").checked;
return formData;
}
function insertNewRecord(data) {
var table = document.getElementById("table_récap").getElementsByTagName('tbody')[0];
var newRow = table.insertRow(table.length);
var genre;
var sport;
var calori;
cell1 = newRow.insertCell(0);
cell1.innerHTML = data.login;
cell2 = newRow.insertCell(1);
cell2.innerHTML = data.age;
cell3 = newRow.insertCell(2);
cell3.innerHTML = data.poids;
cell4 = newRow.insertCell(3);
cell4.innerHTML = data.taille;
cell5 = newRow.insertCell(4);
if (data.M) {
cell5.innerHTML = "Masculin";
genre ="Masc" ;
} else {
cell5.innerHTML = "Féminin";
genre ="Fem";
}
cell6 = newRow.insertCell(5);
if (data.bas) {
cell6.innerHTML = "Bas";
sport = 1.3;
} else if(data.moyen) {
cell6.innerHTML = "Moyen";
sport = 1.55;
} else {
cell6.innerHTML = "Élevé";
sport = 1.75;
}
cell7 = newRow.insertCell(6);
if(genre=="Masc"){
cell7.innerHTML = ((13.707*data.poids+492.3*data.taille)+77.607-6.673*data.age)*sport;
} else{
cell7.innerHTML = (9.740*data.poids+172.9*data.taille+667.051-4.737*data.age)*sport;
}
cell8 = newRow.insertCell(7);
cell8.innerHTML = `<a onClick="onEdit(this)">Edit</a>
<a onClick="onDelete(this)">Delete</a>`;
}
function resetForm() {
document.getElementById("login").value = "";
document.getElementById("age").value = "";
document.getElementById("poids").value = "";
document.getElementById("taille").value = "";
document.getElementById("M").checked = false;
document.getElementById("F").checked = false;
document.getElementById("bas").checked = false;
document.getElementById("moyen").checked = false;
document.getElementById("eleve").checked = false;
selectedRow = null;
}
function onEdit(td) {
selectedRow = td.parentElement.parentElement;
document.getElementById("login").value = selectedRow.cells[0].innerHTML;
document.getElementById("age").value = selectedRow.cells[1].innerHTML;
document.getElementById("poids").value = selectedRow.cells[2].innerHTML;
document.getElementById("taille").value = selectedRow.cells[3].innerHTML;
if (selectedRow.cells[4].innerHTML == "Masuclin") {
document.getElementById("M").checked = true;
document.getElementById("F").checked = false;
} else if (selectedRow.cells[4].innerHTML == "Féminin"){
document.getElementById("M").checked = false;
document.getElementById("F").checked = true;
}
if (selectedRow.cells[5].innerHTML == "Bas") {
document.getElementById("bas").checked = true;
document.getElementById("moyen").checked = false;
document.getElementById("eleve").checked = false;
} else if (selectedRow.cells[5].innerHTML == "Moyen"){
document.getElementById("bas").checked = false;
document.getElementById("moyen").checked = true;
document.getElementById("eleve").checked = false;
} else if (selectedRow.cells[5].innerHTML == "Élevé"){
document.getElementById("bas").checked = false;
document.getElementById("moyen").checked = false;
document.getElementById("eleve").checked = true;
}
}
function updateRecord(formData) {
selectedRow.cells[0].innerHTML = formData.login;
selectedRow.cells[1].innerHTML = formData.age;
selectedRow.cells[2].innerHTML = formData.poids;
selectedRow.cells[3].innerHTML = formData.taille;
if (formData.M) {
selectedRow.cells[4].innerHTML = "Masculin";
} else {
selectedRow.cells[4].innerHTML = "Féminin";
}
if (formData.bas) {
selectedRow.cells[5].innerHTML = "Bas";
} else if (formData.moyen) {
selectedRow.cells[5].innerHTML = "Moyen";
} else if (formData.eleve) {
selectedRow.cells[5].innerHTML = "Élevé"; }
}
function onDelete(td) {
if (confirm('Vous voulez vraiment supprimer cette ligne ?')) {
row = td.parentElement.parentElement;
document.getElementById("table_récap").deleteRow(row.rowIndex);
resetForm();
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment