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

117 lines
2.5 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>
<FileDropzone
2023-06-20 00:50:02 +03:00
:message="`Upload ${field.name || 'Attachments'}${field.required ? '' : ' (optional)'}`"
2023-06-13 00:29:07 +03:00
:submitter-slug="submitterSlug"
:is-direct-upload="isDirectUpload"
:multiple="true"
2023-05-25 22:47:52 +03:00
@upload="onUpload"
/>
</div>
</template>
<script>
import FileDropzone from './dropzone'
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,
IconPaperclip,
IconTrashX
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: () => ({})
},
isDirectUpload: {
type: Boolean,
required: true,
default: false
},
2023-05-25 22:47:52 +03:00
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>