aboutsummaryrefslogtreecommitdiff
path: root/resources/js/components/call-sign-description.vue
blob: 7ab8b6427ba5f4aad2aa141b082ecd2b6910cb04 (plain) (blame)
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
<template>
  <div>
    <div class="form-group">
        <label for="special-call">Special Callsign:</label>
        <select class="form-control" :class="{ 'is-invalid': isInvalid }" id="special-call" v-model="selected" :name="name" required>
          <option v-for="option in options" :key="option.id" :value="option.sign" v-text="option.sign"></option>
        </select> 
    </div>

    <div class="card mb-3">
      <div class="card-body pb-1">
        <div class="card-text" v-html="description"></div>
      </div>
    </div>
  </div>
</template>

<script>
export default {
  props: [ 'name', 'old', 'isInvalid' ],
  mounted() {
    this.$store.dispatch('pullSigns').then(() => {
      try {
        if (this.old) {
          this.$store.dispatch('setSelectedSign', this.old);
        }
        else {
          this.$store.dispatch('setSelectedSign', this.$store.getters.getSigns[0].sign);
        }
      }
      catch {
        console.log('No call signs!');
      }
    });
  },
  computed: {
    options() {
      return this.$store.getters.getSigns;
    },
    selected: {
      get() {
        return this.$store.getters.getSelectedSign;
      },
      set(value) {
        this.$store.dispatch('setSelectedSign', value);
      }
    },
    description() {
      for (let i = 0; i < this.options.length; i++)
        if (this.options[i].sign === this.selected)
          return this.options[i].description;
      return '';
    }
  }
}
</script>