Files

138 lines
3.1 KiB
Vue
Raw Permalink Normal View History

2023-05-25 22:47:52 +03:00
<template>
<div>
2026-04-17 14:49:14 +03:00
<ul
v-if="value.length"
:aria-label="t('uploaded_files')"
class="list-none p-0 m-0"
>
2026-04-16 12:41:42 +03:00
<li
2023-11-07 02:28:06 +02:00
v-for="(val, index) in value"
2023-05-25 22:47:52 +03:00
:key="index"
2023-06-15 01:05:04 +03:00
class="flex mb-2"
2023-05-25 22:47:52 +03:00
>
<input
:value="val"
type="hidden"
:name="`values[${field.uuid}][]`"
>
2023-06-15 01:05:04 +03:00
<a
v-if="val"
2025-03-18 17:34:11 +02:00
class="flex items-center space-x-1.5 w-full attachment-file-name"
2023-06-15 01:05:04 +03:00
:href="attachmentsIndex[val].url"
target="_blank"
>
<IconPaperclip
:width="16"
class="flex-none"
2026-04-17 14:49:14 +03:00
:height="16"
2026-04-16 12:41:42 +03:00
aria-hidden="true"
2023-06-15 01:05:04 +03:00
/>
<span>
{{ attachmentsIndex[val].filename }}
</span>
</a>
2025-03-18 17:34:11 +02:00
<button
2026-04-16 12:41:42 +03:00
type="button"
2025-03-18 17:34:11 +02:00
class="remove-attachment-button"
2026-04-16 12:41:42 +03:00
:aria-label="`${t('clear')} ${attachmentsIndex[val].filename}`"
2025-03-18 17:34:11 +02:00
@click.prevent="removeAttachment(val)"
>
2023-06-15 01:05:04 +03:00
<IconTrashX
:width="18"
2026-04-17 14:49:14 +03:00
:height="19"
2026-04-16 12:41:42 +03:00
aria-hidden="true"
2023-06-15 01:05:04 +03:00
/>
2023-05-25 22:47:52 +03:00
</button>
2026-04-16 12:41:42 +03:00
</li>
</ul>
2023-05-25 22:47:52 +03:00
<template v-else>
<input
value=""
type="hidden"
:name="`values[${field.uuid}][]`"
>
</template>
2024-03-09 18:24:21 +02:00
<div
v-if="field.description && !modelValue.length"
dir="auto"
2025-03-18 17:34:11 +02:00
class="mb-3 px-1 field-description-text"
2024-03-09 18:24:21 +02:00
>
<MarkdownContent :string="field.description" />
</div>
2023-05-25 22:47:52 +03:00
<FileDropzone
:message="`${t('upload')} ${(field.title || field.name) || t('files')}${field.required ? '' : ` (${t('optional')})`}`"
2023-06-13 00:29:07 +03:00
:submitter-slug="submitterSlug"
:multiple="true"
2024-07-02 20:27:25 +03:00
:dry-run="dryRun"
2023-05-25 22:47:52 +03:00
@upload="onUpload"
/>
</div>
</template>
<script>
import FileDropzone from './dropzone'
2024-03-09 18:24:21 +02:00
import MarkdownContent from './markdown_content'
2023-06-15 01:05:04 +03:00
import { IconPaperclip, IconTrashX } from '@tabler/icons-vue'
2023-05-25 22:47:52 +03:00
export default {
name: 'AttachmentStep',
components: {
2023-06-15 01:05:04 +03:00
FileDropzone,
2024-03-09 18:24:21 +02:00
MarkdownContent,
2023-06-15 01:05:04 +03:00
IconPaperclip,
IconTrashX
2023-05-25 22:47:52 +03:00
},
2024-01-26 16:45:32 +02:00
inject: ['t'],
2023-05-25 22:47:52 +03:00
props: {
field: {
type: Object,
required: true
},
2023-06-13 00:29:07 +03:00
submitterSlug: {
2023-05-25 22:47:52 +03:00
type: String,
required: true
},
2024-07-02 20:27:25 +03:00
dryRun: {
type: Boolean,
required: false,
default: false
},
2023-05-25 22:47:52 +03:00
attachmentsIndex: {
type: Object,
required: false,
default: () => ({})
},
modelValue: {
type: Array,
required: false,
default: () => []
}
},
emits: ['attached', 'update:model-value'],
2023-11-07 02:28:06 +02:00
computed: {
value: {
set (value) {
this.$emit('update:model-value', this.modelValue || [])
},
get () {
return this.modelValue || []
}
}
},
2023-05-25 22:47:52 +03:00
methods: {
removeAttachment (uuid) {
2023-11-07 02:28:06 +02:00
this.value.splice(this.value.indexOf(uuid), 1)
2023-05-25 22:47:52 +03:00
2023-11-07 02:28:06 +02:00
this.$emit('update:model-value', this.value)
2023-05-25 22:47:52 +03:00
},
onUpload (attachments) {
attachments.forEach((attachment) => {
this.$emit('attached', attachment)
})
2023-11-07 02:28:06 +02:00
this.$emit('update:model-value', [...this.value, ...attachments.map(a => a.uuid)])
2023-05-25 22:47:52 +03:00
}
}
}
</script>