Optimizacion de funciones JS

This commit is contained in:
imnavajas
2024-02-22 00:15:17 +01:00
parent fd8992b386
commit 547880ca7a

View File

@ -6,7 +6,7 @@ function previewInteriorPlana(lpTagName, isCosido, isTapaDura) {
// Local parameters
let guardaV = 0;
guardaH = 0;
let guardaH = 0;
let styleText = {size: 12, family: 'Public Sans'};
// Get the preview Object parameters
@ -497,12 +497,10 @@ function portadaTapaBlanda(lpTagName, isCosido, isTapaDura) {
function getLomoLibro() {
let _anchoLomo = 0;
$("#tableLineasPresupuesto tbody tr:visible td input[id*='_lomo']").each(function () {
_anchoLomo += parseFloat($(this).val());
});
const anchoLomoInputs = $("#tableLineasPresupuesto tbody tr:visible td input[id*='_lomo']");
const anchoLomo = Array.from(anchoLomoInputs).reduce((sum, input) => sum + parseFloat($(input).val()), 0);
return parseFloat(_anchoLomo.toFixed(2));
return parseFloat(anchoLomo.toFixed(2));
}
@ -668,49 +666,25 @@ function getObjetoLP(lpName, _isCosido, _isTapaDura) {
function getVisibleTabs() {
const table = $('#tableLineasPresupuesto').DataTable();
// Clear all existing tabs
$('*[id*=tab-pv-]').each(function () {
$(this).hide();
$(this).children('.active').each(function () {
$(this).removeClass('active');
});
$('*[id*=pv_]').each(function () {
$(this).removeClass("active show");
});
});
$('*[id*=tab-pv-]').hide().find('.active').removeClass('active');
$('*[id*=pv_]').removeClass('active show');
// Enable active tabs
$('#tableLineasPresupuesto').DataTable().rows().every(function (rowIdx, tableLoop, rowLoop) {
let lpName = this.data().row_id.replace('lp_', '');
let tabName = lpName.replace('_', '-');
//console.log(lpName);
switch (lpName) {
case 'bn':
case 'bnhq':
case 'color':
case 'colorhq':
case 'rot_bn':
case 'rot_color':
case 'guardas':
case 'sobrecubierta':
$("#tab-pv-" + tabName).show();
break;
table.rows().every(function () {
const lpName = this.data().row_id.replace('lp_', '');
const tabName = lpName.replace('_', '-');
case 'cubierta':
$("#tab-pv-" + tabName).show();
$("#tab-pv-esquema-" + tabName).show();
break;
default:
break;
if (['bn', 'bnhq', 'color', 'colorhq', 'rot_bn', 'rot_color', 'guardas', 'cubierta', 'sobrecubierta'].includes(lpName)) {
$(`#tab-pv-${tabName}`).show();
if (lpName === 'cubierta') {
$(`#tab-pv-${tabName}`).show();
$(`#tab-pv-esquema-${tabName}`).show();
}
}
});
}