diff --git a/src/components/feature_type/FeatureTypeCustomForm.vue b/src/components/feature_type/FeatureTypeCustomForm.vue index 7d7ef4c43c852db5690473a3c2aaf39a11607e88..aa7d5f2aede7f098b06733ba0c47ec321f0477c7 100644 --- a/src/components/feature_type/FeatureTypeCustomForm.vue +++ b/src/components/feature_type/FeatureTypeCustomForm.vue @@ -217,10 +217,10 @@ export default { this.$store.commit("feature_type/UPDATE_COLOR_STYLE"); }, }, - beforeDestroy(){ - this.$store.commit("feature_type/EMPTY_CUSTOM_FORM"); + // beforeDestroy(){ + // this.$store.commit("feature_type/EMPTY_CUSTOM_FORM"); - }, + // }, mounted() { for (let el in this.customForm) { if (el && this.form[el]) this.form[el].value = this.customForm[el].value; diff --git a/src/store/modules/feature_type.js b/src/store/modules/feature_type.js index 68916bf77d394a09618b7f2c25c3853656117065..df91b49edfd883f084698d4eb1c8e4c0b5a44b5b 100644 --- a/src/store/modules/feature_type.js +++ b/src/store/modules/feature_type.js @@ -1,54 +1,62 @@ import axios from "axios" import store from '@/store'; +export const RESET = 'RESET'; -const feature_type = { - namespaced: true, - state: { - form: { - colors_style: { - value: null, - options: [], - fields: [], - }, - color: { - id_for_label: "couleur", - label: "Couleur", - field: { - max_length: 128, // ! Vérifier la valeur dans django - }, - html_name: "couleur", - value: "#000000", + +const initialState = () => ({ + form: { + colors_style: { + value: null, + options: [], + fields: [], + }, + color: { + id_for_label: "couleur", + label: "Couleur", + field: { + max_length: 128, // ! Vérifier la valeur dans django }, - title: { - errors: [], - id_for_label: "title", - label: "Titre", - field: { - max_length: 128, // ! Vérifier la valeur dans django - }, - html_name: "title", - value: null, + html_name: "couleur", + value: "#000000", + }, + title: { + errors: [], + id_for_label: "title", + label: "Titre", + field: { + max_length: 128, // ! Vérifier la valeur dans django }, - geom_type: { - id_for_label: "geom_type", - label: "Type de géométrie", - field: { - choices: ["Ligne", "Point", "Polygone"], - max_length: 128, // ! Vérifier la valeur dans django - }, - html_name: "geom_type", - value: "Point", + html_name: "title", + value: null, + }, + geom_type: { + id_for_label: "geom_type", + label: "Type de géométrie", + field: { + choices: ["Ligne", "Point", "Polygone"], + max_length: 128, // ! Vérifier la valeur dans django }, + html_name: "geom_type", + value: "Point", }, - colorsStyleList: [], - customForms: [], - current_feature_type_slug: null, - feature_types: [], }, + colorsStyleList: [], + customForms: [], + current_feature_type_slug: null, + feature_types: [], +}); + +const feature_type = { + namespaced: true, + state: initialState(), + mutations: { - EMPTY_CUSTOM_FORM(state) { - state.customForms = []; + [RESET]: (state) => { + const newState = initialState(); + Object.keys(newState).forEach((key) => { + state[key] = newState[key]; + }); }, SET_FEATURE_TYPES(state, feature_types) { state.feature_types = feature_types; @@ -83,7 +91,9 @@ const feature_type = { ) }, actions: { - + [RESET]: ({ commit }) => { + commit("RESET_STATE"); + }, POST_FEATURE_TYPE({ state }) { const data = { form: state.form, formset: state.customForms } console.log("data", data) diff --git a/src/views/feature_type/Feature_type_edit.vue b/src/views/feature_type/Feature_type_edit.vue index c63a7e2f6f6ae1fee7ad790d9320e959ff58a375..da8320ba7ca15a7b1e14e8e3f6016cd44e27b802 100644 --- a/src/views/feature_type/Feature_type_edit.vue +++ b/src/views/feature_type/Feature_type_edit.vue @@ -122,7 +122,7 @@ <script> import frag from "vue-frag"; -import { mapGetters, mapState } from "vuex"; +import { mapGetters, mapState, mapMutations } from "vuex"; import Dropdown from "@/components/Dropdown.vue"; import FeatureTypeCustomForm from "@/components/feature_type/FeatureTypeCustomForm.vue"; @@ -183,6 +183,7 @@ export default { }, }, methods: { + ...mapMutations('feature_type', ['RESET']), definePageType() { if (this.$router.history.current.name === "ajouter-type-signalement") { this.action = "create"; @@ -264,6 +265,10 @@ export default { } } }, + beforeDestroy(){ + this.RESET(); + + }, /* checkform() { let form_idx = $('#id_form-TOTAL_FORMS').val(); for (var i=0; i <= form_idx;i++ ){