1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
|
<template>
<b-modal
id="configure-connection"
ref="modal"
@ok="onOk"
@hidden="resetForm"
@show="initModal"
>
<template #modal-title>
{{ $t('pageVirtualMedia.modal.title') }}
</template>
<b-form>
<b-form-group
:label="$t('pageVirtualMedia.modal.serverUri')"
label-for="serverUri"
>
<b-form-input
id="serverUri"
v-model="form.serverUri"
type="text"
:state="getValidationState($v.form.serverUri)"
data-test-id="configureConnection-input-serverUri"
@input="$v.form.serverUri.$touch()"
/>
<b-form-invalid-feedback role="alert">
<template v-if="!$v.form.serverUri.required">
{{ $t('global.form.fieldRequired') }}
</template>
</b-form-invalid-feedback>
</b-form-group>
<b-form-group
:label="$t('pageVirtualMedia.modal.username')"
label-for="username"
>
<b-form-input
id="username"
v-model="form.username"
type="text"
data-test-id="configureConnection-input-username"
/>
</b-form-group>
<b-form-group
:label="$t('pageVirtualMedia.modal.password')"
label-for="password"
>
<b-form-input
id="password"
v-model="form.password"
type="password"
data-test-id="configureConnection-input-password"
/>
</b-form-group>
<b-form-group>
<b-form-checkbox
v-model="form.isRW"
data-test-id="configureConnection-input-isRW"
name="check-button"
>
RW
</b-form-checkbox>
</b-form-group>
</b-form>
<template #modal-ok>
{{ $t('global.action.save') }}
</template>
</b-modal>
</template>
<script>
import { required } from 'vuelidate/lib/validators';
import VuelidateMixin from '@/components/Mixins/VuelidateMixin.js';
export default {
mixins: [VuelidateMixin],
props: {
connection: {
type: Object,
default: null,
validator: (prop) => {
console.log(prop);
return true;
},
},
},
data() {
return {
form: {
serverUri: null,
username: null,
password: null,
isRW: false,
},
};
},
watch: {
connection: function (value) {
if (value === null) return;
Object.assign(this.form, value);
},
},
validations() {
return {
form: {
serverUri: {
required,
},
},
};
},
methods: {
handleSubmit() {
this.$v.$touch();
if (this.$v.$invalid) return;
let connectionData = {};
Object.assign(connectionData, this.form);
this.$emit('ok', connectionData);
this.closeModal();
},
initModal() {
if (this.connection) {
Object.assign(this.form, this.connection);
}
},
closeModal() {
this.$nextTick(() => {
this.$refs.modal.hide();
});
},
resetForm() {
this.form.serverUri = null;
this.form.username = null;
this.form.password = null;
this.form.isRW = false;
this.$v.$reset();
},
onOk(bvModalEvt) {
bvModalEvt.preventDefault();
this.handleSubmit();
},
},
};
</script>
|