blob: 5eef38178f69deb99be5145b108a025e3f884bc1 [file] [log] [blame]
Konstantin Aladyshev7c1cfe72023-05-16 09:03:25 +00001<template>
2 <b-modal id="add-destination" ref="modal" @ok="onOk" @hidden="resetForm">
3 <template #modal-title>
4 {{ $t('pageSnmpAlerts.modal.addSnmpDestinationTitle') }}
5 </template>
6 <b-form id="form-destination">
7 <b-container>
8 <b-row>
9 <b-col sm="6">
10 <!-- Add new SNMP alert destination type -->
11 <b-form-group
12 :label="$t('pageSnmpAlerts.modal.ipaddress')"
13 label-for="ip-address"
14 >
15 <b-form-input
16 id="ip-Address"
17 v-model="form.ipAddress"
Surya Vde23ea22024-07-11 15:19:46 +053018 :state="getValidationState(v$.form.ipAddress)"
Konstantin Aladyshev7c1cfe72023-05-16 09:03:25 +000019 data-test-id="snmpAlerts-input-ipAddress"
20 type="text"
Surya Vde23ea22024-07-11 15:19:46 +053021 @blur="v$.form.ipAddress.$touch()"
Konstantin Aladyshev7c1cfe72023-05-16 09:03:25 +000022 />
23
24 <b-form-invalid-feedback role="alert">
Surya Venkatesan69be8242024-09-23 19:55:06 +053025 <template v-if="v$.form.ipAddress.required.$invalid">
Konstantin Aladyshev7c1cfe72023-05-16 09:03:25 +000026 {{ $t('global.form.fieldRequired') }}
27 </template>
Surya Venkatesan69be8242024-09-23 19:55:06 +053028 <template v-if="v$.form.ipAddress.ipAddress.$invalid">
Konstantin Aladyshev7c1cfe72023-05-16 09:03:25 +000029 {{ $t('global.form.invalidFormat') }}
30 </template>
31 </b-form-invalid-feedback>
32 </b-form-group>
33 </b-col>
34 <b-col>
35 <b-form-group label-for="port">
36 <template #label>
37 {{ $t('pageSnmpAlerts.modal.port') }} -
38 <span class="form-text d-inline">
39 {{ $t('global.form.optional') }}
40 </span>
41 </template>
42 <b-form-input
43 id="port"
44 v-model="form.port"
45 type="text"
Surya Vde23ea22024-07-11 15:19:46 +053046 :state="getValidationState(v$.form.port)"
Konstantin Aladyshev7c1cfe72023-05-16 09:03:25 +000047 data-test-id="snmpAlerts-input-port"
Surya Vde23ea22024-07-11 15:19:46 +053048 @blur="v$.form.port.$touch()"
Konstantin Aladyshev7c1cfe72023-05-16 09:03:25 +000049 />
50 <b-form-invalid-feedback role="alert">
51 <template
Surya Vde23ea22024-07-11 15:19:46 +053052 v-if="!v$.form.port.minLength || !v$.form.port.maxLength"
Konstantin Aladyshev7c1cfe72023-05-16 09:03:25 +000053 >
54 {{
55 $t('global.form.valueMustBeBetween', {
56 min: 0,
57 max: 65535,
58 })
59 }}
60 </template>
61 </b-form-invalid-feedback>
62 </b-form-group>
63 </b-col>
64 </b-row>
65 </b-container>
66 </b-form>
67 <template #modal-footer="{ cancel }">
68 <b-button variant="secondary" @click="cancel()">
69 {{ $t('global.action.cancel') }}
70 </b-button>
71 <b-button
72 form="form-user"
73 type="submit"
74 variant="primary"
75 data-test-id="snmpAlerts-button-ok"
76 @click="onOk"
77 >
78 {{ $t('pageSnmpAlerts.addDestination') }}
79 </b-button>
80 </template>
81 </b-modal>
82</template>
83
84<script>
Ed Tanous7d6b44c2024-03-23 14:56:34 -070085import { required, ipAddress, minValue, maxValue } from '@vuelidate/validators';
Konstantin Aladyshev7c1cfe72023-05-16 09:03:25 +000086import VuelidateMixin from '@/components/Mixins/VuelidateMixin.js';
Ed Tanous7d6b44c2024-03-23 14:56:34 -070087import { useVuelidate } from '@vuelidate/core';
Surya Vde23ea22024-07-11 15:19:46 +053088import { useI18n } from 'vue-i18n';
Konstantin Aladyshev7c1cfe72023-05-16 09:03:25 +000089
90export default {
91 mixins: [VuelidateMixin],
Hariharan Rangasamyc5d60f52025-10-31 12:58:56 +053092 emits: ['ok', 'hidden'],
Ed Tanous7d6b44c2024-03-23 14:56:34 -070093 setup() {
94 return {
95 v$: useVuelidate(),
96 };
97 },
Konstantin Aladyshev7c1cfe72023-05-16 09:03:25 +000098 data() {
99 return {
Surya Vde23ea22024-07-11 15:19:46 +0530100 $t: useI18n().t,
Konstantin Aladyshev7c1cfe72023-05-16 09:03:25 +0000101 form: {
102 ipaddress: null,
103 port: null,
104 },
105 };
106 },
107 validations() {
108 return {
109 form: {
110 ipAddress: {
111 required,
112 ipAddress,
113 },
114 port: {
115 minValue: minValue(0),
116 maxValue: maxValue(65535),
117 },
118 },
119 };
120 },
121 methods: {
122 handleSubmit() {
Surya Vde23ea22024-07-11 15:19:46 +0530123 this.v$.$touch();
124 if (this.v$.$invalid) return;
Konstantin Aladyshev7c1cfe72023-05-16 09:03:25 +0000125 this.$emit('ok', {
126 ipAddress: this.form.ipAddress,
127 port: this.form.port,
128 });
129 this.closeModal();
130 },
131 closeModal() {
132 this.$nextTick(() => {
133 this.$refs.modal.hide();
134 });
135 },
136 resetForm() {
137 this.form.ipAddress = '';
138 this.form.port = '';
Surya Vde23ea22024-07-11 15:19:46 +0530139 this.v$.$reset();
Konstantin Aladyshev7c1cfe72023-05-16 09:03:25 +0000140 this.$emit('hidden');
141 },
142 onOk(bvModalEvt) {
143 // prevent modal close
144 bvModalEvt.preventDefault();
145 this.handleSubmit();
146 },
147 },
148};
149</script>