move postPerson fetch method from grant-children to children (to squash)

This commit is contained in:
Mathieu Jaumotte 2021-08-25 21:25:39 +02:00
parent e369e43b00
commit 25f43bc758
3 changed files with 36 additions and 30 deletions

View File

@ -142,15 +142,20 @@ export default {
this.$data.action = action;
},
saveAction() {
console.log('saveAction');
console.log('saveAction for create/edit action');
// edit person
if (this.type === 'person') {
this.$refs.castPerson.postData();
} else if (this.type === 'thirdparty') {
}
// edit thirdparty
else if (this.type === 'thirdparty') {
this.$refs.castThirdparty.postData();
} else {
// => save new person created
// saveAction() ==cast=to==> child.castByType() ==cast=to==> grand-child.postData()
this.$refs.castNew.castByType();
}
// create new person/thirdparty
else {
this.$refs.castNew.createAction();
// saveAction() =====> child.createAction()
}
this.modal.showModal = false;
},

View File

@ -1,4 +1,4 @@
<template>
<template>
<ul class="nav nav-tabs">
<li class="nav-item">
<a class="nav-link" :class="{ active: isActive('person') }">
@ -17,29 +17,32 @@
</a>
</li>
</ul>
<div class="my-4">
<on-the-fly-person
v-if="type === 'person'"
v-bind:action="action"
ref="castPerson">
ref="castPerson"
>
</on-the-fly-person>
<on-the-fly-thirdparty
v-if="type === 'thirdparty'"
v-bind:action="action"
ref="castThirdparty">
ref="castThirdparty"
>
</on-the-fly-thirdparty>
</div>
</div>
</template>
<script>
import OnTheFlyPerson from 'ChillPersonAssets/vuejs/_components/OnTheFly/Person.vue';
import OnTheFlyThirdparty from 'ChillThirdPartyAssets/vuejs/_components/OnTheFly/ThirdParty.vue';
import OnTheFlyThirdparty from 'ChillThirdPartyAssets/vuejs/_components/OnTheFly/ThirdParty.vue';
import { postPerson } from "ChillPersonAssets/vuejs/_api/OnTheFly";
export default {
name: "OnTheFlyCreate",
props: ['action'],
props: ['action'],
components: {
OnTheFlyPerson,
OnTheFlyThirdparty
@ -61,16 +64,22 @@ export default {
},
methods: {
isActive(tab) {
return (this.type === tab) ? true : false;
return (this.type === tab) ? true : false;
},
castByType() {
console.log('saveActionByType');
createAction() {
console.log('createAction before fetch');
if (this.type === 'person') {
this.$refs.castPerson.postData();
console.log('create person with', this.$refs.castPerson.$data.person);
postPerson(this.$refs.castPerson.$data.person)
.then(person => new Promise((resolve, reject) => {
this.person = person;
this.$store.commit('newPriorSuggestion', person);
resolve();
}));
} else if (this.type === 'thirdparty') {
this.$refs.castThirdparty.postData();
} else {
throw Error('Invalid type of entity');
console.log('not yet implemented', type);
}
}
}

View File

@ -80,6 +80,7 @@ import PersonRenderBox from '../Entity/PersonRenderBox.vue';
export default {
name: "OnTheFlyPerson",
props: ['id', 'type', 'action'],
//emits: ['createAction'],
components: {
PersonRenderBox
},
@ -160,15 +161,6 @@ export default {
//console.log('get person', this.person);
resolve();
}));
},
postData() {
console.log('postdata before fetch', this.person);
postPerson(this.person)
.then(person => new Promise((resolve, reject) => {
this.person = person;
this.$store.commit('newPriorSuggestion', person);
resolve();
}));
}
}
}