xref: /openbmc/webui-vue/src/views/Settings/Network/ModalDefaultGateway.vue (revision 4626aec43da32b56b7c1e87e5dc831398e39416c)
1db47b7e1SSean Zhang<template>
2db47b7e1SSean Zhang  <b-modal
3db47b7e1SSean Zhang    id="modal-default-gateway"
4db47b7e1SSean Zhang    ref="modal"
5db47b7e1SSean Zhang    :title="$t('pageNetwork.modal.editIPv6DefaultGatewayTitle')"
6db47b7e1SSean Zhang    @hidden="resetForm"
7db47b7e1SSean Zhang  >
8db47b7e1SSean Zhang    <b-form id="gateway-settings" @submit.prevent="handleSubmit">
9db47b7e1SSean Zhang      <b-row>
10db47b7e1SSean Zhang        <b-col sm="6">
11db47b7e1SSean Zhang          <b-form-group
12db47b7e1SSean Zhang            :label="$t('pageNetwork.gateway')"
13db47b7e1SSean Zhang            label-for="defaultGateway"
14db47b7e1SSean Zhang          >
15db47b7e1SSean Zhang            <b-form-input
16db47b7e1SSean Zhang              id="defaultGateway"
17db47b7e1SSean Zhang              v-model.trim="form.defaultGateway"
18db47b7e1SSean Zhang              data-test-id="network-input-gateway"
19db47b7e1SSean Zhang              type="text"
20*4626aec4SSurya Venkatesan              :state="getValidationState(v$.form.defaultGateway)"
21*4626aec4SSurya Venkatesan              @change="v$.form.defaultGateway.$touch()"
22db47b7e1SSean Zhang            />
23db47b7e1SSean Zhang            <b-form-invalid-feedback role="alert">
24*4626aec4SSurya Venkatesan              <div v-if="v$.form.defaultGateway.required.$invalid">
25db47b7e1SSean Zhang                {{ $t('global.form.fieldRequired') }}
26db47b7e1SSean Zhang              </div>
27*4626aec4SSurya Venkatesan              <div v-if="v$.form.defaultGateway.validateGateway.$invalid">
28db47b7e1SSean Zhang                {{ $t('global.form.invalidFormat') }}
29db47b7e1SSean Zhang              </div>
30db47b7e1SSean Zhang            </b-form-invalid-feedback>
31db47b7e1SSean Zhang          </b-form-group>
32db47b7e1SSean Zhang        </b-col>
33db47b7e1SSean Zhang      </b-row>
34db47b7e1SSean Zhang    </b-form>
35db47b7e1SSean Zhang    <template #modal-footer="{ cancel }">
36db47b7e1SSean Zhang      <b-button variant="secondary" @click="cancel()">
37db47b7e1SSean Zhang        {{ $t('global.action.cancel') }}
38db47b7e1SSean Zhang      </b-button>
39db47b7e1SSean Zhang      <b-button
40db47b7e1SSean Zhang        form="gateway-settings"
41db47b7e1SSean Zhang        type="submit"
42db47b7e1SSean Zhang        variant="primary"
43db47b7e1SSean Zhang        @click="onOk"
44db47b7e1SSean Zhang      >
45db47b7e1SSean Zhang        {{ $t('global.action.add') }}
46db47b7e1SSean Zhang      </b-button>
47db47b7e1SSean Zhang    </template>
48db47b7e1SSean Zhang  </b-modal>
49db47b7e1SSean Zhang</template>
50db47b7e1SSean Zhang
51db47b7e1SSean Zhang<script>
52db47b7e1SSean Zhangimport VuelidateMixin from '@/components/Mixins/VuelidateMixin.js';
53*4626aec4SSurya Venkatesanimport { required } from '@vuelidate/validators';
54*4626aec4SSurya Venkatesanimport { helpers } from 'vuelidate/lib/validators';
55*4626aec4SSurya Venkatesanimport { useVuelidate } from '@vuelidate/core';
56*4626aec4SSurya Venkatesanimport { useI18n } from 'vue-i18n';
57db47b7e1SSean Zhang
58db47b7e1SSean Zhangconst validateGateway = helpers.regex(
59db47b7e1SSean Zhang  'validateGateway',
60db47b7e1SSean Zhang  /^((?:[a-fA-F0-9]{1,4}:){7}[a-fA-F0-9]{1,4}|(?:[a-fA-F0-9]{1,4}:){1,7}:|(?:[a-fA-F0-9]{1,4}:){1,6}:[a-fA-F0-9]{1,4}|(?:[a-fA-F0-9]{1,4}:){1,5}(?::[a-fA-F0-9]{1,4}){1,2}|(?:[a-fA-F0-9]{1,4}:){1,4}(?::[a-fA-F0-9]{1,4}){1,3}|(?:[a-fA-F0-9]{1,4}:){1,3}(?::[a-fA-F0-9]{1,4}){1,4}|(?:[a-fA-F0-9]{1,4}:){1,2}(?::[a-fA-F0-9]{1,4}){1,5}|[a-fA-F0-9]{1,4}:(?::[a-fA-F0-9]{1,4}){1,6}|:(?::[a-fA-F0-9]{1,4}){1,7}|::|(?:[a-fA-F0-9]{1,4}:){6}(?:[0-9]{1,3}\.){3}[0-9]{1,3}|::(?:[a-fA-F0-9]{1,4}:){0,5}(?:[0-9]{1,3}\.){3}[0-9]{1,3}|(?:[a-fA-F0-9]{1,4}:){1,5}:(?:[0-9]{1,3}\.){3}[0-9]{1,3}|(?:[a-fA-F0-9]{1,4}:){1,4}:(?:[0-9]{1,3}\.){3}[0-9]{1,3}|(?:[a-fA-F0-9]{1,4}:){1,3}:(?:[0-9]{1,3}\.){3}[0-9]{1,3}|(?:[a-fA-F0-9]{1,4}:){1,2}:(?:[0-9]{1,3}\.){3}[0-9]{1,3}|[a-fA-F0-9]{1,4}:(?:[0-9]{1,3}\.){3}[0-9]{1,3}|::(?:[0-9]{1,3}\.){3}[0-9]{1,3})$/,
61db47b7e1SSean Zhang);
62db47b7e1SSean Zhang
63db47b7e1SSean Zhangexport default {
64db47b7e1SSean Zhang  mixins: [VuelidateMixin],
65db47b7e1SSean Zhang  props: {
66db47b7e1SSean Zhang    defaultGateway: {
67db47b7e1SSean Zhang      type: String,
68db47b7e1SSean Zhang      default: '',
69db47b7e1SSean Zhang    },
70db47b7e1SSean Zhang  },
71*4626aec4SSurya Venkatesan  setup() {
72*4626aec4SSurya Venkatesan    return {
73*4626aec4SSurya Venkatesan      v$: useVuelidate(),
74*4626aec4SSurya Venkatesan    };
75*4626aec4SSurya Venkatesan  },
76db47b7e1SSean Zhang  data() {
77db47b7e1SSean Zhang    return {
78*4626aec4SSurya Venkatesan      $t: useI18n().t,
79db47b7e1SSean Zhang      form: {
80db47b7e1SSean Zhang        defaultGateway: '',
81db47b7e1SSean Zhang      },
82db47b7e1SSean Zhang    };
83db47b7e1SSean Zhang  },
84db47b7e1SSean Zhang  watch: {
85db47b7e1SSean Zhang    defaultGateway() {
86db47b7e1SSean Zhang      this.form.defaultGateway = this.defaultGateway;
87db47b7e1SSean Zhang    },
88db47b7e1SSean Zhang  },
89db47b7e1SSean Zhang  validations() {
90db47b7e1SSean Zhang    return {
91db47b7e1SSean Zhang      form: {
92db47b7e1SSean Zhang        defaultGateway: {
93db47b7e1SSean Zhang          required,
94db47b7e1SSean Zhang          validateGateway,
95db47b7e1SSean Zhang        },
96db47b7e1SSean Zhang      },
97db47b7e1SSean Zhang    };
98db47b7e1SSean Zhang  },
99db47b7e1SSean Zhang  methods: {
100db47b7e1SSean Zhang    handleSubmit() {
101*4626aec4SSurya Venkatesan      this.v$.$touch();
102*4626aec4SSurya Venkatesan      if (this.v$.$invalid) return;
103db47b7e1SSean Zhang      this.$emit('ok', { IPv6DefaultGateway: this.form.defaultGateway });
104db47b7e1SSean Zhang      this.closeModal();
105db47b7e1SSean Zhang    },
106db47b7e1SSean Zhang    closeModal() {
107db47b7e1SSean Zhang      this.$nextTick(() => {
108db47b7e1SSean Zhang        this.$refs.modal.hide();
109db47b7e1SSean Zhang      });
110db47b7e1SSean Zhang    },
111db47b7e1SSean Zhang    resetForm() {
112db47b7e1SSean Zhang      this.form.defaultGateway = this.defaultGateway;
113*4626aec4SSurya Venkatesan      this.v$.$reset();
114db47b7e1SSean Zhang      this.$emit('hidden');
115db47b7e1SSean Zhang    },
116db47b7e1SSean Zhang    onOk(bvModalEvt) {
117db47b7e1SSean Zhang      // prevent modal close
118db47b7e1SSean Zhang      bvModalEvt.preventDefault();
119db47b7e1SSean Zhang      this.handleSubmit();
120db47b7e1SSean Zhang    },
121db47b7e1SSean Zhang  },
122db47b7e1SSean Zhang};
123db47b7e1SSean Zhang</script>
124