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