Commit a68269dc authored by Giildo's avatar Giildo
Browse files

馃毀 Add the create locale method to the store

parent 85202500
......@@ -117,21 +117,6 @@ export default {
},
},
watch: {
localeSelected: function () {
this.locales.splice(0, this.locales.length);
Object.keys(this.fieldLocal.internationalization.locales[this.localeSelected])
.forEach(fieldName => {
this.locales.push({
key: fieldName,
default: this.defaultLocale.locale[fieldName],
localeValue: this.fieldLocal.internationalization.locales[this.localeSelected][fieldName],
});
});
},
},
created() {
if (!Object.keys(this.field.internationalization.locales).length) {
this.$store.dispatch(
......@@ -155,19 +140,17 @@ export default {
methods: {
onAddLocale(newLocaleName) {
let locale = {
label: '',
hint: '',
};
if (!this.internationalizationOption.props.min) {
locale.prefix = '';
locale.suffix = '';
locale.placeholder = '';
}
this.$store.dispatch(
'form/createNewLocale',
{
id: this.fieldId,
internationalizationOption: this.internationalizationOption,
newLocaleName,
},
);
this.fieldLocal.internationalization.locales[newLocaleName] = locale;
this.updateLocaleList();
this.localeSelected = newLocaleName;
},
onSaveLocalModification(keyUpdated) {
const key = this.locales.find(locale => locale.key === keyUpdated);
......@@ -180,7 +163,7 @@ export default {
}
},
updateLocaleList() {
Object.keys(this.fieldLocal.internationalization.locales)
Object.keys(this.field.internationalization.locales)
.forEach(local => {
this.items.push({
text: local,
......
const defaultLocale = process.env.VUE_APP_DEFAULT_LOCALE;
/**
* Create a new locale
*
* @param {Object} state
* @param {Object} payload
* @param {String} payload.id
* @param {Object} payload.internationalizationOption
* @param {String} payload.newLocaleName
*/
const createNewLocale = ({ commit }, payload) => {
commit('CREATE_NEW_LOCALE', payload)
};
/**
* Initialize the locale object if it doesn't exist
*
......@@ -52,6 +65,7 @@ const updateInternationalizationValue = ({ commit }, payload) => {
};
export default {
createNewLocale,
initInternationalization,
updateInternationalizationDefaultLocale,
updateInternationalizationFieldStatus,
......
const defaultLocale = process.env.VUE_APP_DEFAULT_LOCALE;
/**
* Create a new locale
*
* @param {Object} state
* @param {Object} payload
* @param {String} payload.id
* @param {Object} payload.internationalizationOption
* @param {String} payload.newLocaleName
*/
const CREATE_NEW_LOCALE = (state, { id, internationalizationOption, newLocaleName }) => {
let locale = {
label: '',
hint: '',
};
if (!internationalizationOption.props.min) {
locale.prefix = '';
locale.suffix = '';
locale.placeholder = '';
}
state.fields[id].internationalization.locales[newLocaleName] = locale;
};
/**
* Initialize the locale object if it doesn't exist
*
......@@ -63,6 +87,7 @@ const UPDATE_INTERNATIONALIZATION_VALUE = (state, { id, locale, value }) => {
};
export default {
CREATE_NEW_LOCALE,
INIT_INTERNATIONALIZATION,
UPDATE_INTERNATIONALIZATION_DEFAULT_LOCALE,
UPDATE_INTERNATIONALIZATION_STATUS,
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment