Open document when clicked

This commit is contained in:
Hillel Coren 2016-05-22 22:17:57 +03:00
parent 4aa11be28f
commit 05903d413a
2 changed files with 36 additions and 24 deletions

View File

@ -14,7 +14,7 @@
@stop @stop
@section('content') @section('content')
{!! Former::open($url)->addClass('warn-on-exit main-form')->method($method) !!} {!! Former::open($url)->addClass('warn-on-exit main-form')->method($method) !!}
<div style="display:none"> <div style="display:none">
{!! Former::text('action') !!} {!! Former::text('action') !!}
@ -216,13 +216,13 @@
@else @else
$('#amount').focus(); $('#amount').focus();
@endif @endif
@if (Auth::user()->account->isPro()) @if (Auth::user()->account->isPro())
$('.main-form').submit(function(){ $('.main-form').submit(function(){
if($('#document-upload .fallback input').val())$(this).attr('enctype', 'multipart/form-data') if($('#document-upload .fallback input').val())$(this).attr('enctype', 'multipart/form-data')
else $(this).removeAttr('enctype') else $(this).removeAttr('enctype')
}) })
// Initialize document upload // Initialize document upload
dropzone = new Dropzone('#document-upload', { dropzone = new Dropzone('#document-upload', {
url:{!! json_encode(url('document')) !!}, url:{!! json_encode(url('document')) !!},
@ -286,7 +286,7 @@
} }
} }
} }
if (data) { if (data) {
ko.mapping.fromJS(data, self.mapping, this); ko.mapping.fromJS(data, self.mapping, this);
} }
@ -327,11 +327,11 @@
} }
var expenseCurrencyId = self.expense_currency_id() || self.account_currency_id(); var expenseCurrencyId = self.expense_currency_id() || self.account_currency_id();
var invoiceCurrencyId = self.invoice_currency_id() || self.account_currency_id(); var invoiceCurrencyId = self.invoice_currency_id() || self.account_currency_id();
return expenseCurrencyId != invoiceCurrencyId return expenseCurrencyId != invoiceCurrencyId
|| invoiceCurrencyId != self.account_currency_id() || invoiceCurrencyId != self.account_currency_id()
|| expenseCurrencyId != self.account_currency_id(); || expenseCurrencyId != self.account_currency_id();
}) })
self.addDocument = function() { self.addDocument = function() {
var documentModel = new DocumentModel(); var documentModel = new DocumentModel();
self.documents.push(documentModel); self.documents.push(documentModel);
@ -359,11 +359,17 @@
if (data) { if (data) {
self.update(data); self.update(data);
} }
} }
@if (Auth::user()->account->hasFeature(FEATURE_DOCUMENTS)) @if (Auth::user()->account->hasFeature(FEATURE_DOCUMENTS))
function handleDocumentAdded(file){ function handleDocumentAdded(file){
// open document when clicked
if (file.url) {
file.previewElement.addEventListener("click", function() {
window.open(file.url, '_blank');
});
}
if(file.mock)return; if(file.mock)return;
file.index = model.documents().length; file.index = model.documents().length;
model.addDocument({name:file.name, size:file.size, type:file.type}); model.addDocument({name:file.name, size:file.size, type:file.type});
@ -384,4 +390,4 @@
@endif @endif
</script> </script>
@stop @stop

View File

@ -17,7 +17,7 @@
label.control-label[for=invoice_number] { label.control-label[for=invoice_number] {
font-weight: normal !important; font-weight: normal !important;
} }
select.tax-select { select.tax-select {
width: 50%; width: 50%;
float: left; float: left;
@ -79,7 +79,7 @@
&nbsp;&nbsp;<div class="label label-danger">{{ trans('texts.deleted') }}</div> &nbsp;&nbsp;<div class="label label-danger">{{ trans('texts.deleted') }}</div>
@endif @endif
</h4> </h4>
@can('view', $invoice->client) @can('view', $invoice->client)
@can('edit', $invoice->client) @can('edit', $invoice->client)
<a id="editClientLink" class="pointer" data-bind="click: $root.showClientForm">{{ trans('texts.edit_client') }}</a> | <a id="editClientLink" class="pointer" data-bind="click: $root.showClientForm">{{ trans('texts.edit_client') }}</a> |
@ -90,7 +90,7 @@
</div> </div>
<div style="display:none"> <div style="display:none">
@endif @endif
{!! Former::select('client')->addOption('', '')->data_bind("dropdown: client")->addClass('client-input')->addGroupClass('client_select closer-row') !!} {!! Former::select('client')->addOption('', '')->data_bind("dropdown: client")->addClass('client-input')->addGroupClass('client_select closer-row') !!}
<div class="form-group" style="margin-bottom: 8px"> <div class="form-group" style="margin-bottom: 8px">
@ -419,7 +419,7 @@
->options($taxRateOptions) ->options($taxRateOptions)
->addClass('tax-select') ->addClass('tax-select')
->data_bind('value: tax1') ->data_bind('value: tax1')
->raw() !!} ->raw() !!}
<input type="text" name="tax_name1" data-bind="value: tax_name1" style="display:none"> <input type="text" name="tax_name1" data-bind="value: tax_name1" style="display:none">
<input type="text" name="tax_rate1" data-bind="value: tax_rate1" style="display:none"> <input type="text" name="tax_rate1" data-bind="value: tax_rate1" style="display:none">
{!! Former::select('') {!! Former::select('')
@ -427,7 +427,7 @@
->options($taxRateOptions) ->options($taxRateOptions)
->addClass('tax-select') ->addClass('tax-select')
->data_bind('value: tax2') ->data_bind('value: tax2')
->raw() !!} ->raw() !!}
<input type="text" name="tax_name2" data-bind="value: tax_name2" style="display:none"> <input type="text" name="tax_name2" data-bind="value: tax_name2" style="display:none">
<input type="text" name="tax_rate2" data-bind="value: tax_rate2" style="display:none"> <input type="text" name="tax_rate2" data-bind="value: tax_rate2" style="display:none">
</td> </td>
@ -569,7 +569,7 @@
{!! Former::text('client[work_phone]') {!! Former::text('client[work_phone]')
->label('work_phone') ->label('work_phone')
->data_bind("value: work_phone, valueUpdate: 'afterkeydown'") !!} ->data_bind("value: work_phone, valueUpdate: 'afterkeydown'") !!}
</span> </span>
@if (Auth::user()->hasFeature(FEATURE_INVOICE_SETTINGS)) @if (Auth::user()->hasFeature(FEATURE_INVOICE_SETTINGS))
@ -756,7 +756,7 @@
var $clientSelect = $('select#client'); var $clientSelect = $('select#client');
var invoiceDesigns = {!! $invoiceDesigns !!}; var invoiceDesigns = {!! $invoiceDesigns !!};
var invoiceFonts = {!! $invoiceFonts !!}; var invoiceFonts = {!! $invoiceFonts !!};
$(function() { $(function() {
// create client dictionary // create client dictionary
for (var i=0; i<clients.length; i++) { for (var i=0; i<clients.length; i++) {
@ -844,7 +844,7 @@
} }
@endif @endif
// display blank instead of '0' // display blank instead of '0'
if (!NINJA.parseFloat(model.invoice().discount())) model.invoice().discount(''); if (!NINJA.parseFloat(model.invoice().discount())) model.invoice().discount('');
if (!NINJA.parseFloat(model.invoice().partial())) model.invoice().partial(''); if (!NINJA.parseFloat(model.invoice().partial())) model.invoice().partial('');
@ -966,13 +966,13 @@
@endif @endif
applyComboboxListeners(); applyComboboxListeners();
@if (Auth::user()->account->hasFeature(FEATURE_DOCUMENTS)) @if (Auth::user()->account->hasFeature(FEATURE_DOCUMENTS))
$('.main-form').submit(function(){ $('.main-form').submit(function(){
if($('#document-upload .dropzone .fallback input').val())$(this).attr('enctype', 'multipart/form-data') if($('#document-upload .dropzone .fallback input').val())$(this).attr('enctype', 'multipart/form-data')
else $(this).removeAttr('enctype') else $(this).removeAttr('enctype')
}) })
// Initialize document upload // Initialize document upload
dropzone = new Dropzone('#document-upload .dropzone', { dropzone = new Dropzone('#document-upload .dropzone', {
url:{!! json_encode(url('document')) !!}, url:{!! json_encode(url('document')) !!},
@ -1224,7 +1224,7 @@
} }
onPartialChange(true); onPartialChange(true);
return true; return true;
} }
@ -1379,24 +1379,30 @@
number = number.replace('{$custom2}', client.custom_value2 ? client.custom_value1 : ''); number = number.replace('{$custom2}', client.custom_value2 ? client.custom_value1 : '');
model.invoice().invoice_number(number); model.invoice().invoice_number(number);
} }
@if ($account->hasFeature(FEATURE_DOCUMENTS)) @if ($account->hasFeature(FEATURE_DOCUMENTS))
function handleDocumentAdded(file){ function handleDocumentAdded(file){
// open document when clicked
if (file.url) {
file.previewElement.addEventListener("click", function() {
window.open(file.url, '_blank');
});
}
if(file.mock)return; if(file.mock)return;
file.index = model.invoice().documents().length; file.index = model.invoice().documents().length;
model.invoice().addDocument({name:file.name, size:file.size, type:file.type}); model.invoice().addDocument({name:file.name, size:file.size, type:file.type});
} }
function handleDocumentRemoved(file){ function handleDocumentRemoved(file){
model.invoice().removeDocument(file.public_id); model.invoice().removeDocument(file.public_id);
refreshPDF(true); refreshPDF(true);
} }
function handleDocumentUploaded(file, response){ function handleDocumentUploaded(file, response){
file.public_id = response.document.public_id file.public_id = response.document.public_id
model.invoice().documents()[file.index].update(response.document); model.invoice().documents()[file.index].update(response.document);
refreshPDF(true); refreshPDF(true);
if(response.document.preview_url){ if(response.document.preview_url){
dropzone.emit('thumbnail', file, response.document.preview_url); dropzone.emit('thumbnail', file, response.document.preview_url);
} }