mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
validación correcta. Falta que no se guardan las solapas
This commit is contained in:
@ -417,6 +417,8 @@ return [
|
|||||||
'papel_faja' => 'Seleccione el tipo de papel para la faja',
|
'papel_faja' => 'Seleccione el tipo de papel para la faja',
|
||||||
'gramaje_faja' => 'Seleccione el gramaje para la faja',
|
'gramaje_faja' => 'Seleccione el gramaje para la faja',
|
||||||
|
|
||||||
|
'unidades_envio_mayor_tirada' => 'El número de unidades enviadas debe ser igual a {field} unidades.',
|
||||||
|
|
||||||
'pais' => 'Debe seleccionar un país',
|
'pais' => 'Debe seleccionar un país',
|
||||||
'integer_greatherThan_0' => 'Número entero > 0 requerido',
|
'integer_greatherThan_0' => 'Número entero > 0 requerido',
|
||||||
'greater_than_0' => 'El campo {field} debe ser mayor que 0',
|
'greater_than_0' => 'El campo {field} debe ser mayor que 0',
|
||||||
|
|||||||
@ -78,7 +78,7 @@
|
|||||||
<label for="tirada" class="form-label">
|
<label for="tirada" class="form-label">
|
||||||
<?= lang('Presupuestos.tirada') ?> 1*
|
<?= lang('Presupuestos.tirada') ?> 1*
|
||||||
</label>
|
</label>
|
||||||
<input type="number" class="calcular-presupuesto calcular-solapas form-control text-center num-input" id="tirada"
|
<input type="number" class="calcular-presupuesto calcular-solapas form-control text-center num-input tirada-presupuesto" id="tirada"
|
||||||
name="tirada" step="1" value="50">
|
name="tirada" step="1" value="50">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -86,7 +86,7 @@
|
|||||||
<label for="tirada2" class="form-label">
|
<label for="tirada2" class="form-label">
|
||||||
<?= lang('Presupuestos.tirada') ?> 2
|
<?= lang('Presupuestos.tirada') ?> 2
|
||||||
</label>
|
</label>
|
||||||
<input type="number" class="calcular-presupuesto calcular-solapas form-control text-center num-input" id="tirada2"
|
<input type="number" class="calcular-presupuesto calcular-solapas form-control text-center num-input tirada-presupuesto" id="tirada2"
|
||||||
name="tirada2" step="1" value="">
|
name="tirada2" step="1" value="">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -94,7 +94,7 @@
|
|||||||
<label for="tirada3" class="form-label">
|
<label for="tirada3" class="form-label">
|
||||||
<?= lang('Presupuestos.tirada') ?> 3
|
<?= lang('Presupuestos.tirada') ?> 3
|
||||||
</label>
|
</label>
|
||||||
<input type="number" class="calcular-presupuesto calcular-solapas form-control text-center num-input" id="tirada3"
|
<input type="number" class="calcular-presupuesto calcular-solapas form-control text-center num-input tirada-presupuesto" id="tirada3"
|
||||||
name="tirada3" step="1" value="">
|
name="tirada3" step="1" value="">
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@ -102,7 +102,7 @@
|
|||||||
<label for="tirada4" class="form-label">
|
<label for="tirada4" class="form-label">
|
||||||
<?= lang('Presupuestos.tirada') ?> 4
|
<?= lang('Presupuestos.tirada') ?> 4
|
||||||
</label>
|
</label>
|
||||||
<input type="number" class="calcular-presupuesto calcular-solapas form-control text-center num-input" id="tirada4"
|
<input type="number" class="calcular-presupuesto calcular-solapas form-control text-center num-input tirada-presupuesto" id="tirada4"
|
||||||
name="tirada4" step="1" value="">
|
name="tirada4" step="1" value="">
|
||||||
</div>
|
</div>
|
||||||
</div> <!--//.row -->
|
</div> <!--//.row -->
|
||||||
|
|||||||
@ -62,8 +62,6 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="divErrorEnvios" name="div_error_envios" class="col-sm-10 mb-3 justify-content-center"></div>
|
|
||||||
|
|
||||||
<div id="divDirecciones" class="calcular-presupuesto col-sm-12 d-flex flex-column align-items-center div-direcciones">
|
<div id="divDirecciones" class="calcular-presupuesto col-sm-12 d-flex flex-column align-items-center div-direcciones">
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -83,6 +83,8 @@ class DatosGenerales {
|
|||||||
|
|
||||||
init() {
|
init() {
|
||||||
|
|
||||||
|
const self = this;
|
||||||
|
|
||||||
// Selects
|
// Selects
|
||||||
this.formatoLibro.init();
|
this.formatoLibro.init();
|
||||||
this.cliente.init();
|
this.cliente.init();
|
||||||
@ -100,6 +102,18 @@ 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', () => {
|
||||||
|
let tiradas = self.getTiradas();
|
||||||
|
if (!Array.isArray(tiradas)) {
|
||||||
|
tiradas = [tiradas];
|
||||||
|
}
|
||||||
|
const data = {
|
||||||
|
tiradas: self.getTiradas(),
|
||||||
|
tiradaSeleccionada: self.selectedTirada || parseInt(self.tirada1.val())
|
||||||
|
};
|
||||||
|
$(document).trigger('update-tiradas-envios', data);
|
||||||
|
});
|
||||||
|
|
||||||
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));
|
||||||
|
|
||||||
|
|||||||
@ -33,14 +33,13 @@ class Direcciones {
|
|||||||
this.tiradaSeleccionada = null;
|
this.tiradaSeleccionada = null;
|
||||||
|
|
||||||
this.direcciones.calcularPresupuesto = false;
|
this.direcciones.calcularPresupuesto = false;
|
||||||
|
|
||||||
this.initValidation();
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
init() {
|
init() {
|
||||||
|
|
||||||
|
const self = this;
|
||||||
|
|
||||||
$("#clienteId").on('change', this.handleChangeCliente.bind(this));
|
$("#clienteId").on('change', this.handleChangeCliente.bind(this));
|
||||||
|
|
||||||
this.recogidaTaller.on('change', () => {
|
this.recogidaTaller.on('change', () => {
|
||||||
@ -60,6 +59,27 @@ class Direcciones {
|
|||||||
this.direccionesCliente.init();
|
this.direccionesCliente.init();
|
||||||
this.btnAdd.on('click', this.#insertDireccion.bind(this));
|
this.btnAdd.on('click', this.#insertDireccion.bind(this));
|
||||||
this.btnNew.on('click', this.#nuevaDireccion.bind(this));
|
this.btnNew.on('click', this.#nuevaDireccion.bind(this));
|
||||||
|
|
||||||
|
// evento para actualizar el selector de tiradas
|
||||||
|
$(document).on('update-tiradas-envios', (event, data) => {
|
||||||
|
self.divTiradas.empty();
|
||||||
|
if (data.tiradas.length > 0) {
|
||||||
|
data.tiradas.forEach(tirada => {
|
||||||
|
self.insertTirada(tirada);
|
||||||
|
});
|
||||||
|
|
||||||
|
if (data.tiradaSeleccionada) {
|
||||||
|
self.divTiradas.find('.check-tirada-envio[tirada="' + data.tiradaSeleccionada + '"]').trigger('click');
|
||||||
|
self.selectedTirada = data.tiradaSeleccionada;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
self.tiradaSeleccionada = null;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
self.divTiradas.trigger('change');
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -161,6 +181,48 @@ class Direcciones {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
validate(goToNext = true) {
|
||||||
|
|
||||||
|
let errores = [];
|
||||||
|
|
||||||
|
$('#divDirecciones').removeClass('is-invalid');
|
||||||
|
if ($('.check-tirada-envio:checked').length > 0) {
|
||||||
|
let unidades = parseInt($($('.check-tirada-envio:checked')[0]).attr('tirada'));
|
||||||
|
let total_envio = 0;
|
||||||
|
// se recorre el array this.direcciones
|
||||||
|
this.direcciones.forEach(direccion => {
|
||||||
|
total_envio += parseInt(direccion.getUnidades());
|
||||||
|
});
|
||||||
|
if (total_envio > unidades) {
|
||||||
|
$('#divDirecciones').addClass('is-invalid');
|
||||||
|
errores.push(window.translations["validation"].unidades_envio_mayor_tirada.replace('{field}', total_envio));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
const skAlert = document.getElementById('sk-alert');
|
||||||
|
skAlert.innerHTML = '';
|
||||||
|
const uniqueErrors = [...new Set(errores)];
|
||||||
|
|
||||||
|
if (uniqueErrors.length > 0) {
|
||||||
|
const message = window.translations["validation"].fix_errors +
|
||||||
|
`<ul class="mb-0">
|
||||||
|
${uniqueErrors.map(err => `<li>${err}</li>`).join('')}
|
||||||
|
</ul>`;
|
||||||
|
popErrorAlert(message, 'sk-alert', false);
|
||||||
|
errores = [];
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
document.getElementById('sk-alert').innerHTML = '';
|
||||||
|
errores = [];
|
||||||
|
if (goToNext)
|
||||||
|
this.validatorStepper.next();
|
||||||
|
else
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
initValidation() {
|
initValidation() {
|
||||||
|
|
||||||
const stepper = this.validatorStepper;
|
const stepper = this.validatorStepper;
|
||||||
@ -171,7 +233,7 @@ class Direcciones {
|
|||||||
validators: {
|
validators: {
|
||||||
callback: {
|
callback: {
|
||||||
callback: () => {
|
callback: () => {
|
||||||
const div = $('#divErrorEnvios'); // Selecciona el div
|
|
||||||
|
|
||||||
div.find('.fv-plugins-message-container').remove();
|
div.find('.fv-plugins-message-container').remove();
|
||||||
|
|
||||||
|
|||||||
@ -114,12 +114,14 @@ class PresupuestoCliente {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.calcularPresupuesto = true;
|
this.calcularPresupuesto = true;
|
||||||
|
$('.tirada-presupuesto').trigger('change');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
$(".calcular-presupuesto").on('change', this.checkForm.bind(this));
|
$(".calcular-presupuesto").on('change', this.checkForm.bind(this));
|
||||||
$(".calcular-solapas").on('change', this.calcularSolapas.bind(this));
|
$(".calcular-solapas").on('change', this.calcularSolapas.bind(this));
|
||||||
$(".calcular-lomo").on('change', this.checkLomoInterior.bind(this));
|
$(".calcular-lomo").on('change', this.checkLomoInterior.bind(this));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -198,11 +200,9 @@ class PresupuestoCliente {
|
|||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
this.actualizarTiradasEnvio = true;
|
this.actualizarTiradasEnvio = true;
|
||||||
this.direcciones.divTiradas.empty();
|
//this.direcciones.divTiradas.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
this.divTiradasPrecios.empty();
|
|
||||||
|
|
||||||
let datos_to_check = this.#prepareData();
|
let datos_to_check = this.#prepareData();
|
||||||
|
|
||||||
if (Object.values(datos_to_check).every(this.#isValidDataForm)) {
|
if (Object.values(datos_to_check).every(this.#isValidDataForm)) {
|
||||||
@ -213,8 +213,6 @@ class PresupuestoCliente {
|
|||||||
$('#loader').modal('show');
|
$('#loader').modal('show');
|
||||||
}, 0);
|
}, 0);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// Si se está ejecutando la petición, abortar la petición anterior
|
// Si se está ejecutando la petición, abortar la petición anterior
|
||||||
this.ajax_calcular.abort();
|
this.ajax_calcular.abort();
|
||||||
|
|
||||||
@ -249,9 +247,6 @@ class PresupuestoCliente {
|
|||||||
|
|
||||||
if (currentElement !== 'resumen-libro') {
|
if (currentElement !== 'resumen-libro') {
|
||||||
this.#validateCurrentForm(currentElement, nextElement);
|
this.#validateCurrentForm(currentElement, nextElement);
|
||||||
if (currentElement === 'cubierta-libro' && this.disenioCubierta.acabadoCubierta.getVal() == 0) {
|
|
||||||
alertWarningMessage(window.translations.cubiertaSinAcabado, window.translations.cubiertaSinAcabadoText);
|
|
||||||
}
|
|
||||||
//this.#goToForm(nextElement);
|
//this.#goToForm(nextElement);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
@ -312,21 +307,9 @@ class PresupuestoCliente {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 'direcciones-libro':
|
case 'direcciones-libro':
|
||||||
this.direcciones.allowNext = false;
|
if (this.direcciones.validate(false)) {
|
||||||
validateForm(this.direcciones.formValidation).then((status) => {
|
|
||||||
if (status !== 'Valid') {
|
|
||||||
this.direcciones.allowNext = true;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
this.#goToForm(nextForm);
|
this.#goToForm(nextForm);
|
||||||
this.direcciones.allowNext = true;
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
).catch(error => {
|
|
||||||
this.direcciones.allowNext = true;
|
|
||||||
console.error('Error al validar:', error);
|
|
||||||
return false;
|
|
||||||
});
|
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -524,7 +507,10 @@ class PresupuestoCliente {
|
|||||||
let tiradas = { ...response.tiradas };
|
let tiradas = { ...response.tiradas };
|
||||||
tiradas = Object.keys(tiradas).map((key) => tiradas[key]);
|
tiradas = Object.keys(tiradas).map((key) => tiradas[key]);
|
||||||
tiradas.sort((a, b) => a - b);
|
tiradas.sort((a, b) => a - b);
|
||||||
this.divTiradasPrecios.empty();
|
|
||||||
|
if (this.actualizarTiradasEnvio) {
|
||||||
|
this.direcciones.divTiradas.empty();
|
||||||
|
}
|
||||||
|
|
||||||
popAlert2Hide();
|
popAlert2Hide();
|
||||||
|
|
||||||
@ -564,15 +550,15 @@ class PresupuestoCliente {
|
|||||||
|
|
||||||
$('#alert-cubierta-sin-acabado').addClass('d-none');
|
$('#alert-cubierta-sin-acabado').addClass('d-none');
|
||||||
}
|
}
|
||||||
else{
|
else {
|
||||||
$('#alert-cubierta-sin-acabado').removeClass('d-none');
|
$('#alert-cubierta-sin-acabado').removeClass('d-none');
|
||||||
$(window).scrollTop(0);
|
$(window).scrollTop(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if( this.datos.cubierta.acabado )
|
if (this.datos.cubierta.acabado)
|
||||||
setTimeout(() => {
|
setTimeout(() => {
|
||||||
$(`#containerTiradasEnvios .tirada-envio input[tirada="${this.direcciones.tiradaSeleccionada}"]`).trigger('click');
|
$(`#containerTiradasEnvios .tirada-envio input[tirada="${this.direcciones.tiradaSeleccionada}"]`).trigger('click');
|
||||||
}, 0);
|
}, 0);
|
||||||
}
|
}
|
||||||
$('#loader').modal('hide');
|
$('#loader').modal('hide');
|
||||||
// DEBUG
|
// DEBUG
|
||||||
@ -597,7 +583,7 @@ class PresupuestoCliente {
|
|||||||
break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
this.direcciones.formValidation.validate();
|
this.direcciones.validate();
|
||||||
break;
|
break;
|
||||||
|
|
||||||
default:
|
default:
|
||||||
@ -608,13 +594,27 @@ class PresupuestoCliente {
|
|||||||
|
|
||||||
|
|
||||||
#prevtStep() {
|
#prevtStep() {
|
||||||
if (this.validationStepper._currentIndex >= 1 && this.validationStepper._currentIndex <= 4) {
|
switch (this.validationStepper._currentIndex) {
|
||||||
/*if (this.validationStepper._currentIndex == 2) {
|
|
||||||
if (this.disenioCubierta.acabadoCubierta.getVal() == 0) {
|
case 1:
|
||||||
alertWarningMessage(window.translations.cubiertaSinAcabado, window.translations.cubiertaSinAcabadoText);
|
if (this.disenioInterior.validate(false))
|
||||||
}
|
this.validationStepper.previous();
|
||||||
}*/
|
break;
|
||||||
this.validationStepper.previous();
|
|
||||||
|
|
||||||
|
case 2:
|
||||||
|
if (this.disenioCubierta.validate(false))
|
||||||
|
this.validationStepper.previous();
|
||||||
|
break;
|
||||||
|
|
||||||
|
case 3:
|
||||||
|
if (this.direcciones.formValidation.validate(false))
|
||||||
|
this.validationStepper.previous();
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
this.validationStepper.previous();
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
$('html, body').animate({ scrollTop: 0 }, 'slow');
|
$('html, body').animate({ scrollTop: 0 }, 'slow');
|
||||||
}
|
}
|
||||||
@ -856,19 +856,6 @@ class PresupuestoCliente {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
async function validateForm(formValidation) {
|
|
||||||
try {
|
|
||||||
const validationResult = await formValidation.validate();
|
|
||||||
return validationResult;
|
|
||||||
} catch (error) {
|
|
||||||
console.error('Error durante la validación:', error);
|
|
||||||
throw error;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
function isValid(value) {
|
function isValid(value) {
|
||||||
if (value === null || value === undefined || value === '') {
|
if (value === null || value === undefined || value === '') {
|
||||||
return false;
|
return false;
|
||||||
|
|||||||
Reference in New Issue
Block a user