mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
Version 1.0
This commit is contained in:
@ -5,18 +5,28 @@ class Catalogo {
|
||||
|
||||
constructor() {
|
||||
|
||||
/* Definiciones */
|
||||
this.tirada_no_pod = 100;
|
||||
this.tirada_pod = 1;
|
||||
|
||||
this.cliente = new ClassSelect($("#cliente_id"), '/catalogo/libros/clientlist', "Seleccione un cliente");
|
||||
/* Mapeado de elementos */
|
||||
this.tipo_impresion = $("#tipo_impresion");
|
||||
this.paginas_cubierta = $("#cubierta_paginas");
|
||||
this.sobrecubiertaItems = $('.sobrecubierta_items').add('.sobrecubierta_pod_items');
|
||||
this.paginasSobrecubierta = $('#sobrecubierta_paginas');
|
||||
this.negro = $('#negro_paginas');
|
||||
this.color = $('#color_paginas');
|
||||
this.total = $('#paginas');
|
||||
|
||||
/* Select2 para clientes */
|
||||
this.cliente = new ClassSelect($("#cliente_id"), '/catalogo/libros/clientlist', "Seleccione un cliente");
|
||||
|
||||
/* Select2 para tipos de encuadernacion */
|
||||
this.encuadernacion = new ClassSelect($("#encuadernacion_id"), '/importador/getencuadernacion', "Seleccione una encuadernación");
|
||||
|
||||
this.compPapelNegro = new ClassSelect($("#negro_papel_id"), '/presupuestoadmin/papelgenerico', "Seleccione un papel", false,
|
||||
/* Select2 para impresion en Negro */
|
||||
this.selectPapelNegro = new ClassSelect($("#negro_papel_id"), '/presupuestoadmin/papelgenerico', "Seleccione un papel", false,
|
||||
{
|
||||
|
||||
tipo_impresion: () => this.encuadernacion.getVal(),
|
||||
tirada: () => this.tirada_no_pod,
|
||||
ancho: () => this.getDimensionLibro().ancho,
|
||||
@ -26,7 +36,7 @@ class Catalogo {
|
||||
tipo: () => this.tipo_impresion.val().includes('hq') ? 'negrohq' : 'negro',
|
||||
});
|
||||
|
||||
this.compPapelNegroPod = new ClassSelect($("#negro_pod_papel_id"), '/presupuestoadmin/papelgenerico', "Seleccione un papel", false,
|
||||
this.selectPapelNegroPod = new ClassSelect($("#negro_pod_papel_id"), '/presupuestoadmin/papelgenerico', "Seleccione un papel", false,
|
||||
{
|
||||
tipo_impresion: () => this.encuadernacion.getVal(),
|
||||
tirada: () => this.tirada_pod,
|
||||
@ -37,10 +47,10 @@ class Catalogo {
|
||||
tipo: () => this.tipo_impresion.val().includes('hq') ? 'negrohq' : 'negro',
|
||||
});
|
||||
|
||||
this.compGramajeNegro = new ClassSelect($('#negro_gramaje'), '/presupuestoadmin/papelgramaje', 'Seleccione un gramaje', false,
|
||||
this.selectGramajeNegro = new ClassSelect($('#negro_gramaje'), '/presupuestoadmin/papelgramaje', 'Seleccione un gramaje', false,
|
||||
{
|
||||
tipo_impresion: () => this.encuadernacion.getVal(),
|
||||
papel_generico: () => this.compPapelNegro.getVal(),
|
||||
papel_generico: () => this.selectPapelNegro.getVal(),
|
||||
tirada: () => this.tirada_no_pod,
|
||||
ancho: () => this.getDimensionLibro().ancho,
|
||||
alto: () => this.getDimensionLibro().alto,
|
||||
@ -49,7 +59,21 @@ class Catalogo {
|
||||
tipo: () => this.tipo_impresion.val().includes('hq') ? 'negrohq' : 'negro',
|
||||
});
|
||||
|
||||
this.compPapelColor = new ClassSelect($("#color_papel_id"), '/presupuestoadmin/papelgenerico', "Seleccione un papel", false,
|
||||
this.selectGramajeNegroPod = new ClassSelect($('#negro_pod_gramaje'), '/presupuestoadmin/papelgramaje', 'Seleccione un gramaje', false,
|
||||
{
|
||||
tipo_impresion: () => this.encuadernacion.getVal(),
|
||||
papel_generico: () => this.selectPapelNegroPod.getVal(),
|
||||
tirada: () => this.tirada_pod,
|
||||
ancho: () => this.getDimensionLibro().ancho,
|
||||
alto: () => this.getDimensionLibro().alto,
|
||||
sopalas: 0,
|
||||
lomo: 0,
|
||||
tipo: () => this.tipo_impresion.val().includes('hq') ? 'negrohq' : 'negro',
|
||||
});
|
||||
|
||||
|
||||
/* Select2 para impresion en Color */
|
||||
this.selectPapelColor = new ClassSelect($("#color_papel_id"), '/presupuestoadmin/papelgenerico', "Seleccione un papel", false,
|
||||
{
|
||||
tipo_impresion: () => this.encuadernacion.getVal(),
|
||||
tirada: () => this.tirada_no_pod,
|
||||
@ -60,10 +84,21 @@ class Catalogo {
|
||||
tipo: () => this.tipo_impresion.val().includes('hq') ? 'colorhq' : 'color',
|
||||
});
|
||||
|
||||
this.compGramajeColor = new ClassSelect($('#color_gramaje'), '/presupuestoadmin/papelgramaje', 'Seleccione un gramaje', false,
|
||||
this.selectPapelColorPod = new ClassSelect($("#color_pod_papel_id"), '/presupuestoadmin/papelgenerico', "Seleccione un papel", false,
|
||||
{
|
||||
tipo_impresion: () => this.encuadernacion.getVal(),
|
||||
papel_generico: () => this.compPapelColor.getVal(),
|
||||
tirada: () => this.tirada_pod,
|
||||
ancho: () => this.getDimensionLibro().ancho,
|
||||
alto: () => this.getDimensionLibro().alto,
|
||||
sopalas: 0,
|
||||
lomo: 0,
|
||||
tipo: () => this.tipo_impresion.val().includes('hq') ? 'colorhq' : 'color',
|
||||
});
|
||||
|
||||
this.selectGramajeColor = new ClassSelect($('#color_gramaje'), '/presupuestoadmin/papelgramaje', 'Seleccione un gramaje', false,
|
||||
{
|
||||
tipo_impresion: () => this.encuadernacion.getVal(),
|
||||
papel_generico: () => this.selectPapelColor.getVal(),
|
||||
tirada: () => this.tirada_no_pod,
|
||||
ancho: () => this.getDimensionLibro().ancho,
|
||||
alto: () => this.getDimensionLibro().alto,
|
||||
@ -72,47 +107,63 @@ class Catalogo {
|
||||
tipo: () => this.tipo_impresion.val().includes('hq') ? 'colorhq' : 'color',
|
||||
});
|
||||
|
||||
this.compPapelCubierta = new ClassSelect($("#cubierta_papel_id"), '/presupuestoadmin/papelgenerico', "Seleccione un papel", false,
|
||||
this.selectGramajeColorPod = new ClassSelect($('#color_pod_gramaje'), '/presupuestoadmin/papelgramaje', 'Seleccione un gramaje', false,
|
||||
{
|
||||
tipo_impresion: () => this.encuadernacion.getVal(),
|
||||
papel_generico: () => this.selectPapelColorPod.getVal(),
|
||||
tirada: () => this.tirada_pod,
|
||||
ancho: () => this.getDimensionLibro().ancho,
|
||||
alto: () => this.getDimensionLibro().alto,
|
||||
sopalas: 0,
|
||||
lomo: 0,
|
||||
tipo: () => this.tipo_impresion.val().includes('hq') ? 'colorhq' : 'color',
|
||||
});
|
||||
|
||||
/* Select2 para impresion de cubiertas */
|
||||
this.selectPapelCubierta = new ClassSelect($("#cubierta_papel_id"), '/presupuestoadmin/papelgenerico', "Seleccione un papel", false,
|
||||
{
|
||||
tipo_impresion: this.encuadernacion.getVal(),
|
||||
tirada: () => this.tirada_no_pod,
|
||||
ancho: () => this.getDimensionLibro().ancho,
|
||||
alto: () => this.getDimensionLibro().alto,
|
||||
sopalas: () => $('#cubierta_solapas_ancho').val(),
|
||||
sopalas: () => $('#cubierta_ancho_solapas').val(),
|
||||
lomo: () => 0,
|
||||
tipo: 'colorhq',
|
||||
uso: 'cubierta',
|
||||
});
|
||||
this.compGramajeCubierta = new ClassSelect($('#cubierta_gramaje'), '/presupuestoadmin/papelgramaje', 'Seleccione un gramaje', false,
|
||||
|
||||
this.selectPapelCubiertaPod = new ClassSelect($("#cubierta_pod_papel_id"), '/presupuestoadmin/papelgenerico', "Seleccione un papel", false,
|
||||
{
|
||||
tipo_impresion: this.encuadernacion.getVal(),
|
||||
tirada: () => this.tirada_pod,
|
||||
ancho: () => this.getDimensionLibro().ancho,
|
||||
alto: () => this.getDimensionLibro().alto,
|
||||
sopalas: () => $('#cubierta_ancho_solapas').val(),
|
||||
lomo: () => 0,
|
||||
tipo: 'colorhq',
|
||||
uso: 'cubierta',
|
||||
});
|
||||
|
||||
this.selectGramajeCubierta = new ClassSelect($('#cubierta_gramaje'), '/presupuestoadmin/papelgramaje', 'Seleccione un gramaje', false,
|
||||
{
|
||||
tipo_impresion: () => this.encuadernacion.getVal(),
|
||||
papel_generico: () => this.compPapelCubierta.getVal(),
|
||||
papel_generico: () => this.selectPapelCubierta.getVal(),
|
||||
tirada: () => this.tirada_no_pod,
|
||||
ancho: () => this.getDimensionLibro().ancho,
|
||||
alto: () => this.getDimensionLibro().alto,
|
||||
sopalas: () => $('#cubierta_solapas_ancho').val(),
|
||||
sopalas: () => $('#cubierta_ancho_solapas').val(),
|
||||
lomo: 0,
|
||||
tipo: 'colorhq',
|
||||
});
|
||||
this.compPapelSobrecubierta = new ClassSelect($("#sobrecubierta_papel_id"), '/presupuestoadmin/papelgenerico', "Seleccione un papel", false,
|
||||
{
|
||||
tipo_impresion: this.encuadernacion.getVal(),
|
||||
tirada: () => this.tirada_no_pod,
|
||||
ancho: () => this.getDimensionLibro().ancho,
|
||||
alto: () => this.getDimensionLibro().alto,
|
||||
sopalas: () => $('#compSolapasSobrecubierta').val(),
|
||||
lomo: () => 0,
|
||||
tipo: 'colorhq',
|
||||
uso: 'sobrecubierta',
|
||||
});
|
||||
this.compGramajeSobrecubierta = new ClassSelect($('#sobrecubierta_gramaje'), '/presupuestoadmin/papelgramaje', 'Seleccione un gramaje', false,
|
||||
|
||||
this.selectGramajeCubiertaPod = new ClassSelect($('#cubierta_pod_gramaje'), '/presupuestoadmin/papelgramaje', 'Seleccione un gramaje', false,
|
||||
{
|
||||
tipo_impresion: () => this.encuadernacion.getVal(),
|
||||
papel_generico: () => this.compPapelSobrecubierta.getVal(),
|
||||
tirada: () => this.tirada_no_pod,
|
||||
papel_generico: () => this.selectPapelCubiertaPod.getVal(),
|
||||
tirada: () => this.tirada_pod,
|
||||
ancho: () => this.getDimensionLibro().ancho,
|
||||
alto: () => this.getDimensionLibro().alto,
|
||||
sopalas: () => $('#compSolapasSobrecubierta').val(),
|
||||
sopalas: () => $('#cubierta_ancho_solapas').val(),
|
||||
lomo: 0,
|
||||
tipo: 'colorhq',
|
||||
});
|
||||
@ -125,6 +176,56 @@ class Catalogo {
|
||||
"cubierta": 1
|
||||
}
|
||||
);
|
||||
|
||||
/* Select2 para impresion de sobrecubierta */
|
||||
this.selectPapelSobrecubierta = new ClassSelect($("#sobrecubierta_papel_id"), '/presupuestoadmin/papelgenerico', "Seleccione un papel", false,
|
||||
{
|
||||
tipo_impresion: this.encuadernacion.getVal(),
|
||||
tirada: () => this.tirada_no_pod,
|
||||
ancho: () => this.getDimensionLibro().ancho,
|
||||
alto: () => this.getDimensionLibro().alto,
|
||||
sopalas: () => $('#sobrecubierta_ancho_solapas').val(),
|
||||
lomo: () => 0,
|
||||
tipo: 'colorhq',
|
||||
uso: 'sobrecubierta',
|
||||
});
|
||||
|
||||
this.selectPapelSobrecubiertaPod = new ClassSelect($("#sobrecubierta_pod_papel_id"), '/presupuestoadmin/papelgenerico', "Seleccione un papel", false,
|
||||
{
|
||||
tipo_impresion: this.encuadernacion.getVal(),
|
||||
tirada: () => this.tirada_pod,
|
||||
ancho: () => this.getDimensionLibro().ancho,
|
||||
alto: () => this.getDimensionLibro().alto,
|
||||
sopalas: () => $('#sobrecubierta_ancho_solapas').val(),
|
||||
lomo: () => 0,
|
||||
tipo: 'colorhq',
|
||||
uso: 'sobrecubierta',
|
||||
});
|
||||
|
||||
this.selectGramajeSobrecubierta = new ClassSelect($('#sobrecubierta_gramaje'), '/presupuestoadmin/papelgramaje', 'Seleccione un gramaje', false,
|
||||
{
|
||||
tipo_impresion: () => this.encuadernacion.getVal(),
|
||||
papel_generico: () => this.selectPapelSobrecubierta.getVal(),
|
||||
tirada: () => this.tirada_no_pod,
|
||||
ancho: () => this.getDimensionLibro().ancho,
|
||||
alto: () => this.getDimensionLibro().alto,
|
||||
sopalas: () => $('#sobrecubierta_ancho_solapas').val(),
|
||||
lomo: 0,
|
||||
tipo: 'colorhq',
|
||||
});
|
||||
|
||||
this.selectGramajeSobrecubiertaPod = new ClassSelect($('#sobrecubierta_pod_gramaje'), '/presupuestoadmin/papelgramaje', 'Seleccione un gramaje', false,
|
||||
{
|
||||
tipo_impresion: () => this.encuadernacion.getVal(),
|
||||
papel_generico: () => this.selectPapelSobrecubiertaPod.getVal(),
|
||||
tirada: () => this.tirada_pod,
|
||||
ancho: () => this.getDimensionLibro().ancho,
|
||||
alto: () => this.getDimensionLibro().alto,
|
||||
sopalas: () => $('#sobrecubierta_ancho_solapas').val(),
|
||||
lomo: 0,
|
||||
tipo: 'colorhq',
|
||||
});
|
||||
|
||||
this.acabadosSobrecubierta = new ClassSelect($("#sobrecubierta_acabado_id"),
|
||||
'/serviciosacabados/getacabados',
|
||||
'Seleccione acabado',
|
||||
@ -134,15 +235,18 @@ class Catalogo {
|
||||
}
|
||||
);
|
||||
|
||||
this.sobrecubiertaItems = $('.sobrecubierta_items');
|
||||
this.paginasSobrecubierta = $('#sobrecubierta_paginas');
|
||||
|
||||
}
|
||||
|
||||
init() {
|
||||
|
||||
const self = this;
|
||||
|
||||
// Eliminar elementos que no se usan
|
||||
$('[id*="_pod_paginas"]').remove();
|
||||
$('[id*="_pod_ancho_solapas"]').remove();
|
||||
$('[id*="_pod_acabado_id"]').remove();
|
||||
|
||||
|
||||
// Fuerza el foco en el campo de búsqueda de select2
|
||||
$(document).on('select2:open', () => {
|
||||
document.querySelector('.select2-search__field').focus();
|
||||
@ -155,39 +259,52 @@ class Catalogo {
|
||||
|
||||
this.encuadernacion.init();
|
||||
|
||||
this.compPapelNegro.init();
|
||||
this.compPapelNegroPod.init();
|
||||
this.compGramajeNegro.init();
|
||||
this.compPapelColor.init();
|
||||
this.compGramajeColor.init();
|
||||
this.compPapelCubierta.init();
|
||||
this.compGramajeCubierta.init();
|
||||
this.compPapelSobrecubierta.init();
|
||||
this.compGramajeSobrecubierta.init();
|
||||
this.selectPapelNegro.init();
|
||||
this.selectPapelNegroPod.init();
|
||||
this.selectGramajeNegro.init();
|
||||
this.selectGramajeNegroPod.init();
|
||||
|
||||
this.selectPapelColor.init();
|
||||
this.selectPapelColorPod.init();
|
||||
this.selectGramajeColor.init();
|
||||
this.selectGramajeColorPod.init();
|
||||
|
||||
this.selectPapelCubierta.init();
|
||||
this.selectPapelCubiertaPod.init();
|
||||
this.selectGramajeCubierta.init();
|
||||
this.selectGramajeCubiertaPod.init();
|
||||
this.acabadoCubierta.init();
|
||||
|
||||
this.selectPapelSobrecubierta.init();
|
||||
this.selectPapelSobrecubiertaPod.init();
|
||||
this.selectGramajeSobrecubierta.init();
|
||||
this.selectGramajeSobrecubiertaPod.init();
|
||||
this.acabadosSobrecubierta.init();
|
||||
|
||||
|
||||
// Al cargar la página
|
||||
this.toggleSobrecubiertaFields();
|
||||
|
||||
this.compPapelNegro.item.on('select2:select', function () {
|
||||
self.compGramajeNegro.empty();
|
||||
});
|
||||
|
||||
this.cliente.item.on('change', () => {
|
||||
|
||||
|
||||
});
|
||||
|
||||
// Inicializacino de eventos
|
||||
this.tipo_impresion.on("change", this.updateOpcionesComparador.bind(this));
|
||||
this.selectPapelNegro.item.on('select2:select', function () {
|
||||
self.selectGramajeNegro.empty();
|
||||
});
|
||||
|
||||
this.total.on('input change', () => {
|
||||
this.validarMultiploDe4([this.total, this.color, this.negro]);
|
||||
});
|
||||
this.color.on('input change', this.actualizarDesdeColor.bind(this));
|
||||
this.negro.on('input change', this.actualizarDesdeNegro.bind(this));
|
||||
this.tipo_impresion.on("change", this.updateOpcionesImpresion.bind(this));
|
||||
|
||||
// Al cambiar el selector de paginas de sobrecubierta
|
||||
this.paginasSobrecubierta.on('change', this.toggleSobrecubiertaFields.bind(this));
|
||||
|
||||
this.updateOpcionesComparador();
|
||||
// Al cambiar el tipo de encuadernacion
|
||||
this.encuadernacion.onChange(this.enableSobrecubiertaLines.bind(this));
|
||||
|
||||
|
||||
this.updateOpcionesImpresion();
|
||||
|
||||
$(document).on('change', '.warning-change', function () {
|
||||
$(this).addClass('bg-warning');
|
||||
@ -196,33 +313,59 @@ class Catalogo {
|
||||
});
|
||||
}
|
||||
|
||||
actualizarDesdeColor() {
|
||||
const total = parseInt(this.total.val(), 10) || 0;
|
||||
const color = parseInt(this.color.val(), 10) || 0;
|
||||
const negro = Math.max(total - color, 0);
|
||||
this.negro.val(negro);
|
||||
this.validarMultiploDe4([this.total, this.color, this.negro]);
|
||||
}
|
||||
|
||||
updateOpcionesComparador() {
|
||||
actualizarDesdeNegro() {
|
||||
const total = parseInt(this.total.val(), 10) || 0;
|
||||
const negro = parseInt(this.negro.val(), 10) || 0;
|
||||
const color = Math.max(total - negro, 0);
|
||||
this.color.val(color);
|
||||
this.validarMultiploDe4([this.total, this.color, this.negro]);
|
||||
}
|
||||
|
||||
validarMultiploDe4(campos) {
|
||||
campos.forEach($el => {
|
||||
const val = parseInt($el.val(), 10) || 0;
|
||||
if (val % 4 !== 0) {
|
||||
$el.css('color', 'red');
|
||||
} else {
|
||||
$el.css('color', '');
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
updateOpcionesImpresion() {
|
||||
$('.negro_items').off('change');
|
||||
$('.color_items').off('change');
|
||||
|
||||
const selValue = this.tipo_impresion.val();
|
||||
const elements_negro = $('.negro-line');
|
||||
const elements_color = $('.color-line');
|
||||
|
||||
if (selValue.includes('color')) {
|
||||
Array.from(elements_color).forEach(element => {
|
||||
$(element).removeClass('d-none');
|
||||
});
|
||||
}
|
||||
else {
|
||||
Array.from(elements_color).forEach(element => {
|
||||
$(element).addClass('d-none');
|
||||
});
|
||||
}
|
||||
Array.from(elements_negro).forEach(element => {
|
||||
$(element).removeClass('d-none');
|
||||
|
||||
// Buscar elementos por clase dinámica (negro-*-line y color-*-line)
|
||||
const elements_negro = $('*').filter(function () {
|
||||
return [...this.classList].some(cls => /^negro.*line$/.test(cls));
|
||||
});
|
||||
|
||||
const elements_color = $('*').filter(function () {
|
||||
return [...this.classList].some(cls => /^color.*line$/.test(cls));
|
||||
});
|
||||
|
||||
if (selValue.includes('color')) {
|
||||
elements_color.removeClass('d-none');
|
||||
} else {
|
||||
elements_color.addClass('d-none');
|
||||
}
|
||||
|
||||
elements_negro.removeClass('d-none');
|
||||
}
|
||||
|
||||
|
||||
|
||||
getDimensionLibro() {
|
||||
let ancho = $('#ancho').val();
|
||||
let alto = $('#alto').val();;
|
||||
@ -237,6 +380,33 @@ class Catalogo {
|
||||
}
|
||||
}
|
||||
|
||||
enableSobrecubiertaLines() {
|
||||
|
||||
// Buscar elementos por clase dinámica (sobrecubierta-*-line)
|
||||
const elements_sobrecubierta = $('*').filter(function () {
|
||||
return [...this.classList].some(cls => /^sobrecubierta.*line$/.test(cls));
|
||||
});
|
||||
|
||||
switch (parseInt(this.encuadernacion.getVal(), 10)) {
|
||||
case 5:
|
||||
case 6:
|
||||
case 7:
|
||||
case 8:
|
||||
case 21:
|
||||
console.log("Desactivar sobrecubierta:" + this.encuadernacion.getVal());
|
||||
elements_sobrecubierta.addClass('d-none');
|
||||
|
||||
break;
|
||||
|
||||
default:
|
||||
console.log("Activar sobrecubierta:" + this.encuadernacion.getVal());
|
||||
elements_sobrecubierta.removeClass('d-none');
|
||||
|
||||
break;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
document.addEventListener('DOMContentLoaded', function () {
|
||||
|
||||
Reference in New Issue
Block a user