From def674a2e4153b2909f2fc37450d9961acb2147e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Kristia=CC=81n=20Feldsam?= Date: Mon, 29 Apr 2019 22:16:23 +0200 Subject: [PATCH] Option to disable PDF realtime preview MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Kristián Feldsam --- app/Http/Controllers/AccountController.php | 1 + app/Models/Account.php | 1 + app/Ninja/Transformers/AccountTransformer.php | 1 + ...95445_add_realtime_preview_to_accounts.php | 32 +++++++++++++++++++ resources/lang/en/texts.php | 4 ++- resources/views/accounts/management.blade.php | 14 ++++++++ resources/views/invoices/edit.blade.php | 12 ++++--- resources/views/invoices/pdf.blade.php | 10 +++++- 8 files changed, 69 insertions(+), 6 deletions(-) create mode 100644 database/migrations/2019_04_29_195445_add_realtime_preview_to_accounts.php diff --git a/app/Http/Controllers/AccountController.php b/app/Http/Controllers/AccountController.php index 2435f70119e8..6fcd6288f326 100644 --- a/app/Http/Controllers/AccountController.php +++ b/app/Http/Controllers/AccountController.php @@ -820,6 +820,7 @@ class AccountController extends BaseController $user->save(); $account->live_preview = Input::get('live_preview') ? true : false; + $account->realtime_preview = Input::get('realtime_preview') ? true : false; // Automatically disable live preview when using a large font $fonts = Cache::get('fonts')->filter(function ($font) use ($account) { diff --git a/app/Models/Account.php b/app/Models/Account.php index 2bfd0916dbca..29956689674e 100644 --- a/app/Models/Account.php +++ b/app/Models/Account.php @@ -127,6 +127,7 @@ class Account extends Eloquent 'enable_client_portal_dashboard', 'page_size', 'live_preview', + 'realtime_preview', 'invoice_number_padding', 'enable_second_tax_rate', 'auto_bill_on_due_date', diff --git a/app/Ninja/Transformers/AccountTransformer.php b/app/Ninja/Transformers/AccountTransformer.php index 6434d990370f..461b4c496689 100644 --- a/app/Ninja/Transformers/AccountTransformer.php +++ b/app/Ninja/Transformers/AccountTransformer.php @@ -352,6 +352,7 @@ class AccountTransformer extends EntityTransformer 'enable_client_portal_dashboard' => (bool) $account->enable_client_portal_dashboard, 'page_size' => $account->page_size, 'live_preview' => (bool) $account->live_preview, + 'realtime_preview' => (bool) $account->realtime_preview, 'invoice_number_padding' => (int) $account->invoice_number_padding, 'enable_second_tax_rate' => (bool) $account->enable_second_tax_rate, 'auto_bill_on_due_date' => (bool) $account->auto_bill_on_due_date, diff --git a/database/migrations/2019_04_29_195445_add_realtime_preview_to_accounts.php b/database/migrations/2019_04_29_195445_add_realtime_preview_to_accounts.php new file mode 100644 index 000000000000..5012c4fe4925 --- /dev/null +++ b/database/migrations/2019_04_29_195445_add_realtime_preview_to_accounts.php @@ -0,0 +1,32 @@ +boolean('realtime_preview')->after('live_preview')->default(1); + }); + } + + /** + * Reverse the migrations. + * + * @return void + */ + public function down() + { + Schema::table('accounts', function ($table) { + $table->dropColumn('realtime_preview'); + }); + } +} diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index f223fc96cc7c..7c5f7e3b2167 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -2041,7 +2041,9 @@ $LANG = array( 'update_credit' => 'Update Credit', 'updated_credit' => 'Successfully updated credit', 'edit_credit' => 'Edit Credit', - 'live_preview_help' => 'Display a live PDF preview on the invoice page.
Disable this to improve performance when editing invoices.', + 'realtime_preview' => 'Realtime Preview', + 'realtime_preview_help' => 'Realtime refresh PDF preview on the invoice page when editing invoice.
Disable this to improve performance when editing invoices.', + 'live_preview_help' => 'Display a live PDF preview on the invoice page.', 'force_pdfjs_help' => 'Replace the built-in PDF viewer in :chrome_link and :firefox_link.
Enable this if your browser is automatically downloading the PDF.', 'force_pdfjs' => 'Prevent Download', 'redirect_url' => 'Redirect URL', diff --git a/resources/views/accounts/management.blade.php b/resources/views/accounts/management.blade.php index 9bda2dc1e0e3..fa1cdfb173ff 100644 --- a/resources/views/accounts/management.blade.php +++ b/resources/views/accounts/management.blade.php @@ -172,6 +172,7 @@ {!! Former::open('settings/account_management') !!} {!! Former::populateField('live_preview', intval($account->live_preview)) !!} + {!! Former::populateField('realtime_preview', intval($account->realtime_preview)) !!} {!! Former::populateField('force_pdfjs', intval(Auth::user()->force_pdfjs)) !!}
@@ -221,6 +222,11 @@ ->help(trans('texts.live_preview_help') . '
' . trans('texts.recommend_on')) ->value(1) !!} + {!! Former::checkbox('realtime_preview') + ->text(trans('texts.enable')) + ->help(trans('texts.realtime_preview_help')) + ->value(1) !!} + {!! Former::checkbox('force_pdfjs') ->text(trans('texts.enable')) ->value(1) @@ -378,6 +384,11 @@ } } + function updateCheckboxes() { + var checked = $('#live_preview').is(':checked'); + $('#realtime_preview').prop('disabled', ! checked); + } + jQuery(document).ready(function($){ function updatePlanModal() { var plan = $('#plan').val(); @@ -407,6 +418,9 @@ updatePlanModal(); onPlanChange(); + $('#live_preview').change(updateCheckboxes); + updateCheckboxes(); + if(window.location.hash) { var hash = window.location.hash; $(hash).modal('toggle'); diff --git a/resources/views/invoices/edit.blade.php b/resources/views/invoices/edit.blade.php index 99897505140d..e4b138682894 100644 --- a/resources/views/invoices/edit.blade.php +++ b/resources/views/invoices/edit.blade.php @@ -550,6 +550,10 @@ @endif @else @if (!$invoice->is_deleted) + @if ( ! Auth::user()->account->realtime_preview && Auth::user()->account->live_preview) + {!! Button::normal('PDF')->withAttributes(['id' => 'refreshPdfButton', 'onclick' => 'refreshPDF(true,true)'])->appendIcon(Icon::create('refresh')) !!} + @endif + @if ($invoice->isSent()) {!! Button::success(trans("texts.save_{$entityType}"))->withAttributes(array('id' => 'saveButton', 'onclick' => 'onSaveClick()'))->appendIcon(Icon::create('floppy-disk')) !!} @else @@ -577,7 +581,7 @@ - @include('invoices.pdf', ['account' => Auth::user()->account, 'hide_pdf' => ! Auth::user()->account->live_preview]) + @include('invoices.pdf', ['account' => Auth::user()->account, 'hide_pdf' => ! Auth::user()->account->live_preview, 'realtime_preview' => Auth::user()->account->realtime_preview]) @if (!Auth::user()->account->isPro())
@@ -1026,11 +1030,11 @@ $('.client-input').val(getClientDisplayName(selected)); // if there's an invoice number pattern we'll apply it now setInvoiceNumber(selected); - refreshPDF(true); + refreshPDF(true, true); } else if (oldId) { model.loadClient($.parseJSON(ko.toJSON(new ClientModel()))); model.invoice().client().country = false; - refreshPDF(true); + refreshPDF(true, true); } }); @@ -1092,7 +1096,7 @@ @if ($invoice->client->id) $input.trigger('change'); @else - refreshPDF(true); + refreshPDF(true, true); @endif var client = model.invoice().client(); diff --git a/resources/views/invoices/pdf.blade.php b/resources/views/invoices/pdf.blade.php index bff62bc1819a..45dca635c656 100644 --- a/resources/views/invoices/pdf.blade.php +++ b/resources/views/invoices/pdf.blade.php @@ -112,7 +112,12 @@ var isRefreshing = false; var needsRefresh = false; - function refreshPDF(force) { + function refreshPDF(force, manual) { + @if (isset($realtime_preview) && ! $realtime_preview) + if (manual !== true) return; + $('#refreshPdfButton').attr('disabled', true); + @endif + try { return getPDFString(refreshPDFCB, force); } catch (exception) { @@ -179,6 +184,9 @@ }); }); } + @if (isset($realtime_preview) && ! $realtime_preview) + $('#refreshPdfButton').attr('disabled', false); + @endif } function showMoreDesigns() {