summaryrefslogtreecommitdiffstats
path: root/webapp/src/components/ConfiguratorModuleEntry.vue
blob: 7907742c52bb3738bcad6d4abcb37044e91a40d7 (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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
<i18n>
{
  "en": {
    "name": "Name",
    "script": "iPXE Script",
    "titleNew": "Create entry",
    "titleExisting": "Edit entry"
  },
  "de": {
    "name": "Name",
    "script": "iPXE Script",
    "titleNew": "Eintrag erstellen",
    "titleExisting": "Eintrag bearbeiten"
  }
}
</i18n>

<template>
  <v-card>
    <v-card-title primary-title class="dialog-title elevation-3">
      <div class="headline">{{ dialog.info.id ? $t('titleExisting') : $t('titleNew') }}</div>
    </v-card-title>
    <v-card-text>
      <v-text-field prepend-icon="label" :label="$t('name')" color="primary" v-model="name"></v-text-field>
      <v-textarea prepend-icon="code" rows="20" :label="$t('script')" color="primary" v-model="script"></v-textarea>
    </v-card-text>
    <v-divider></v-divider>
    <v-card-actions>
      <v-spacer></v-spacer>
      <v-btn flat="flat" @click="setDialog({ show: false })">{{ $t('cancel') }}</v-btn>
      <v-btn :color="dialog.info.id ? 'primary' : 'success'" @click="saveEntry">{{ dialog.info.id ? $t('save') : $t('create') }}</v-btn>
    </v-card-actions>
  </v-card>
</template>

<script>
import axios from 'axios'
import { mapState } from 'vuex'

export default {
  name: 'ConfiguratorModuleEntry',
  data () {
    return {
      name: '',
      script: ''
    }
  },
  computed: {
    ...mapState('configurator', ['dialog'])
  },
  watch: {
    dialog: {
      immediate: true,
      deep: true,
      handler (value) {
        if (value.type === 'entry' && value.show) {
          this.name = value.info.name
          this.script = value.info.script
        }
      }
    }
  },
  methods: {
    setDialog (data) {
      this.$store.commit('configurator/setDialog', data)
    },
    async saveEntry () {
      await axios.post('/api/configurator/entries/' + this.dialog.info.id, {
        name: this.name,
        script: this.script
      })
      this.$store.dispatch('configurator/loadData')
      this.setDialog({ show: false })
    }
  }
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.dialog-title {
  z-index: 1;
}
</style>