Files
safekat/httpdocs/assets/js/safekat/pages/presupuestoCliente/disenioCubierta.js

1168 lines
43 KiB
JavaScript

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"),
'/configuracion/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"),
'/configuracion/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"),
'/configuracion/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"),
'/configuracion/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"),
'/configuracion/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"),
'/configuracion/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"),
'/configuracion/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,
"cliente": 1
}
);
this.acabadoSobrecubierta = new ClassSelect($("#acabadoSobrecubierta"),
'/serviciosacabados/getacabados',
'',
false,
{
[this.csrf_token]: this.csrf_hash,
"sobrecubierta": 1,
"cliente": 1
}
);
this.acabadoFaja = new ClassSelect($("#acabadoFaja"),
'/serviciosacabados/getacabados',
'',
false,
{
[this.csrf_token]: this.csrf_hash,
"sobrecubierta": 1,
"cliente": 1
}
);
// 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 || datosCubierta.tapa == "dura") {
if (datosCubierta.lomoRedondo)
this.tapaDuraLomoRedondo.trigger('click');
else
this.tapaDuraLomoRecto.trigger('click');
setTimeout(() => {
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');
}, 100);
}
else {
this.tapaBlanda.addClass('selected');
this.#handleMenuTipoCubierta();
setTimeout(() => {
this.carasCubierta.val(datosCubierta.paginas).trigger('change');
if (datosCubierta.solapas) {
// Activar con-solapas
this.conSolapas.addClass('selected')
.find('.image-presupuesto').addClass('selected');
this.sinSolapas.removeClass('selected')
.find('.image-presupuesto').removeClass('selected');
this.divTamanioSolapas.removeClass('d-none');
this.tamanioSolapasCubierta.val(datosCubierta.solapas_ancho);
} else {
// Asegurar que sin-solapas queda seleccionado (no togglear)
this.divTamanioSolapas.addClass('d-none');
}
}, 100);
}
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);
}
}
validate(goToNext = true) {
let errores = [];
let continueCheck = true;
// diseño cubierta
$('#divTipoCubierta').removeClass('is-invalid');
if ($('.tipo-cubierta.selected').length == 0) {
$('#divTipoCubierta').addClass('is-invalid');
errores.push(window.translations["validation"].tipo_cubierta);
continueCheck = false;
}
// solapas cubierta
$('#divSolapasCubierta').removeClass('is-invalid');
if (!$('#divSolapasCubierta').hasClass("d-none") && $('.solapas-cubierta.selected').length == 0 && continueCheck) {
$('#divSolapasCubierta').addClass('is-invalid');
errores.push(window.translations["validation"].opcion_solapas);
}
// opciones tapa dura y lomo redondo
$('#papelGuardas').removeClass('is-invalid');
$('#gramajeGuardas').removeClass('is-invalid');
if (!$('#divConfigTapaDura').hasClass('d-none') && continueCheck) {
if ($('#papelGuardas').select2('data').length == 0) {
$('#papelGuardas').addClass('is-invalid');
errores.push(window.translations["validation"].papel_guardas);
}
if ($('#gramajeGuardas').select2('data').length == 0) {
$('#gramajeGuardas').addClass('is-invalid');
errores.push(window.translations["validation"].gramaje_guardas);
}
}
// papel
$('#divPapelCubierta').removeClass('is-invalid');
if ($('.custom-selector-papel-cubierta input[type="radio"]:checked').length == 0 && continueCheck) {
$('#divPapelCubierta').addClass('is-invalid');
errores.push(window.translations["validation"].papel_cubierta);
continueCheck = false;
}
else if (!$('#divPapelEspecialCubierta').hasClass("d-none")) {
if ($('#papelEspecialCubiertaSel').select2('data').length == 0 && continueCheck) {
$('#divPapelEspecialCubierta').addClass('is-invalid');
errores.push(window.translations["validation"].papel_cubierta_especial);
continueCheck = false;
}
}
// gramaje
$('#divGramajeCubierta').removeClass('is-invalid');
if ($('.custom-selector-gramaje-cubierta input[type="radio"]:checked').length == 0 && continueCheck) {
$('#divGramajeCubierta').addClass('is-invalid');
errores.push(window.translations["validation"].gramaje_cubierta);
}
// sobrecubierta
$('#papelSobrecubierta').removeClass('is-invalid');
$('#gramajeSobrecubierta').removeClass('is-invalid');
if ($("#addSobrecubierta").prop("checked") == true) {
if ($('#papelSobrecubierta').select2('data').length == 0) {
$('#papelSobrecubierta').addClass('is-invalid');
errores.push(window.translations["validation"].papel_sobrecubierta);
}
if ($('#gramajeSobrecubierta').select2('data').length == 0) {
$('#gramajeSobrecubierta').addClass('is-invalid');
errores.push(window.translations["validation"].gramaje_sobrecubierta);
}
}
// faja
$('#papelFaja').removeClass('is-invalid');
$('#gramajeFaja').removeClass('is-invalid');
if ($("#addFaja").prop("checked") == true) {
if ($('#papelFaja').select2('data').length == 0) {
$('#papelFaja').addClass('is-invalid');
errores.push(window.translations["validation"].papel_faja);
}
if ($('#gramajeFaja').select2('data').length == 0) {
$('#gramajeFaja').addClass('is-invalid');
errores.push(window.translations["validation"].gramaje_faja);
}
}
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;
}
}
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);
this.divPapelCubierta.removeClass('is-invalid');
this.divGramajeCubierta.removeClass('is-invalid');
this.divGramajeCubierta.empty();
this.divPapelCubierta.empty();
this.textoPapelCubierta.addClass('d-none');
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();
this.divGramajeCubierta.removeClass("is-invalid");
if ($('.tipo-cubierta.selected').length > 0) {
const tapa_dura = this.tapaBlanda.hasClass("selected") ? 0 : 1;
new Ajax('/configuracion/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('/configuracion/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 = $('<div>', {
class: 'custom-selector custom-selector-papel-cubierta d-flex flex-column align-items-center justify-content-center'
});
var radioButton = $('<input>', {
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 = $('<label>', {
for: 'papelCubierta_' + papel.id,
text: papel.nombre
});
radioButton.on('click', this.#handleGramajeCubierta.bind(this));
container.append(radioButton).append(label);
$('#divPapelCubierta').append(container);
if (this.papelCubierta == papel.id) {
radioButton.prop('checked', true);
radioButton.trigger('click');
}
});
if (response.papeles_especiales.length > 0) {
this.divPapelCubierta.removeClass('d-none');
var container = $('<div>', {
class: 'custom-selector custom-selector-papel-cubierta d-flex flex-column align-items-center justify-content-center'
});
var radioButton = $('<input>', {
type: 'radio',
name: 'calcular-presupuesto papel-cubierta',
id: 'papelEspecialCubierta',
value: 'option1'
});
// Crear una etiqueta para el radio button
var label = $('<label>', {
for: 'papelEspecialCubierta',
text: 'PAPEL ESPECIAL'
});
radioButton.on('click', this.#handleGramajeCubierta.bind(this));
response.papeles_especiales.forEach(papel => {
if (papel.id == this.papelCubierta) {
radioButton.prop('checked', true);
radioButton.trigger('click');
this.papelEspecial.setOption(papel.id, papel.nombre);
this.#handlePapelCubiertaEspecial();
}
});
container.append(radioButton).append(label);
$('#divPapelCubierta').append(container);
}
}
#handleGramajeCubierta() {
const context = this;
// Accede al ID del elemento que disparó el evento
const element = $(event.target);
const papel = element[0].id.split('_')[1];
this.papelCubierta = papel;
$('#' + papel).prop('checked', true);
if (element[0].id == 'papelEspecialCubierta') {
/*if (!this.cargando)
this.gramaje = null;*/
this.divGramajeCubierta.empty();
this.divPapelEspecial.removeClass("d-none");
$('#papelEspecialCubiertaSel').off("change");
this.papelEspecial.empty();
$('#papelEspecialCubiertaSel').on("change", this.#handlePapelCubiertaEspecial.bind(this));
}
else {
this.divPapelEspecial.addClass("d-none");
$('#papelEspecialCubiertaSel').off("change");
this.papelEspecial.empty();
$('#papelEspecialCubiertaSel').on("change", this.#handlePapelCubiertaEspecial.bind(this));
this.divGramajeCubierta.empty();
const tapa_dura = this.tapaBlanda.hasClass("selected") ? 0 : 1;
new Ajax('/configuracion/papelesgenericos/getpapelcliente',
{
[this.csrf_token]: this.csrf_hash,
papel: papel,
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();
}
if (this.cargando)
this.cargando = false;
}
fillGramajes(response) {
this.divGramajeCubierta.empty()
let showGramaje = false;
if (response.papeles.length <= 0 && response.papeles_especiales.length <= 0) {
return;
}
let papel = response.papeles.length > 0 ? response.papeles : response.papeles_especiales;
papel.forEach(valor => {
var container = $('<div>', {
class: 'custom-selector custom-selector-gramaje-cubierta d-flex flex-column align-items-center justify-content-center gramaje-cubierta',
});
var radioButton = $('<input>', {
type: 'radio', // Tipo de input
name: 'calcular-presupuesto gramaje-cubierta',
id: 'gramajeCubierta_' + valor.gramaje, // ID único
value: 'option1' // Valor del radio button
});
// Crear una etiqueta para el radio button
var label = $('<label>', {
for: "gramajeCubierta_" + valor.gramaje,
text: valor.gramaje + " gr"
});
radioButton.on('click', (event) => {
const element = $(event.target);
const gramaje = element[0].id;
this.presupuestoCliente.checkForm(event);
});
container.append(radioButton).append(label);
$('#divGramajeCubierta').append(container);
if (this.gramaje != null) {
if (this.gramaje == parseInt(valor.gramaje)) {
radioButton.prop('checked', true);
radioButton.trigger('click');
}
}
showGramaje = true;
});
if ($("#divGramajeCubierta").hasClass("d-none") && showGramaje) {
$("#divGramajeCubierta").removeClass("d-none");
}
else if (!showGramaje) {
$("#divGramajeCubierta").addClass("d-none");
}
}
#handleTamanioSolapas() {
const min = parseInt(this.tamanioSolapasCubierta[0].min);
const max = parseInt(this.tamanioSolapasCubierta[0].max);
if (this.tamanioSolapasCubierta.val() < min || this.tamanioSolapasCubierta.val() == '' || isNaN(this.tamanioSolapasCubierta.val())) {
this.tamanioSolapasCubierta.val(min);
}
else if (this.tamanioSolapasCubierta.val() > max)
this.tamanioSolapasCubierta.val(max);
}
#handleClickGramaje(customOption) {
const el = customOption[0];
if (el.checked) {
// If custom option element is radio, remove checked from the siblings (closest `.row`)
if (el.type === 'radio') {
const customRadioOptionList = [].slice.call(el.closest('.row').querySelectorAll('.custom-option'))
customRadioOptionList.map(function (customRadioOptionEL) {
customRadioOptionEL.closest('.custom-option').classList.remove('checked')
})
}
el.closest('.custom-option').classList.add('checked')
} else {
el.closest('.custom-option').classList.remove('checked')
}
}
#handleInputs() {
const id = $(this).attr('id');
const min = parseInt($('#' + id).attr('min'));
const max = parseInt($('#' + id).attr('max'));
if ($('#' + id).val() < min || $('#' + id).val() == '' || isNaN($('#' + id).val())) {
$('#' + id).val(min);
}
else if ($('#' + id).val() > max)
$('#' + id).val(max);
}
}
export default DisenioCubierta;