blob: 45bd41141527b66752d0783eb963c4714c746a83 [file] [log] [blame]
Dixsie Wolmersb34349d2021-11-02 22:06:35 -05001<template>
2 <b-modal
3 id="modal-add-ipv4"
4 ref="modal"
5 :title="$t('pageNetwork.table.addIpv4Address')"
6 @hidden="resetForm"
7 >
8 <b-form id="form-ipv4" @submit.prevent="handleSubmit">
9 <b-row>
10 <b-col sm="6">
11 <b-form-group
12 :label="$t('pageNetwork.modal.ipAddress')"
13 label-for="ipAddress"
14 >
15 <b-form-input
16 id="ipAddress"
17 v-model="form.ipAddress"
18 type="text"
Surya Vde23ea22024-07-11 15:19:46 +053019 :state="getValidationState(v$.form.ipAddress)"
20 @input="v$.form.ipAddress.$touch()"
Dixsie Wolmersb34349d2021-11-02 22:06:35 -050021 />
22 <b-form-invalid-feedback role="alert">
Surya Venkatesan4626aec2024-09-19 15:06:49 +053023 <template v-if="v$.form.ipAddress.required.$invalid">
Dixsie Wolmersb34349d2021-11-02 22:06:35 -050024 {{ $t('global.form.fieldRequired') }}
25 </template>
Surya Venkatesan4626aec2024-09-19 15:06:49 +053026 <template v-if="v$.form.ipAddress.ipAddress.$invalid">
Dixsie Wolmersb34349d2021-11-02 22:06:35 -050027 {{ $t('global.form.invalidFormat') }}
28 </template>
29 </b-form-invalid-feedback>
30 </b-form-group>
31 </b-col>
32 <b-col sm="6">
33 <b-form-group
34 :label="$t('pageNetwork.modal.gateway')"
35 label-for="gateway"
36 >
37 <b-form-input
38 id="gateway"
39 v-model="form.gateway"
40 type="text"
Surya Vde23ea22024-07-11 15:19:46 +053041 :state="getValidationState(v$.form.gateway)"
42 @input="v$.form.gateway.$touch()"
Dixsie Wolmersb34349d2021-11-02 22:06:35 -050043 />
44 <b-form-invalid-feedback role="alert">
Surya Venkatesan4626aec2024-09-19 15:06:49 +053045 <template v-if="v$.form.gateway.required.$invalid">
Dixsie Wolmersb34349d2021-11-02 22:06:35 -050046 {{ $t('global.form.fieldRequired') }}
47 </template>
Surya Venkatesan4626aec2024-09-19 15:06:49 +053048 <template v-if="v$.form.gateway.ipAddress.$invalid">
Dixsie Wolmersb34349d2021-11-02 22:06:35 -050049 {{ $t('global.form.invalidFormat') }}
50 </template>
51 </b-form-invalid-feedback>
52 </b-form-group>
53 </b-col>
54 </b-row>
55 <b-row>
56 <b-col sm="6">
57 <b-form-group
58 :label="$t('pageNetwork.modal.subnetMask')"
59 label-for="subnetMask"
60 >
61 <b-form-input
62 id="subnetMask"
63 v-model="form.subnetMask"
64 type="text"
Surya Vde23ea22024-07-11 15:19:46 +053065 :state="getValidationState(v$.form.subnetMask)"
66 @input="v$.form.subnetMask.$touch()"
Dixsie Wolmersb34349d2021-11-02 22:06:35 -050067 />
68 <b-form-invalid-feedback role="alert">
Surya Venkatesan4626aec2024-09-19 15:06:49 +053069 <template v-if="v$.form.subnetMask.required.$invalid">
Dixsie Wolmersb34349d2021-11-02 22:06:35 -050070 {{ $t('global.form.fieldRequired') }}
71 </template>
Surya Venkatesan4626aec2024-09-19 15:06:49 +053072 <template v-if="v$.form.subnetMask.ipAddress.$invalid">
Dixsie Wolmersb34349d2021-11-02 22:06:35 -050073 {{ $t('global.form.invalidFormat') }}
74 </template>
75 </b-form-invalid-feedback>
76 </b-form-group>
77 </b-col>
78 </b-row>
79 </b-form>
jason westoverd36ac8a2025-11-03 20:58:59 -060080 <template #footer="{ cancel }">
Dixsie Wolmersb34349d2021-11-02 22:06:35 -050081 <b-button variant="secondary" @click="cancel()">
82 {{ $t('global.action.cancel') }}
83 </b-button>
84 <b-button form="form-ipv4" type="submit" variant="primary" @click="onOk">
85 {{ $t('global.action.add') }}
86 </b-button>
87 </template>
88 </b-modal>
89</template>
90
91<script>
92import VuelidateMixin from '@/components/Mixins/VuelidateMixin.js';
Ed Tanous7d6b44c2024-03-23 14:56:34 -070093import { useVuelidate } from '@vuelidate/core';
94
95import { ipAddress, required } from '@vuelidate/validators';
Surya Vde23ea22024-07-11 15:19:46 +053096import { useI18n } from 'vue-i18n';
Dixsie Wolmersb34349d2021-11-02 22:06:35 -050097
98export default {
99 mixins: [VuelidateMixin],
100 props: {
jason westoverd36ac8a2025-11-03 20:58:59 -0600101 modelValue: {
102 type: Boolean,
103 default: false,
104 },
Dixsie Wolmersb34349d2021-11-02 22:06:35 -0500105 defaultGateway: {
106 type: String,
107 default: '',
108 },
109 },
jason westoverd36ac8a2025-11-03 20:58:59 -0600110 emits: ['ok', 'hidden', 'update:modelValue'],
Ed Tanous7d6b44c2024-03-23 14:56:34 -0700111 setup() {
112 return {
113 v$: useVuelidate(),
114 };
115 },
Dixsie Wolmersb34349d2021-11-02 22:06:35 -0500116 data() {
117 return {
Surya Vde23ea22024-07-11 15:19:46 +0530118 $t: useI18n().t,
Dixsie Wolmersb34349d2021-11-02 22:06:35 -0500119 form: {
120 ipAddress: '',
121 gateway: '',
122 subnetMask: '',
123 },
124 };
125 },
126 watch: {
127 defaultGateway() {
128 this.form.gateway = this.defaultGateway;
129 },
jason westoverd36ac8a2025-11-03 20:58:59 -0600130 modelValue: {
131 handler(newValue) {
132 if (newValue) {
133 this.$nextTick(() => {
134 this.$refs.modal?.show();
135 });
136 }
137 },
138 immediate: true,
139 },
Dixsie Wolmersb34349d2021-11-02 22:06:35 -0500140 },
141 validations() {
142 return {
143 form: {
144 ipAddress: {
145 required,
146 ipAddress,
147 },
148 gateway: {
149 required,
150 ipAddress,
151 },
152 subnetMask: {
153 required,
154 ipAddress,
155 },
156 },
157 };
158 },
159 methods: {
jason westoverd36ac8a2025-11-03 20:58:59 -0600160 show() {
161 this.$refs.modal?.show();
162 },
163 hide() {
164 this.$refs.modal?.hide();
165 },
Dixsie Wolmersb34349d2021-11-02 22:06:35 -0500166 handleSubmit() {
Surya Vde23ea22024-07-11 15:19:46 +0530167 this.v$.$touch();
168 if (this.v$.$invalid) return;
Dixsie Wolmersb34349d2021-11-02 22:06:35 -0500169 this.$emit('ok', {
170 Address: this.form.ipAddress,
171 Gateway: this.form.gateway,
172 SubnetMask: this.form.subnetMask,
173 });
174 this.closeModal();
175 },
176 closeModal() {
177 this.$nextTick(() => {
178 this.$refs.modal.hide();
179 });
180 },
181 resetForm() {
182 this.form.ipAddress = null;
183 this.form.gateway = this.defaultGateway;
184 this.form.subnetMask = null;
Surya Vde23ea22024-07-11 15:19:46 +0530185 this.v$.$reset();
jason westoverd36ac8a2025-11-03 20:58:59 -0600186 this.$emit('update:modelValue', false);
Dixsie Wolmersb34349d2021-11-02 22:06:35 -0500187 this.$emit('hidden');
188 },
189 onOk(bvModalEvt) {
190 // prevent modal close
191 bvModalEvt.preventDefault();
192 this.handleSubmit();
193 },
194 },
195};
196</script>