blob: 91ef34f0450e84962726436234266fe7e62db964 [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 Vde23ea22024-07-11 15:19:46 +053025 <template v-if="!v$.form.ipAddress.required">
Konstantin Aladyshev7c1cfe72023-05-16 09:03:25 +000026 {{ $t('global.form.fieldRequired') }}
27 </template>
Surya Vde23ea22024-07-11 15:19:46 +053028 <template v-if="!v$.form.ipAddress.ipAddress">
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],
Ed Tanous7d6b44c2024-03-23 14:56:34 -070092 setup() {
93 return {
94 v$: useVuelidate(),
95 };
96 },
Konstantin Aladyshev7c1cfe72023-05-16 09:03:25 +000097 data() {
98 return {
Surya Vde23ea22024-07-11 15:19:46 +053099 $t: useI18n().t,
Konstantin Aladyshev7c1cfe72023-05-16 09:03:25 +0000100 form: {
101 ipaddress: null,
102 port: null,
103 },
104 };
105 },
106 validations() {
107 return {
108 form: {
109 ipAddress: {
110 required,
111 ipAddress,
112 },
113 port: {
114 minValue: minValue(0),
115 maxValue: maxValue(65535),
116 },
117 },
118 };
119 },
120 methods: {
121 handleSubmit() {
Surya Vde23ea22024-07-11 15:19:46 +0530122 this.v$.$touch();
123 if (this.v$.$invalid) return;
Konstantin Aladyshev7c1cfe72023-05-16 09:03:25 +0000124 this.$emit('ok', {
125 ipAddress: this.form.ipAddress,
126 port: this.form.port,
127 });
128 this.closeModal();
129 },
130 closeModal() {
131 this.$nextTick(() => {
132 this.$refs.modal.hide();
133 });
134 },
135 resetForm() {
136 this.form.ipAddress = '';
137 this.form.port = '';
Surya Vde23ea22024-07-11 15:19:46 +0530138 this.v$.$reset();
Konstantin Aladyshev7c1cfe72023-05-16 09:03:25 +0000139 this.$emit('hidden');
140 },
141 onOk(bvModalEvt) {
142 // prevent modal close
143 bvModalEvt.preventDefault();
144 this.handleSubmit();
145 },
146 },
147};
148</script>