summaryrefslogtreecommitdiff
path: root/src/views/_sila/Overview/Network/ModalDns.vue
blob: 641fe78d204962310752925af2509712e9a773a9 (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
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
85
86
87
88
89
90
91
92
<template>
  <b-modal
    id="modal-dns"
    ref="modal"
    :title="$t('pageNetwork.table.addDnsAddress')"
    @hidden="resetForm"
  >
    <b-form id="form-dns" @submit.prevent="handleSubmit">
      <b-row>
        <b-col>
          <b-form-group
            :label="$t('pageNetwork.modal.staticDns')"
            label-for="staticDns"
          >
            <b-form-input
              id="staticDns"
              v-model="form.staticDns"
              type="text"
              :state="getIpValidationState($v.form.staticDns)"
              @input="$v.form.staticDns.$touch()"
            />
            <b-form-invalid-feedback role="alert">
              <template v-if="!$v.form.staticDns.required">
                {{ $t('global.form.fieldRequired') }}
              </template>
              <template v-if="!$v.form.staticDns.ipAddress">
                {{ $t('global.form.invalidFormat') }}
              </template>
            </b-form-invalid-feedback>
          </b-form-group>
        </b-col>
      </b-row>
    </b-form>
    <template #modal-footer="{ cancel }">
      <b-button variant="secondary" @click="cancel()">
        {{ $t('global.action.cancel') }}
      </b-button>
      <b-button form="form-dns" type="submit" variant="primary" @click="onOk">
        {{ $t('global.action.add') }}
      </b-button>
    </template>
  </b-modal>
</template>

<script>
import VuelidateMixin from '@/components/_sila/Mixins/VuelidateMixin.js';
import { ipAddress, required } from 'vuelidate/lib/validators';

export default {
  mixins: [VuelidateMixin],
  data() {
    return {
      form: {
        staticDns: null,
      },
    };
  },
  validations() {
    return {
      form: {
        staticDns: {
          required,
          ipAddress,
        },
      },
    };
  },
  methods: {
    handleSubmit() {
      this.$v.$touch();
      if (this.$v.$invalid) return;
      this.$emit('ok', [this.form.staticDns]);
      this.closeModal();
    },
    closeModal() {
      this.$nextTick(() => {
        this.$refs.modal.hide();
      });
    },
    resetForm() {
      this.form.staticDns = null;
      this.$v.$reset();
      this.$emit('hidden');
    },
    onOk(bvModalEvt) {
      // prevent modal close
      bvModalEvt.preventDefault();
      this.handleSubmit();
    },
  },
};
</script>