Q8 en légende (Encore quelques améliorations nécessaires)

master
Raphael LACOTE 2 years ago
parent 5021d71f4d
commit abacdcbbad

@ -13,14 +13,6 @@
<navbar></navbar> <navbar></navbar>
<team></team> <team></team>
<!--<div class="team">
<team-add @add-team="addTeam"></team-add>
</div>
<teamcard v-for="team in allTeam"
:id="team.id"
:name="team.name"
:description="team.description">
</teamcard>-->
</div> </div>
<script src="./src/misc/constant.js"></script> <script src="./src/misc/constant.js"></script>
@ -29,8 +21,8 @@
<script type="module"> <script type="module">
import { createApp } from 'https://unpkg.com/vue@3/dist/vue.esm-browser.js';
import { createApp } from 'https://unpkg.com/vue@3/dist/vue.esm-browser.js';
import Navbar from './src/view/navbar.js'; import Navbar from './src/view/navbar.js';
import Team from './src/view/team.js' import Team from './src/view/team.js'

@ -1,9 +1,13 @@
export default { export default {
props: {
teamAEdit: {
type: String,
require: true
},
},
data: function() { data: function() {
return { return {
id: '', id:'',
name: '', name: '',
description: '', description: '',
errorMessage: '', errorMessage: '',
@ -13,6 +17,7 @@ export default {
methods: { methods: {
addTeam: function () { addTeam: function () {
try { try {
this.errorMessage = ''; this.errorMessage = '';
if (!this.id) { if (!this.id) {
throw new RequiredFieldError("ID"); throw new RequiredFieldError("ID");
@ -36,7 +41,11 @@ export default {
const team = { id: this.id, name: this.name, description: this.description}; const team = { id: this.id, name: this.name, description: this.description};
console.log('form.addTeam', team); console.log('form.addTeam', team);
if (this.teamAEdit != null) {
this.$emit('teamModifie', team);
} else {
this.$emit('teamAjoute', team); this.$emit('teamAjoute', team);
}
this.id = ''; this.id = '';
this.name = ''; this.name = '';
@ -59,6 +68,7 @@ export default {
<div> <div>
<label>ID</label><br/> <label>ID</label><br/>
<input type="text" v-model="id"/> <input type="text" v-model="id"/>
{{this.id}}
</div> </div>
<div> <div>
<label>Name</label><br/> <label>Name</label><br/>

@ -5,14 +5,31 @@ import teamCard from './teamcard.js';
export default { export default {
data: function() { data: function() {
return { return {
allTeam: [] allTeam: [],
teamAEdit: null
} }
}, },
methods: { methods: {
recupTeam: function (team) { recupTeam: function (team) {
console.log('team.addTeam', team); console.log('team.addTeam', team);
this.allTeam.push(team); this.allTeam.push(team);
},
editParam: function (team) {
this.teamAEdit=team
console.log('lanceEdit')
},
updateTeam: function (team) {
console.log('update')
for (var i = 0; i < this.allTeam.length; i++) {
if (this.allTeam[i].id == this.teamAEdit.id) {
console.log('update + +')
this.allTeam[i].name = team.name
this.allTeam[i].description=team.description
}
} }
}
}, },
components: { components: {
teamCard, teamCard,
@ -22,12 +39,13 @@ export default {
<section> <section>
<h2>News form</h2> <h2>News form</h2>
<div class="team"> <div class="team">
<teamAdd v-on:teamAjoute="recupTeam"></teamAdd> <teamAdd :teamAEdit="this.teamAEdit" v-on:teamAjoute="recupTeam" v-on:teamModifie="updateTeam"></teamAdd>
</div> </div>
<teamCard v-for="team in allTeam" <teamCard v-for="team in allTeam"
:id="team.id" :id="team.id"
:name="team.name" :name="team.name"
:description="team.description"> :description="team.description"
v-on:teamEditer="editParam">
</teamCard> </teamCard>
</section> </section>
` `

@ -21,6 +21,9 @@ export default {
methods: { methods: {
editTeam: function () { editTeam: function () {
this.isEdit = !this.isEdit; this.isEdit = !this.isEdit;
const team = { id: this.id, name: this.name, description: this.description };
this.$emit('teamEditer', team);
} }
}, },
computed: { computed: {
@ -37,7 +40,7 @@ export default {
<span>ID of the Team : {{ id }}</span> <span>ID of the Team : {{ id }}</span>
<p>Name : {{ name }}</p> <p>Name : {{ name }}</p>
<p>Description : {{ description20 }}</p> <p>Description : {{ description20 }}</p>
<button name="button" @click="editTeam">Editer</button> <input type="submit" value="Edit" @click="editTeam"/>
</div> </div>
` `
} }
Loading…
Cancel
Save