Merge pull request #1328 from csalvador/develop-fixAJAX

Develop fix ajax
This commit is contained in:
Laurent Destailleur 2013-11-29 02:59:11 -08:00
commit e27d109f2d

View File

@ -153,9 +153,9 @@ if (! empty($conf->margin->enabled)) {
<?php
// Editor wysiwyg
require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
$nbrows=ROWS_2;
if (! empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) $nbrows=$conf->global->MAIN_INPUT_DESC_HEIGHT;
$enable=(isset($conf->global->FCKEDITOR_ENABLE_DETAILS)?$conf->global->FCKEDITOR_ENABLE_DETAILS:0);
$nbrows=ROWS_2;
if (! empty($conf->global->MAIN_INPUT_DESC_HEIGHT)) $nbrows=$conf->global->MAIN_INPUT_DESC_HEIGHT;
$enable=(isset($conf->global->FCKEDITOR_ENABLE_DETAILS)?$conf->global->FCKEDITOR_ENABLE_DETAILS:0);
$doleditor=new DolEditor('product_desc', GETPOST('product_desc'), '', 150, 'dolibarr_details', '', false, true, $enable, $nbrows, 70);
$doleditor->Create();
?>
@ -242,7 +242,6 @@ $(document).ready(function() {
$('#service_duration_area').hide();
$('#idprod').change(function() {
if ($(this).val() > 0) {
// Update vat rate combobox
@ -260,11 +259,11 @@ $(document).ready(function() {
if (typeof data != 'undefined') {
$('#product_ref').val(data.ref);
$('#product_label').val(data.label);
$('#origin_tva_tx_cache').val(data.tva_tx);
$('#price_base_type').val(data.pricebasetype).trigger('change');
$('#price_ht').val(data.price_ht).trigger('change');
$('#origin_price_ht_cache').val(data.price_ht);
//$('#origin_price_ttc_cache').val(data.price_ttc);
$('#origin_tva_tx_cache').val(data.tva_tx);
$('#select_type').val(data.type).attr('disabled','disabled').trigger('change');
//$('#price_base_type_area').show();
$('#qty').val(data.qty);
@ -279,14 +278,11 @@ $(document).ready(function() {
}, 'json');
<?php } ?>
} else {
} else {
$('#price_ttc').val('');
$('#price_ttc').val('');
// Restore vat rate combobox
getVATRates('getSellerVATRates', 'tva_tx');
// For compatibility with combobox
// For compatibility with combobox
<?php if (empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)) { ?>
$('#select_type').val('').removeAttr('disabled').trigger('change');
$('#product_ref').val('');
@ -423,59 +419,66 @@ $(document).ready(function() {
});
function update_price(input, output) {
$.ajax({
type: 'POST',
url: '<?php echo DOL_URL_ROOT; ?>/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});
$.ajax({
type: 'POST',
url: '<?php echo DOL_URL_ROOT; ?>/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) {
var productid = (idprod?idprod:0);
$.post('<?php echo DOL_URL_ROOT; ?>/core/ajax/vatrates.php', {
'action': action,
'id': <?php echo $buyer->id; ?>,
'productid': productid,
'htmlname': htmlname },
function(data) {
if (typeof data != 'undefined' && data.error == null) {
$("#" + htmlname).html(data.value).trigger('change');
}
}, 'json');
$.ajax({
type: "POST",
url: '<?php echo DOL_URL_ROOT;?>/core/ajax/vatrates.php',
data: {
'action': action,
'id': <?php echo $buyer->id; ?>,
'productid': productid,
'htmlname': htmlname
},
success: function(data){
if (typeof data != 'undefined' && data.error == null) {
$("#" + htmlname).html(data.value).trigger('change');
}
},
dataType: "json",
async: false
});
}
// Check if decription is not empty for free line
@ -524,7 +527,7 @@ $("#idprod").change(function() {
$("#fournprice").empty();
$("#buying_price").show();
if ($(this).val() > 0)
{
{
$.post('<?php echo DOL_URL_ROOT; ?>/fourn/ajax/getSupplierPrices.php', {'idprod': $(this).val()}, function(data) {
if (data && data.length > 0) {
var options = '';
@ -555,8 +558,8 @@ $("#idprod").change(function() {
}
},
'json');
} else {
$("#fournprice").hide();
} else {
$("#fournprice").hide();
$('#buying_price').val('');
}
});