From 2ac99d14c0a83a004555e79dbeefe53c723b5bb0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jaime=20Jim=C3=A9nez?= Date: Thu, 24 Oct 2024 21:05:59 +0200 Subject: [PATCH] click para moverse del menu --- .../cliente/viewPresupuestoclienteForm.php | 12 +- .../presupuestoCliente/datosGenerales.js | 19 ++- .../pages/presupuestoCliente/direcciones.js | 20 ++- .../presupuestoCliente/disenioCubierta.js | 9 +- .../presupuestoCliente/disenioInterior.js | 4 +- .../presupuestoCliente/presupuestoCliente.js | 158 +++++++++++++++++- 6 files changed, 188 insertions(+), 34 deletions(-) diff --git a/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/viewPresupuestoclienteForm.php b/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/viewPresupuestoclienteForm.php index 76999017..fee3258d 100644 --- a/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/viewPresupuestoclienteForm.php +++ b/ci4/app/Views/themes/vuexy/form/presupuestos/cliente/viewPresupuestoclienteForm.php @@ -29,7 +29,7 @@
-
+
-
+
-
+
-
+
-
+
-
+
diff --git a/httpdocs/assets/js/safekat/pages/presupuestoCliente/datosGenerales.js b/httpdocs/assets/js/safekat/pages/presupuestoCliente/datosGenerales.js index 45819d5d..1c17089c 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoCliente/datosGenerales.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoCliente/datosGenerales.js @@ -5,7 +5,9 @@ import tarjetaTiradasPrecio from './tarjetaTiradasPrecio.js'; class DatosGenerales { constructor(domItem, wizardForm, validatorStepper) { + this.domItem = domItem; + this.allowNext = true; this.wizardStep = wizardForm.querySelector('#datos-generales'); this.validatorStepper = validatorStepper; @@ -116,25 +118,25 @@ class DatosGenerales { const value4 = $("#tirada4").val(); let tiradas = [value]; - if(!(value.length > 0 && Number.isInteger(parseInt(value)) && parseInt(value) > 0)){ + if (!(value.length > 0 && Number.isInteger(parseInt(value)) && parseInt(value) > 0)) { return { valid: false, message: window.translations["validation"].integer_greatherThan_0, }; } - if(value2.length > 0 && Number.isInteger(parseInt(value2)) && parseInt(value2) > 0){ + if (value2.length > 0 && Number.isInteger(parseInt(value2)) && parseInt(value2) > 0) { tiradas.push(value2); } - if(value3.length > 0 && Number.isInteger(parseInt(value3)) && parseInt(value3) > 0){ + if (value3.length > 0 && Number.isInteger(parseInt(value3)) && parseInt(value3) > 0) { tiradas.push(value3); } - if(value4.length > 0 && Number.isInteger(parseInt(value4)) && parseInt(value4) > 0){ + if (value4.length > 0 && Number.isInteger(parseInt(value4)) && parseInt(value4) > 0) { tiradas.push(value4); } // comprobar si hay valores > 30 const noPOD = (tiradas.some(tirada => parseInt(tirada) > 30)); const siPOD = (tiradas.some(tirada => parseInt(tirada) <= 30)); - if(noPOD && siPOD){ + if (noPOD && siPOD) { return { valid: false, message: "No se pueden mezclar tiradas <30 con >30", @@ -367,7 +369,8 @@ class DatosGenerales { submitButton: new FormValidation.plugins.SubmitButton() } }).on('core.form.valid', () => { - stepper.next(); + if (this.allowNext) + stepper.next(); }); } @@ -528,8 +531,8 @@ class DatosGenerales { $('#addSobrecubierta').prop('checked', false).trigger('change'); $(".sobrecubierta-items").addClass('d-none'); } - else{ - if($('#addSobrecubierta').hasClass('d-none')){ + else { + if ($('#addSobrecubierta').hasClass('d-none')) { $('#addSobrecubierta').removeClass('d-none'); } } diff --git a/httpdocs/assets/js/safekat/pages/presupuestoCliente/direcciones.js b/httpdocs/assets/js/safekat/pages/presupuestoCliente/direcciones.js index f3370f61..1472fc2b 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoCliente/direcciones.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoCliente/direcciones.js @@ -12,6 +12,7 @@ class Direcciones { this.domItem = domItem; this.wizardStep = wizardForm.querySelector('#direcciones-libro'); this.validatorStepper = validatorStepper; + this.allowNext = true; this.unidadesAdd = this.domItem.find('#unidadesEnvio'); this.btnAdd = this.domItem.find('#insertarDireccion'); @@ -19,7 +20,7 @@ class Direcciones { this.entregaPieCallero = this.domItem.find('#entregaPieCalle'); this.direccionesCliente = new ClassSelect($("#direcciones"), '/misdirecciones/getSelect2'); - + this.divDirecciones = $(this.domItem.find('#divDirecciones')); this.divTiradas = this.domItem.find('#containerTiradasEnvios'); @@ -94,13 +95,13 @@ class Direcciones { let peticion = new Ajax('/misdirecciones/getDireccionPresupuesto/' + id, {}, {}, (response) => { - let tarjeta = new tarjetaDireccion(this.divDirecciones, divId, response.data[0]); - tarjeta.setUnidades(unidades); - tarjeta.setEntregaPalets(entregaPalets); - tarjeta.card.find('.direccion-editar').on('click', this.#editUnits.bind(self)); - tarjeta.card.find('.direccion-eliminar').on('click', this.#deleteDireccion.bind(self)); - this.divDirecciones.append(tarjeta.card); - this.direcciones.push(tarjeta); + let tarjeta = new tarjetaDireccion(this.divDirecciones, divId, response.data[0]); + tarjeta.setUnidades(unidades); + tarjeta.setEntregaPalets(entregaPalets); + tarjeta.card.find('.direccion-editar').on('click', this.#editUnits.bind(self)); + tarjeta.card.find('.direccion-eliminar').on('click', this.#deleteDireccion.bind(self)); + this.divDirecciones.append(tarjeta.card); + this.direcciones.push(tarjeta); }, () => { console.error('Error getting address'); @@ -175,7 +176,8 @@ class Direcciones { submitButton: new FormValidation.plugins.SubmitButton() } }).on('core.form.valid', () => { - stepper.next(); + if (this.allowNext) + stepper.next(); }); } diff --git a/httpdocs/assets/js/safekat/pages/presupuestoCliente/disenioCubierta.js b/httpdocs/assets/js/safekat/pages/presupuestoCliente/disenioCubierta.js index d3d85a9d..dc440e5c 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoCliente/disenioCubierta.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoCliente/disenioCubierta.js @@ -1,7 +1,9 @@ class DisenioCubierta { constructor(domItem, wizardForm, validatorStepper) { + this.domItem = domItem; + this.allowNext = true; this.wizardStep = wizardForm.querySelector('#cubierta-libro'); this.validatorStepper = validatorStepper; @@ -28,7 +30,7 @@ class DisenioCubierta { this.papelGuardas = this.domItem.find("#papelGuardas"); this.guardasImpresas = this.domItem.find("#guardasImpresas"); this.cabezada = this.domItem.find("#cabezada"); - + this.cartulinaEstucada = this.domItem.find("#cartulinaEstucada"); this.estucadoMate = this.domItem.find("#estucadoMate"); @@ -174,7 +176,7 @@ class DisenioCubierta { }, 0); } - if(datosSobrecubierta && datosSobrecubierta.papel) { + if (datosSobrecubierta && datosSobrecubierta.papel) { this.sobrecubierta.trigger('click'); this.papelSobrecubierta.val(datosSobrecubierta.papel.code + "_" + datosSobrecubierta.gramaje).trigger('change'); this.solapasSobrecubierta.val(datosSobrecubierta.solapas_ancho); @@ -313,7 +315,8 @@ class DisenioCubierta { submitButton: new FormValidation.plugins.SubmitButton() } }).on('core.form.valid', () => { - stepper.next(); + if (this.allowNext) + stepper.next(); }); } diff --git a/httpdocs/assets/js/safekat/pages/presupuestoCliente/disenioInterior.js b/httpdocs/assets/js/safekat/pages/presupuestoCliente/disenioInterior.js index 415b23e6..24e35e4e 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoCliente/disenioInterior.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoCliente/disenioInterior.js @@ -5,6 +5,7 @@ class DisenioInterior { this.wizardStep = wizardForm.querySelector('#interior-libro'); this.validatorStepper = validatorStepper; + this.allowNext = true; this.disenioInterior = this.domItem.find(".disenio-interior"); this.divPapelInterior = this.domItem.find("#divPapelInterior"); @@ -364,7 +365,8 @@ class DisenioInterior { submitButton: new FormValidation.plugins.SubmitButton() } }).on('core.form.valid', () => { - stepper.next(); + if (this.allowNext) + stepper.next(); }); } diff --git a/httpdocs/assets/js/safekat/pages/presupuestoCliente/presupuestoCliente.js b/httpdocs/assets/js/safekat/pages/presupuestoCliente/presupuestoCliente.js index c49157ec..2bdc5862 100644 --- a/httpdocs/assets/js/safekat/pages/presupuestoCliente/presupuestoCliente.js +++ b/httpdocs/assets/js/safekat/pages/presupuestoCliente/presupuestoCliente.js @@ -35,6 +35,8 @@ class PresupuestoCliente { this.divTiradasPrecios = $("#divTiradasPrecio"); + this.titulosMenu = $(".titulos-menu"); + this.datos = {}; this.ajax_calcular = new Ajax('/presupuestocliente/calcular', {}, this.datos, @@ -65,6 +67,8 @@ class PresupuestoCliente { this.btnPrev.on('click', this.#prevtStep.bind(this)); this.btnSave.on('click', this.#savePresupuesto.bind(this)); + this.titulosMenu.on('click', this.#handleTitulosMenu.bind(this)); + if (window.location.href.includes("edit")) { this.#cargarPresupuesto(); @@ -79,7 +83,7 @@ class PresupuestoCliente { } $(".calcular-presupuesto").on('change', this.checkForm.bind(this)); - + } @@ -111,7 +115,7 @@ class PresupuestoCliente { const noPOD = (tiradas.some(tirada => parseInt(tirada) > 30)); const siPOD = (tiradas.some(tirada => parseInt(tirada) <= 30)); - + this.datosGenerales.formValidation.validateField('tirada'); return !(noPOD && siPOD); } @@ -149,16 +153,16 @@ class PresupuestoCliente { if (datos_to_check.posPaginasColor == "" || datos_to_check.posPaginasColor == null) { delete datos_to_check.posPaginasColor; } - if(datos_to_check.cubierta.acabados.barniz == undefined){ + if (datos_to_check.cubierta.acabados.barniz == undefined) { delete datos_to_check.cubierta.acabados.barniz; } - if(datos_to_check.cubierta.acabados.plastificado == undefined){ + if (datos_to_check.cubierta.acabados.plastificado == undefined) { delete datos_to_check.cubierta.acabados.plastificado; } - if(datos_to_check.cubierta.acabados.estampado == undefined){ + if (datos_to_check.cubierta.acabados.estampado == undefined) { delete datos_to_check.cubierta.acabados.estampado; } - if(datos_to_check.sobrecubierta.plastificado == undefined){ + if (datos_to_check.sobrecubierta.plastificado == undefined) { delete datos_to_check.sobrecubierta.plastificado; } @@ -242,6 +246,136 @@ class PresupuestoCliente { }*/ + #handleTitulosMenu(event) { + + $('.titulos-menu').removeClass('crossed'); + + const nextElement = $(event.target).attr('data-target') + const currentElement = $('.dstepper-block.active').attr('id'); + + if (currentElement === nextElement) { + return; + } + + if (currentElement !== 'resumen-libro') { + this.#validateCurrentForm(currentElement, nextElement); + } + else { + this.#goToForm(nextElement); + } + } + + #goToForm(form) { + + switch (form) { + case '#datos-generales': + this.validationStepper.to(1); + break; + + case '#interior-libro': + this.validationStepper.to(2); + break; + + case '#cubierta-libro': + this.validationStepper.to(3); + break; + + case '#direcciones-libro': + this.validationStepper.to(4); + break; + + case '#resumen-libro': + this.validationStepper.to(5); + break; + + default: + break; + } + } + + + #validateCurrentForm(form, nextForm) { + + switch (form) { + case 'datos-generales': + this.datosGenerales.allowNext = false; + validateForm(this.datosGenerales.formValidation).then((status) => { + if (status !== 'Valid') { + this.datosGenerales.allowNext = true; + return false; + } + this.#goToForm(nextForm); + this.datosGenerales.allowNext = true; + return true; + }).catch(error => { + this.datosGenerales.allowNext = true; + console.error('Error al validar:', error); + return false; + }); + break; + + case 'interior-libro': + this.disenioInterior.allowNext = false; + validateForm(this.disenioInterior.formValidation).then((status) => { + if (status !== 'Valid') { + this.disenioInterior.allowNext = true; + return false; + } + this.#goToForm(nextForm); + this.disenioInterior.allowNext = true; + return true; + } + ).catch(error => { + this.disenioInterior.allowNext = true; + console.error('Error al validar:', error); + return false; + }); + break; + + case 'cubierta-libro': + this.disenioCubierta.allowNext = false; + validateForm(this.disenioCubierta.formValidation).then((status) => { + if (status !== 'Valid') { + this.disenioCubierta.allowNext = true; + return false; + } + this.#goToForm(nextForm); + this.disenioCubierta.allowNext = true; + return true; + } + ).catch(error => { + this.disenioCubierta.allowNext = true; + console.error('Error al validar:', error); + return false; + }); + break; + + case 'direcciones-libro': + this.direcciones.allowNext = false; + validateForm(this.direcciones.formValidation).then((status) => { + if (status !== 'Valid') { + this.direcciones.allowNext = true; + return false; + } + this.#goToForm(nextForm); + this.direcciones.allowNext = true; + return true; + } + ).catch(error => { + this.direcciones.allowNext = true; + console.error('Error al validar:', error); + return false; + }); + break; + + default: + return false; + } + } + + + + stepperHandler() { const element = $('.fv-plugins-bootstrap5.fv-plugins-framework.active'); @@ -451,7 +585,7 @@ class PresupuestoCliente { }, }; let lomoRedondo = 0; - if(this.disenioCubierta.disenioCubierta.filter('.selected').length > 0) + if (this.disenioCubierta.disenioCubierta.filter('.selected').length > 0) lomoRedondo = this.disenioCubierta.disenioCubierta.filter('.selected').attr('id').includes('Redondo') ? 1 : 0; this.datos.cubierta.lomoRedondo = lomoRedondo; @@ -546,6 +680,16 @@ 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) { if (value === null || value === undefined || value === '') {