Files
docuseal/app/javascript/submission_form/attachment_step.vue
T

121 lines
2.6 KiB
Vue
Raw Normal View History

2023-05-25 22:47:52 +03:00
<template>
<div>
2023-11-07 02:28:06 +02:00
<div v-if="value.length">
2023-05-25 22:47:52 +03:00
<div
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"
class="flex items-center space-x-1.5 w-full"
:href="attachmentsIndex[val].url"
target="_blank"
>
<IconPaperclip
:width="16"
class="flex-none"
:heigh="16"
/>
<span>
{{ attachmentsIndex[val].filename }}
</span>
</a>
2023-11-07 02:28:06 +02:00
<button @click.prevent="removeAttachment(val)">
2023-06-15 01:05:04 +03:00
<IconTrashX
:width="18"
:heigh="19"
/>
2023-05-25 22:47:52 +03:00
</button>
</div>
2023-06-15 01:05:04 +03:00
</div>
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"
class="mb-3 px-1"
>
<MarkdownContent :string="field.description" />
</div>
2023-05-25 22:47:52 +03:00
<FileDropzone
2024-01-26 16:45:32 +02:00
:message="`${t('upload')} ${field.name || t('files')}${field.required ? '' : ` (${t('optional')})`}`"
2023-06-13 00:29:07 +03:00
:submitter-slug="submitterSlug"
:multiple="true"
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
},
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>