mirror of
				https://github.com/invoiceninja/invoiceninja.git
				synced 2025-11-03 23:47:32 -05:00 
			
		
		
		
	Lazy load invoice documents
This commit is contained in:
		
							parent
							
								
									ea2f154b1f
								
							
						
					
					
						commit
						ee2ef4608e
					
				@ -998,47 +998,59 @@
 | 
				
			|||||||
        })
 | 
					        })
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // Initialize document upload
 | 
					        // Initialize document upload
 | 
				
			||||||
        dropzone = new Dropzone('#document-upload .dropzone', {
 | 
					        window.dropzone = false;
 | 
				
			||||||
            url:{!! json_encode(url('document')) !!},
 | 
					        $('a[data-toggle="tab"]').on('shown.bs.tab', function (e) {
 | 
				
			||||||
            params:{
 | 
					            if (window.dropzone) {
 | 
				
			||||||
                _token:"{{ Session::getToken() }}"
 | 
					                return;
 | 
				
			||||||
            },
 | 
					 | 
				
			||||||
            acceptedFiles:{!! json_encode(implode(',',\App\Models\Document::$allowedMimes)) !!},
 | 
					 | 
				
			||||||
            addRemoveLinks:true,
 | 
					 | 
				
			||||||
            @foreach(['default_message', 'fallback_message', 'fallback_text', 'file_too_big', 'invalid_file_type', 'response_error', 'cancel_upload', 'cancel_upload_confirmation', 'remove_file'] as $key)
 | 
					 | 
				
			||||||
                "dict{{Utils::toClassCase($key)}}":"{{trans('texts.dropzone_'.$key)}}",
 | 
					 | 
				
			||||||
            @endforeach
 | 
					 | 
				
			||||||
            maxFileSize:{{floatval(MAX_DOCUMENT_SIZE/1000)}},
 | 
					 | 
				
			||||||
        });
 | 
					 | 
				
			||||||
        if(dropzone instanceof Dropzone){
 | 
					 | 
				
			||||||
            dropzone.on("addedfile",handleDocumentAdded);
 | 
					 | 
				
			||||||
            dropzone.on("removedfile",handleDocumentRemoved);
 | 
					 | 
				
			||||||
            dropzone.on("success",handleDocumentUploaded);
 | 
					 | 
				
			||||||
            for (var i=0; i<model.invoice().documents().length; i++) {
 | 
					 | 
				
			||||||
                var document = model.invoice().documents()[i];
 | 
					 | 
				
			||||||
                var mockFile = {
 | 
					 | 
				
			||||||
                    name:document.name(),
 | 
					 | 
				
			||||||
                    size:document.size(),
 | 
					 | 
				
			||||||
                    type:document.type(),
 | 
					 | 
				
			||||||
                    public_id:document.public_id(),
 | 
					 | 
				
			||||||
                    status:Dropzone.SUCCESS,
 | 
					 | 
				
			||||||
                    accepted:true,
 | 
					 | 
				
			||||||
                    url:document.preview_url()||document.url(),
 | 
					 | 
				
			||||||
                    mock:true,
 | 
					 | 
				
			||||||
                    index:i
 | 
					 | 
				
			||||||
                };
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
                dropzone.emit('addedfile', mockFile);
 | 
					 | 
				
			||||||
                dropzone.emit('complete', mockFile);
 | 
					 | 
				
			||||||
                if(document.preview_url()){
 | 
					 | 
				
			||||||
                    dropzone.emit('thumbnail', mockFile, document.preview_url()||document.url());
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                else if(document.type()=='jpeg' || document.type()=='png' || document.type()=='svg'){
 | 
					 | 
				
			||||||
                    dropzone.emit('thumbnail', mockFile, document.url());
 | 
					 | 
				
			||||||
                }
 | 
					 | 
				
			||||||
                dropzone.files.push(mockFile);
 | 
					 | 
				
			||||||
            }
 | 
					            }
 | 
				
			||||||
        }
 | 
					
 | 
				
			||||||
 | 
					            var target = $(e.target).attr('href') // activated tab
 | 
				
			||||||
 | 
					            if (target != '#attached-documents') {
 | 
				
			||||||
 | 
					                return;
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					            window.dropzone = new Dropzone('#document-upload .dropzone', {
 | 
				
			||||||
 | 
					                url:{!! json_encode(url('document')) !!},
 | 
				
			||||||
 | 
					                params:{
 | 
				
			||||||
 | 
					                    _token:"{{ Session::getToken() }}"
 | 
				
			||||||
 | 
					                },
 | 
				
			||||||
 | 
					                acceptedFiles:{!! json_encode(implode(',',\App\Models\Document::$allowedMimes)) !!},
 | 
				
			||||||
 | 
					                addRemoveLinks:true,
 | 
				
			||||||
 | 
					                @foreach(['default_message', 'fallback_message', 'fallback_text', 'file_too_big', 'invalid_file_type', 'response_error', 'cancel_upload', 'cancel_upload_confirmation', 'remove_file'] as $key)
 | 
				
			||||||
 | 
					                    "dict{{Utils::toClassCase($key)}}":"{{trans('texts.dropzone_'.$key)}}",
 | 
				
			||||||
 | 
					                @endforeach
 | 
				
			||||||
 | 
					                maxFileSize:{{floatval(MAX_DOCUMENT_SIZE/1000)}},
 | 
				
			||||||
 | 
					            });
 | 
				
			||||||
 | 
					            if(dropzone instanceof Dropzone){
 | 
				
			||||||
 | 
					                dropzone.on("addedfile",handleDocumentAdded);
 | 
				
			||||||
 | 
					                dropzone.on("removedfile",handleDocumentRemoved);
 | 
				
			||||||
 | 
					                dropzone.on("success",handleDocumentUploaded);
 | 
				
			||||||
 | 
					                for (var i=0; i<model.invoice().documents().length; i++) {
 | 
				
			||||||
 | 
					                    var document = model.invoice().documents()[i];
 | 
				
			||||||
 | 
					                    var mockFile = {
 | 
				
			||||||
 | 
					                        name:document.name(),
 | 
				
			||||||
 | 
					                        size:document.size(),
 | 
				
			||||||
 | 
					                        type:document.type(),
 | 
				
			||||||
 | 
					                        public_id:document.public_id(),
 | 
				
			||||||
 | 
					                        status:Dropzone.SUCCESS,
 | 
				
			||||||
 | 
					                        accepted:true,
 | 
				
			||||||
 | 
					                        url:document.preview_url()||document.url(),
 | 
				
			||||||
 | 
					                        mock:true,
 | 
				
			||||||
 | 
					                        index:i
 | 
				
			||||||
 | 
					                    };
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					                    dropzone.emit('addedfile', mockFile);
 | 
				
			||||||
 | 
					                    dropzone.emit('complete', mockFile);
 | 
				
			||||||
 | 
					                    if(document.preview_url()){
 | 
				
			||||||
 | 
					                        dropzone.emit('thumbnail', mockFile, document.preview_url());
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                    else if(document.type()=='jpeg' || document.type()=='png' || document.type()=='svg'){
 | 
				
			||||||
 | 
					                        dropzone.emit('thumbnail', mockFile, document.url());
 | 
				
			||||||
 | 
					                    }
 | 
				
			||||||
 | 
					                    dropzone.files.push(mockFile);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        });
 | 
				
			||||||
        @endif
 | 
					        @endif
 | 
				
			||||||
	});
 | 
						});
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user