master
dohodin 2 years ago
parent 993a0815ae
commit 9a05a188f7

@ -1,8 +1,8 @@
export default { export default {
props: { props: {
teamAEdit: { teamAEdit: {
type: String, require: true,
require: true default: ""
}, },
}, },
data: function() { data: function() {
@ -18,6 +18,12 @@ export default {
addTeam: function () { addTeam: function () {
try { try {
if (this.teamAEdit != null) {
this.id = this.teamAEdit.id
this.name = this.teamAEdit.name
this.description = this.teamAEdit.description
}
this.errorMessage = ''; this.errorMessage = '';
if (!this.id) { if (!this.id) {
throw new RequiredFieldError("ID"); throw new RequiredFieldError("ID");
@ -35,11 +41,13 @@ export default {
throw new StringSize("Name", NAME_MINIMAL_SIZE) throw new StringSize("Name", NAME_MINIMAL_SIZE)
} }
const team = { id: this.id, name: this.name, description: this.description}; const team = { id: this.id, name: this.name, description: this.description };
if (this.teamAEdit != null) { if (this.teamAEdit != null) {
this.$emit('teamModifie', team); this.$emit('teamModifie', team);
} else { } else {
this.$emit('teamAjoute', team); this.$emit('teamAjoute', team);
} }
@ -47,7 +55,7 @@ export default {
this.name = ''; this.name = '';
this.description = ''; this.description = '';
}catch (error) { } catch (error) {
if (error instanceof RequiredFieldError) { if (error instanceof RequiredFieldError) {
this.errorMessage=error this.errorMessage=error
} }
@ -56,22 +64,25 @@ export default {
} }
return null; return null;
} }
}, }
}, },
template: `<section> template: `<section>
<form @submit.prevent> <form @submit.prevent>
<div v-bind:style="{ color: errorColor}">{{ errorMessage }}</div> <div v-bind:style="{ color: errorColor}">{{ errorMessage }}</div>
<div> <div>
<label>ID</label><br/> <label>ID</label><br/>
<input type="text" v-model="id"/> <p v-if=this.teamAEdit><input type="text" v-model="this.teamAEdit.id" /></p>
<p v-else><input type="text" v-model="this.id" /></p>
</div> </div>
<div> <div>
<label>Name</label><br/> <label>Name</label><br/>
<input type="text" v-model="name"/> <p v-if=this.teamAEdit><input type="text" v-model="this.teamAEdit.name" /></p>
<p v-else><input type="text" v-model="this.name" /></p>
</div> </div>
<div> <div>
<label>Description</label><br/> <label>Description</label><br/>
<textarea v-model="description"></textarea> <p v-if=this.teamAEdit><textarea v-model="this.teamAEdit.description"/></p>
<p v-else><textarea v-model="this.description" /></p>
</div> </div>
<input type="submit" value="Create Team" @click="addTeam"/> <input type="submit" value="Create Team" @click="addTeam"/>
</form> </form>

@ -17,14 +17,11 @@ export default {
editParam: function (team) { editParam: function (team) {
this.teamAEdit=team this.teamAEdit=team
console.log('lanceEdit')
}, },
updateTeam: function (team) { updateTeam: function (team) {
console.log('update')
for (var i = 0; i < this.allTeam.length; i++) { for (var i = 0; i < this.allTeam.length; i++) {
if (this.allTeam[i].id == this.teamAEdit.id) { if (this.allTeam[i].id == this.teamAEdit.id) {
console.log('update + +')
this.allTeam[i].name = team.name this.allTeam[i].name = team.name
this.allTeam[i].description=team.description this.allTeam[i].description=team.description
} }

Loading…
Cancel
Save