vue_activity location: add NewLocation fields, submit activity form with hidden field (+)

This commit is contained in:
2021-10-15 09:09:47 +02:00
parent 4d4662a634
commit e6845326d7
9 changed files with 175 additions and 11 deletions

View File

@@ -21,7 +21,7 @@
</VueMultiselect>
<!--
-->
<new-location></new-location>
<new-location @saveNewLocation="saveNewLocation"></new-location>
</div>
</div>
</teleport>
@@ -31,7 +31,7 @@
import { mapState } from "vuex";
import VueMultiselect from 'vue-multiselect';
import NewLocation from './Location/NewLocation.vue';
import { getLocations } from '../api.js';
import { getLocations, postLocation } from '../api.js';
export default {
name: "Location",
@@ -51,7 +51,7 @@ export default {
return this.activity.location;
},
set(value) {
this.$store.commit('updateLocation', value);
this.$store.dispatch('updateLocation', value);
}
}
},
@@ -62,13 +62,40 @@ export default {
getLocationsList() {
getLocations().then(response => new Promise(resolve => {
console.log('getLocations', response);
this.locations = response.results;
this.locations = response.results.filter(l => l.availableForUsers === true);
resolve();
}))
},
customLabel(value) {
return `${value.locationType.title.fr} ${value.name}`;
},
saveNewLocation(selected) {
console.log('saveNewLocation', selected);
console.log('post location')
let body = {
type: 'location',
name: selected.name,
address: { id: selected.addressId },
locationtype: { id: selected.type },
email: selected.email,
phonenumber1: selected.phonenumber1,
phonenumber2: selected.phonenumber2,
}
//this.$store.dispatch('addLocationSelected', body);
postLocation(body).then(location => new Promise(resolve => {
this.locations.push(location);
this.location.set(location);
resolve();
}));
}
}
}
/*
*
* TODO
* - multiselect, n'affiche pas l'item choisi
* - addAddress, les multiselect pays/localité/adresse ne se remplissent pas
*
*/
</script>