2020-02-12 17:04:50 +01:00
|
|
|
<template>
|
2020-02-13 08:50:20 +01:00
|
|
|
<form-wrapper :fail="fail" :success="success">
|
2020-02-12 23:24:35 +01:00
|
|
|
<form @submit.prevent="handleSubmit" @keydown="form.onKeydown($event)">
|
2020-02-26 22:26:26 +01:00
|
|
|
<form-select :options="options" :form="form" fieldName="lang" :label="$t('settings.language')" />
|
2020-02-13 12:55:00 +01:00
|
|
|
<form-buttons :isBusy="form.isBusy" :caption="$t('commons.save')" />
|
2020-02-12 23:24:35 +01:00
|
|
|
</form>
|
|
|
|
</form-wrapper>
|
2020-02-12 17:04:50 +01:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
|
2020-02-12 23:24:35 +01:00
|
|
|
import Form from './../../components/Form'
|
|
|
|
|
2020-02-12 17:04:50 +01:00
|
|
|
export default {
|
|
|
|
data(){
|
|
|
|
return {
|
2020-02-12 23:24:35 +01:00
|
|
|
success: '',
|
|
|
|
fail: '',
|
|
|
|
form: new Form({
|
2020-02-27 12:18:46 +01:00
|
|
|
lang: ''
|
2020-02-26 22:26:26 +01:00
|
|
|
}),
|
|
|
|
options: [
|
2020-02-27 09:37:23 +01:00
|
|
|
{ text: this.$t('languages.en'), value: 'en' },
|
|
|
|
{ text: this.$t('languages.fr'), value: 'fr' },
|
2020-02-26 22:26:26 +01:00
|
|
|
]
|
2020-02-12 17:04:50 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2020-02-27 12:18:46 +01:00
|
|
|
async mounted() {
|
|
|
|
|
|
|
|
const { data } = await this.axios.get('/api/settings')
|
|
|
|
|
|
|
|
data.settings.forEach((setting) => {
|
|
|
|
this.form[setting.key] = setting.value
|
|
|
|
})
|
|
|
|
},
|
|
|
|
|
2020-02-12 17:04:50 +01:00
|
|
|
methods : {
|
2020-02-27 12:18:46 +01:00
|
|
|
handleSubmit(e) {
|
|
|
|
e.preventDefault()
|
|
|
|
|
|
|
|
this.fail = ''
|
|
|
|
this.success = ''
|
2020-02-12 17:04:50 +01:00
|
|
|
|
2020-02-27 12:18:46 +01:00
|
|
|
this.form.post('/api/settings', {returnError: true})
|
|
|
|
.then(response => {
|
|
|
|
this.$router.go()
|
|
|
|
})
|
|
|
|
.catch(error => {
|
|
|
|
if( error.response.status === 400 ) {
|
|
|
|
this.fail = error.response.data.message
|
|
|
|
}
|
|
|
|
else if( error.response.status !== 422 ) {
|
|
|
|
this.$router.push({ name: 'genericError', params: { err: error.response } });
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
2020-02-12 17:04:50 +01:00
|
|
|
},
|
|
|
|
}
|
|
|
|
</script>
|