mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
trabajando en la validación de los datosgenerales
This commit is contained in:
@ -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 +
|
||||
`<ul class="mb-0">
|
||||
${uniqueErrors.map(err => `<li>${err}</li>`).join('')}
|
||||
${this.errores.map(err => `<li>${err}</li>`).join('')}
|
||||
</ul>`;
|
||||
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(`<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>`;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@ -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 => `<li>${err}</li>`).join('')}
|
||||
</ul>`;
|
||||
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, '');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user