correct some ajax bugs caused by tpl recent updates

This commit is contained in:
Christophe Battarel 2012-09-19 12:02:06 +02:00
parent 951b98a963
commit de93c819f4
2 changed files with 24 additions and 21 deletions

View File

@ -133,7 +133,7 @@
</td> </td>
</tr> </tr>
<?php if ($conf->service->enabled && $line->product_type == 1 && $dateSelector) { ?> <?php if (! empty($conf->service->enabled) && $line->product_type == 1 && $dateSelector) { ?>
<tr id="service_duration_area" <?php echo $bc[$var]; ?>> <tr id="service_duration_area" <?php echo $bc[$var]; ?>>
<td colspan="11"><?php echo $langs->trans('ServiceLimitedDuration').' '.$langs->trans('From').' '; ?> <td colspan="11"><?php echo $langs->trans('ServiceLimitedDuration').' '.$langs->trans('From').' '; ?>
<?php <?php
@ -329,9 +329,9 @@ $(document).ready(function() {
<?php } ?> <?php } ?>
<?php if (! empty($conf->margin->enabled)) { ?> <?php if (! empty($conf->margin->enabled)) { ?>
$.post('<?php echo DOL_URL_ROOT; ?>/fourn/ajax/getSupplierPrices.php', {'idprod': <?php echo $line->fk_product; ?>}, function(data) { $.post('<?php echo DOL_URL_ROOT; ?>/fourn/ajax/getSupplierPrices.php', {'idprod': <?php echo $line->fk_product?$line->fk_product:0; ?>}, function(data) {
if (data.length > 0) { if (data && data.length > 0) {
var options = ''; var options = '';
var trouve=false; var trouve=false;
$(data).each(function() { $(data).each(function() {

View File

@ -32,7 +32,7 @@
<td<?php echo (! empty($conf->global->MAIN_VIEW_LINE_NUMBER) ? ' colspan="4"' : ' colspan="3"'); ?>> <td<?php echo (! empty($conf->global->MAIN_VIEW_LINE_NUMBER) ? ' colspan="4"' : ' colspan="3"'); ?>>
<?php <?php
echo $langs->trans("AddNewLine").' - '; echo $langs->trans("AddNewLine").' - ';
if ($conf->service->enabled) if (! empty($conf->service->enabled))
echo $langs->trans('RecordedProductsAndServices'); echo $langs->trans('RecordedProductsAndServices');
else else
echo $langs->trans('RecordedProducts'); echo $langs->trans('RecordedProducts');
@ -46,9 +46,9 @@ if (! empty($conf->margin->enabled)) {
?> ?>
<td align="right"><?php echo $langs->trans('BuyingPrice'); ?></td> <td align="right"><?php echo $langs->trans('BuyingPrice'); ?></td>
<?php <?php
if($conf->global->DISPLAY_MARGIN_RATES) if (! empty($conf->global->DISPLAY_MARGIN_RATES))
$colspan++; $colspan++;
if($conf->global->DISPLAY_MARK_RATES) if (! empty($conf->global->DISPLAY_MARK_RATES))
$colspan++; $colspan++;
} }
?> ?>
@ -100,9 +100,9 @@ if (! empty($conf->margin->enabled)) {
<input type="text" size="5" id="buying_price" name="buying_price" value="<?php echo (isset($_POST["buying_price"])?$_POST["buying_price"]:''); ?>"> <input type="text" size="5" id="buying_price" name="buying_price" value="<?php echo (isset($_POST["buying_price"])?$_POST["buying_price"]:''); ?>">
</td> </td>
<?php <?php
if($conf->global->DISPLAY_MARGIN_RATES) if (! empty($conf->global->DISPLAY_MARGIN_RATES))
$colspan++; $colspan++;
if($conf->global->DISPLAY_MARK_RATES) if (! empty($conf->global->DISPLAY_MARK_RATES))
$colspan++; $colspan++;
} }
?> ?>
@ -115,9 +115,10 @@ if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER))
else else
$colspan = 9; $colspan = 9;
if (! empty($conf->margin->enabled)) { if (! empty($conf->margin->enabled)) {
if($conf->global->DISPLAY_MARGIN_RATES) $colspan++; // For the buying price
if (! empty($conf->global->DISPLAY_MARGIN_RATES))
$colspan++; $colspan++;
if($conf->global->DISPLAY_MARK_RATES) if (! empty($conf->global->DISPLAY_MARK_RATES))
$colspan++; $colspan++;
} }
?> ?>
@ -139,10 +140,12 @@ if (! empty($conf->margin->enabled)) {
?> ?>
<script type="text/javascript"> <script type="text/javascript">
$("#idprod").change(function() { $("#idprod").change(function() {
$("#np_fournprice options").remove(); $("#fournprice options").remove();
$("#np_buying_price").show(); $("#fournprice").hide();
$("#buying_price").val("");
$("#buying_price").show();
$.post('<?php echo DOL_URL_ROOT; ?>/fourn/ajax/getSupplierPrices.php', {'idprod': $(this).val()}, function(data) { $.post('<?php echo DOL_URL_ROOT; ?>/fourn/ajax/getSupplierPrices.php', {'idprod': $(this).val()}, function(data) {
if (data.length > 0) { if (data && data.length > 0) {
var options = ''; var options = '';
var i = 0; var i = 0;
$(data).each(function() { $(data).each(function() {
@ -150,20 +153,20 @@ $("#idprod").change(function() {
options += '<option value="'+this.id+'" price="'+this.price+'"'; options += '<option value="'+this.id+'" price="'+this.price+'"';
if (i == 1) { if (i == 1) {
options += ' selected'; options += ' selected';
$("#np_buying_price").val(this.price); $("#buying_price").val(this.price);
} }
options += '>'+this.label+'</option>'; options += '>'+this.label+'</option>';
}); });
options += '<option value=null><?php echo $langs->trans("InputPrice"); ?></option>'; options += '<option value=null><?php echo $langs->trans("InputPrice"); ?></option>';
$("#np_fournprice").html(options); $("#fournprice").html(options);
$("#np_buying_price").hide(); $("#buying_price").hide();
$("#np_fournprice").show(); $("#fournprice").show();
$("#np_fournprice").change(function() { $("#fournprice").change(function() {
var selval = $(this).find('option:selected').attr("price"); var selval = $(this).find('option:selected').attr("price");
if (selval) if (selval)
$("#np_buying_price").val(selval).hide(); $("#buying_price").val(selval).hide();
else else
$('#np_buying_price').show(); $('#buying_price').show();
}); });
} }
}, },