Skip to content

Commit 5e07db8

Browse files
authored
Merge pull request #43 from devforth/readonly_colums_fix
Read-only property added for columns
2 parents f71ffdf + ea66ff0 commit 5e07db8

File tree

4 files changed

+41
-11
lines changed

4 files changed

+41
-11
lines changed

adminforth/plugins/rich-editor/custom/quillEditor.vue

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<template>
2-
32
<div
43
class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500
54
focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400
@@ -200,6 +199,7 @@ onMounted(() => {
200199
201200
quill = new Quill(editor.value as HTMLElement, {
202201
theme: "snow",
202+
readOnly:props.column?.editReadonly,
203203
placeholder: 'Type here...',
204204
// formats : ['complete'],
205205
modules: {
@@ -431,7 +431,7 @@ function approveCompletion(type: 'all' | 'word') {
431431
}
432432
433433
async function startCompletion() {
434-
if (!props.meta.shouldComplete) {
434+
if (!props.meta.shouldComplete || props.column?.editReadonly ) {
435435
return;
436436
}
437437
completion.value = null;

adminforth/spa/src/afcl/Select.vue

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<input
55
ref="inputEl"
66
type="text"
7+
:readonly="isReadonly"
78
v-model="search"
89
@click="inputClick"
910
@input="inputInput"
@@ -101,6 +102,10 @@ const props = defineProps({
101102
type: String,
102103
default: '',
103104
},
105+
isReadonly: {
106+
type: Boolean,
107+
default: false,
108+
},
104109
});
105110
106111
const emit = defineEmits(['update:modelValue']);
@@ -141,6 +146,9 @@ function updateFromProps() {
141146
}
142147
143148
function inputClick() {
149+
if (props.isReadonly) {
150+
return;
151+
}
144152
if (!showDropdown.value) {
145153
showDropdown.value = true;
146154
} else {

adminforth/spa/src/components/CustomDatePicker.vue

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@
99
<IconCalendar class="w-4 h-4 text-gray-500 dark:text-gray-400"/>
1010
</div>
1111

12-
<input ref="datepickerStartEl" type="text"
12+
<input ref="datepickerStartEl" type="text"
1313
class="bg-gray-50 border leading-none border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
14-
:placeholder="$t('Select date')"
15-
>
14+
:placeholder="$t('Select date')" :disabled="isReadonly" />
15+
1616
</div>
1717
</div>
1818
</div>
@@ -27,7 +27,7 @@
2727

2828
<input v-model="startTime" type="time" id="start-time" onfocus="this.showPicker()" onclick="this.showPicker()" step="1"
2929
class="bg-gray-50 border leading-none border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
30-
value="00:00" required/>
30+
value="00:00" :disabled="isReadonly" required/>
3131
</div>
3232
</div>
3333
</div>
@@ -71,7 +71,10 @@ const props = defineProps({
7171
},
7272
autoHide: {
7373
type: Boolean,
74-
}
74+
},
75+
isReadonly: {
76+
type: Boolean,
77+
},
7578
});
7679
7780
const emit = defineEmits(['update:valueStart']);

adminforth/spa/src/components/GroupsTable.vue

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
:key="column.name"
2121
v-if="currentValues !== null"
2222
class="bg-ligftForm dark:bg-gray-800 dark:border-gray-700 block md:table-row"
23-
:class="{ 'border-b': i !== group.columns.length - 1, 'opacity-50 pointer-events-none': column.editReadonly && source === 'edit'}"
23+
:class="{ 'border-b': i !== group.columns.length - 1}"
2424
>
2525
<td class="px-6 py-4 flex items-center block md:table-cell pb-0 md:pb-4"
2626
:class="{'rounded-bl-lg border-b-none': i === group.columns.length - 1}"> <!--align-top-->
@@ -59,20 +59,23 @@
5959
:options="columnOptions[column.name] || []"
6060
:placeholder = "columnOptions[column.name]?.length ?$t('Select...'): $t('There are no options available')"
6161
:modelValue="currentValues[column.name]"
62+
:isReadonly="column.editReadonly && source === 'edit'"
6263
@update:modelValue="setCurrentValue(column.name, $event)"
6364
></Select>
6465
<Select
6566
class="w-full"
6667
v-else-if="column.enum"
6768
:options="column.enum"
6869
:modelValue="currentValues[column.name]"
70+
:isReadonly="column.editReadonly && source === 'edit'"
6971
@update:modelValue="setCurrentValue(column.name, $event)"
7072
></Select>
7173
<Select
7274
class="w-full"
7375
v-else-if="column.type === 'boolean'"
7476
:options="getBooleanOptions(column)"
7577
:modelValue="currentValues[column.name]"
78+
:isReadonly="column.editReadonly && source === 'edit'"
7679
@update:modelValue="setCurrentValue(column.name, $event)"
7780
></Select>
7881
<input
@@ -81,6 +84,7 @@
8184
step="1"
8285
class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-40 p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
8386
placeholder="0"
87+
:isReadonly="column.editReadonly && source === 'edit'"
8488
:value="currentValues[column.name]"
8589
@input="setCurrentValue(column.name, $event.target.value)"
8690
>
@@ -90,6 +94,7 @@
9094
:valueStart="currentValues[column.name]"
9195
auto-hide
9296
@update:valueStart="setCurrentValue(column.name, $event)"
97+
:isReadonly="column.editReadonly && source === 'edit'"
9398
/>
9499
<input
95100
v-else-if="['decimal', 'float'].includes(column.type)"
@@ -99,13 +104,15 @@
99104
placeholder="0.0"
100105
:value="currentValues[column.name]"
101106
@input="setCurrentValue(column.name, $event.target.value)"
107+
:readonly="column.editReadonly && source === 'edit'"
102108
/>
103109
<textarea
104110
v-else-if="['text', 'richtext'].includes(column.type)"
105111
class="bg-gray-50 border border-gray-300 text-gray-900 text-sm rounded-lg focus:ring-blue-500 focus:border-blue-500 block w-full p-2.5 dark:bg-gray-700 dark:border-gray-600 dark:placeholder-gray-400 dark:text-white dark:focus:ring-blue-500 dark:focus:border-blue-500"
106112
:placeholder="$t('Text')"
107113
:value="currentValues[column.name]"
108114
@input="setCurrentValue(column.name, $event.target.value)"
115+
:readonly="column.editReadonly && source === 'edit'"
109116
>
110117
</textarea>
111118
<textarea
@@ -126,7 +133,8 @@
126133
autocomplete="false"
127134
data-lpignore="true"
128135
readonly
129-
onfocus="this.removeAttribute('readonly');"
136+
ref="readonlyInputs"
137+
@focus="onFocusHandler($event, column, source)"
130138
>
131139

132140
<button
@@ -171,6 +179,9 @@
171179
columnOptions: any,
172180
}>();
173181
182+
const customComponentsInValidity: Ref<Record<string, boolean>> = ref({});
183+
const customComponentsEmptiness: Ref<Record<string, boolean>> = ref({});
184+
174185
const getBooleanOptions = (column: any) => {
175186
const options: Array<{ label: string; value: boolean | null }> = [
176187
{ label: t('Yes'), value: true },
@@ -181,12 +192,20 @@
181192
}
182193
return options;
183194
};
195+
function onFocusHandler(event:FocusEvent, column:any, source:string, ) {
196+
const focusedInput = event.target as HTMLInputElement;
197+
if(!focusedInput) return;
198+
if (column.editReadonly && source === 'edit') return;
199+
else {
200+
focusedInput.removeAttribute('readonly');
201+
}
202+
}
203+
184204
185205
const emit = defineEmits(['update:customComponentsInValidity', 'update:customComponentsEmptiness']);
186206
187207
188-
const customComponentsInValidity: Ref<Record<string, boolean>> = ref({});
189-
const customComponentsEmptiness: Ref<Record<string, boolean>> = ref({});
208+
190209
191210
watch(customComponentsInValidity, (newVal) => {
192211
emit('update:customComponentsInValidity', newVal);

0 commit comments

Comments
 (0)