import { getToken } from '../../common/common.js'; import { capitalizeFirstLetter } from '../../common/common.js'; import Ajax from '../../components/ajax.js'; import ClassSelect from '../../components/select2.js'; class DisenioCubierta { constructor(domItem, wizardForm, validatorStepper, presupuestoCliente) { this.domItem = domItem; this.allowNext = true; this.presupuestoCliente = presupuestoCliente; this.csrf_token = getToken(); this.csrf_hash = $('#mainContainer').find('input[name="' + this.csrf_token + '"]').val(); this.wizardStep = wizardForm.querySelector('#cubierta-libro'); this.validatorStepper = validatorStepper; this.disenioCubierta = this.domItem.find(".tipo-cubierta"); this.solapasCubierta = this.domItem.find(".solapas-cubierta"); this.textoPapelCubierta = this.domItem.find("#textoPapelCubierta"); this.divPapelEspecial = this.domItem.find("#divPapelEspecialCubierta"); this.papelEspecial = new ClassSelect($("#papelEspecialCubiertaSel"), '/papelesgenericos/selectpapelespecial', window.translations["selectPapel"], false, { [this.csrf_token]: this.csrf_hash, tipo: 'colorhq', cubierta: 1, ancho: () => { return this.presupuestoCliente.datosGenerales.getDimensionLibro().ancho }, alto: () => { return this.presupuestoCliente.datosGenerales.getDimensionLibro().alto }, solapas: () => { return $('#solapas_cubierta').hasClass("d-none") ? 0 : $('#solapas_cubierta').val() }, lomo: () => { return $('#lc').val() }, tapa_dura: () => { return this.tapaBlanda.hasClass("selected") ? 0 : 1 }, tirada: () => { return this.presupuestoCliente.datosGenerales.getTiradas()[0] }, } ); this.divSolapas = this.domItem.find("#divSolapasCubierta"); this.divCarasImpresion = this.domItem.find("#divCarasImpresion"); this.divConfigGuardas = this.domItem.find("#divConfigTapaDura"); this.carasCubierta = this.domItem.find("#carasCubierta"); this.tapaBlanda = this.domItem.find("#tapaBlanda"); this.tapaDuraLomoRecto = this.domItem.find("#tapaDura"); this.tapaDuraLomoRedondo = this.domItem.find("#tapaDuraLomoRedondo"); this.sinSolapas = this.domItem.find("#solapasCubiertaNo"); this.conSolapas = this.domItem.find("#solapasCubiertaSi"); this.divTamanioSolapas = this.domItem.find("#divTamanioSolapas"); this.textoSolapasCubierta = this.domItem.find("#textoSolapasCubierta"); this.tamanioSolapasCubierta = $(this.domItem.find("#solapasCubierta")); this.papelGuardas = new ClassSelect($("#papelGuardas"), '/papelesgenericos/getpapelcliente', window.translations["selectPapel"], false, { [this.csrf_token]: this.csrf_hash, tipo: () => 'colorhq', tirada: () => { return this.presupuestoCliente.datosGenerales.getTiradas()[0] }, ancho: () => { return this.presupuestoCliente.datosGenerales.getDimensionLibro().ancho }, alto: () => { return this.presupuestoCliente.datosGenerales.getDimensionLibro().alto }, solapas: 0, lomo: 0, guardas: 1, forSelect2: 1, }, "", true, ); this.gramajeGuardas = new ClassSelect($("#gramajeGuardas"), '/papelesgenericos/getpapelcliente', window.translations["selectGramaje"], false, { [this.csrf_token]: this.csrf_hash, tipo: 'colorhq', papel: () => { return this.papelGuardas.getVal() }, tirada: () => { return this.presupuestoCliente.datosGenerales.getTiradas()[0] }, ancho: () => { return this.presupuestoCliente.datosGenerales.getDimensionLibro().ancho }, alto: () => { return $('#altoFaja').val() }, solapas: 0, lomo: 0, guardas: 1, forSelect2: 1, }, "", true ); this.guardasImpresas = this.domItem.find("#guardasImpresas"); this.cabezada = this.domItem.find("#cabezada"); this.divPapelCubierta = this.domItem.find("#divPapelCubierta"); this.divGramajeCubierta = this.domItem.find("#divGramajeCubierta"); this.acabadoCubierta = this.domItem.find("#acabadoCubierta"); this.configuracionSobrecubierta = this.domItem.find(".config-sobrecubierta"); this.sobrecubierta = this.domItem.find("#addSobrecubierta"); this.papelSobrecubierta = new ClassSelect($("#papelSobrecubierta"), '/papelesgenericos/getpapelcliente', window.translations["selectPapel"], false, { [this.csrf_token]: this.csrf_hash, tipo: 'colorhq', sobrecubierta: 1, ancho: () => { return this.presupuestoCliente.datosGenerales.getDimensionLibro().ancho }, alto: () => { return this.presupuestoCliente.datosGenerales.getDimensionLibro().alto }, solapas: () => { return $('#solapasSobrecubierta').val() }, lomo: () => { return parseFloat($('#lsc').val()) + parseFloat($('#lc').val()) }, tirada: () => { return this.presupuestoCliente.datosGenerales.getTiradas()[0] }, forSelect2: 1, }, "", true, ); this.gramajeSobrecubierta = new ClassSelect($("#gramajeSobrecubierta"), '/papelesgenericos/getpapelcliente', window.translations["selectPapel"], false, { [this.csrf_token]: this.csrf_hash, tipo: 'colorhq', sobrecubierta: 1, papel: () => { return this.papelSobrecubierta.getVal() }, ancho: () => { return this.presupuestoCliente.datosGenerales.getDimensionLibro().ancho }, alto: () => { return this.presupuestoCliente.datosGenerales.getDimensionLibro().alto }, solapas: () => { return $('#solapasSobrecubierta').val() }, lomo: () => { return parseFloat($('#lsc').val()) + parseFloat($('#lc').val()) }, tirada: () => { return this.presupuestoCliente.datosGenerales.getTiradas()[0] }, forSelect2: 1, }, "", true, ); this.acabadoSobrecubierta = this.domItem.find("#acabadoSobrecubierta"); this.configuracionFaja = this.domItem.find(".config-faja"); this.faja = this.domItem.find("#addFaja"); this.papelFaja = new ClassSelect($("#papelFaja"), '/papelesgenericos/getpapelcliente', window.translations["selectPapel"], false, { [this.csrf_token]: this.csrf_hash, tipo: 'colorhq', sobrecubierta: 1, ancho: () => { return this.presupuestoCliente.datosGenerales.getDimensionLibro().ancho }, alto: () => { return $('#altoFaja').val() }, solapas: () => { return $('#solapasFaja').val() }, lomo: () => { return parseFloat($('#lsc').val()) + parseFloat($('#lc').val()) }, tirada: () => { return this.presupuestoCliente.datosGenerales.getTiradas()[0] }, forSelect2: 1, }, "", true, ); this.gramajeFaja = new ClassSelect($("#gramajeFaja"), '/papelesgenericos/getpapelcliente', window.translations["selectGramaje"], false, { [this.csrf_token]: this.csrf_hash, tipo: 'colorhq', papel: () => { return this.papelFaja.getVal() }, sobrecubierta: 1, ancho: () => { return this.presupuestoCliente.datosGenerales.getDimensionLibro().ancho }, alto: () => { return $('#altoFaja').val() }, solapas: () => { return $('#solapasFaja').val() }, lomo: () => { return parseFloat($('#lsc').val()) + parseFloat($('#lc').val()) }, tirada: () => { return this.presupuestoCliente.datosGenerales.getTiradas()[0] }, forSelect2: 1, }, "", true ); this.solapasSobrecubierta = this.domItem.find("#solapasSobrecubierta"); this.textoSolapasSobrecubierta = this.domItem.find("#textoLimitesSolapasSobrecubierta"); this.solapasFaja = this.domItem.find("#solapasFaja"); this.altoFaja = this.domItem.find("#altoFaja"); this.textoSolapasFaja = this.domItem.find("#textoLimitesSolapasFaja"); this.fresado = $(this.domItem.find("#fresado")[0]); this.cosido = $(this.domItem.find("#cosido")[0]); this.rl_cubierta = $(".rl-cubierta"); this.rl_papel_cubierta = $("#rl_papel_cubierta"); this.rl_caras_cubierta = $("#rl_caras_cubierta"); this.rl_acabado_cubierta = $("#rl_acabado_cubierta"); this.rl_sobrecubierta = $(".rl-sobrecubierta"); this.rl_no_sobrecubierta = $("#rl_no_sobrecubierta"); this.rl_papel_sobrecubierta = $('#rl_papel_sobrecubierta'); this.rl_tamanio_sobrecubierta = $('#rl_tamanio_sobrecubierta'); this.rl_acabado_sobrecubierta = $("#rl_acabado_sobrecubierta"); this.rl_lomo_cubierta = $("#rl_lomo_cubierta"); this.acabadoCubierta = new ClassSelect($("#acabadoCubierta"), '/serviciosacabados/getacabados', '', false, { [this.csrf_token]: this.csrf_hash, "cubierta": 1 } ); this.acabadoSobrecubierta = new ClassSelect($("#acabadoSobrecubierta"), '/serviciosacabados/getacabados', '', false, { [this.csrf_token]: this.csrf_hash, "sobrecubierta": 1 } ); this.acabadoFaja = new ClassSelect($("#acabadoFaja"), '/serviciosacabados/getacabados', '', false, { [this.csrf_token]: this.csrf_hash, "sobrecubierta": 1 } ); this.initValidation(); // Creamos un nuevo observador que detecta cambios en los atributos this.observer = new MutationObserver(mutations => { mutations.forEach(mutation => { if (mutation.type === 'attributes' && mutation.attributeName === 'class') { const targetElement = mutation.target; // check if targetElement has class 'selected' if (targetElement.classList.contains('tipo-cubierta')) { this.#handleMenuTipoCubierta(); } else if (targetElement.classList.contains('solapas-cubierta')) { this.#handleMenuSolapas(); } } }); }); this.papelCubierta = null; this.gramaje = null; this.cargando = true; this.presupuestoConfirmado = false; this.papelForResumen = ""; this.gramajeForResumen = ""; } init() { const self = this; this.papelEspecial.init(); this.acabadoCubierta.init(); this.acabadoSobrecubierta.init(); this.acabadoFaja.init(); this.papelGuardas.init(); this.gramajeGuardas.init(); this.papelSobrecubierta.init(); this.gramajeSobrecubierta.init(); this.papelFaja.init(); this.gramajeFaja.init(); $('#papelEspecialCubiertaSel').on("change", this.#handlePapelCubiertaEspecial.bind(this)); // Eventos this.disenioCubierta.on('click', this.#handleDisenioCubierta.bind(this)); this.solapasCubierta.on('click', this.#handleSolapasCubierta.bind(this)); this.tamanioSolapasCubierta.on('change', this.#handleTamanioSolapas.bind(this)); this.altoFaja.on('blur', this.#handleInputs); this.solapasSobrecubierta.on('blur', this.#handleInputs); this.solapasFaja.on('blur', this.#handleInputs); this.carasCubierta.on('change', this.#handleCarasCubierta.bind(this)); this.sobrecubierta.on('change', () => { this.sobrecubierta.is(":checked") ? this.configuracionSobrecubierta.removeClass("d-none") : this.configuracionSobrecubierta.addClass("d-none") } ); this.faja.on('change', () => { this.faja.is(":checked") ? this.configuracionFaja.removeClass("d-none") : this.configuracionFaja.addClass("d-none"); const div = $('#divExtras'); // Selecciona el div div.find('.fv-plugins-message-container').remove(); }); this.papelFaja.item.on('change', () => { this.gramajeFaja.empty(); }); this.papelGuardas.item.on('change', () => { this.gramajeGuardas.empty(); }); // Observadores this.observer.observe(this.tapaBlanda[0], { attributes: true }); this.observer.observe(this.tapaDuraLomoRecto[0], { attributes: true }); this.observer.observe(this.tapaDuraLomoRedondo[0], { attributes: true }); this.observer.observe(this.conSolapas[0], { attributes: true }); this.observer.observe(this.sinSolapas[0], { attributes: true }); } cargarDatos(datosCubierta, datosGuardas, datosSobrecubierta, datosFaja) { this.papelCubierta = datosCubierta.papel.id; this.gramaje = datosCubierta.gramaje; if (datosCubierta.lomoRedondo) { this.tapaDuraLomoRedondo.trigger('click'); } else { if (datosCubierta.tapa == "dura") { this.tapaDuraLomoRecto.trigger('click'); } else { this.tapaBlanda.trigger('click'); } } setTimeout(() => { if (datosCubierta.tapa == "dura") { this.papelGuardas.setOption(datosGuardas.papel_id, datosGuardas.papel); this.gramajeGuardas.setOption(datosGuardas.gramaje, datosGuardas.gramaje); this.guardasImpresas.val(datosGuardas.paginas).trigger('change'); this.cabezada.val(datosCubierta.cabezada).trigger('change'); } else { this.carasCubierta.val(datosCubierta.paginas).trigger('change'); if (datosCubierta.solapas) { this.conSolapas.trigger('click'); this.tamanioSolapasCubierta.val(datosCubierta.solapas_ancho); } else { this.sinSolapas.trigger('click'); } } }, 0); this.divPapelCubierta.find(`[cod="${datosCubierta.papel.code}"]`).addClass('selected'); setTimeout(function () { $(`#divGramajeCubierta .gramaje-cubierta input[data-value="${datosCubierta.gramaje}"]`).trigger('click'); }, 0); this.acabadoCubierta.setOption(datosCubierta.acabado.id, datosCubierta.acabado.text); if (datosSobrecubierta && datosSobrecubierta.papel) { this.sobrecubierta.trigger('click'); this.papelSobrecubierta.setOption(datosSobrecubierta.papel_id, datosSobrecubierta.papel); this.gramajeSobrecubierta.setOption(datosSobrecubierta.gramaje, datosSobrecubierta.gramaje); this.solapasSobrecubierta.val(datosSobrecubierta.solapas_ancho); this.acabadoSobrecubierta.setOption(datosSobrecubierta.acabado.id, datosSobrecubierta.acabado.text); } if (Object.prototype.toString.call(datosFaja) === '[object Object]') { this.faja.trigger('click'); this.papelFaja.setOption(datosFaja.papel.papel_id, datosFaja.papel.papel); this.gramajeFaja.setOption(datosFaja.papel.gramaje, datosFaja.papel.gramaje); this.solapasFaja.val(datosFaja.solapas_ancho); this.altoFaja.val(datosFaja.alto); this.acabadoFaja.setOption(datosFaja.acabado.id, datosFaja.acabado.text); } } initValidation() { const stepper = this.validatorStepper; this.formValidation = FormValidation.formValidation(this.wizardStep, { fields: { div_tipo_cubierta: { validators: { callback: { callback: function (input) { const div = $('#divTipoCubierta'); // Selecciona el div div.find('.fv-plugins-message-container').remove(); if ($('.tipo-cubierta.selected').length > 0) { return true; } else { div.append(`
${window.translations["validation"].tipo_cubierta}
`); } return false; }, } } }, div_solapas_cubierta: { validators: { callback: { callback: function (input) { const div = $('#divSolapasCubierta'); if (div.hasClass("d-none")) return true; div.find('.fv-plugins-message-container').remove(); if ($('.solapas-cubierta.selected').length > 0) { return true; } else { div.append(`
${window.translations["validation"].opcion_solapas}
`); } return false; }, } } }, div_papel_cubierta: { validators: { callback: { callback: function (input) { $('#divPapelCubierta').find('.fv-plugins-message-container').remove(); $('#divPapelEspecialCubierta').find('.fv-plugins-message-container').remove(); const papelSeleccionado = $('.custom-selector-papel-cubierta input[type="radio"]:checked'); if (papelSeleccionado.length > 0) { return true; } else { $('#divPapelCubierta').append(`
${window.translations["validation"].papel_interior}
`); } return false; }, } } }, div_papel_especial_cubierta: { validators: { callback: { callback: function (input) { $('#divPapelEspecialCubierta').find('.fv-plugins-message-container').remove(); if ($('#divPapelEspecialCubierta').hasClass("d-none")) return true; if ($('#papelEspecialCubiertaSel').select2('data').length > 0) return true; else { $('#divPapelEspecialCubierta').append(`
${window.translations["validation"].papel_interior}
`); return false; } } } } }, div_gramaje_cubierta: { validators: { callback: { callback: function (input) { const divGramajeInterior = $('#divGramajeCubierta'); // Selecciona el div divGramajeInterior.find('.fv-plugins-message-container').remove(); const gramajeSeleccionado = $('.custom-selector-gramaje-cubierta input[type="radio"]:checked'); if (gramajeSeleccionado.length > 0) { return true; } else { divGramajeInterior.append(`
${window.translations["validation"].gramaje_interior}
`); } return false; }, } } }, div_config_tapa_dura: { validators: { callback: { callback: function (input) { const div = $('#divConfigTapaDura'); // Selecciona el div div.find('.fv-plugins-message-container').remove(); if ($('divConfigTapaDura').hasClass('d-none')) return true; const papelGuardas = $('#papelGuardas').select2('data').length > 0; const gramajeGuardas = $('#gramajeGuardas').select2('data').length > 0; if (papelGuardas && gramajeGuardas) { return true; } else { div.append(`
${window.translations["validation"].extras_cubierta}
`); return false; } }, } } }, div_extras: { validators: { callback: { callback: function (input) { const div = $('#divExtras'); // Selecciona el div div.find('.fv-plugins-message-container').remove(); let error = false; if ($("#addFaja").prop("checked") == true) { const papelFaja = $('#papelFaja').select2('data').length > 0; const gramajeFaja = $('#gramajeFaja').select2('data').length > 0; if (!papelFaja || !gramajeFaja) { error = true; } } if ($("#addSobrecubierta").prop("checked") == true) { const papelSobrecubierta = $('#papelSobrecubierta').select2('data').length > 0; const gramajeSobrecubierta = $('#gramajeSobrecubierta').select2('data').length > 0; if (!papelSobrecubierta || !gramajeSobrecubierta) { error = true; } } if (error) { div.append(`
${window.translations["validation"].extras_cubierta}
`); return false; } }, } } }, }, plugins: { trigger: new FormValidation.plugins.Trigger(), bootstrap5: new FormValidation.plugins.Bootstrap5({ // Use this for enabling/changing valid/invalid class // eleInvalidClass: '', eleValidClass: '', rowSelector: function (field, ele) { // field is the field name // ele is the field element switch (field) { case 'div_tipo_cubierta': case 'div_solapas_cubierta': case 'div_papel_cubierta': case 'div_gramaje_cubierta': case 'div_papel_especial_cubierta': case 'div_config_tapa_dura': return '.col-sm-10'; case 'div_extras': return '.col-sm-12'; default: return '.col-sm-3'; } } }), autoFocus: new FormValidation.plugins.AutoFocus(), submitButton: new FormValidation.plugins.SubmitButton() } }).on('core.form.valid', () => { if (this.allowNext) stepper.next(); }); } getLomoCubierta() { const lomoRedondo = this.tapaDuraLomoRedondo.hasClass("selected"); const tapaBlanda = this.tapaBlanda.hasClass("selected"); let anchoCarton = parseFloat(6); let lomoVal = parseFloat($('#lc').val()); if (lomoRedondo) anchoCarton += 6; // ancho carton if (!tapaBlanda) lomoVal += anchoCarton; return lomoVal; } processMenuLateral() { let menu_off = true; const papel = this.getPapel(true); const gramaje = this.getGramaje(); if (papel != null && gramaje != null) { this.rl_papel_cubierta.text(papel + " " + gramaje + " gr"); this.rl_acabado_cubierta.text("Acabado: " + this.acabadoCubierta.getText()); this.rl_lomo_cubierta.text("Lomo: " + (this.getLomoCubierta().toFixed(0) + " mm")); this.rl_papel_cubierta.removeClass('d-none'); this.rl_acabado_cubierta.removeClass('d-none'); this.rl_lomo_cubierta.removeClass('d-none'); if (this.carasCubierta.find('option:selected').length > 0) { this.rl_caras_cubierta.text("Impresa " + this.carasCubierta.find('option:selected').text()); this.rl_caras_cubierta.removeClass('d-none'); menu_off = false; } else { this.rl_caras_cubierta.addClass('d-none'); } menu_off = false; } else { this.rl_papel_cubierta.addClass('d-none'); this.rl_acabado_cubierta.addClass('d-none'); this.rl_lomo_cubierta.addClass('d-none'); } if (!menu_off) this.rl_cubierta.removeClass('d-none'); else this.rl_cubierta.addClass('d-none'); // Sobrecubierta solo se muestra si cubierta ok if (!this.rl_cubierta.hasClass('d-none')) { this.rl_sobrecubierta.removeClass('d-none'); if (!this.sobrecubierta.is(":checked")) { this.rl_no_sobrecubierta.removeClass('d-none'); this.rl_papel_sobrecubierta.addClass('d-none'); this.rl_tamanio_sobrecubierta.addClass('d-none'); this.rl_acabado_sobrecubierta.addClass('d-none'); } else { this.rl_no_sobrecubierta.addClass('d-none'); this.rl_papel_sobrecubierta.removeClass('d-none'); this.rl_tamanio_sobrecubierta.removeClass('d-none'); this.rl_acabado_sobrecubierta.removeClass('d-none'); const sobrecubierta = this.getSobrecubierta(true); this.rl_papel_sobrecubierta.text(sobrecubierta.papel + " " + sobrecubierta.gramaje + " gr") this.rl_tamanio_sobrecubierta.text("Solapas: " + sobrecubierta.solapas + " mm") this.rl_acabado_sobrecubierta.text("Acabado: " + this.acabadoSobrecubierta.getText()); } } else { this.rl_sobrecubierta.addClass('d-none'); } } getSolapasCubierta() { try { if (this.solapasCubierta.hasClass("selected").length == 0) return null; else { if (this.sinSolapas.hasClass("selected")) return false; else if (this.conSolapas.hasClass("selected")) return parseInt(this.tamanioSolapasCubierta.val()); else return null; } } catch (error) { return null; } } getPapel(forResumen = false) { try { if (this.presupuestoConfirmado) return this.papelForResumen; let checkedPapel = $('.custom-selector-papel-cubierta input[type="radio"]:checked'); if (this.papelCubierta != null && checkedPapel != null && checkedPapel.length > 0) { if (forResumen) { if (checkedPapel.length == 0) return null; let radioButtonId = checkedPapel[0].id; if (radioButtonId == 'papelEspecialCubierta') return capitalizeFirstLetter(this.papelEspecial.getText()); else { let associatedLabel = $('label[for="' + radioButtonId + '"]'); return capitalizeFirstLetter($(associatedLabel[0]).text().toLocaleLowerCase()); } } else { if (this.divPapelEspecial.hasClass('d-none')) return this.papelCubierta; else { return this.papelEspecial.getVal(); } } } return null; } catch (e) { return null; } } getGramaje() { let checkedGramaje = $('.custom-selector-gramaje-cubierta input[type="radio"]:checked'); try { if (this.presupuestoConfirmado) return this.gramajeForResumen; if (checkedGramaje.length == 0) return null; return checkedGramaje[0].id.split('_')[1]; } catch (e) { return null; } } getAcabados(forResumen = false) { try { let acabado; if (forResumen) { acabado = this.acabadoCubierta.getText(); } else { acabado = this.acabadoCubierta.getVal(); } return acabado; } catch (e) { return null; } } getCabezada(forResumen = false) { try { if (this.tapaBlanda.hasClass("selected")) return false; else if (forResumen) return this.domItem.find("#cabezada").children("option:selected").text(); else return this.domItem.find("#cabezada").children("option:selected").val(); } catch (e) { return null; } } getGuardas(forResumen = false) { try { if (this.tapaBlanda.hasClass("selected")) { return false; } else { let guardas = {}; if (forResumen) { guardas.papel = this.papelGuardas.getText(); guardas.gramaje = this.gramajeGuardas.getText(); guardas.caras = this.domItem.find("#guardasImpresas").children("option:selected").text(); } else { guardas.papel = this.papelGuardas.getVal(); guardas.gramaje = this.gramajeGuardas.getVal(); guardas.caras = this.domItem.find("#guardasImpresas").children("option:selected").val(); } return guardas; } } catch (e) { return null; } } getSobrecubierta(forResumen = false) { try { if (!this.sobrecubierta.is(":checked")) { return false; } else { if (forResumen) { let sobrecubierta = {}; sobrecubierta.papel = this.papelSobrecubierta.getText(); sobrecubierta.gramaje = this.gramajeSobrecubierta.getText(); sobrecubierta.solapas = this.domItem.find("#solapasSobrecubierta").val(); sobrecubierta.acabado = this.acabadoSobrecubierta.getText(); return sobrecubierta; } else { let sobrecubierta = {}; sobrecubierta.papel = this.papelSobrecubierta.getVal(); sobrecubierta.gramaje = this.gramajeSobrecubierta.getVal(); sobrecubierta.solapas = this.domItem.find("#solapasSobrecubierta").val(); sobrecubierta.acabado = this.acabadoSobrecubierta.getVal(); return sobrecubierta; } } } catch (e) { return null; } } getFaja() { try { if (!this.faja.is(":checked")) { return 0; } else { let faja = {}; faja.alto = this.domItem.find("#altoFaja").val(); faja.papel = this.papelFaja.getVal(); faja.gramaje = this.gramajeFaja.getVal(); faja.solapas = this.domItem.find("#solapasFaja").val(); faja.acabado = this.acabadoFaja.getVal(); return faja; } } catch (e) { return null; } } #handleCarasCubierta() { // Si es a dos caras } #handleDisenioCubierta(event) { // Accede al ID del elemento que disparó el evento const element = $(event.target); let class2Find = '.tipo-cubierta'; let containers = element.closest(class2Find).parent().find(class2Find); for (let container of containers) { if (container != element.closest(class2Find)[0]) { $(container).removeClass('selected'); $(container).find('.image-presupuesto').removeClass('selected'); } } element.closest(class2Find).toggleClass('selected'); element.closest('.image-presupuesto').toggleClass('selected'); if (this.tapaBlanda.hasClass("selected")) { this.divGramajeCubierta.addClass("d-none"); } else { this.divGramajeCubierta.removeClass("d-none"); } element.trigger('change'); } #handleSolapasCubierta(event) { // Accede al ID del elemento que disparó el evento const element = $(event.target); let class2Find = '.solapas-cubierta'; let containers = element.closest(class2Find).parent().find(class2Find); for (let container of containers) { if (container != element.closest(class2Find)[0]) { $(container).removeClass('selected'); $(container).find('.image-presupuesto').removeClass('selected'); } } element.closest(class2Find).toggleClass('selected'); element.closest('.image-presupuesto').toggleClass('selected'); element.trigger('change'); } #handleMenuTipoCubierta() { if (this.tapaBlanda.hasClass("selected")) { this.divSolapas.removeClass("d-none"); this.divCarasImpresion.removeClass("d-none"); this.divConfigGuardas.addClass("d-none"); this.sinSolapas.addClass('selected'); this.conSolapas.removeClass('selected'); } else if (this.tapaDuraLomoRecto.hasClass("selected") || this.tapaDuraLomoRedondo.hasClass("selected")) { this.solapasCubierta.removeClass("selected"); this.divSolapas.addClass("d-none"); this.divCarasImpresion.addClass("d-none"); this.divConfigGuardas.removeClass("d-none"); } else { this.divSolapas.addClass("d-none"); this.divCarasImpresion.addClass("d-none"); this.divConfigGuardas.addClass("d-none"); } this.#handleMenuPapel(); } #handleMenuSolapas() { if (this.conSolapas.hasClass("selected")) { this.divTamanioSolapas.removeClass("d-none"); } else { this.divTamanioSolapas.addClass("d-none"); } } #handleMenuPapel() { this.divGramajeCubierta.empty(); const tapa_dura = this.tapaBlanda.hasClass("selected") ? 0 : 1; new Ajax('/papelesgenericos/getpapelcliente', { [this.csrf_token]: this.csrf_hash, tipo: 'colorhq', cubierta: 1, ancho: this.presupuestoCliente.datosGenerales.getDimensionLibro().ancho, alto: this.presupuestoCliente.datosGenerales.getDimensionLibro().alto, solapas: $('#solapas_cubierta').hasClass("d-none") ? 0 : $('#solapas_cubierta').val(), lomo: $('#lc').val(), tapa_dura: tapa_dura, tirada: this.presupuestoCliente.datosGenerales.getTiradas()[0], }, {}, (response) => { this.fillPapeles(response); }, (response) => { console.log(response); } ).get(); } #handlePapelCubiertaEspecial() { const context = this; this.papelCubierta = this.papelEspecial.getVal(); const tapa_dura = this.tapaBlanda.hasClass("selected") ? 0 : 1; new Ajax('/papelesgenericos/getpapelcliente', { [this.csrf_token]: this.csrf_hash, papel: this.papelCubierta, tipo: 'colorhq', cubierta: 1, ancho: this.presupuestoCliente.datosGenerales.getDimensionLibro().ancho, alto: this.presupuestoCliente.datosGenerales.getDimensionLibro().alto, solapas: $('#solapas_cubierta').hasClass("d-none") ? 0 : $('#solapas_cubierta').val(), lomo: $('#lc').val(), tapa_dura: tapa_dura, tirada: this.presupuestoCliente.datosGenerales.getTiradas()[0], }, {}, this.fillGramajes.bind(context), (response) => { console.log(response); } ).get(); } fillPapeles(response) { this.divPapelCubierta.empty(); this.divGramajeCubierta.empty(); if (response.papeles.length > 0) { this.textoPapelCubierta.removeClass('d-none'); } else { this.textoPapelCubierta.addClass("d-none"); } response.papeles.forEach(papel => { var container = $('
', { class: 'custom-selector custom-selector-papel-cubierta d-flex flex-column align-items-center justify-content-center' }); var radioButton = $('', { type: 'radio', // Tipo de input name: 'calcular-presupuesto papel-cubierta', id: 'papelCubierta_' + papel.id, // ID único value: 'option1' // Valor del radio button }); // Crear una etiqueta para el radio button var label = $('