feat: disable certain field if created from external service
This commit is contained in:
parent
9be4469223
commit
6396618674
4 changed files with 43 additions and 0 deletions
|
|
@ -13,6 +13,14 @@ const props = withDefaults(
|
|||
fileExist?: boolean
|
||||
fileName2Long?: boolean
|
||||
}
|
||||
disableFields?: (
|
||||
| 'file'
|
||||
| 'title'
|
||||
| 'description'
|
||||
| 'keyword'
|
||||
| 'category'
|
||||
| 'author'
|
||||
)[]
|
||||
mode: 'create' | 'edit'
|
||||
fileNameLabel?: string
|
||||
title?: string
|
||||
|
|
@ -63,6 +71,25 @@ function reset() {
|
|||
}
|
||||
|
||||
function submit() {
|
||||
if (props.mode === 'edit') {
|
||||
return emit('submit', {
|
||||
mode: props.mode,
|
||||
file: props.disableFields?.includes('file') ? undefined : file.value,
|
||||
title: props.disableFields?.includes('title') ? undefined : props.title,
|
||||
description: props.disableFields?.includes('description')
|
||||
? undefined
|
||||
: props.description ?? '',
|
||||
keyword: props.disableFields?.includes('keyword')
|
||||
? undefined
|
||||
: props.keyword,
|
||||
category: props.disableFields?.includes('category')
|
||||
? undefined
|
||||
: props.category,
|
||||
author: props.disableFields?.includes('author')
|
||||
? undefined
|
||||
: props.author,
|
||||
})
|
||||
}
|
||||
emit('submit', {
|
||||
mode: props.mode,
|
||||
file: file.value,
|
||||
|
|
@ -168,6 +195,7 @@ const file = ref<File | undefined>()
|
|||
? 'ไม่สามารถเพิ่มไฟล์ที่ชื่อยาวเกิน 85 ตัวอักษรได้'
|
||||
: ''
|
||||
"
|
||||
:disable="disableFields?.includes('file')"
|
||||
id="inputFile"
|
||||
:rules="[
|
||||
(v) => v !== undefined || mode === 'edit' || 'โปรดอัปโหลดไฟล์',
|
||||
|
|
@ -186,6 +214,7 @@ const file = ref<File | undefined>()
|
|||
dense
|
||||
class="q-my-sm"
|
||||
placeholder="กรอกชื่อเรื่อง"
|
||||
:disable="disableFields?.includes('title')"
|
||||
:model-value="title"
|
||||
:rules="[
|
||||
(v) =>
|
||||
|
|
@ -204,6 +233,7 @@ const file = ref<File | undefined>()
|
|||
class="q-mt-sm no-resize"
|
||||
type="textarea"
|
||||
placeholder="กรอกรายละเอียด"
|
||||
:disable="disableFields?.includes('description')"
|
||||
:model-value="description"
|
||||
@update:model-value="(v) => $emit('update:description', v)"
|
||||
id="inputDescription"
|
||||
|
|
@ -224,6 +254,7 @@ const file = ref<File | undefined>()
|
|||
multiple
|
||||
input-debounce="0"
|
||||
@new-value="createCategory"
|
||||
:disable="disableFields?.includes('category')"
|
||||
:options="filterDataCategory"
|
||||
@filter="filterCategory"
|
||||
@update:model-value="(v) => $emit('update:category', v)"
|
||||
|
|
@ -245,6 +276,7 @@ const file = ref<File | undefined>()
|
|||
multiple
|
||||
hide-dropdown-icon
|
||||
input-debounce="0"
|
||||
:disable="disableFields?.includes('keyword')"
|
||||
:model-value="props.keyword"
|
||||
@update:model-value="(v) => $emit('update:keyword', v)"
|
||||
@new-value="createKeyword"
|
||||
|
|
@ -261,6 +293,7 @@ const file = ref<File | undefined>()
|
|||
dense
|
||||
class="q-my-sm"
|
||||
placeholder="เจ้าของผลงาน"
|
||||
:disable="disableFields?.includes('author')"
|
||||
:model-value="author"
|
||||
:rules="[
|
||||
(v) =>
|
||||
|
|
|
|||
|
|
@ -18,6 +18,7 @@ const fileFormData = ref<{
|
|||
keyword?: string[]
|
||||
category?: string[]
|
||||
author?: string
|
||||
metadata?: Record<string, unknown>
|
||||
}>({})
|
||||
const fileFormType = ref<'edit' | 'create'>('create')
|
||||
const fileFormError = ref<{ fileExist?: boolean; fileName2Long?: boolean }>({})
|
||||
|
|
@ -38,6 +39,7 @@ function triggerFileEdit(
|
|||
keyword: string[]
|
||||
category: string[]
|
||||
author: string
|
||||
metadata?: Record<string, unknown>
|
||||
},
|
||||
pathname: string,
|
||||
file?: string,
|
||||
|
|
@ -51,6 +53,7 @@ function triggerFileEdit(
|
|||
keyword: value.keyword,
|
||||
category: value.category,
|
||||
author: value.author,
|
||||
metadata: value.metadata,
|
||||
}
|
||||
fileNameLabel.value = file
|
||||
}
|
||||
|
|
@ -133,6 +136,11 @@ async function submitFileForm(
|
|||
:mode="fileFormType"
|
||||
:error="fileFormError"
|
||||
:fileNameLabel="fileNameLabel"
|
||||
:disableFields="
|
||||
fileFormData.metadata && Object.keys(fileFormData.metadata).length > 1
|
||||
? ['file', 'title', 'author']
|
||||
: []
|
||||
"
|
||||
v-model:open="fileFormState"
|
||||
v-model:title="fileFormData.title"
|
||||
v-model:description="fileFormData.description"
|
||||
|
|
|
|||
|
|
@ -247,6 +247,7 @@ function triggerFileDelete(pathname: string) {
|
|||
keyword: value.keyword,
|
||||
category: value.category,
|
||||
author: value.author,
|
||||
metadata: value.metadata,
|
||||
},
|
||||
value.pathname,
|
||||
value.fileName,
|
||||
|
|
|
|||
|
|
@ -235,6 +235,7 @@ onMounted(() => {
|
|||
keyword: value.keyword,
|
||||
category: value.category,
|
||||
author: value.author,
|
||||
metadata: value.metadata,
|
||||
},
|
||||
value.pathname,
|
||||
value.fileName,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue