From ee2ef4608e3ddba7264198719f4f7ff49e5f9fc0 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Wed, 25 May 2016 11:59:46 +0300 Subject: [PATCH 1/5] Lazy load invoice documents --- resources/views/invoices/edit.blade.php | 92 ++++++++++++++----------- 1 file changed, 52 insertions(+), 40 deletions(-) diff --git a/resources/views/invoices/edit.blade.php b/resources/views/invoices/edit.blade.php index 3ca6acafba59..26b42a0bd90b 100644 --- a/resources/views/invoices/edit.blade.php +++ b/resources/views/invoices/edit.blade.php @@ -998,47 +998,59 @@ }) // Initialize document upload - 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 Date: Wed, 25 May 2016 12:10:22 +0300 Subject: [PATCH 2/5] Prevent setting pdfstring when saving an invoice --- resources/views/invoices/edit.blade.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/resources/views/invoices/edit.blade.php b/resources/views/invoices/edit.blade.php index 26b42a0bd90b..5099ded5206b 100644 --- a/resources/views/invoices/edit.blade.php +++ b/resources/views/invoices/edit.blade.php @@ -1230,7 +1230,7 @@ } } - preparePdfData(''); + submitAction(''); } function getSendToEmails() { From ba561c7d0d3b3f3672608344d382735d908f611f Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Wed, 25 May 2016 14:42:20 +0300 Subject: [PATCH 3/5] Prevent clicking save while document is still uploading --- resources/lang/en/texts.php | 2 ++ resources/views/invoices/edit.blade.php | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 2b9f2e5f4aec..481de829b614 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -1311,6 +1311,8 @@ $LANG = array( 'new_start_date' => 'New start date', 'security' => 'Security', 'see_whats_new' => 'See what\'s new in v:version', + 'wait_for_upload' => 'Please wait for the document upload to complete.' + ); return $LANG; diff --git a/resources/views/invoices/edit.blade.php b/resources/views/invoices/edit.blade.php index 5099ded5206b..c27057b2b284 100644 --- a/resources/views/invoices/edit.blade.php +++ b/resources/views/invoices/edit.blade.php @@ -1265,6 +1265,11 @@ } function onFormSubmit(event) { + if (window.countUploadingDocuments > 0) { + alert("{!! trans('texts.wait_for_upload') !!}"); + return false; + } + if (!isSaveValid()) { model.showClientForm(); return false; @@ -1435,6 +1440,7 @@ model.invoice().invoice_number(number); } + window.countUploadingDocuments = 0; @if ($account->hasFeature(FEATURE_DOCUMENTS)) function handleDocumentAdded(file){ // open document when clicked @@ -1446,6 +1452,7 @@ if(file.mock)return; file.index = model.invoice().documents().length; model.invoice().addDocument({name:file.name, size:file.size, type:file.type}); + window.countUploadingDocuments++; } function handleDocumentRemoved(file){ @@ -1456,6 +1463,7 @@ function handleDocumentUploaded(file, response){ file.public_id = response.document.public_id model.invoice().documents()[file.index].update(response.document); + window.countUploadingDocuments--; refreshPDF(true); if(response.document.preview_url){ From df2a6527988ca59718a35b7666c0bee32f937403 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Wed, 25 May 2016 15:18:12 +0300 Subject: [PATCH 4/5] Change document to click to full size --- resources/views/expenses/edit.blade.php | 2 +- resources/views/invoices/edit.blade.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/resources/views/expenses/edit.blade.php b/resources/views/expenses/edit.blade.php index 41af3f1e801e..873da5451ea0 100644 --- a/resources/views/expenses/edit.blade.php +++ b/resources/views/expenses/edit.blade.php @@ -249,7 +249,7 @@ public_id:document.public_id(), status:Dropzone.SUCCESS, accepted:true, - url:document.preview_url()||document.url(), + url:document.url(), mock:true, index:i }; diff --git a/resources/views/invoices/edit.blade.php b/resources/views/invoices/edit.blade.php index c27057b2b284..235266c64a54 100644 --- a/resources/views/invoices/edit.blade.php +++ b/resources/views/invoices/edit.blade.php @@ -1034,7 +1034,7 @@ public_id:document.public_id(), status:Dropzone.SUCCESS, accepted:true, - url:document.preview_url()||document.url(), + url:document.url(), mock:true, index:i }; From 4a4494a2f3b9704bda1290655df5315af8db65d9 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Wed, 25 May 2016 16:16:34 +0300 Subject: [PATCH 5/5] Fix for cancelled accounts --- .../2016_03_22_168362_add_documents.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/database/migrations/2016_03_22_168362_add_documents.php b/database/migrations/2016_03_22_168362_add_documents.php index 233f420c198b..d921deeafaed 100644 --- a/database/migrations/2016_03_22_168362_add_documents.php +++ b/database/migrations/2016_03_22_168362_add_documents.php @@ -18,7 +18,7 @@ class AddDocuments extends Migration { $table->boolean('invoice_embed_documents')->default(1); $table->boolean('document_email_attachment')->default(1); }); - + \DB::table('accounts')->update(array('logo' => '')); Schema::dropIfExists('documents'); Schema::create('documents', function($t) @@ -41,14 +41,14 @@ class AddDocuments extends Migration { $t->timestamps(); - $t->foreign('account_id')->references('id')->on('accounts'); - $t->foreign('user_id')->references('id')->on('users'); - $t->foreign('invoice_id')->references('id')->on('invoices'); - $t->foreign('expense_id')->references('id')->on('expenses'); - - + $t->foreign('account_id')->references('id')->on('accounts')->onDelete('cascade'); + $t->foreign('user_id')->references('id')->on('users')->onDelete('cascade'); + $t->foreign('invoice_id')->references('id')->on('invoices')->onDelete('cascade'); + $t->foreign('expense_id')->references('id')->on('expenses')->onDelete('cascade'); + + $t->unique( array('account_id','public_id') ); - }); + }); } /** * Reverse the migrations. @@ -65,7 +65,7 @@ class AddDocuments extends Migration { $table->dropColumn('invoice_embed_documents'); $table->dropColumn('document_email_attachment'); }); - + Schema::dropIfExists('documents'); } }