trabajando en la validación de los datosgenerales

This commit is contained in:
2025-06-25 13:55:31 +02:00
parent c3bce03921
commit 647c0bd72d
2 changed files with 172 additions and 86 deletions

View File

@ -103,9 +103,13 @@ class DatosGenerales {
this.pagColorConsecutivas.on('change', this.#handPaginasConsecutivas.bind(this)); this.pagColorConsecutivas.on('change', this.#handPaginasConsecutivas.bind(this));
this.papelDiferente.on('change', this.#handlePapelDiferente.bind(this)); this.papelDiferente.on('change', this.#handlePapelDiferente.bind(this));
$('.tirada-presupuesto').on('change', () => { $('.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(); let tiradas = self.getTiradas();
if (!Array.isArray(tiradas)) { if (!Array.isArray(tiradas)) {
tiradas = [tiradas]; tiradas = [tiradas];
@ -120,7 +124,21 @@ class DatosGenerales {
this.anchoPersonalizado.on("change", this.#checkValue.bind(this)); this.anchoPersonalizado.on("change", this.#checkValue.bind(this));
this.altoPersonalizado.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.retractilado.on('change', this.#eventRetractilado.bind(this));
this.retractilado5.on('change', this.#eventRetractilado.bind(this)); this.retractilado5.on('change', this.#eventRetractilado.bind(this));
@ -132,80 +150,16 @@ class DatosGenerales {
this.errores = []; this.errores = [];
// Titulo // Titulo
if (this.titulo.val().trim() === '') { this.validateTitulo();
this.errores.push(window.translations["validation"].titulo_requerido);
this.titulo.addClass('is-invalid');
} else {
this.titulo.removeClass('is-invalid');
}
// Cliente // Cliente
if ($(this.excluirRotativa).prop('hidden')) { this.validateCliente();
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');
}
}
// Tirada // Tirada
let tiradas = this.getTiradas(); this.validateTiradas();
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');
}
}
// formato libro // formato libro
if (this.checkFormatoPersonalizado.is(':checked')) { this.validateFormatoLibro();
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');
}
}
// Paginas // Paginas
if (this.paginasColor.val() == '' || isNaN(this.paginasColor.val()) || parseInt(this.paginasColor.val()) < 0) { if (this.paginasColor.val() == '' || isNaN(this.paginasColor.val()) || parseInt(this.paginasColor.val()) < 0) {
@ -258,15 +212,14 @@ class DatosGenerales {
const skAlert = document.getElementById('sk-alert'); const skAlert = document.getElementById('sk-alert');
skAlert.innerHTML = ''; 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 + const message = window.translations["validation"].fix_errors +
`<ul class="mb-0"> `<ul class="mb-0">
${uniqueErrors.map(err => `<li>${err}</li>`).join('')} ${this.errores.map(err => `<li>${err}</li>`).join('')}
</ul>`; </ul>`;
popErrorAlert(message, 'sk-alert', false); popErrorAlert(message, 'sk-alert', false);
this.errores = [];
return false; return false;
} }
else { 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() { processMenuLateral() {
@ -582,6 +633,10 @@ class DatosGenerales {
if (target.value < target.min) { if (target.value < target.min) {
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) { #eventRetractilado(event) {
@ -634,7 +689,7 @@ class DatosGenerales {
$('#addSobrecubierta').prop('checked', false).trigger('change'); $('#addSobrecubierta').prop('checked', false).trigger('change');
$(".sobrecubierta-items").addClass('d-none'); $(".sobrecubierta-items").addClass('d-none');
if (this.grapado.hasClass('selected')){ if (this.grapado.hasClass('selected')) {
$("#tapaBlanda").addClass('selected'); $("#tapaBlanda").addClass('selected');
$("#tapaBlanda").removeClass('d-none'); $("#tapaBlanda").removeClass('d-none');
@ -695,7 +750,7 @@ class DatosGenerales {
this.domItem.find('#grapado').show(); this.domItem.find('#grapado').show();
} }
if( totalPaginas < 20){ if (totalPaginas < 20) {
this.domItem.find('#espiral').removeClass('selected'); this.domItem.find('#espiral').removeClass('selected');
this.domItem.find('#espiral').find('.image-presupuesto').removeClass('selected'); this.domItem.find('#espiral').find('.image-presupuesto').removeClass('selected');
this.domItem.find('#espiral').hide(); this.domItem.find('#espiral').hide();
@ -832,6 +887,38 @@ class DatosGenerales {
return servicios; 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(`<li>${error}</li>`, '').replace(error, '');
}
}
addError(error) {
if ($('#sk-alert').html() == '') {
const message = window.translations["validation"].fix_errors +
`<ul class="mb-0">` +
`<li>${error}</li>` +
`</ul>`;
popErrorAlert(message, 'sk-alert', false);
return false;
}
else {
$('#sk-alert').html() +=
`<ul class="mb-0">` +
`<li>${error}</li>` +
`</ul>`;
}
}
} }

View File

@ -340,9 +340,9 @@ class DisenioCubierta {
}); });
this.papelSobrecubierta.item.on('change', () => { this.papelSobrecubierta.item.on('change', () => {
this.papelSobrecubierta.item.find('option').remove(); this.gramajeSobrecubierta.item.find('option').remove();
this.papelSobrecubierta.item.val(null); this.gramajeSobrecubierta.item.val(null);
this.papelSobrecubierta.item.trigger('select2:clear'); this.gramajeSobrecubierta.item.trigger('select2:clear');
}); });
this.papelFaja.item.on('change', () => { this.papelFaja.item.on('change', () => {
@ -487,7 +487,6 @@ class DisenioCubierta {
${this.errores.map(err => `<li>${err}</li>`).join('')} ${this.errores.map(err => `<li>${err}</li>`).join('')}
</ul>`; </ul>`;
popErrorAlert(message, 'sk-alert', false); popErrorAlert(message, 'sk-alert', false);
this.errores = [];
return false; return false;
} }
else { else {
@ -951,7 +950,7 @@ class DisenioCubierta {
element.trigger('change'); element.trigger('change');
if (this.validateSobrecubierta()) { if (this.validateSolapasCubierta()) {
this.removeError(window.translations["validation"].opcion_solapas); this.removeError(window.translations["validation"].opcion_solapas);
} }
} }
@ -1317,7 +1316,7 @@ class DisenioCubierta {
} }
else { else {
document.getElementById('sk-alert').innerHTML = document.getElementById('sk-alert').innerHTML. document.getElementById('sk-alert').innerHTML = document.getElementById('sk-alert').innerHTML.
replace(window.translations["validation"].error, ''); replace(error, '');
} }
} }
} }