Files
docuseal/app/javascript/template_builder/dropzone.vue
T

114 lines
2.8 KiB
Vue
Raw Normal View History

2023-07-01 00:15:15 +03:00
<template>
<div
class="flex h-60 w-full"
@dragover.prevent
@drop.prevent="onDropFiles"
>
<label
2024-07-09 23:47:46 +03:00
id="document_dropzone"
2024-03-27 13:47:17 +02:00
class="w-full relative hover:bg-base-200/30 rounded-md border border-2 border-base-content/10 border-dashed"
2023-07-01 00:15:15 +03:00
:for="inputId"
:class="{ 'opacity-50': isLoading || isProcessing }"
>
<div class="absolute top-0 right-0 left-0 bottom-0 flex items-center justify-center">
<div class="flex flex-col items-center">
<IconInnerShadowTop
v-if="isLoading || isProcessing"
class="animate-spin"
:width="40"
:height="40"
/>
<IconCloudUpload
v-else
:width="40"
:height="40"
/>
<div
v-if="message"
class="font-medium text-lg mb-1"
>
{{ message }}
</div>
<div class="text-sm">
2024-01-04 01:05:36 +02:00
<span class="font-medium">{{ t('click_to_upload') }}</span> {{ t('or_drag_and_drop_files') }}
2023-07-01 00:15:15 +03:00
</div>
</div>
</div>
<form
ref="form"
2023-07-01 00:15:15 +03:00
class="hidden"
>
<input
:id="inputId"
ref="input"
type="file"
name="files[]"
2023-09-05 20:33:40 +03:00
:accept="acceptFileTypes"
multiple
@change="upload"
>
</form>
2023-07-01 00:15:15 +03:00
</label>
</div>
</template>
<script>
import Upload from './upload'
import { IconCloudUpload, IconInnerShadowTop } from '@tabler/icons-vue'
export default {
name: 'FileDropzone',
components: {
IconCloudUpload,
IconInnerShadowTop
},
2024-01-04 01:05:36 +02:00
inject: ['baseFetch', 't'],
2023-07-01 00:15:15 +03:00
props: {
templateId: {
type: [Number, String],
required: true
},
2023-09-05 20:33:40 +03:00
acceptFileTypes: {
type: String,
required: false,
default: 'image/*, application/pdf'
2023-07-01 00:15:15 +03:00
}
},
emits: ['success'],
data () {
return {
isLoading: false,
isProcessing: false
}
},
computed: {
inputId () {
return 'el' + Math.random().toString(32).split('.')[1]
},
message () {
if (this.isLoading) {
2024-01-04 01:05:36 +02:00
return this.t('uploading')
2023-07-01 00:15:15 +03:00
} else if (this.isProcessing) {
2024-01-04 01:05:36 +02:00
return this.t('processing_')
2023-09-05 20:33:40 +03:00
} else if (this.acceptFileTypes === 'image/*, application/pdf') {
2024-01-04 01:05:36 +02:00
return this.t('add_pdf_documents_or_images')
2023-09-05 20:33:40 +03:00
} else {
2024-01-04 01:05:36 +02:00
return this.t('add_documents_or_images')
2023-07-01 00:15:15 +03:00
}
}
},
methods: {
upload: Upload.methods.upload,
onDropFiles (e) {
2023-09-05 20:33:40 +03:00
if (this.acceptFileTypes !== 'image/*, application/pdf' || [...e.dataTransfer.files].every((f) => f.type.match(/(?:image\/)|(?:application\/pdf)/))) {
2023-08-04 22:10:49 +03:00
this.$refs.input.files = e.dataTransfer.files
2023-07-01 00:15:15 +03:00
2023-08-04 22:10:49 +03:00
this.upload()
} else {
alert('Only PDF and images are supported.')
}
2023-07-01 00:15:15 +03:00
}
}
}
</script>