From 302a230bf2b5e2b4a96adbbfa58ddbdbd5ddadc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Doursenaud?= Date: Thu, 21 Nov 2013 18:00:27 +0100 Subject: [PATCH] Made update price synchronous to avoid dependency hell --- htdocs/core/tpl/objectline_add.tpl.php | 73 ++++++++++++++------------ 1 file changed, 39 insertions(+), 34 deletions(-) diff --git a/htdocs/core/tpl/objectline_add.tpl.php b/htdocs/core/tpl/objectline_add.tpl.php index 6e1c3c687f9..207351d0596 100644 --- a/htdocs/core/tpl/objectline_add.tpl.php +++ b/htdocs/core/tpl/objectline_add.tpl.php @@ -423,40 +423,45 @@ $(document).ready(function() { }); function update_price(input, output) { - $.post('/core/ajax/price.php', { - 'amount': $('#' + input).val(), - 'output': output, - 'tva_tx': $('#tva_tx').val() - }, - function(data) { - var addline=false; - if (typeof data[output] != 'undefined') { - // Hide price_ttc if no vat - //if ($('#tva_tx').val() > 0 || ($('#tva_tx').val() == 0 && output == 'price_ht')) { - $('#' + output).val(data[output]); - //} - if ($('#idprod').val() == 0 && $('#select_type').val() >= 0) { - if (typeof CKEDITOR == 'object' && typeof CKEDITOR.instances != 'undefined' && CKEDITOR.instances['product_desc'] != 'undefined') { - var content = CKEDITOR.instances['product_desc'].getData(); - } else { - var content = $('#product_desc').val(); - } - if (content.length > 0) { - addline=true; - } - } else { - addline=true; - } - } else { - $('#' + input).val(''); - $('#' + output).val(''); - } - if (addline) { - $('#addlinebutton').removeAttr('disabled'); - } else { - $('#addlinebutton').attr('disabled','disabled'); - } - }, 'json'); + $.ajax({ + type: 'POST', + url: '/core/ajax/price.php', + data: { + 'amount': $('#' + input).val(), + 'output': output, + 'tva_tx': $('#tva_tx').val() + }, + success: function(data) { + var addline=false; + if (typeof data[output] != 'undefined') { + // Hide price_ttc if no vat + //if ($('#tva_tx').val() > 0 || ($('#tva_tx').val() == 0 && output == 'price_ht')) { + $('#' + output).val(data[output]); + //} + if ($('#idprod').val() == 0 && $('#select_type').val() >= 0) { + if (typeof CKEDITOR == 'object' && typeof CKEDITOR.instances != 'undefined' && CKEDITOR.instances['product_desc'] != 'undefined') { + var content = CKEDITOR.instances['product_desc'].getData(); + } else { + var content = $('#product_desc').val(); + } + if (content.length > 0) { + addline=true; + } + } else { + addline=true; + } + } else { + $('#' + input).val(''); + $('#' + output).val(''); + } + if (addline) { + $('#addlinebutton').removeAttr('disabled'); + } else { + $('#addlinebutton').attr('disabled','disabled'); + } + }, + dataType: 'json', + async: false}); } function getVATRates(action, htmlname, idprod) {