forked from platypush/platypush
58 lines
1.2 KiB
Vue
58 lines
1.2 KiB
Vue
<template>
|
|
<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">
|
|
<ToggleSwitch :value="value.state" @input="toggle"
|
|
@click.stop :disabled="loading || value.is_read_only" />
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</template>
|
|
|
|
<script>
|
|
import ToggleSwitch from "@/components/elements/ToggleSwitch"
|
|
import EntityIcon from "./EntityIcon"
|
|
import EntityMixin from "./EntityMixin"
|
|
|
|
export default {
|
|
name: 'Switch',
|
|
components: {ToggleSwitch, EntityIcon},
|
|
mixins: [EntityMixin],
|
|
|
|
methods: {
|
|
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)
|
|
}
|
|
},
|
|
},
|
|
}
|
|
</script>
|
|
|
|
<style lang="scss" scoped>
|
|
@import "common";
|
|
|
|
.switch-container {
|
|
.switch {
|
|
direction: rtl;
|
|
}
|
|
}
|
|
</style>
|