mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
replace store by data() for OnTheFly creation in AddPersons component
This commit is contained in:
parent
ccb302ad28
commit
34df295801
@ -70,12 +70,10 @@ export default {
|
||||
switch (this.radioType) {
|
||||
case 'person':
|
||||
return this.$refs.castPerson.$data.person;
|
||||
//break;
|
||||
case 'thirdparty':
|
||||
return this.$refs.castThirdparty.$data.thirdparty;
|
||||
//break;
|
||||
default:
|
||||
throw 'error with entity';
|
||||
throw Error('Invalid type of entity')
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -22,7 +22,6 @@ let initPromise = getAccompanyingCourse(id)
|
||||
state: {
|
||||
accompanyingCourse: accompanying_course,
|
||||
addressContext: {},
|
||||
priorSuggestion: {},
|
||||
errorMsg: []
|
||||
},
|
||||
getters: {
|
||||
@ -48,25 +47,9 @@ let initPromise = getAccompanyingCourse(id)
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
hasPriorSuggestion(state, getters) {
|
||||
return state.priorSuggestion.key ? true : false;
|
||||
}
|
||||
},
|
||||
mutations: {
|
||||
newPriorSuggestion(state, entity) {
|
||||
console.log('### mutation newPriorSuggestion', entity);
|
||||
if (entity !== null) {
|
||||
let suggestion = {
|
||||
key: entity.type + entity.id,
|
||||
relevance: 0.5,
|
||||
result: entity
|
||||
}
|
||||
state.priorSuggestion = suggestion;
|
||||
} else {
|
||||
state.priorSuggestion = {};
|
||||
}
|
||||
},
|
||||
catchError(state, error) {
|
||||
console.log('### mutation: a new error have been catched and pushed in store !', error);
|
||||
state.errorMsg.push(error);
|
||||
|
@ -92,7 +92,6 @@ import OnTheFly from 'ChillMainAssets/vuejs/_components/OnTheFly.vue';
|
||||
import PersonSuggestion from './AddPersons/PersonSuggestion';
|
||||
import { searchPersons, searchPersons_2 } from 'ChillPersonAssets/vuejs/_api/AddPersons';
|
||||
import { postPerson } from "ChillPersonAssets/vuejs/_api/OnTheFly";
|
||||
import {mapGetters, mapState} from "vuex";
|
||||
|
||||
export default {
|
||||
name: 'AddPersons',
|
||||
@ -116,13 +115,12 @@ export default {
|
||||
search: {
|
||||
query: "",
|
||||
suggested: [],
|
||||
selected: []
|
||||
selected: [],
|
||||
priorSuggestion: {}
|
||||
}
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
...mapState(['priorSuggestion']),
|
||||
...mapGetters(['hasPriorSuggestion']),
|
||||
query: {
|
||||
set(query) {
|
||||
return this.setQuery(query);
|
||||
@ -173,6 +171,12 @@ export default {
|
||||
return 'radio';
|
||||
}
|
||||
return 'checkbox';
|
||||
},
|
||||
priorSuggestion() {
|
||||
return this.search.priorSuggestion;
|
||||
},
|
||||
hasPriorSuggestion() {
|
||||
return this.search.priorSuggestion.key ? true : false;
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
@ -225,13 +229,28 @@ export default {
|
||||
return item.result.type + item.result.id;
|
||||
},
|
||||
addPriorSuggestion() {
|
||||
console.log('echo', this.hasPriorSuggestion);
|
||||
if (this.hasPriorSuggestion) {
|
||||
console.log('addPriorSuggestion',);
|
||||
this.suggested.unshift(this.priorSuggestion);
|
||||
this.selected.unshift(this.priorSuggestion);
|
||||
|
||||
console.log('reset priorSuggestion');
|
||||
this.$store.commit('newPriorSuggestion', null);
|
||||
this.newPriorSuggestion(null);
|
||||
}
|
||||
},
|
||||
newPriorSuggestion(entity) {
|
||||
console.log('newPriorSuggestion', entity);
|
||||
if (entity !== null) {
|
||||
let suggestion = {
|
||||
key: entity.type + entity.id,
|
||||
relevance: 0.5,
|
||||
result: entity
|
||||
}
|
||||
this.search.priorSuggestion = suggestion;
|
||||
console.log('ici', this.search.priorSuggestion);
|
||||
} else {
|
||||
this.search.priorSuggestion = {};
|
||||
}
|
||||
},
|
||||
saveFormOnTheFly({ type, data }) {
|
||||
@ -243,8 +262,8 @@ export default {
|
||||
console.log('type person with', data);
|
||||
postPerson(data)
|
||||
.then(person => new Promise((resolve, reject) => {
|
||||
this.person = person;
|
||||
this.$store.commit('newPriorSuggestion', person);
|
||||
//this.person = person;
|
||||
this.newPriorSuggestion(person);
|
||||
resolve();
|
||||
}));
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user