2022-04-10 13:07:36 +02:00
|
|
|
<template>
|
2022-04-12 22:24:19 +02:00
|
|
|
<div class="switch-container">
|
2022-04-10 13:07:36 +02:00
|
|
|
<div class="col-10 label">
|
|
|
|
<div class="name" v-text="value.name" />
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="col-2 switch pull-right">
|
2022-04-12 01:10:09 +02:00
|
|
|
<ToggleSwitch :value="value.state" @input="toggle"
|
2022-04-24 22:18:29 +02:00
|
|
|
@click.stop :disabled="loading || value.is_read_only" />
|
2022-04-10 13:07:36 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import ToggleSwitch from "@/components/elements/ToggleSwitch"
|
|
|
|
import Utils from "@/Utils"
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'Switch',
|
|
|
|
components: {ToggleSwitch},
|
|
|
|
emits: ['input'],
|
|
|
|
mixins: [Utils],
|
|
|
|
props: {
|
|
|
|
value: {
|
|
|
|
type: Object,
|
|
|
|
required: true,
|
|
|
|
},
|
|
|
|
|
2022-04-12 01:10:09 +02:00
|
|
|
loading: {
|
|
|
|
type: Boolean,
|
|
|
|
default: false,
|
|
|
|
},
|
2022-04-10 13:07:36 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
methods: {
|
2022-04-12 01:10:09 +02:00
|
|
|
async toggle(event) {
|
|
|
|
event.stopPropagation()
|
|
|
|
this.$emit('loading', true)
|
|
|
|
|
|
|
|
try {
|
|
|
|
await this.request('entities.execute', {
|
|
|
|
id: this.value.id,
|
|
|
|
action: 'toggle',
|
|
|
|
})
|
|
|
|
} finally {
|
|
|
|
this.$emit('loading', false)
|
|
|
|
}
|
2022-04-10 13:07:36 +02:00
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
|
|
|
</script>
|
|
|
|
|
2022-04-12 16:00:31 +02:00
|
|
|
<style lang="scss" scoped>
|
2022-04-10 13:07:36 +02:00
|
|
|
@import "vars";
|
2022-04-12 22:24:19 +02:00
|
|
|
|
|
|
|
.switch-container {
|
|
|
|
.switch {
|
|
|
|
direction: rtl;
|
|
|
|
}
|
|
|
|
}
|
2022-04-10 13:07:36 +02:00
|
|
|
</style>
|