mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
99 lines
3.6 KiB
JavaScript
99 lines
3.6 KiB
JavaScript
import 'es6-promise/auto';
|
|
import { createStore } from 'vuex';
|
|
|
|
const debug = process.env.NODE_ENV !== 'production';
|
|
//console.log('window.activity', window.activity);
|
|
|
|
const addIdToValue = (string, id) => {
|
|
let array = string ? string.split(',') : [];
|
|
array.push(id.toString());
|
|
let str = array.join();
|
|
return str;
|
|
};
|
|
|
|
const removeIdFromValue = (string, id) => {
|
|
let array = string.split(',');
|
|
array = array.filter(el => el !== id.toString());
|
|
let str = array.join();
|
|
return str;
|
|
};
|
|
|
|
const store = createStore({
|
|
strict: debug,
|
|
state: {
|
|
activity: window.activity
|
|
},
|
|
getters: {
|
|
},
|
|
mutations: {
|
|
addPersonsInvolved(state, payload) {
|
|
//console.log('### mutation addPersonsInvolved', payload.result.type);
|
|
switch (payload.result.type) {
|
|
case 'person':
|
|
state.activity.persons.push(payload.result);
|
|
break;
|
|
case 'thirdparty':
|
|
state.activity.thirdParties.push(payload.result);
|
|
break;
|
|
case 'user':
|
|
state.activity.users.push(payload.result);
|
|
break;
|
|
};
|
|
},
|
|
removePersonInvolved(state, payload) {
|
|
//console.log('### mutation removePersonInvolved', payload.type);
|
|
switch (payload.type) {
|
|
case 'person':
|
|
state.activity.persons = state.activity.persons.filter(person => person !== payload);
|
|
break;
|
|
case 'thirdparty':
|
|
state.activity.thirdParties = state.activity.thirdParties.filter(thirdparty => thirdparty !== payload);
|
|
break;
|
|
case 'user':
|
|
state.activity.users = state.activity.users.filter(user => user !== payload);
|
|
break;
|
|
};
|
|
}
|
|
},
|
|
actions: {
|
|
addPersonsInvolved({ commit }, payload) {
|
|
console.log('### action addPersonsInvolved', payload.result.type);
|
|
switch (payload.result.type) {
|
|
case 'person':
|
|
let aPersons = document.getElementById("chill_activitybundle_activity_persons");
|
|
aPersons.value = addIdToValue(aPersons.value, payload.result.id);
|
|
break;
|
|
case 'thirdparty':
|
|
let aThirdParties = document.getElementById("chill_activitybundle_activity_thirdParties");
|
|
aThirdParties.value = addIdToValue(aThirdParties.value, payload.result.id);
|
|
break;
|
|
case 'user':
|
|
let aUsers = document.getElementById("chill_activitybundle_activity_users");
|
|
aUsers.value = addIdToValue(aUsers.value, payload.result.id);
|
|
break;
|
|
};
|
|
commit('addPersonsInvolved', payload);
|
|
},
|
|
removePersonInvolved({ commit }, payload) {
|
|
console.log('### action removePersonInvolved', payload);
|
|
switch (payload.type) {
|
|
case 'person':
|
|
let aPersons = document.getElementById("chill_activitybundle_activity_persons");
|
|
aPersons.value = removeIdFromValue(aPersons.value, payload.id);
|
|
break;
|
|
case 'thirdparty':
|
|
let aThirdParties = document.getElementById("chill_activitybundle_activity_thirdParties");
|
|
aThirdParties.value = removeIdFromValue(aThirdParties.value, payload.id);
|
|
break;
|
|
case 'user':
|
|
let aUsers = document.getElementById("chill_activitybundle_activity_users");
|
|
aUsers.value = removeIdFromValue(aUsers.value, payload.id);
|
|
break;
|
|
};
|
|
commit('removePersonInvolved', payload);
|
|
}
|
|
}
|
|
});
|
|
|
|
export default store;
|