forked from tom.biard/ScienceQuest
parent
116244c2eb
commit
a9dffe805d
@ -0,0 +1,39 @@
|
||||
<script>
|
||||
import LigneScientifique from './ligneScientifique.vue';
|
||||
|
||||
export default{
|
||||
data() {
|
||||
return {
|
||||
//données obtenues par l'api
|
||||
scientifiques: [
|
||||
{prenom:"marie",nom:"curie",date:"1900-01-13",descriptif:"radaition qqch comme ca"},
|
||||
{prenom:"albert",nom:"einstein",date:"1900-01-13",descriptif:"theorie"}
|
||||
]
|
||||
};
|
||||
},
|
||||
components: { LigneScientifique }
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
<template>
|
||||
<table class="table">
|
||||
<thead>
|
||||
<tr>
|
||||
<th scope="col">Prenom</th>
|
||||
<th scope="col">Nom</th>
|
||||
<th scope="col">Descriptif</th>
|
||||
<th scope="col">Date de naissance</th>
|
||||
<th scope="col">Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<LigneScientifique v-for="scientifique in scientifiques"
|
||||
:prenom="scientifique.prenom"
|
||||
:nom="scientifique.nom"
|
||||
:date="scientifique.date"
|
||||
:descriptif="scientifique.descriptif"
|
||||
></LigneScientifique>
|
||||
</tbody>
|
||||
</table>
|
||||
</template>
|
@ -0,0 +1,79 @@
|
||||
<script>
|
||||
export default {
|
||||
props: ["id", "nom", "prenom", "descriptif","date"],
|
||||
data(){
|
||||
return{
|
||||
modeEdition:false, //vrai = remplacer les champs par des inputs
|
||||
|
||||
nomAffiche:this.nom,
|
||||
prenomAffiche:this.prenom,
|
||||
descriptifAffiche:this.descriptif,
|
||||
dateAffiche:this.date
|
||||
}
|
||||
},
|
||||
methods:{
|
||||
changerModeEdition: function(){
|
||||
this.modeEdition=!this.modeEdition
|
||||
},
|
||||
annuler: function(){
|
||||
//remettre les valeurs a 0
|
||||
this.nomAffiche=this.nom,
|
||||
this.prenomAffiche=this.prenom,
|
||||
this.descriptifAffiche=this.descriptif,
|
||||
this.dateAffiche=this.date
|
||||
|
||||
this.changerModeEdition()
|
||||
},
|
||||
sauverScientifique: function(){
|
||||
const donnees={
|
||||
id:this.id,
|
||||
nom:this.nomAffiche,
|
||||
prenom:this.prenomAffiche,
|
||||
descriptif:this.descriptifAffiche,
|
||||
date:this.dateAffiche,
|
||||
}
|
||||
|
||||
fetch("localhost/api/v1/scientifiques", {method:"PUT", body:JSON.stringify(donnees)})
|
||||
this.changerModeEdition()
|
||||
}
|
||||
}
|
||||
}
|
||||
</script>
|
||||
|
||||
|
||||
<template>
|
||||
<tr v-if="!this.modeEdition">
|
||||
<td>
|
||||
<p>{{ prenomAffiche }}</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>{{ nomAffiche }}</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>{{ descriptifAffiche }}</p>
|
||||
</td>
|
||||
<td>
|
||||
<p>{{ dateAffiche }}</p>
|
||||
</td>
|
||||
<button v-on:click="changerModeEdition()">Modifier</button>
|
||||
</tr>
|
||||
<tr v-if="this.modeEdition">
|
||||
|
||||
<td>
|
||||
<input class="form-control" type="text" v-model="prenomAffiche">
|
||||
</td>
|
||||
<td>
|
||||
<input class="form-control" type="text" v-model="nomAffiche">
|
||||
</td>
|
||||
<td>
|
||||
<textarea class="form-control" v-model="descriptifAffiche"></textarea>
|
||||
</td>
|
||||
<td>
|
||||
<input class="form-control" type="date" v-model="dateAffiche">
|
||||
</td>
|
||||
|
||||
<!-- TODO : aussi faire this.modeEdition=!this.modeEdition dans sauverScientifique -->
|
||||
<button v-on:click="sauverScientifique()">Sauvegarder</button>
|
||||
<button v-on:click="annuler()">Annuler</button>
|
||||
</tr>
|
||||
</template>
|
Loading…
Reference in new issue