make onTheFly with API call

This commit is contained in:
Julie Lenaerts 2021-09-01 17:35:11 +02:00
parent 19a4542e2b
commit 820def6294
3 changed files with 79 additions and 12 deletions

View File

@ -0,0 +1,36 @@
/*
* GET a thirdparty by id
*/
const getThirdparty = (id) => {
const url = `/api/1.0/thirdparty/thirdparty/${id}.json`;
return fetch(url)
.then(response => {
if (response.ok) {
return response.json();
}
throw Error('Error with request resource response');
});
};
/*
* POST a new person
*/
const postThirdparty = (body) => {
const url = `/api/1.0/thirdparty/thirdparty.json`;
return fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json;charset=utf-8'
},
body: JSON.stringify(body)
})
.then(response => {
if (response.ok) { return response.json(); }
throw Error('Error with request resource response');
});
};
export {
getThirdparty,
postThirdparty
};

View File

@ -26,7 +26,7 @@
<time v-else-if="thirdparty.deathdate" datetime="{{ thirdparty.deathdate.datetime }}" title="{{ thirdparty.deathdate }}"> <time v-else-if="thirdparty.deathdate" datetime="{{ thirdparty.deathdate.datetime }}" title="{{ thirdparty.deathdate }}">
{{ birthdate }} - {{ deathdate }} {{ birthdate }} - {{ deathdate }}
</time> </time>
<span class="age">{{ thirdparty.age }}</span> <span v-if="options.addAge == true" class="age">{{ thirdparty.age }}</span>
</p> </p>
</div> </div>
</div> </div>
@ -37,9 +37,9 @@
<i class="fa fa-li fa-map-marker"></i> <i class="fa fa-li fa-map-marker"></i>
<show-address :address="thirdparty.address" :isMultiline="isMultiline"></show-address> <show-address :address="thirdparty.address" :isMultiline="isMultiline"></show-address>
</li> </li>
<li v-if="thirdparty.telephone"> <li v-if="thirdparty.phonenumber">
<i class="fa fa-li fa-mobile"></i> <i class="fa fa-li fa-mobile"></i>
<a :href="'tel: ' + thirdparty.telephone">{{ thirdparty.telephone }}</a> <a :href="'tel: ' + thirdparty.phonenumber">{{ thirdparty.phonenumber }}</a>
</li> </li>
<li v-if="thirdparty.email"> <li v-if="thirdparty.email">
<i class="fa fa-li fa-envelope-o"></i> <i class="fa fa-li fa-envelope-o"></i>

View File

@ -9,6 +9,7 @@
addAltNames: true, addAltNames: true,
addId: true, addId: true,
addLink: false, addLink: false,
addAge: false,
hLevel: 3, hLevel: 3,
addCenter: true, addCenter: true,
addNoData: true, addNoData: true,
@ -40,7 +41,7 @@
<div class="input-group mb-3"> <div class="input-group mb-3">
<span class="input-group-text" id="phonenumber"><i class="fa fa-fw fa-phone"></i></span> <span class="input-group-text" id="phonenumber"><i class="fa fa-fw fa-phone"></i></span>
<input class="form-control form-control-lg" <input class="form-control form-control-lg"
v-model="thirdparty.telephone" v-model="thirdparty.phonenumber"
v-bind:placeholder="$t('thirdparty.phonenumber')" v-bind:placeholder="$t('thirdparty.phonenumber')"
v-bind:aria-label="$t('thirdparty.phonenumber')" v-bind:aria-label="$t('thirdparty.phonenumber')"
aria-describedby="phonenumber" /> aria-describedby="phonenumber" />
@ -50,7 +51,8 @@
</template> </template>
<script> <script>
import ThirdPartyRenderBox from '../Entity/ThirdPartyRenderBox.vue' import ThirdPartyRenderBox from '../Entity/ThirdPartyRenderBox.vue';
import { getThirdparty, postThirdparty } from '../../_api/OnTheFly';
export default { export default {
name: "OnTheFlyThirdParty", name: "OnTheFlyThirdParty",
@ -61,18 +63,47 @@ export default {
data: function() { data: function() {
return { return {
thirdparty: { thirdparty: {
text : "Bart Maes", type: 'thirdparty'
firstName : "Bart",
lastName : "Maes",
email : "bartmaes@gmail.com",
telephone : "0475 94 66 15",
} }
} }
} },
methods: {
loadThirdparty(){
getThirdparty(this.id).then(thirdparty => new Promise((resolve, reject) => {
this.thirdparty = thirdparty;
resolve();
}));
},
postData() {
postThirdparty(this.thirdparty).then(thirdparty => new Promise((resolve, reject) => {
this.thirdparty = thirdparty;
resolve();
}))
}
},
mounted() {
if (this.action !== 'create'){
this.loadThirdparty();
}
},
} }
// TODO move in ChillThirdpartyAssets // TODO move in ChillThirdpartyAssets
</script> </script>
<style lang="css" scoped> <style lang="scss" scoped>
div.flex-table {
div.item-bloc {
div.item-row {
div.item-col:last-child {
justify-content: flex-start;
}
}
}
}
dl {
dd {
margin-left: 1em;
}
}
</style> </style>