blob: 38b1cede3e23398b21bf36d9d093f6263901c084 [file] [log] [blame]
Konstantin Aladyshev7c1cfe72023-05-16 09:03:25 +00001<template>
jason westoverd36ac8a2025-11-03 20:58:59 -06002 <b-modal
3 id="add-destination"
4 ref="modal"
5 :title="$t('pageSnmpAlerts.modal.addSnmpDestinationTitle')"
6 @ok="onOk"
7 @hidden="resetForm"
8 >
Konstantin Aladyshev7c1cfe72023-05-16 09:03:25 +00009 <b-form id="form-destination">
10 <b-container>
11 <b-row>
12 <b-col sm="6">
13 <!-- Add new SNMP alert destination type -->
14 <b-form-group
15 :label="$t('pageSnmpAlerts.modal.ipaddress')"
16 label-for="ip-address"
17 >
18 <b-form-input
19 id="ip-Address"
20 v-model="form.ipAddress"
Surya Vde23ea22024-07-11 15:19:46 +053021 :state="getValidationState(v$.form.ipAddress)"
Konstantin Aladyshev7c1cfe72023-05-16 09:03:25 +000022 data-test-id="snmpAlerts-input-ipAddress"
23 type="text"
Surya Vde23ea22024-07-11 15:19:46 +053024 @blur="v$.form.ipAddress.$touch()"
Konstantin Aladyshev7c1cfe72023-05-16 09:03:25 +000025 />
26
27 <b-form-invalid-feedback role="alert">
Surya Venkatesan69be8242024-09-23 19:55:06 +053028 <template v-if="v$.form.ipAddress.required.$invalid">
Konstantin Aladyshev7c1cfe72023-05-16 09:03:25 +000029 {{ $t('global.form.fieldRequired') }}
30 </template>
Surya Venkatesan69be8242024-09-23 19:55:06 +053031 <template v-if="v$.form.ipAddress.ipAddress.$invalid">
Konstantin Aladyshev7c1cfe72023-05-16 09:03:25 +000032 {{ $t('global.form.invalidFormat') }}
33 </template>
34 </b-form-invalid-feedback>
35 </b-form-group>
36 </b-col>
37 <b-col>
38 <b-form-group label-for="port">
39 <template #label>
40 {{ $t('pageSnmpAlerts.modal.port') }} -
41 <span class="form-text d-inline">
42 {{ $t('global.form.optional') }}
43 </span>
44 </template>
45 <b-form-input
46 id="port"
47 v-model="form.port"
48 type="text"
Surya Vde23ea22024-07-11 15:19:46 +053049 :state="getValidationState(v$.form.port)"
Konstantin Aladyshev7c1cfe72023-05-16 09:03:25 +000050 data-test-id="snmpAlerts-input-port"
Surya Vde23ea22024-07-11 15:19:46 +053051 @blur="v$.form.port.$touch()"
Konstantin Aladyshev7c1cfe72023-05-16 09:03:25 +000052 />
53 <b-form-invalid-feedback role="alert">
54 <template
Surya Vde23ea22024-07-11 15:19:46 +053055 v-if="!v$.form.port.minLength || !v$.form.port.maxLength"
Konstantin Aladyshev7c1cfe72023-05-16 09:03:25 +000056 >
57 {{
58 $t('global.form.valueMustBeBetween', {
59 min: 0,
60 max: 65535,
61 })
62 }}
63 </template>
64 </b-form-invalid-feedback>
65 </b-form-group>
66 </b-col>
67 </b-row>
68 </b-container>
69 </b-form>
jason westoverd36ac8a2025-11-03 20:58:59 -060070 <template #footer="{ cancel }">
Konstantin Aladyshev7c1cfe72023-05-16 09:03:25 +000071 <b-button variant="secondary" @click="cancel()">
72 {{ $t('global.action.cancel') }}
73 </b-button>
74 <b-button
75 form="form-user"
76 type="submit"
77 variant="primary"
78 data-test-id="snmpAlerts-button-ok"
79 @click="onOk"
80 >
81 {{ $t('pageSnmpAlerts.addDestination') }}
82 </b-button>
83 </template>
84 </b-modal>
85</template>
86
87<script>
Ed Tanous7d6b44c2024-03-23 14:56:34 -070088import { required, ipAddress, minValue, maxValue } from '@vuelidate/validators';
Konstantin Aladyshev7c1cfe72023-05-16 09:03:25 +000089import VuelidateMixin from '@/components/Mixins/VuelidateMixin.js';
Ed Tanous7d6b44c2024-03-23 14:56:34 -070090import { useVuelidate } from '@vuelidate/core';
Surya Vde23ea22024-07-11 15:19:46 +053091import { useI18n } from 'vue-i18n';
Konstantin Aladyshev7c1cfe72023-05-16 09:03:25 +000092
93export default {
94 mixins: [VuelidateMixin],
Hariharan Rangasamyc5d60f52025-10-31 12:58:56 +053095 emits: ['ok', 'hidden'],
Ed Tanous7d6b44c2024-03-23 14:56:34 -070096 setup() {
97 return {
98 v$: useVuelidate(),
99 };
100 },
Konstantin Aladyshev7c1cfe72023-05-16 09:03:25 +0000101 data() {
102 return {
Surya Vde23ea22024-07-11 15:19:46 +0530103 $t: useI18n().t,
Konstantin Aladyshev7c1cfe72023-05-16 09:03:25 +0000104 form: {
105 ipaddress: null,
106 port: null,
107 },
108 };
109 },
110 validations() {
111 return {
112 form: {
113 ipAddress: {
114 required,
115 ipAddress,
116 },
117 port: {
118 minValue: minValue(0),
119 maxValue: maxValue(65535),
120 },
121 },
122 };
123 },
124 methods: {
125 handleSubmit() {
Surya Vde23ea22024-07-11 15:19:46 +0530126 this.v$.$touch();
127 if (this.v$.$invalid) return;
Konstantin Aladyshev7c1cfe72023-05-16 09:03:25 +0000128 this.$emit('ok', {
129 ipAddress: this.form.ipAddress,
130 port: this.form.port,
131 });
132 this.closeModal();
133 },
134 closeModal() {
135 this.$nextTick(() => {
136 this.$refs.modal.hide();
137 });
138 },
139 resetForm() {
140 this.form.ipAddress = '';
141 this.form.port = '';
Surya Vde23ea22024-07-11 15:19:46 +0530142 this.v$.$reset();
Konstantin Aladyshev7c1cfe72023-05-16 09:03:25 +0000143 this.$emit('hidden');
144 },
145 onOk(bvModalEvt) {
146 // prevent modal close
147 bvModalEvt.preventDefault();
148 this.handleSubmit();
149 },
150 },
151};
152</script>