blob: b2eaaaea08b9c6c82f1b12018ea7f0817ce5a3ad [file] [log] [blame]
Mateusz Gapski2224ece2020-09-02 17:00:06 +02001<template>
2 <b-modal
3 id="configure-connection"
4 ref="modal"
5 @ok="onOk"
6 @hidden="resetForm"
7 @show="initModal"
8 >
Derick Montague602e98a2020-10-21 16:20:00 -05009 <template #modal-title>
Mateusz Gapski2224ece2020-09-02 17:00:06 +020010 {{ $t('pageVirtualMedia.modal.title') }}
11 </template>
12 <b-form>
13 <b-form-group
14 :label="$t('pageVirtualMedia.modal.serverUri')"
15 label-for="serverUri"
16 >
17 <b-form-input
18 id="serverUri"
19 v-model="form.serverUri"
20 type="text"
Surya Vde23ea22024-07-11 15:19:46 +053021 :state="getValidationState(v$.form.serverUri)"
Mateusz Gapski2224ece2020-09-02 17:00:06 +020022 data-test-id="configureConnection-input-serverUri"
Surya Vde23ea22024-07-11 15:19:46 +053023 @input="v$.form.serverUri.$touch()"
Mateusz Gapski2224ece2020-09-02 17:00:06 +020024 />
25 <b-form-invalid-feedback role="alert">
Surya Venkatesan69be8242024-09-23 19:55:06 +053026 <template v-if="v$.form.serverUri.required.$invalid">
Mateusz Gapski2224ece2020-09-02 17:00:06 +020027 {{ $t('global.form.fieldRequired') }}
28 </template>
29 </b-form-invalid-feedback>
30 </b-form-group>
31 <b-form-group
32 :label="$t('pageVirtualMedia.modal.username')"
33 label-for="username"
34 >
35 <b-form-input
36 id="username"
37 v-model="form.username"
38 type="text"
jason westoverd36ac8a2025-11-03 20:58:59 -060039 autocomplete="username"
Mateusz Gapski2224ece2020-09-02 17:00:06 +020040 data-test-id="configureConnection-input-username"
41 />
42 </b-form-group>
43 <b-form-group
44 :label="$t('pageVirtualMedia.modal.password')"
45 label-for="password"
46 >
47 <b-form-input
48 id="password"
49 v-model="form.password"
50 type="password"
jason westoverd36ac8a2025-11-03 20:58:59 -060051 autocomplete="current-password"
Mateusz Gapski2224ece2020-09-02 17:00:06 +020052 data-test-id="configureConnection-input-password"
53 />
54 </b-form-group>
55 <b-form-group>
56 <b-form-checkbox
57 v-model="form.isRW"
58 data-test-id="configureConnection-input-isRW"
59 name="check-button"
60 >
61 RW
62 </b-form-checkbox>
63 </b-form-group>
64 </b-form>
Derick Montague602e98a2020-10-21 16:20:00 -050065 <template #modal-ok>
Mateusz Gapski2224ece2020-09-02 17:00:06 +020066 {{ $t('global.action.save') }}
67 </template>
Sukanya Pandey38357132020-12-22 13:40:59 +053068 <template #modal-cancel>
69 {{ $t('global.action.cancel') }}
70 </template>
Mateusz Gapski2224ece2020-09-02 17:00:06 +020071 </b-modal>
72</template>
73
74<script>
Ed Tanous7d6b44c2024-03-23 14:56:34 -070075import { required } from '@vuelidate/validators';
SurenNeware61859092020-10-01 09:37:32 +053076import VuelidateMixin from '@/components/Mixins/VuelidateMixin.js';
Ed Tanous7d6b44c2024-03-23 14:56:34 -070077import { useVuelidate } from '@vuelidate/core';
Surya Vde23ea22024-07-11 15:19:46 +053078import { useI18n } from 'vue-i18n';
Mateusz Gapski2224ece2020-09-02 17:00:06 +020079
80export default {
81 mixins: [VuelidateMixin],
82 props: {
83 connection: {
84 type: Object,
85 default: null,
Derick Montague602e98a2020-10-21 16:20:00 -050086 },
Mateusz Gapski2224ece2020-09-02 17:00:06 +020087 },
Hariharan Rangasamyc5d60f52025-10-31 12:58:56 +053088 emits: ['ok'],
Ed Tanous7d6b44c2024-03-23 14:56:34 -070089 setup() {
90 return {
91 v$: useVuelidate(),
92 };
93 },
Mateusz Gapski2224ece2020-09-02 17:00:06 +020094 data() {
95 return {
Surya Vde23ea22024-07-11 15:19:46 +053096 $t: useI18n().t,
Mateusz Gapski2224ece2020-09-02 17:00:06 +020097 form: {
98 serverUri: null,
99 username: null,
100 password: null,
Derick Montague602e98a2020-10-21 16:20:00 -0500101 isRW: false,
102 },
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200103 };
104 },
105 watch: {
Derick Montague602e98a2020-10-21 16:20:00 -0500106 connection: function (value) {
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200107 if (value === null) return;
108 Object.assign(this.form, value);
Derick Montague602e98a2020-10-21 16:20:00 -0500109 },
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200110 },
111 validations() {
112 return {
113 form: {
114 serverUri: {
Derick Montague602e98a2020-10-21 16:20:00 -0500115 required,
116 },
117 },
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200118 };
119 },
120 methods: {
121 handleSubmit() {
Surya Vde23ea22024-07-11 15:19:46 +0530122 this.v$.$touch();
123 if (this.v$.$invalid) return;
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200124 let connectionData = {};
125 Object.assign(connectionData, this.form);
126 this.$emit('ok', connectionData);
127 this.closeModal();
128 },
129 initModal() {
130 if (this.connection) {
131 Object.assign(this.form, this.connection);
132 }
133 },
134 closeModal() {
135 this.$nextTick(() => {
136 this.$refs.modal.hide();
137 });
138 },
139 resetForm() {
140 this.form.serverUri = null;
141 this.form.username = null;
142 this.form.password = null;
143 this.form.isRW = false;
Surya Vde23ea22024-07-11 15:19:46 +0530144 this.v$.$reset();
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200145 },
146 onOk(bvModalEvt) {
147 bvModalEvt.preventDefault();
148 this.handleSubmit();
Derick Montague602e98a2020-10-21 16:20:00 -0500149 },
150 },
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200151};
152</script>