1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-16 08:02:40 +01:00
invoiceninja/resources/views/generic/dropzone.blade.php

184 lines
5.6 KiB
PHP
Raw Normal View History

2019-08-07 02:44:38 +02:00
@section('header')
@parent
<link href="/vendors/css/dropzone.min.css" rel="stylesheet">
<link href="/vendors/css/dropzone-basic.min.css" rel="stylesheet">
2019-08-07 05:07:06 +02:00
<link href="/vendors/css/sweetalert.css" rel="stylesheet">
2019-08-07 02:44:38 +02:00
<style>
.dropzone {
background: white;
border-radius: 5px;
border: 2px dashed rgb(0, 135, 247);
border-image: none;
max-width: 500px;
margin-left: auto;
margin-right: auto;
}
2019-08-08 02:22:54 +02:00
.dropzone .dz-preview .dz-image {
width: 250px;
height: 250px;
}
2019-08-07 02:44:38 +02:00
</style>
@stop
<div id="dropzone">
<form class="dropzone needsclick" id="demo-upload">
<div class="dz-message needsclick">
{{ ctrans('texts.dropzone_default_message')}}<br>
</div>
</form>
</div>
@push('scripts')
<script src="/vendors/js/dropzone.min.js"></script>
2019-08-07 05:07:06 +02:00
<script src="/vendors/js/sweetalert.min.js"></script>
2019-08-07 02:44:38 +02:00
<script>
2019-08-08 13:07:26 +02:00
var contact = {!! auth()->user() !!};
2019-08-07 02:44:38 +02:00
Dropzone.autoDiscover = false;
window.countUploadingDocuments = 0;
window.dropzone = new Dropzone('.dropzone', {
url: '{!! $url !!}',
params: {
'_token': '{{ csrf_token() }}',
@foreach($params as $key => $value)
'{!! $key !!}' : '{!! $value !!}',
@endforeach
},
2019-08-08 02:22:54 +02:00
thumbnailWidth: 250,
thumbnailHeight: 250,
2019-08-07 02:44:38 +02:00
addRemoveLinks: true,
dictRemoveFileConfirmation: "{{ctrans('texts.are_you_sure')}}",
dictDefaultMessage : "{{ctrans('texts.dropzone_default_message')}}",
dictFallbackMessage : "{{ctrans('texts.dropzone_fallback_message')}}",
dictFallbackText : "{{ctrans('texts.dropzone_fallback_text')}}",
dictFileTooBig : "{{ctrans('texts.dropzone_file_too_big')}}",
dictInvalidFileType : "{{ctrans('texts.dropzone_invalid_file_type')}}",
dictResponseError : "{{ctrans('texts.dropzone_response_error')}}",
dictCancelUpload : "{{ctrans('texts.dropzone_cancel_upload')}}",
dictCancelUploadConfirmation : "{{ctrans('texts.dropzone_cancel_upload_confirmation')}}",
dictRemoveFile : "{{ctrans('texts.dropzone_remove_file')}}",
parallelUploads: 1,
maxFiles: {{ $multi_upload ? 100000 : 1 }},
clickable: true,
maxfilesexceeded: function(file) {
this.removeAllFiles();
this.addFile(file);
},
init: function(){
// this.on("addedfile", handleFileAdded);
// this.on("removedfile", handleFileRemoved);
this.on("error", function(file){if (!file.accepted) this.removeFile(file);});
},
});
2019-08-07 05:07:06 +02:00
if (dropzone instanceof Dropzone) {
2019-08-08 13:07:26 +02:00
dropzone.on('addedfile', handleDocumentAdded);
dropzone.on('removedfile', handleDocumentRemoved);
dropzone.on('success', handleDocumentUploaded);
2019-08-07 05:07:06 +02:00
//dropzone.on('canceled', handleDocumentCanceled);
dropzone.on('error', handleDocumentError);
2019-08-08 13:18:02 +02:00
var mockFile = makeMockFile();
2019-08-08 13:07:26 +02:00
if(contact.avatar) {
dropzone.emit('addedfile', mockFile);
dropzone.emit('complete', mockFile);
}
var documentType = contact.avatar_type;
var previewUrl = contact.avatar;
var documentUrl = contact.avatar;
if (contact && previewUrl) {
dropzone.emit('thumbnail', mockFile, previewUrl);
} else if (documentType == 'jpeg' || documentType == 'png' || documentType == 'svg') {
dropzone.emit('thumbnail', mockFile, documentUrl);
}
dropzone.files.push(mockFile);
2019-08-07 05:07:06 +02:00
}
2019-08-08 13:18:02 +02:00
function makeMockFile()
{
var mockFile = {
name: contact.avatar,
size: contact.avatar_size,
type: contact.avatar_type,
status: Dropzone.SUCCESS,
accepted: true,
url: contact.avatar,
mock: true
};
return mockFile;
}
2019-08-07 05:07:06 +02:00
function handleDocumentError(file, responseText) {
2019-08-08 13:18:02 +02:00
dropzone.removeFile(file);
2019-08-07 08:56:19 +02:00
2019-08-08 13:18:02 +02:00
for (var error in responseText.errors) {
2019-08-07 08:56:19 +02:00
2019-08-08 13:18:02 +02:00
swal({title: '{{ctrans('texts.error')}}', text: responseText.errors[error]});
}
2019-08-07 08:56:19 +02:00
2019-08-07 05:07:06 +02:00
}
2019-08-08 13:07:26 +02:00
function handleDocumentAdded(file){
if (contact.avatar) {
file.previewElement.addEventListener("click", function() {
window.open(contact.avatar, '_blank');
});
}
if(file.mock)return;
if (window.addDocument) {
addDocument(file);
}
}
function handleDocumentUploaded(file, response){
contact = response;
dropzone.files = [];
2019-08-08 13:18:02 +02:00
var mockFile = makeMockFile();
2019-08-08 13:07:26 +02:00
if(contact.avatar) {
dropzone.emit('complete', mockFile);
}
var documentType = contact.avatar_type;
var previewUrl = contact.avatar;
var documentUrl = contact.avatar;
if (contact && previewUrl) {
dropzone.emit('thumbnail', mockFile, previewUrl);
} else if (documentType == 'jpeg' || documentType == 'png' || documentType == 'svg') {
dropzone.emit('thumbnail', mockFile, documentUrl);
}
dropzone.files.push(mockFile);
}
function handleDocumentRemoved(file){
if (window.deleteDocument) {
deleteDocument(file);
}
$.ajax({
url: '{!! $url !!}',
type: 'DELETE',
headers: {
'X-CSRF-TOKEN': '{{ csrf_token() }}'
},
success: function(result) {
// Do something with the result
}
});
}
2019-08-07 02:44:38 +02:00
</script>
2019-08-08 13:07:26 +02:00
@endpush