blob: 682528b76fa2de5e1cedb32158b7e5e70fb65fda [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"
39 data-test-id="configureConnection-input-username"
40 />
41 </b-form-group>
42 <b-form-group
43 :label="$t('pageVirtualMedia.modal.password')"
44 label-for="password"
45 >
46 <b-form-input
47 id="password"
48 v-model="form.password"
49 type="password"
50 data-test-id="configureConnection-input-password"
51 />
52 </b-form-group>
53 <b-form-group>
54 <b-form-checkbox
55 v-model="form.isRW"
56 data-test-id="configureConnection-input-isRW"
57 name="check-button"
58 >
59 RW
60 </b-form-checkbox>
61 </b-form-group>
62 </b-form>
Derick Montague602e98a2020-10-21 16:20:00 -050063 <template #modal-ok>
Mateusz Gapski2224ece2020-09-02 17:00:06 +020064 {{ $t('global.action.save') }}
65 </template>
Sukanya Pandey38357132020-12-22 13:40:59 +053066 <template #modal-cancel>
67 {{ $t('global.action.cancel') }}
68 </template>
Mateusz Gapski2224ece2020-09-02 17:00:06 +020069 </b-modal>
70</template>
71
72<script>
Ed Tanous7d6b44c2024-03-23 14:56:34 -070073import { required } from '@vuelidate/validators';
SurenNeware61859092020-10-01 09:37:32 +053074import VuelidateMixin from '@/components/Mixins/VuelidateMixin.js';
Ed Tanous7d6b44c2024-03-23 14:56:34 -070075import { useVuelidate } from '@vuelidate/core';
Surya Vde23ea22024-07-11 15:19:46 +053076import { useI18n } from 'vue-i18n';
Mateusz Gapski2224ece2020-09-02 17:00:06 +020077
78export default {
79 mixins: [VuelidateMixin],
80 props: {
81 connection: {
82 type: Object,
83 default: null,
Derick Montague602e98a2020-10-21 16:20:00 -050084 validator: (prop) => {
Mateusz Gapski2224ece2020-09-02 17:00:06 +020085 console.log(prop);
86 return true;
Derick Montague602e98a2020-10-21 16:20:00 -050087 },
88 },
Mateusz Gapski2224ece2020-09-02 17:00:06 +020089 },
Hariharan Rangasamyc5d60f52025-10-31 12:58:56 +053090 emits: ['ok'],
Ed Tanous7d6b44c2024-03-23 14:56:34 -070091 setup() {
92 return {
93 v$: useVuelidate(),
94 };
95 },
Mateusz Gapski2224ece2020-09-02 17:00:06 +020096 data() {
97 return {
Surya Vde23ea22024-07-11 15:19:46 +053098 $t: useI18n().t,
Mateusz Gapski2224ece2020-09-02 17:00:06 +020099 form: {
100 serverUri: null,
101 username: null,
102 password: null,
Derick Montague602e98a2020-10-21 16:20:00 -0500103 isRW: false,
104 },
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200105 };
106 },
107 watch: {
Derick Montague602e98a2020-10-21 16:20:00 -0500108 connection: function (value) {
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200109 if (value === null) return;
110 Object.assign(this.form, value);
Derick Montague602e98a2020-10-21 16:20:00 -0500111 },
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200112 },
113 validations() {
114 return {
115 form: {
116 serverUri: {
Derick Montague602e98a2020-10-21 16:20:00 -0500117 required,
118 },
119 },
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200120 };
121 },
122 methods: {
123 handleSubmit() {
Surya Vde23ea22024-07-11 15:19:46 +0530124 this.v$.$touch();
125 if (this.v$.$invalid) return;
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200126 let connectionData = {};
127 Object.assign(connectionData, this.form);
128 this.$emit('ok', connectionData);
129 this.closeModal();
130 },
131 initModal() {
132 if (this.connection) {
133 Object.assign(this.form, this.connection);
134 }
135 },
136 closeModal() {
137 this.$nextTick(() => {
138 this.$refs.modal.hide();
139 });
140 },
141 resetForm() {
142 this.form.serverUri = null;
143 this.form.username = null;
144 this.form.password = null;
145 this.form.isRW = false;
Surya Vde23ea22024-07-11 15:19:46 +0530146 this.v$.$reset();
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200147 },
148 onOk(bvModalEvt) {
149 bvModalEvt.preventDefault();
150 this.handleSubmit();
Derick Montague602e98a2020-10-21 16:20:00 -0500151 },
152 },
Mateusz Gapski2224ece2020-09-02 17:00:06 +0200153};
154</script>