aboutsummaryrefslogtreecommitdiff
path: root/src/components/settings_modal/helpers/boolean_setting.vue
blob: 11b354edba8fbe52b2548fa5868a288e76a11c06 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
<template>
  <label
    class="BooleanSetting"
  >
    <Checkbox
      :checked="state"
      @change="update"
      :disabled="disabled"
      >
      <span
        v-if="!!$slots.default"
        class="label"
        >
        <slot />
      </span>
    </Checkbox>
    <span v-if="isChanged">
      <strong>CHANGED</strong>
    </span>
  </label>
</template>

<script>
import { get, set } from 'lodash'
import Checkbox from 'src/components/checkbox/checkbox.vue'
export default {
  props: [
    'path',
    'disabled'
  ],
  components: {
    Checkbox
  },
  computed: {
    pathDefault () {
      const [firstSegment, ...rest] = this.path.split('.')
      return [firstSegment + 'DefaultValue', ...rest].join('.')
    },
    state () {
      return get(this.$parent, this.path)
    },
    isChanged () {
      return get(this.$parent, this.path) !== get(this.$parent, this.pathDefault)
    }
  },
  methods: {
    update (e) {
      set(this.$parent, this.path, e)
    }
  }
}
</script>

<style lang="scss">
.BooleanSetting {
}
</style>