From 647c0bd72d9fd48979152ea7aaa473ea48679807 Mon Sep 17 00:00:00 2001 From: Jaime Jimenez Date: Wed, 25 Jun 2025 13:55:31 +0200 Subject: [PATCH] =?UTF-8?q?trabajando=20en=20la=20validaci=C3=B3n=20de=20l?= =?UTF-8?q?os=20datosgenerales?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../presupuestoCliente/datosGenerales.js | 247 ++++++++++++------ .../presupuestoCliente/disenioCubierta.js | 11 +- 2 files changed, 172 insertions(+), 86 deletions(-) diff --git a/httpdocs/assets/js/safekat/pages/presupuestoCliente/datosGenerales.js b/httpdocs/assets/js/safekat/pages/presupuestoCliente/datosGenerales.js index 2076bab5..17b2e151 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoCliente/datosGenerales.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoCliente/datosGenerales.js @@ -103,9 +103,13 @@ class DatosGenerales { this.pagColorConsecutivas.on('change', this.#handPaginasConsecutivas.bind(this)); this.papelDiferente.on('change', this.#handlePapelDiferente.bind(this)); + $('.tirada-presupuesto').on('change', () => { - - self.validate(false); + + if (this.validateTiradas()) { + this.removeError(window.translations["validation"].tirada_integer_greatherThan_0); + this.removeError(window.translations["validation"].tirada_pod_nopod); + } let tiradas = self.getTiradas(); if (!Array.isArray(tiradas)) { tiradas = [tiradas]; @@ -120,7 +124,21 @@ class DatosGenerales { this.anchoPersonalizado.on("change", this.#checkValue.bind(this)); this.altoPersonalizado.on("change", this.#checkValue.bind(this)); - this.titulo.on('change', () => { $(".titulo").html(this.titulo.val()); }); + this.titulo.on('change', () => { + $(".titulo").html(this.titulo.val()); + if (this.validateTitulo()) { + this.removeError(window.translations["validation"].titulo_requerido); + } + else { + this.addError(window.translations["validation"].titulo_requerido); + } + }); + + this.cliente.item.on('change', () => { + if (this.validateCliente()) { + this.removeError(window.translations["validation"].cliente); + } + }); this.retractilado.on('change', this.#eventRetractilado.bind(this)); this.retractilado5.on('change', this.#eventRetractilado.bind(this)); @@ -132,86 +150,22 @@ class DatosGenerales { this.errores = []; // Titulo - if (this.titulo.val().trim() === '') { - this.errores.push(window.translations["validation"].titulo_requerido); - this.titulo.addClass('is-invalid'); - } else { - this.titulo.removeClass('is-invalid'); - } + this.validateTitulo(); // Cliente - if ($(this.excluirRotativa).prop('hidden')) { - if ($('#clienteId').val() === null || $('#clienteId').val().length === 0) { - this.errores.push(window.translations["validation"].cliente); - $('#clienteId').addClass('is-invalid'); - } else { - $('#clienteId').removeClass('is-invalid'); - } - } else { - if (this.cliente.getVal() <= 0) { - this.errores.push(window.translations["validation"].cliente); - this.cliente.item.addClass('is-invalid'); - } else { - this.cliente.item.removeClass('is-invalid'); - } - } + this.validateCliente(); // Tirada - let tiradas = this.getTiradas(); - if (tiradas.length === 0 || tiradas.some(tirada => - !Number.isInteger(tirada) || - parseInt(tirada) <= 0 || - tirada == "")) { - - this.errores.push(window.translations["validation"].tirada_integer_greatherThan_0); - this.tirada1.addClass('is-invalid'); - - } else { - this.tirada1.removeClass('is-invalid'); - // Comprobar tiradas POD - const noPOD = tiradas.some(tirada => parseInt(tirada) > 30); - const siPOD = tiradas.some(tirada => parseInt(tirada) <= 30); - if (noPOD && siPOD) { - this.errores.push(window.translations["validation"].tirada_pod_nopod); - this.tirada1.addClass('is-invalid'); - } - else { - this.tirada1.removeClass('is-invalid'); - } - } + this.validateTiradas(); // formato libro - if (this.checkFormatoPersonalizado.is(':checked')) { - if (this.anchoPersonalizado.val().length === 0 || isNaN(this.anchoPersonalizado.val()) || - parseFloat(this.anchoPersonalizado.val()) <= 0) { - this.errores.push(window.translations["validation"].papelFormatoAncho); - this.anchoPersonalizado.addClass('is-invalid'); - } else { - this.anchoPersonalizado.removeClass('is-invalid'); - } - if (this.altoPersonalizado.val().length === 0 || isNaN(this.altoPersonalizado.val()) || - parseFloat(this.altoPersonalizado.val()) <= 0) { - this.errores.push(window.translations["validation"].papelFormatoAlto); - this.altoPersonalizado.addClass('is-invalid'); - } else { - this.altoPersonalizado.removeClass('is-invalid'); - } - } else { - const options = $("#papelFormatoId").select2('data'); - const hasValidOption = options.some(option => parseInt(option.id) > 0); - if (options !== null && options.length > 0 && hasValidOption) { - this.papelFormatoId.removeClass('is-invalid'); - } else { - this.errores.push(window.translations["validation"].papelFormato); - this.papelFormatoId.addClass('is-invalid'); - } - } + this.validateFormatoLibro(); // Paginas if (this.paginasColor.val() == '' || isNaN(this.paginasColor.val()) || parseInt(this.paginasColor.val()) < 0) { this.errores.push(window.translations["validation"].paginasColor); this.paginasColor.addClass('is-invalid'); - } + } else if (parseInt(this.paginasColor.val()) % 2 != 0) { this.errores.push(window.translations["validation"].paginas_pares); this.paginasColor.addClass('is-invalid'); @@ -222,7 +176,7 @@ class DatosGenerales { if (this.paginasNegro.val() == '' || isNaN(this.paginasNegro.val()) || parseInt(this.paginasNegro.val()) < 0) { this.errores.push(window.translations["validation"].paginasNegro); this.paginasNegro.addClass('is-invalid'); - } + } else if (parseInt(this.paginasNegro.val()) % 2 != 0) { this.errores.push(window.translations["validation"].paginas_pares); this.paginasNegro.addClass('is-invalid'); @@ -258,15 +212,14 @@ class DatosGenerales { const skAlert = document.getElementById('sk-alert'); skAlert.innerHTML = ''; - const uniqueErrors = [...new Set(this.errores)]; + this.errores = [...new Set(this.errores)]; - if (uniqueErrors.length > 0) { + if (this.errores.length > 0) { const message = window.translations["validation"].fix_errors + ``; popErrorAlert(message, 'sk-alert', false); - this.errores = []; return false; } else { @@ -279,6 +232,104 @@ class DatosGenerales { } } + validateFormatoLibro() { + + let noError = true; + if (this.checkFormatoPersonalizado.is(':checked')) { + if (this.anchoPersonalizado.val().length === 0 || isNaN(this.anchoPersonalizado.val()) || + parseFloat(this.anchoPersonalizado.val()) <= 0) { + this.errores.push(window.translations["validation"].papelFormatoAncho); + this.anchoPersonalizado.addClass('is-invalid'); + noError = false; + } else { + this.anchoPersonalizado.removeClass('is-invalid'); + } + if (this.altoPersonalizado.val().length === 0 || isNaN(this.altoPersonalizado.val()) || + parseFloat(this.altoPersonalizado.val()) <= 0) { + this.errores.push(window.translations["validation"].papelFormatoAlto); + this.altoPersonalizado.addClass('is-invalid'); + noError = false; + } else { + this.altoPersonalizado.removeClass('is-invalid'); + } + } else { + const options = $("#papelFormatoId").select2('data'); + const hasValidOption = options.some(option => parseInt(option.id) > 0); + if (options !== null && options.length > 0 && hasValidOption) { + this.papelFormatoId.removeClass('is-invalid'); + } else { + this.errores.push(window.translations["validation"].papelFormato); + this.papelFormatoId.addClass('is-invalid'); + noError = false; + } + } + return noError; + } + + validateTiradas() { + + let tiradas = this.getTiradas(); + if (tiradas.length === 0 || tiradas.some(tirada => + !Number.isInteger(tirada) || + parseInt(tirada) <= 0 || + tirada == "")) { + + this.errores.push(window.translations["validation"].tirada_integer_greatherThan_0); + this.tirada1.addClass('is-invalid'); + return false; + + } else { + this.tirada1.removeClass('is-invalid'); + // Comprobar tiradas POD + const noPOD = tiradas.some(tirada => parseInt(tirada) > 30); + const siPOD = tiradas.some(tirada => parseInt(tirada) <= 30); + if (noPOD && siPOD) { + this.errores.push(window.translations["validation"].tirada_pod_nopod); + this.tirada1.addClass('is-invalid'); + return false; + } + else { + this.tirada1.removeClass('is-invalid'); + return true; + } + } + } + + validateCliente() { + + if ($(this.excluirRotativa).prop('hidden')) { + if ($('#clienteId').val() === null || $('#clienteId').val().length === 0) { + this.errores.push(window.translations["validation"].cliente); + $('#clienteId').addClass('is-invalid'); + return false; + } else { + $('#clienteId').removeClass('is-invalid'); + return true; + } + } else { + if (this.cliente.getVal() <= 0) { + this.errores.push(window.translations["validation"].cliente); + this.cliente.item.addClass('is-invalid'); + return false; + } else { + this.cliente.item.removeClass('is-invalid'); + return true; + } + } + } + + validateTitulo() { + + if (this.titulo.val().trim() === '') { + this.errores.push(window.translations["validation"].titulo_requerido); + this.titulo.addClass('is-invalid'); + return false; + } else { + this.titulo.removeClass('is-invalid'); + return true; + } + } + processMenuLateral() { @@ -572,7 +623,7 @@ class DatosGenerales { } const dimensionLibro = this.getDimensionLibro(); if (dimensionLibro && dimensionLibro.alto) { - + $('#altoFaja').closest('.config-faja').find('.form-text').text('Entre 50 y ' + dimensionLibro.alto + ' mm'); } } @@ -582,6 +633,10 @@ class DatosGenerales { if (target.value < target.min) { target.value = target.min; } + if (this.validateFormatoLibro()) { + this.removeError(window.translations["validation"].papelFormatoAncho); + this.removeError(window.translations["validation"].papelFormatoAlto); + } } #eventRetractilado(event) { @@ -634,7 +689,7 @@ class DatosGenerales { $('#addSobrecubierta').prop('checked', false).trigger('change'); $(".sobrecubierta-items").addClass('d-none'); - if (this.grapado.hasClass('selected')){ + if (this.grapado.hasClass('selected')) { $("#tapaBlanda").addClass('selected'); $("#tapaBlanda").removeClass('d-none'); @@ -695,7 +750,7 @@ class DatosGenerales { this.domItem.find('#grapado').show(); } - if( totalPaginas < 20){ + if (totalPaginas < 20) { this.domItem.find('#espiral').removeClass('selected'); this.domItem.find('#espiral').find('.image-presupuesto').removeClass('selected'); this.domItem.find('#espiral').hide(); @@ -832,6 +887,38 @@ class DatosGenerales { return servicios; } + removeError(error) { + const hasError = this.errores.filter(err => err === error).length > 0; + if (hasError) { + // remove the item from this.errores + this.errores = this.errores.filter(err => err !== error); + } + if (this.errores.length == 0) { + document.getElementById('sk-alert').innerHTML = ''; + } + else { + document.getElementById('sk-alert').innerHTML = document.getElementById('sk-alert').innerHTML + .replace(`
  • ${error}
  • `, '').replace(error, ''); + } + } + + addError(error) { + + if ($('#sk-alert').html() == '') { + const message = window.translations["validation"].fix_errors + + ``; + popErrorAlert(message, 'sk-alert', false); + return false; + } + else { + $('#sk-alert').html() += + ``; + } + } } diff --git a/httpdocs/assets/js/safekat/pages/presupuestoCliente/disenioCubierta.js b/httpdocs/assets/js/safekat/pages/presupuestoCliente/disenioCubierta.js index 0cb63017..da6df22b 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoCliente/disenioCubierta.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoCliente/disenioCubierta.js @@ -340,9 +340,9 @@ class DisenioCubierta { }); this.papelSobrecubierta.item.on('change', () => { - this.papelSobrecubierta.item.find('option').remove(); - this.papelSobrecubierta.item.val(null); - this.papelSobrecubierta.item.trigger('select2:clear'); + this.gramajeSobrecubierta.item.find('option').remove(); + this.gramajeSobrecubierta.item.val(null); + this.gramajeSobrecubierta.item.trigger('select2:clear'); }); this.papelFaja.item.on('change', () => { @@ -487,7 +487,6 @@ class DisenioCubierta { ${this.errores.map(err => `
  • ${err}
  • `).join('')} `; popErrorAlert(message, 'sk-alert', false); - this.errores = []; return false; } else { @@ -951,7 +950,7 @@ class DisenioCubierta { element.trigger('change'); - if (this.validateSobrecubierta()) { + if (this.validateSolapasCubierta()) { this.removeError(window.translations["validation"].opcion_solapas); } } @@ -1317,7 +1316,7 @@ class DisenioCubierta { } else { document.getElementById('sk-alert').innerHTML = document.getElementById('sk-alert').innerHTML. - replace(window.translations["validation"].error, ''); + replace(error, ''); } } }