Fix: [ task #498 ] add same tests in edit mode

This commit is contained in:
Regis Houssin 2012-08-28 16:11:40 +02:00
parent 62a7847c5b
commit c0bde33b1f

View File

@ -33,7 +33,7 @@
<input type="hidden" name="id" value="<?php echo $this->id; ?>"> <input type="hidden" name="id" value="<?php echo $this->id; ?>">
<input type="hidden" name="lineid" value="<?php echo $line->id; ?>"> <input type="hidden" name="lineid" value="<?php echo $line->id; ?>">
<input type="hidden" id="product_type" name="type" value="<?php echo $line->product_type; ?>"> <input type="hidden" id="product_type" name="type" value="<?php echo $line->product_type; ?>">
<input type="hidden" id="product_id" name="productid" value="<?php echo (! empty($line->fk_product)?$line->fk_product:''); ?>" /> <input type="hidden" id="product_id" name="productid" value="<?php echo (! empty($line->fk_product)?$line->fk_product:0); ?>" />
<tr <?php echo $bc[$var]; ?>> <tr <?php echo $bc[$var]; ?>>
<td<?php echo (! empty($conf->global->MAIN_VIEW_LINE_NUMBER) ? ' colspan="2"' : ''); ?>> <td<?php echo (! empty($conf->global->MAIN_VIEW_LINE_NUMBER) ? ' colspan="2"' : ''); ?>>
@ -139,7 +139,7 @@
<script type="text/javascript"> <script type="text/javascript">
$(document).ready(function() { $(document).ready(function() {
<?php if ($conf->global->MAIN_FEATURES_LEVEL > 1) { ?> <?php if ($conf->global->MAIN_FEATURES_LEVEL > 1) { ?>
if ($('#product_type').val() == 0) { if ($('#product_type').val() == 0) {
$('#service_duration_area').hide(); $('#service_duration_area').hide();
@ -171,7 +171,22 @@ $(document).ready(function() {
} else if (type == 1) { } else if (type == 1) {
$('#service_duration_area').show(); $('#service_duration_area').show();
} }
if (($('#price_ht').val().length > 0) || ($('#price_ttc').val().length > 0)) { var addline=false;
if ($('#price_ht').val().length > 0) {
if ($('#product_id').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;
}
}
if (addline) {
$('#savelinebutton').removeAttr('disabled'); $('#savelinebutton').removeAttr('disabled');
} else { } else {
$('#savelinebutton').attr('disabled','disabled'); $('#savelinebutton').attr('disabled','disabled');
@ -185,87 +200,123 @@ $(document).ready(function() {
}); });
$('#price_ht').focusin(function() { $('#price_ht').focusin(function() {
$('#price_base_type').html('HT'); $('#price_base_type').val('HT');
}); });
$('#price_ht').onDelayedKeyup({ $('#price_ht').bind('change keyup input', function() {
handler: function() { if ($('#price_base_type').val() == 'HT') {
$('#price_base_type').html('HT'); update_price('price_ht', 'price_ttc');
$.post('<?php echo DOL_URL_ROOT; ?>/core/ajax/price.php', {
'action': 'get_ttc',
'pu_ht': $(this).val(),
'tva_tx': $('#tva_tx').val()
},
function(data) {
if (data && data.price.length > 0) {
$('#price_ttc').val(data.price);
if (($('#product_id').val().length > 0) || ($('#select_type').val() >= 0)) {
$('#savelinebutton').removeAttr('disabled');
} else {
$('#savelinebutton').attr('disabled','disabled');
}
} else {
$('#price_ttc').val('');
$('#savelinebutton').attr('disabled','disabled');
}
}, 'json');
} }
}); });
$('#price_ttc').focusin(function() { $('#price_ttc').focusin(function() {
$('#price_base_type').html('TTC'); $('#price_base_type').val('TTC');
}); });
$('#price_ttc').onDelayedKeyup({ $('#price_ttc').bind('change keyup input', function() {
handler: function() { if ($('#price_base_type').val() == 'TTC') {
update_price('price_ttc', 'price_ht');
}
});
if ($('#tva_tx').val() == 0) {
$('#price_ttc').attr('disabled','disabled');
}
$('#tva_tx').change(function() {
if ($(this).val() == 0) {
$('#price_ttc').attr('disabled','disabled');
$('#price_ttc').val('');
} else {
$('#price_ttc').removeAttr('disabled');
if ($('#price_base_type').val() == 'HT') {
update_price('price_ht', 'price_ttc');
} else if ($('#price_base_type').val() == 'TTC') {
update_price('price_ttc', 'price_ht');
}
}
});
function update_price(input, output) {
$.post('<?php echo DOL_URL_ROOT; ?>/core/ajax/price.php', { $.post('<?php echo DOL_URL_ROOT; ?>/core/ajax/price.php', {
'action': 'get_ht', 'amount': $('#' + input).val(),
'pu_ttc': $(this).val(), 'output': output,
'tva_tx': $('#tva_tx').val() 'tva_tx': $('#tva_tx').val()
}, },
function(data) { function(data) {
if (data && data.price.length > 0) { var addline=false;
$('#price_ht').val(data.price); if (typeof data[output] != 'undefined') {
if (($('#product_id').val().length > 0) || ($('#select_type').val() >= 0)) { // Hide price_ttc if no vat
if ($('#tva_tx').val() > 0 || ($('#tva_tx').val() == 0 && output == 'price_ht')) {
$('#' + output).val(data[output]);
}
if ($('#product_id').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) {
$('#savelinebutton').removeAttr('disabled'); $('#savelinebutton').removeAttr('disabled');
} else { } else {
$('#savelinebutton').attr('disabled','disabled'); $('#savelinebutton').attr('disabled','disabled');
} }
}, 'json');
}
// Check if decription is not empty for free line
<?php if (! empty($conf->fckeditor->enabled) && ! empty($conf->global->FCKEDITOR_ENABLE_DETAILS)) { ?>
CKEDITOR.on('instanceReady', function() {
CKEDITOR.instances['product_desc'].on('key', function() {
var addline=false;
if ($('#product_id').val() == 0 && $('#select_type').val() >= 0 && $('#price_ht').val().length > 0) {
var content = CKEDITOR.instances['product_desc'].getData();
if (content.length > 0) {
addline=true;
}
} else if ($('#product_id').val() > 0 && $('#price_ht').val().length > 0) {
addline=true;
}
if (addline) {
$('#savelinebutton').removeAttr('disabled');
} else { } else {
$('#price_ht').val('');
$('#savelinebutton').attr('disabled','disabled'); $('#savelinebutton').attr('disabled','disabled');
} }
}, 'json');
}
}); });
});
$('#tva_tx').change(function() { <?php } else { ?>
if ($('#price_base_type').html() == 'HT') { $('#product_desc').onDelayedKeyup({
$.post('<?php echo DOL_URL_ROOT; ?>/core/ajax/price.php', { 'handler': function() {
'action': 'get_ttc', var addline=false;
'pu_ht': $('#price_ht').val(), if ($('#product_id').val() == 0 && $('#select_type').val() >= 0 && $('#price_ht').val().length > 0) {
'tva_tx': $(this).val() var content = $('#product_desc').val();
}, if (content.length > 0) {
function(data) { addline=true;
if (data && data.price.length > 0) {
$('#price_ttc').val(data.price);
} }
}, 'json'); } else if ($('#product_id').val() > 0 && $('#price_ht').val().length > 0) {
addline=true;
}
if (addline) {
$('#savelinebutton').removeAttr('disabled');
} else { } else {
$.post('<?php echo DOL_URL_ROOT; ?>/core/ajax/price.php', { $('#savelinebutton').attr('disabled','disabled');
'action': 'get_ht',
'pu_ttc': $('#price_ttc').val(),
'tva_tx': $(this).val()
},
function(data) {
if (data && data.price.length > 0) {
$('#price_ht').val(data.price);
} }
}, 'json');
} }
}); });
<?php } ?> <?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; ?>}, function(data) {
if (data.length > 0) { if (data.length > 0) {