1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00

Fix for dev channel Chrome crash

This commit is contained in:
Hillel Coren 2015-12-29 09:52:02 +02:00
parent d1de95303b
commit 898e31c8b5
5 changed files with 39 additions and 36 deletions

View File

@ -29885,6 +29885,7 @@ var isChrome = !!window.chrome && !isOpera && !isEdge; // Chrome 1+
var isChromium = isChrome && navigator.userAgent.indexOf('Chromium') >= 0;
var isIE = /*@cc_on!@*/false || !!document.documentMode; // At least IE6
var pdfDoc;
var invoiceOld;
var refreshTimer;
function generatePDF(invoice, javascript, force, cb) {
@ -29901,23 +29902,23 @@ function generatePDF(invoice, javascript, force, cb) {
refreshTimer = setTimeout(function() {
generatePDF(invoice, javascript, true, cb);
}, 500);
return;
return pdfDoc;
}
invoice = calculateAmounts(invoice);
var a = copyObject(invoice);
var b = copyObject(invoiceOld);
if (!force && _.isEqual(a, b)) {
return;
if (_.isEqual(a, b)) {
return pdfDoc;
}
invoiceOld = invoice;
doc = GetPdfMake(invoice, javascript, cb);
pdfDoc = GetPdfMake(invoice, javascript, cb);
if (cb) {
doc.getDataUrl(cb);
pdfDoc.getDataUrl(cb);
}
return doc;
return pdfDoc;
}
function copyObject(orig) {

View File

@ -7,6 +7,7 @@ var isChrome = !!window.chrome && !isOpera && !isEdge; // Chrome 1+
var isChromium = isChrome && navigator.userAgent.indexOf('Chromium') >= 0;
var isIE = /*@cc_on!@*/false || !!document.documentMode; // At least IE6
var pdfDoc;
var invoiceOld;
var refreshTimer;
function generatePDF(invoice, javascript, force, cb) {
@ -23,23 +24,23 @@ function generatePDF(invoice, javascript, force, cb) {
refreshTimer = setTimeout(function() {
generatePDF(invoice, javascript, true, cb);
}, 500);
return;
return pdfDoc;
}
invoice = calculateAmounts(invoice);
var a = copyObject(invoice);
var b = copyObject(invoiceOld);
if (!force && _.isEqual(a, b)) {
return;
if (_.isEqual(a, b)) {
return pdfDoc;
}
invoiceOld = invoice;
doc = GetPdfMake(invoice, javascript, cb);
pdfDoc = GetPdfMake(invoice, javascript, cb);
if (cb) {
doc.getDataUrl(cb);
pdfDoc.getDataUrl(cb);
}
return doc;
return pdfDoc;
}
function copyObject(orig) {

View File

@ -196,7 +196,6 @@
{!! Former::text('product_key')->useDatalist($products->toArray(), 'product_key')
->data_bind("value: product_key, valueUpdate: 'afterkeydown', attr: {name: 'invoice_items[' + \$index() + '][product_key]'}")
->addClass('datalist')
->onkeyup('onItemChange()')
->raw()
!!}
</td>
@ -206,12 +205,12 @@
<input type="text" data-bind="value: task_public_id, attr: {name: 'invoice_items[' + $index() + '][task_public_id]'}" style="display: none"/>
</td>
<td>
<input onkeyup="onItemChange()" data-bind="value: prettyCost, valueUpdate: 'afterkeydown', attr: {name: 'invoice_items[' + $index() + '][cost]'}"
style="text-align: right" class="form-control"/>
<input data-bind="value: prettyCost, valueUpdate: 'afterkeydown', attr: {name: 'invoice_items[' + $index() + '][cost]'}"
style="text-align: right" class="form-control invoice-item"/>
</td>
<td style="{{ $account->hide_quantity ? 'display:none' : '' }}">
<input onkeyup="onItemChange()" data-bind="value: prettyQty, valueUpdate: 'afterkeydown', attr: {name: 'invoice_items[' + $index() + '][qty]'}"
style="text-align: right" class="form-control" name="quantity"/>
<input data-bind="value: prettyQty, valueUpdate: 'afterkeydown', attr: {name: 'invoice_items[' + $index() + '][qty]'}"
style="text-align: right" class="form-control invoice-item" name="quantity"/>
</td>
<td style="display:none;" data-bind="visible: $root.invoice_item_taxes.show">
<select class="form-control" style="width:100%" data-bind="value: tax, options: $root.tax_rates, optionsText: 'displayName', attr: {name: 'invoice_items[' + $index() + '][tax]'}"></select>
@ -727,7 +726,8 @@
var $input = $('select#client');
$input.combobox().on('change', function(e) {
var clientId = parseInt($('input[name=client]').val(), 10);
var oldId = model.invoice().client().public_id();
var clientId = parseInt($('input[name=client]').val(), 10) || 0;
if (clientId > 0) {
var selected = clientMap[clientId];
model.loadClient(selected);
@ -735,7 +735,7 @@
$('.client-input').val(getClientDisplayName(selected));
// if there's an invoice number pattern we'll apply it now
setInvoiceNumber(selected);
} else {
} else if (oldId) {
model.loadClient($.parseJSON(ko.toJSON(new ClientModel())));
model.invoice().client().country = false;
}
@ -750,7 +750,7 @@
}
$('#invoice_footer, #terms, #public_notes, #invoice_number, #invoice_date, #due_date, #start_date, #po_number, #discount, #currency_id, #invoice_design_id, #recurring, #is_amount_discount, #partial, #custom_text_value1, #custom_text_value2').change(function() {
setTimeout(function() {
setTimeout(function() {
refreshPDF(true);
}, 1);
});
@ -789,8 +789,6 @@
});
$('label.radio').addClass('radio-inline');
applyComboboxListeners();
@if ($invoice->client->id)
$input.trigger('change');
@ -806,12 +804,15 @@
@if (isset($tasks) && $tasks)
NINJA.formIsChanged = true;
@endif
applyComboboxListeners();
});
function applyComboboxListeners() {
var selectorStr = '.invoice-table input, .invoice-table select, .invoice-table textarea';
$(selectorStr).off('blur').on('blur', function() {
refreshPDF(true);
var selectorStr = '.invoice-table input, .invoice-table select, .invoice-table textarea';
$(selectorStr).off('change').on('change', function(event) {
onItemChange();
refreshPDF(true);
});
$('textarea').on('keyup focus', function(e) {
@ -821,7 +822,7 @@
});
@if (Auth::user()->account->fill_products)
$('.datalist').on('input', function() {
$('.datalist').off('input').on('input', function() {
var key = $(this).val();
for (var i=0; i<products.length; i++) {
var product = products[i];
@ -839,11 +840,10 @@
model.tax(self.model.getTaxRateById(product.default_tax_rate.public_id));
}
@endif
break;
model.product_key(key);
break;
}
}
onItemChange();
refreshPDF();
});
@endif
}
@ -963,14 +963,14 @@
if (contact.send_invoice()) {
parts.push(contact.displayName());
}
}
}
return parts.join('\n');
}
function preparePdfData(action) {
var invoice = createInvoiceModel();
var design = getDesignJavascript();
var design = getDesignJavascript();
if (!design) return;
doc = generatePDF(invoice, design, true);

View File

@ -258,15 +258,15 @@ function InvoiceModel(data) {
self.addItem = function() {
var itemModel = new ItemModel();
@if ($account->hide_quantity)
itemModel.qty(1);
itemModel.qty(1);
@endif
self.invoice_items.push(itemModel);
applyComboboxListeners();
applyComboboxListeners();
return itemModel;
}
if (data) {
ko.mapping.fromJS(data, self.mapping, self);
ko.mapping.fromJS(data, self.mapping, self);
} else {
self.addItem();
}

View File

@ -89,14 +89,15 @@
var needsRefresh = false;
function refreshPDF(force) {
//console.log('refresh PDF - force: ' + force + ' ' + (new Date()).getTime())
return getPDFString(refreshPDFCB, force);
}
function refreshPDFCB(string) {
if (!string) return;
PDFJS.workerSrc = '{{ asset('js/pdf_viewer.worker.js') }}';
if ({{ Auth::check() && Auth::user()->force_pdfjs ? 'false' : 'true' }} && (isFirefox || (isChrome && !isChromium))) {
$('#theFrame').attr('src', string).show();
if ({{ Auth::check() && Auth::user()->force_pdfjs ? 'false' : 'true' }} && (isFirefox || isChrome)) {
$('#theFrame').attr('src', string).show();
} else {
if (isRefreshing) {
//needsRefresh = true;