2020-03-14 14:13:37 +01:00
|
|
|
<template>
|
|
|
|
<div class="field">
|
2023-07-02 18:07:12 +02:00
|
|
|
<input
|
|
|
|
:id="option.name"
|
|
|
|
v-model="option.value"
|
|
|
|
type="checkbox"
|
|
|
|
class="switch is-rounded mr-2"
|
|
|
|
@change="update_setting"
|
|
|
|
/>
|
2023-07-26 12:59:16 +02:00
|
|
|
<label class="pt-0" :for="option.name">
|
2022-02-19 06:39:14 +01:00
|
|
|
<slot name="label" />
|
2020-03-14 14:13:37 +01:00
|
|
|
</label>
|
2023-07-02 18:07:12 +02:00
|
|
|
<i
|
|
|
|
class="is-size-7"
|
|
|
|
:class="{ 'has-text-info': is_success, 'has-text-danger': is_error }"
|
|
|
|
v-text="info"
|
|
|
|
/>
|
2022-02-19 06:39:14 +01:00
|
|
|
<p v-if="$slots['info']" class="help">
|
|
|
|
<slot name="info" />
|
2020-03-14 14:13:37 +01:00
|
|
|
</p>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2023-07-18 15:48:56 +02:00
|
|
|
import webapi from '@/webapi'
|
2020-03-14 14:13:37 +01:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'SettingsCheckbox',
|
2024-02-27 17:18:58 +01:00
|
|
|
props: { category_name: String, option_name: String },
|
2020-03-14 14:13:37 +01:00
|
|
|
|
2022-02-19 06:39:14 +01:00
|
|
|
data() {
|
2020-03-14 14:13:37 +01:00
|
|
|
return {
|
|
|
|
timerDelay: 2000,
|
|
|
|
timerId: -1,
|
|
|
|
statusUpdate: ''
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
computed: {
|
2022-02-19 06:39:14 +01:00
|
|
|
option() {
|
2023-07-02 18:07:12 +02:00
|
|
|
const option = this.$store.getters.settings_option(
|
|
|
|
this.category_name,
|
|
|
|
this.option_name
|
2022-02-19 06:39:14 +01:00
|
|
|
)
|
2023-07-02 18:07:12 +02:00
|
|
|
if (!option) {
|
|
|
|
return {
|
|
|
|
category: this.category_name,
|
|
|
|
name: this.option_name,
|
|
|
|
value: false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return option
|
2020-03-14 14:13:37 +01:00
|
|
|
},
|
|
|
|
|
2022-02-19 06:39:14 +01:00
|
|
|
info() {
|
2023-07-02 18:07:12 +02:00
|
|
|
if (this.is_success) {
|
2022-05-20 13:44:22 +02:00
|
|
|
return this.$t('setting.saved')
|
2023-07-02 18:07:12 +02:00
|
|
|
} else if (this.is_error) {
|
2022-05-20 13:44:22 +02:00
|
|
|
return this.$t('setting.not-saved')
|
2020-03-14 14:13:37 +01:00
|
|
|
}
|
|
|
|
return ''
|
2022-05-20 13:44:22 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
is_success() {
|
|
|
|
return this.statusUpdate === 'success'
|
|
|
|
},
|
|
|
|
|
|
|
|
is_error() {
|
|
|
|
return this.statusUpdate === 'error'
|
2020-03-14 14:13:37 +01:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
2022-02-19 06:39:14 +01:00
|
|
|
update_setting() {
|
2020-03-14 14:13:37 +01:00
|
|
|
this.timerId = -1
|
|
|
|
const option = {
|
2023-07-02 18:07:12 +02:00
|
|
|
category: this.category_name,
|
2020-03-14 14:13:37 +01:00
|
|
|
name: this.option_name,
|
2023-07-02 18:07:12 +02:00
|
|
|
value: this.option.value
|
2020-03-14 14:13:37 +01:00
|
|
|
}
|
2022-02-19 06:39:14 +01:00
|
|
|
webapi
|
2023-07-02 18:07:12 +02:00
|
|
|
.settings_update(this.category_name, option)
|
2022-02-19 06:39:14 +01:00
|
|
|
.then(() => {
|
2024-02-21 14:02:47 +01:00
|
|
|
this.$store.dispatch('update_settings_option', option)
|
2022-02-19 06:39:14 +01:00
|
|
|
this.statusUpdate = 'success'
|
|
|
|
})
|
|
|
|
.catch(() => {
|
|
|
|
this.statusUpdate = 'error'
|
|
|
|
})
|
|
|
|
.finally(() => {
|
|
|
|
this.timerId = window.setTimeout(this.clear_status, this.timerDelay)
|
|
|
|
})
|
2020-03-14 14:13:37 +01:00
|
|
|
},
|
|
|
|
|
2023-06-07 21:25:54 +02:00
|
|
|
clear_status() {
|
2023-07-02 18:07:12 +02:00
|
|
|
if (this.is_error) {
|
|
|
|
this.option.value = !this.option.value
|
|
|
|
}
|
2020-03-14 14:13:37 +01:00
|
|
|
this.statusUpdate = ''
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2022-02-19 06:39:14 +01:00
|
|
|
<style></style>
|