1
+ <template >
2
+ <div class =" flex" >
3
+ <component
4
+ v-if =" column?.components?.[props.source]?.file"
5
+ :is =" getCustomComponent(column.components[props.source])"
6
+ :column =" column"
7
+ :value =" value"
8
+ @update:value =" $emit('update:modelValue', $event)"
9
+ :meta =" column.components[props.source].meta"
10
+ :record =" currentValues"
11
+ @update:inValidity =" $emit('update:inValidity', $event)"
12
+ @update:emptiness =" $emit('update:emptiness', $event)"
13
+ />
14
+ <Select
15
+ v-else-if =" column.foreignResource"
16
+ ref =" input"
17
+ class =" w-full"
18
+ :options =" columnOptions[column.name] || []"
19
+ :placeholder = " columnOptions[column.name]?.length ?$t('Select...'): $t('There are no options available')"
20
+ :modelValue =" value"
21
+ :readonly =" column.editReadonly && source === 'edit'"
22
+ @update:modelValue =" $emit('update:modelValue', $event)"
23
+ />
24
+ <Select
25
+ v-else-if =" column.enum"
26
+ ref =" input"
27
+ class =" w-full"
28
+ :options =" column.enum"
29
+ :modelValue =" value"
30
+ :readonly =" column.editReadonly && source === 'edit'"
31
+ @update:modelValue =" $emit('update:modelValue', $event)"
32
+ />
33
+ <Select
34
+ v-else-if =" (type || column.type) === 'boolean'"
35
+ ref =" input"
36
+ class =" w-full"
37
+ :options =" getBooleanOptions(column)"
38
+ :modelValue =" value"
39
+ :readonly =" column.editReadonly && source === 'edit'"
40
+ @update:modelValue =" $emit('update:modelValue', $event)"
41
+ />
42
+ <input
43
+ v-else-if =" ['integer'].includes(type || column.type)"
44
+ ref =" input"
45
+ type =" number"
46
+ step =" 1"
47
+ class =" bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg block w-40 p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white focus:ring-lightPrimary focus:border-lightPrimary dark:focus:ring-darkPrimary dark:focus:border-darkPrimary"
48
+ placeholder =" 0"
49
+ :readonly =" column.editReadonly && source === 'edit'"
50
+ :value =" value"
51
+ @input =" $emit('update:modelValue', $event.target.value)"
52
+ >
53
+ <CustomDatePicker
54
+ v-else-if =" ['datetime'].includes(type || column.type)"
55
+ ref =" input"
56
+ :column =" column"
57
+ :valueStart =" value"
58
+ auto-hide
59
+ @update:valueStart =" $emit('update:modelValue', $event)"
60
+ :readonly =" column.editReadonly && source === 'edit'"
61
+ />
62
+ <input
63
+ v-else-if =" ['decimal', 'float'].includes(type || column.type)"
64
+ ref =" input"
65
+ type =" number"
66
+ step =" 0.1"
67
+ class =" bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg block w-40 p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white focus:ring-lightPrimary focus:border-lightPrimary dark:focus:ring-darkPrimary dark:focus:border-darkPrimary"
68
+ placeholder =" 0.0"
69
+ :value =" value"
70
+ @input =" $emit('update:modelValue', $event.target.value)"
71
+ :readonly =" column.editReadonly && source === 'edit'"
72
+ />
73
+ <textarea
74
+ v-else-if =" ['text', 'richtext'].includes(type || column.type)"
75
+ ref =" input"
76
+ class =" bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white focus:ring-lightPrimary focus:border-lightPrimary dark:focus:ring-darkPrimary dark:focus:border-darkPrimary"
77
+ :placeholder =" $t('Text')"
78
+ :value =" value"
79
+ @input =" $emit('update:modelValue', $event.target.value)"
80
+ :readonly =" column.editReadonly && source === 'edit'"
81
+ />
82
+ <textarea
83
+ v-else-if =" ['json'].includes(type || column.type)"
84
+ ref =" input"
85
+ class =" bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white focus:ring-lightPrimary focus:border-lightPrimary dark:focus:ring-darkPrimary dark:focus:border-darkPrimary"
86
+ :placeholder =" $t('Text')"
87
+ :value =" value"
88
+ @input =" $emit('update:modelValue', $event.target.value)"
89
+ />
90
+ <input
91
+ v-else
92
+ ref =" input"
93
+ :type =" !column.masked || unmasked[column.name] ? 'text' : 'password'"
94
+ class =" bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white focus:ring-lightPrimary focus:border-lightPrimary dark:focus:ring-darkPrimary dark:focus:border-darkPrimary"
95
+ :placeholder =" $t('Text')"
96
+ :value =" value"
97
+ @input =" $emit('update:modelValue', $event.target.value)"
98
+ autocomplete =" false"
99
+ data-lpignore =" true"
100
+ readonly
101
+ @focus =" onFocusHandler($event, column, source)"
102
+ >
103
+
104
+ <button
105
+ v-if =" deletable"
106
+ type =" button"
107
+ class =" h-6 inset-y-2 right-0 flex items-center px-2 pt-4 z-index-100 focus:outline-none"
108
+ @click =" $emit('delete')"
109
+ >
110
+ <IconTrashBinSolid class =" w-6 h-6 text-gray-400" />
111
+ </button >
112
+ <button
113
+ v-else-if =" column.masked"
114
+ type =" button"
115
+ @click =" $emit('update:unmasked')"
116
+ class =" h-6 inset-y-2 right-0 flex items-center px-2 pt-4 z-index-100 focus:outline-none"
117
+ >
118
+ <IconEyeSolid class =" w-6 h-6 text-gray-400" v-if =" !unmasked[column.name]" />
119
+ <IconEyeSlashSolid class =" w-6 h-6 text-gray-400" v-else />
120
+ </button >
121
+ </div >
122
+ </template >
123
+
124
+ <script setup lang="ts">
125
+ import { IconEyeSlashSolid , IconEyeSolid , IconTrashBinSolid } from ' @iconify-prerendered/vue-flowbite' ;
126
+ import CustomDatePicker from " @/components/CustomDatePicker.vue" ;
127
+ import Select from ' @/afcl/Select.vue' ;
128
+ import { ref } from ' vue' ;
129
+ import { getCustomComponent } from ' @/utils' ;
130
+ import { useI18n } from ' vue-i18n' ;
131
+
132
+ const { t } = useI18n ();
133
+
134
+ const props = defineProps <{
135
+ source: ' create' | ' edit' ,
136
+ column: any ,
137
+ type: string ,
138
+ value: any ,
139
+ currentValues: any ,
140
+ mode: string ,
141
+ columnOptions: any ,
142
+ unmasked: any ,
143
+ deletable: boolean ,
144
+ }>();
145
+
146
+ const input = ref (null );
147
+
148
+ const getBooleanOptions = (column : any ) => {
149
+ const options: Array <{ label: string ; value: boolean | null }> = [
150
+ { label: t (' Yes' ), value: true },
151
+ { label: t (' No' ), value: false },
152
+ ];
153
+ if (! column .required [props .mode ]) {
154
+ options .push ({ label: t (' Unset' ), value: null });
155
+ }
156
+ return options ;
157
+ };
158
+
159
+ function onFocusHandler(event : FocusEvent , column : any , source : string , ) {
160
+ const focusedInput = event .target as HTMLInputElement ;
161
+ if (! focusedInput ) return ;
162
+ if (column .editReadonly && source === ' edit' ) return ;
163
+ else {
164
+ focusedInput .removeAttribute (' readonly' );
165
+ }
166
+ }
167
+
168
+ function focus() {
169
+ if (input .value ?.focus ) input .value ?.focus ();
170
+ }
171
+
172
+ defineExpose ({
173
+ focus ,
174
+ });
175
+ </script >
0 commit comments