Merge pull request #1842 from cuneytsenturk/master
File group drag and drop developement
This commit is contained in:
@ -11,6 +11,10 @@
|
||||
<div v-if="preview == 'single'" class="dz-preview dz-preview-single" :class="previewClasses" ref="previewSingle">
|
||||
<div class="dz-preview-cover">
|
||||
<img class="dz-preview-img" data-dz-thumbnail>
|
||||
<i class="fas fa-file-image display-3 d-none" data-dz-thumbnail-image></i>
|
||||
<i class="far fa-file-pdf display-3 d-none" data-dz-thumbnail-pdf></i>
|
||||
<i class="far fa-file-word d-none" data-dz-thumbnail-word></i>
|
||||
<i class="far fa-file-excel d-none" data-dz-thumbnail-excel></i>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -20,6 +24,10 @@
|
||||
<div class="col-auto">
|
||||
<div class="avatar">
|
||||
<img class="avatar-img rounded" data-dz-thumbnail>
|
||||
<i class="fas fa-file-image display-3 d-none" data-dz-thumbnail-image></i>
|
||||
<i class="far fa-file-pdf display-3 d-none" data-dz-thumbnail-pdf></i>
|
||||
<i class="far fa-file-word d-none" data-dz-thumbnail-word></i>
|
||||
<i class="far fa-file-excel d-none" data-dz-thumbnail-excel></i>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@ -133,6 +141,24 @@ export default {
|
||||
} else {
|
||||
self.$emit('change', self.files);
|
||||
}
|
||||
|
||||
if (file.type.indexOf("image") == -1) {
|
||||
var ext = file.name.split('.').pop();
|
||||
|
||||
if (ext == "pdf") {
|
||||
file.previewElement.querySelector("[data-dz-thumbnail]").classList.add("d-none");
|
||||
file.previewElement.querySelector("[data-dz-thumbnail-pdf]").classList.remove("d-none");
|
||||
} else if ((ext.indexOf("doc") != -1) || (ext.indexOf("docx") != -1)) {
|
||||
file.previewElement.querySelector("[data-dz-thumbnail]").classList.add("d-none");
|
||||
file.previewElement.querySelector("[data-dz-thumbnail-word]").classList.remove("d-none");
|
||||
} else if ((ext.indexOf("xls") != -1) || (ext.indexOf("xlsx") != -1)) {
|
||||
file.previewElement.querySelector("[data-dz-thumbnail]").classList.add("d-none");
|
||||
file.previewElement.querySelector("[data-dz-thumbnail-excel]").classList.remove("d-none");
|
||||
} else {
|
||||
file.previewElement.querySelector("[data-dz-thumbnail]").classList.add("d-none");
|
||||
file.previewElement.querySelector("[data-dz-thumbnail-image]").classList.remove("d-none");
|
||||
}
|
||||
}
|
||||
}),
|
||||
|
||||
dropzone.on('removedfile', function (file) {
|
||||
@ -163,15 +189,27 @@ export default {
|
||||
if (self.attachments.length) {
|
||||
setTimeout(() => {
|
||||
self.attachments.forEach(async (attachment) => {
|
||||
let blob = await self.getAttachmentContent(attachment.path);
|
||||
let file = new File([blob], attachment.name, { type: blob.type });
|
||||
var mockFile = {
|
||||
id: attachment.id,
|
||||
name: attachment.name,
|
||||
size: attachment.size,
|
||||
type: attachment.type,
|
||||
download: attachment.downloadPath,
|
||||
dropzone: 'edit',
|
||||
};
|
||||
|
||||
dropzone.displayExistingFile(file, attachment.path, () => {
|
||||
if (attachment.downloadPath) {
|
||||
file.previewElement.querySelector("[data-dz-download]").href = attachment.downloadPath;
|
||||
file.previewElement.querySelector("[data-dz-download]").classList.remove("d-none");
|
||||
}
|
||||
});
|
||||
dropzone.emit("addedfile", mockFile);
|
||||
dropzone.options.thumbnail.call(dropzone, mockFile, attachment.path);
|
||||
|
||||
// Make sure that there is no progress bar, etc...
|
||||
dropzone.emit("complete", mockFile);
|
||||
});
|
||||
|
||||
self.files.forEach(async (attachment) => {
|
||||
if (attachment.download) {
|
||||
attachment.previewElement.querySelector("[data-dz-download]").href = attachment.download;
|
||||
attachment.previewElement.querySelector("[data-dz-download]").classList.remove("d-none");
|
||||
}
|
||||
});
|
||||
|
||||
if (self.preview == 'single' && self.attachments.length == 1) {
|
||||
@ -186,12 +224,6 @@ export default {
|
||||
|
||||
preview.innerHTML = '';
|
||||
},
|
||||
|
||||
async getAttachmentContent(imageUrl) {
|
||||
return await axios.get(imageUrl, { responseType: 'blob' }).then(function (response) {
|
||||
return response.data;
|
||||
});
|
||||
}
|
||||
},
|
||||
|
||||
async mounted() {
|
||||
|
6
resources/assets/js/plugins/form.js
vendored
6
resources/assets/js/plugins/form.js
vendored
@ -347,7 +347,11 @@ export default class Form {
|
||||
|
||||
submit() {
|
||||
FormData.prototype.appendRecursive = function(data, wrapper = null) {
|
||||
for(var name in data) {
|
||||
for (var name in data) {
|
||||
if (name == "previewElement" || name == "previewTemplate") {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (wrapper) {
|
||||
if ((typeof data[name] == 'object' || Array.isArray(data[name])) && ((data[name] instanceof File != true ) && (data[name] instanceof Blob != true))) {
|
||||
this.appendRecursive(data[name], wrapper + '[' + name + ']');
|
||||
|
@ -45,17 +45,24 @@
|
||||
@foreach($value as $attachment)
|
||||
@php
|
||||
$attachments[] = [
|
||||
'id' => $attachment->id,
|
||||
'name' => $attachment->filename . '.' . $attachment->extension,
|
||||
'path' => route('uploads.get', $attachment->id),
|
||||
'downloadPath' => route('uploads.download', $attachment->id)
|
||||
'path' => route('uploads.get', $attachment->id),
|
||||
'type' => $attachment->mime_type,
|
||||
'size' => $attachment->size,
|
||||
'downloadPath' => route('uploads.download', $attachment->id),
|
||||
];
|
||||
@endphp
|
||||
@endforeach
|
||||
@elseif ($value instanceof \Plank\Mediable\Media)
|
||||
@php
|
||||
$attachments[] = [
|
||||
'id' => $value->id,
|
||||
'name' => $value->filename . '.' . $value->extension,
|
||||
'path' => route('uploads.get', $value->id)
|
||||
'path' => route('uploads.get', $value->id),
|
||||
'type' => $value->mime_type,
|
||||
'size' => $value->size,
|
||||
'downloadPath' => false,
|
||||
];
|
||||
@endphp
|
||||
@else
|
||||
@ -63,12 +70,16 @@
|
||||
$attachment = \Plank\Mediable\Media::find($value);
|
||||
|
||||
$attachments[] = [
|
||||
'id' => $attachment->id,
|
||||
'name' => $attachment->filename . '.' . $attachment->extension,
|
||||
'path' => route('uploads.get', $attachment->id)
|
||||
'path' => route('uploads.get', $attachment->id),
|
||||
'type' => $attachment->mime_type,
|
||||
'size' => $attachment->size,
|
||||
'downloadPath' => false,
|
||||
];
|
||||
@endphp
|
||||
@endif
|
||||
|
||||
|
||||
:attachments="{{ json_encode($attachments) }}"
|
||||
@endif
|
||||
|
||||
|
@ -38,9 +38,9 @@
|
||||
|
||||
{{ Form::textGroup('reference', trans('general.reference'), 'file', []) }}
|
||||
|
||||
{{ Form::fileGroup('attachment', trans('general.attachment'), '', ['dropzone-class' => 'form-file']) }}
|
||||
|
||||
{{ Form::selectGroup('document_id', trans_choice('general.bills', 1), 'file-invoice', [], null, ['disabled' => 'true']) }}
|
||||
|
||||
{{ Form::fileGroup('attachment', trans('general.attachment'), '', ['dropzone-class' => 'w-100', 'multiple' => 'multiple', 'options' => ['acceptedFiles' => $file_types]], null, 'col-md-12') }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -57,19 +57,12 @@
|
||||
|
||||
{{ Form::textGroup('reference', trans('general.reference'), 'file',[]) }}
|
||||
|
||||
@if ($payment->attachment)
|
||||
<div class="col-md-6">
|
||||
@php $file = $payment->attachment; @endphp
|
||||
@include('partials.media.file')
|
||||
</div>
|
||||
@else
|
||||
{{ Form::fileGroup('attachment', trans('general.attachment'), '', ['dropzone-class' => 'form-file']) }}
|
||||
@endif
|
||||
|
||||
@if ($payment->bill)
|
||||
{{ Form::textGroup('document', trans_choice('general.bills', 1), 'file-invoice', ['disabled' => 'true'], $payment->bill->document_number) }}
|
||||
{{ Form::hidden('document_id', $payment->bill->id) }}
|
||||
@endif
|
||||
|
||||
{{ Form::fileGroup('attachment', trans('general.attachment'), '', ['dropzone-class' => 'w-100', 'multiple' => 'multiple', 'options' => ['acceptedFiles' => $file_types]], $payment->attachment, 'col-md-12') }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -38,9 +38,9 @@
|
||||
|
||||
{{ Form::textGroup('reference', trans('general.reference'), 'file', []) }}
|
||||
|
||||
{{ Form::fileGroup('attachment', trans('general.attachment'), '', ['dropzone-class' => 'form-file']) }}
|
||||
|
||||
{{ Form::selectGroup('document_id', trans_choice('general.invoices', 1), 'file-invoice', [], null, ['disabled' => 'true']) }}
|
||||
|
||||
{{ Form::fileGroup('attachment', trans('general.attachment'), '', ['dropzone-class' => 'w-100', 'multiple' => 'multiple', 'options' => ['acceptedFiles' => $file_types]], null, 'col-md-12') }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
@ -57,19 +57,12 @@
|
||||
|
||||
{{ Form::textGroup('reference', trans('general.reference'), 'file',[]) }}
|
||||
|
||||
@if ($revenue->attachment)
|
||||
<div class="col-md-6">
|
||||
@php $file = $revenue->attachment; @endphp
|
||||
@include('partials.media.file')
|
||||
</div>
|
||||
@else
|
||||
{{ Form::fileGroup('attachment', trans('general.attachment'), '', ['dropzone-class' => 'form-file']) }}
|
||||
@endif
|
||||
|
||||
@if ($revenue->invoice)
|
||||
{{ Form::textGroup('document', trans_choice('general.invoices', 1), 'file-invoice', ['disabled' => 'true'], $revenue->invoice->document_number) }}
|
||||
{{ Form::hidden('document_id', $revenue->invoice->id) }}
|
||||
@endif
|
||||
|
||||
{{ Form::fileGroup('attachment', trans('general.attachment'), '', ['dropzone-class' => 'w-100', 'multiple' => 'multiple', 'options' => ['acceptedFiles' => $file_types]], $revenue->attachment, 'col-md-12') }}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
Reference in New Issue
Block a user