2022-04-10 13:07:36 +02:00
|
|
|
<template>
|
2022-05-01 15:34:15 +02:00
|
|
|
<div class="entity switch-container">
|
|
|
|
<div class="head">
|
|
|
|
<div class="col-1 icon">
|
|
|
|
<EntityIcon :icon="value.meta?.icon || {}"
|
|
|
|
:loading="loading" :error="error" />
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="col-9 label">
|
|
|
|
<div class="name" v-text="value.name" />
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<div class="col-2 switch pull-right">
|
2022-10-23 00:28:01 +02:00
|
|
|
<ToggleSwitch
|
|
|
|
:value="value.is_write_only ? false : value.state"
|
|
|
|
:disabled="loading || value.is_read_only"
|
|
|
|
@input="toggle"
|
|
|
|
@click.stop />
|
2022-05-01 15:34:15 +02:00
|
|
|
</div>
|
2022-04-10 13:07:36 +02:00
|
|
|
</div>
|
|
|
|
</div>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import ToggleSwitch from "@/components/elements/ToggleSwitch"
|
2022-05-01 15:34:15 +02:00
|
|
|
import EntityIcon from "./EntityIcon"
|
|
|
|
import EntityMixin from "./EntityMixin"
|
2022-04-10 13:07:36 +02:00
|
|
|
|
|
|
|
export default {
|
|
|
|
name: 'Switch',
|
2022-05-01 15:34:15 +02:00
|
|
|
components: {ToggleSwitch, EntityIcon},
|
|
|
|
mixins: [EntityMixin],
|
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',
|
|
|
|
})
|
2022-10-23 00:28:01 +02:00
|
|
|
|
|
|
|
if (this.value.is_write_only) {
|
|
|
|
// Show a quick on/off animation for write-only switches
|
|
|
|
const self = this
|
|
|
|
self.value.state = true
|
|
|
|
setTimeout(() => self.value.state = false, 250)
|
|
|
|
}
|
2022-04-12 01:10:09 +02:00
|
|
|
} 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-05-01 15:34:15 +02:00
|
|
|
@import "common";
|
2022-04-12 22:24:19 +02:00
|
|
|
|
|
|
|
.switch-container {
|
|
|
|
.switch {
|
|
|
|
direction: rtl;
|
|
|
|
}
|
|
|
|
}
|
2022-04-10 13:07:36 +02:00
|
|
|
</style>
|