mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
995 lines
34 KiB
JavaScript
995 lines
34 KiB
JavaScript
import ClassSelect from '../../components/select2.js';
|
|
|
|
class DatosGenerales {
|
|
|
|
constructor(domItem, wizardForm, validatorStepper) {
|
|
|
|
this.domItem = domItem;
|
|
|
|
this.wizardStep = wizardForm.querySelector('#datos-generales');
|
|
this.validatorStepper = validatorStepper;
|
|
|
|
this.formatoLibro = new ClassSelect($("#papelFormatoId"), '/papel-formato/getSelect2', window.translations["formatoLibro"]);
|
|
this.cliente = new ClassSelect($("#clienteId"), '/clientes/cliente/getSelect2', window.translations["selectCliente"]);
|
|
|
|
this.titulo = this.domItem.find("#titulo");
|
|
this.autor = this.domItem.find("#autor");
|
|
this.isbn = this.domItem.find("#isbn");
|
|
this.coleccion = this.domItem.find("#coleccion");
|
|
this.referenciaCliente = this.domItem.find("#referenciaCliente");
|
|
|
|
this.tirada1 = this.domItem.find("#tirada");
|
|
this.tirada2 = this.domItem.find("#tirada2");
|
|
this.tirada3 = this.domItem.find("#tirada3");
|
|
this.tirada4 = this.domItem.find("#tirada4");
|
|
|
|
this.papelFormatoId = this.domItem.find("#papelFormatoId");
|
|
this.checkFormatoPersonalizado = this.domItem.find("#papelFormatoPersonalizado");
|
|
this.formatoPersonalizado = this.domItem.find("#formatoPersonalizado");
|
|
this.formatoEstandar = this.domItem.find("#formatoEstandar");
|
|
this.anchoPersonalizado = this.domItem.find("#papelFormatoAncho");
|
|
this.altoPersonalizado = this.domItem.find("#papelFormatoAlto");
|
|
|
|
this.fresado = $(this.domItem.find("#fresado")[0]);
|
|
this.cosido = $(this.domItem.find("#cosido")[0]);
|
|
this.grapado = $(this.domItem.find("#grapado")[0]);
|
|
this.espiral = $(this.domItem.find("#espiral")[0]);
|
|
this.wireo = $(this.domItem.find("#wireo")[0]);
|
|
|
|
this.tiposLibro = this.domItem.find(".tipo-libro");
|
|
|
|
this.paginas = this.domItem.find("#paginas");
|
|
this.paginasNegro = this.domItem.find("#paginasNegro");
|
|
this.paginasColor = this.domItem.find("#paginasColor");
|
|
this.divPaginasCuaderillo = this.domItem.find("#divPaginasCuadernillo");
|
|
this.paginasCuadernillo = this.domItem.find("#paginasCuadernillo");
|
|
this.divPaginasColorConsecutivas = this.domItem.find("#divPaginasColorConsecutivas");
|
|
this.pagColorConsecutivas = this.domItem.find("#pagColorConsecutivas");
|
|
this.divPapelDiferente = this.domItem.find("#divPapelDiferente");
|
|
this.papelDiferente = this.domItem.find("#papelDiferente");
|
|
this.divPosPaginasColor = this.domItem.find("#divPosPaginasColor");
|
|
this.posPaginasColor = this.domItem.find("#posPaginasColor");
|
|
|
|
this.ivaReducido = this.domItem.find("#ivaReducido");
|
|
this.excluirRotativa = this.domItem.find("#excluirRotativa");
|
|
this.prototipo = this.domItem.find("#prototipo");
|
|
this.ferro = this.domItem.find("#ferro");
|
|
this.ferroDigital = this.domItem.find("#ferroDigital");
|
|
this.marcapaginas = this.domItem.find("#marcapaginas");
|
|
this.retractilado = this.domItem.find("#retractilado");
|
|
this.retractilado5 = this.domItem.find("#retractilado5");
|
|
|
|
this.rl_datos_generales = $(".rl-datos-generales");
|
|
this.rl_tipo = $("#rl_tipo");
|
|
this.rl_tipo_cubierta = $('#rl_tipo_cubierta');
|
|
this.rl_tamanio = $("#rl_tamanio");
|
|
this.rl_tiradas = $("#rl_tiradas");
|
|
this.rl_paginas = $("#rl_paginas");
|
|
|
|
this.rl_servicios_extra = $(".rl-servicios-extra");
|
|
this.rl_prototipo = $("#rl_prototipo");
|
|
this.rl_ferro = $("#rl_ferro");
|
|
this.rl_ferroDigital = $("#rl_ferroDigital");
|
|
this.rl_marcapaginas = $("#rl_marcapaginas");
|
|
this.rl_retractilado = $("#rl_retractilado");
|
|
this.rl_retractilado5 = $("#rl_retractilado5");
|
|
|
|
this.selectedTirada = null;
|
|
|
|
this.cargando = false;
|
|
|
|
this.errores = [];
|
|
}
|
|
|
|
|
|
init() {
|
|
|
|
const self = this;
|
|
|
|
// Selects
|
|
this.formatoLibro.init();
|
|
this.cliente.init();
|
|
|
|
// Inicializa el tipo de impresion
|
|
this.#handlePaginas();
|
|
|
|
// Eventos
|
|
this.checkFormatoPersonalizado.bind('change', this.#handleFormatoLibro.bind(this));
|
|
this.formatoLibro.item.on('change', this.#handleFormatoLibro.bind(this));
|
|
this.tiposLibro.on('click', this.#handleTipolibro.bind(this));
|
|
this.domItem.find('.input-paginas').on('change', this.#handlePaginas.bind(this));
|
|
this.anchoPersonalizado.on('blur', this.#handleCheckFormatoPersonalizado.bind(this));
|
|
this.altoPersonalizado.on('blur', this.#handleCheckFormatoPersonalizado.bind(this));
|
|
this.pagColorConsecutivas.on('change', this.#handPaginasConsecutivas.bind(this));
|
|
this.papelDiferente.on('change', this.#handlePapelDiferente.bind(this));
|
|
|
|
// check ferro y prototipo
|
|
this.domItem.on('change', 'input[type="checkbox"][data-tarifa-extra-excluyente="1"]', (e) => {
|
|
|
|
const current = $(e.target);
|
|
|
|
if (current.is(':checked')) {
|
|
this.domItem.find('input[type="checkbox"][data-tarifa-extra-excluyente="1"]')
|
|
.not(current)
|
|
.prop('checked', false);
|
|
|
|
if ((current.data('tarifa-nombre')?.toString().toLowerCase() || '').includes('2')) {
|
|
$('#direccionesFerroPrototipo2').removeClass('d-none');
|
|
}
|
|
$('#direccionesFerroPrototipo').removeClass('d-none');
|
|
}
|
|
else {
|
|
if (this.domItem.find('input[type="checkbox"][data-tarifa-extra-excluyente="1"]').prop('checked').length === 0) {
|
|
|
|
$('#direccionesFerroPrototipo').addClass('d-none');
|
|
$('#divDireccionesFerroPrototipo').empty();
|
|
$('#direccionesFerroPrototipo2').addClass('d-none');
|
|
$('#divDireccionesFerroPrototipo2').empty();
|
|
}
|
|
}
|
|
});
|
|
|
|
|
|
|
|
$('.tirada-presupuesto').on('change', () => {
|
|
|
|
if (this.validateTiradas()) {
|
|
this.removeError(window.translations["validation"].tirada_integer_greatherThan_0);
|
|
this.removeError(window.translations["validation"].tirada_pod_nopod);
|
|
}
|
|
else {
|
|
this.addErrors();
|
|
}
|
|
let tiradas = self.getTiradas();
|
|
if (!Array.isArray(tiradas)) {
|
|
tiradas = [tiradas];
|
|
}
|
|
const data = {
|
|
tiradas: self.getTiradas(),
|
|
tiradaSeleccionada: self.selectedTirada || parseInt(self.tirada1.val())
|
|
};
|
|
$(document).trigger('update-tiradas-envios', data);
|
|
});
|
|
|
|
this.anchoPersonalizado.on("change", this.#checkValue.bind(this));
|
|
this.altoPersonalizado.on("change", this.#checkValue.bind(this));
|
|
|
|
this.titulo.on('change', () => {
|
|
$(".titulo").html(this.titulo.val());
|
|
if (this.validateTitulo()) {
|
|
this.removeError(window.translations["validation"].titulo_requerido);
|
|
}
|
|
else {
|
|
this.addErrors();
|
|
}
|
|
});
|
|
|
|
this.cliente.item.on('change', () => {
|
|
if (this.validateCliente()) {
|
|
this.removeError(window.translations["validation"].cliente);
|
|
}
|
|
else {
|
|
this.addErrors();
|
|
}
|
|
});
|
|
|
|
this.retractilado.on('change', this.#eventRetractilado.bind(this));
|
|
this.retractilado5.on('change', this.#eventRetractilado.bind(this));
|
|
}
|
|
|
|
|
|
validate(goToNext = true) {
|
|
|
|
this.errores = [];
|
|
|
|
// Titulo
|
|
this.validateTitulo();
|
|
|
|
// Cliente
|
|
this.validateCliente();
|
|
|
|
// Tirada
|
|
this.validateTiradas();
|
|
|
|
// formato libro
|
|
this.validateFormatoLibro();
|
|
|
|
// Paginas
|
|
this.validatePaginas();
|
|
|
|
// Tipo de libro
|
|
this.validateTipoLibro();
|
|
|
|
this.addErrors();
|
|
|
|
if (this.errores.length > 0) {
|
|
|
|
return false;
|
|
}
|
|
else {
|
|
if (goToNext)
|
|
this.validatorStepper.next();
|
|
else
|
|
return true;
|
|
}
|
|
}
|
|
|
|
validateTipoLibro() {
|
|
|
|
let noError = true;
|
|
|
|
if ($('.tipo-libro.selected').length > 0) {
|
|
if ($('#cosido').hasClass('selected') || $('#grapado').hasClass('selected')) {
|
|
const value = parseInt($("#paginas").val());
|
|
if (value % 4 != 0) {
|
|
if (parseInt(this.paginas.val()) % 4 != 0) {
|
|
this.errores.push(window.translations["validation"].paginas_multiplo_4);
|
|
this.paginas.addClass('is-invalid');
|
|
noError = false;
|
|
} else {
|
|
this.paginas.removeClass('is-invalid');
|
|
}
|
|
}
|
|
}
|
|
this.domItem.find('#divTipoLibro').removeClass('is-invalid');
|
|
} else {
|
|
this.errores.push(window.translations["validation"].tipo_libro);
|
|
this.domItem.find('#divTipoLibro').addClass('is-invalid');
|
|
noError = false;
|
|
}
|
|
|
|
return noError;
|
|
}
|
|
|
|
validatePaginas() {
|
|
|
|
let noError = true;
|
|
|
|
if (this.paginasColor.val() == '' || isNaN(this.paginasColor.val()) || parseInt(this.paginasColor.val()) < 0) {
|
|
this.errores.push(window.translations["validation"].paginasColor);
|
|
this.paginasColor.addClass('is-invalid');
|
|
noError = false;
|
|
}
|
|
else if (parseInt(this.paginasColor.val()) % 2 != 0) {
|
|
this.errores.push(window.translations["validation"].paginas_pares);
|
|
this.paginasColor.addClass('is-invalid');
|
|
noError = false;
|
|
}
|
|
else {
|
|
this.paginasColor.removeClass('is-invalid');
|
|
}
|
|
if (this.paginasNegro.val() == '' || isNaN(this.paginasNegro.val()) || parseInt(this.paginasNegro.val()) < 0) {
|
|
this.errores.push(window.translations["validation"].paginasNegro);
|
|
this.paginasNegro.addClass('is-invalid');
|
|
noError = false;
|
|
}
|
|
else if (parseInt(this.paginasNegro.val()) % 2 != 0) {
|
|
this.errores.push(window.translations["validation"].paginas_pares);
|
|
this.paginasNegro.addClass('is-invalid');
|
|
noError = false;
|
|
}
|
|
else {
|
|
this.paginasNegro.removeClass('is-invalid');
|
|
}
|
|
if (this.paginas.val() == '' || isNaN(this.paginas.val()) || parseInt(this.paginas.val()) <= 0) {
|
|
this.errores.push(window.translations["validation"].paginas);
|
|
this.paginas.addClass('is-invalid');
|
|
noError = false;
|
|
} else {
|
|
this.paginas.removeClass('is-invalid');
|
|
}
|
|
|
|
return noError;
|
|
}
|
|
|
|
validateFormatoLibro() {
|
|
|
|
let noError = true;
|
|
if (this.checkFormatoPersonalizado.is(':checked')) {
|
|
if (this.anchoPersonalizado.val().length === 0 || isNaN(this.anchoPersonalizado.val()) ||
|
|
parseFloat(this.anchoPersonalizado.val()) <= 0) {
|
|
this.errores.push(window.translations["validation"].papelFormatoAncho);
|
|
this.anchoPersonalizado.addClass('is-invalid');
|
|
noError = false;
|
|
} else {
|
|
this.anchoPersonalizado.removeClass('is-invalid');
|
|
}
|
|
if (this.altoPersonalizado.val().length === 0 || isNaN(this.altoPersonalizado.val()) ||
|
|
parseFloat(this.altoPersonalizado.val()) <= 0) {
|
|
this.errores.push(window.translations["validation"].papelFormatoAlto);
|
|
this.altoPersonalizado.addClass('is-invalid');
|
|
noError = false;
|
|
} else {
|
|
this.altoPersonalizado.removeClass('is-invalid');
|
|
}
|
|
} else {
|
|
const options = $("#papelFormatoId").select2('data');
|
|
const hasValidOption = options.some(option => parseInt(option.id) > 0);
|
|
if (options !== null && options.length > 0 && hasValidOption) {
|
|
this.papelFormatoId.removeClass('is-invalid');
|
|
} else {
|
|
this.errores.push(window.translations["validation"].papelFormato);
|
|
this.papelFormatoId.addClass('is-invalid');
|
|
noError = false;
|
|
}
|
|
}
|
|
return noError;
|
|
}
|
|
|
|
validateTiradas() {
|
|
|
|
let tiradas = this.getTiradas();
|
|
if (tiradas.length === 0 || tiradas.some(tirada =>
|
|
!Number.isInteger(tirada) ||
|
|
parseInt(tirada) <= 0 ||
|
|
tirada == "")) {
|
|
|
|
this.errores.push(window.translations["validation"].tirada_integer_greatherThan_0);
|
|
this.tirada1.addClass('is-invalid');
|
|
return false;
|
|
|
|
} else {
|
|
this.tirada1.removeClass('is-invalid');
|
|
// Comprobar tiradas POD
|
|
const noPOD = tiradas.some(tirada => parseInt(tirada) > 30);
|
|
const siPOD = tiradas.some(tirada => parseInt(tirada) <= 30);
|
|
if (noPOD && siPOD) {
|
|
this.errores.push(window.translations["validation"].tirada_pod_nopod);
|
|
this.tirada1.addClass('is-invalid');
|
|
return false;
|
|
}
|
|
else {
|
|
this.tirada1.removeClass('is-invalid');
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
|
|
validateCliente() {
|
|
|
|
if ($(this.excluirRotativa).prop('hidden')) {
|
|
if ($('#clienteId').val() === null || $('#clienteId').val().length === 0) {
|
|
this.errores.push(window.translations["validation"].cliente);
|
|
$('#clienteId').addClass('is-invalid');
|
|
return false;
|
|
} else {
|
|
$('#clienteId').removeClass('is-invalid');
|
|
return true;
|
|
}
|
|
} else {
|
|
if (this.cliente.getVal() <= 0) {
|
|
this.errores.push(window.translations["validation"].cliente);
|
|
this.cliente.item.addClass('is-invalid');
|
|
return false;
|
|
} else {
|
|
this.cliente.item.removeClass('is-invalid');
|
|
return true;
|
|
}
|
|
}
|
|
}
|
|
|
|
validateTitulo() {
|
|
|
|
if (this.titulo.val().trim() === '') {
|
|
this.errores.push(window.translations["validation"].titulo_requerido);
|
|
this.titulo.addClass('is-invalid');
|
|
return false;
|
|
} else {
|
|
this.titulo.removeClass('is-invalid');
|
|
return true;
|
|
}
|
|
}
|
|
|
|
|
|
processMenuLateral() {
|
|
|
|
let menu_off = true;
|
|
|
|
if (this.tiposLibro.filter('.selected').length > 0) {
|
|
let tipo = String(this.tiposLibro.filter('.selected').attr('id'));
|
|
tipo = tipo.charAt(0).toUpperCase() + tipo.slice(1);
|
|
this.rl_tipo.text(tipo);
|
|
this.rl_tipo.removeClass('d-none');
|
|
menu_off = false;
|
|
}
|
|
else {
|
|
this.rl_tipo.addClass('d-none');
|
|
}
|
|
if ($('.tipo-cubierta.selected').length > 0) {
|
|
this.rl_tipo_cubierta.text($($('.tipo-cubierta.selected').find('.form-label')).text());
|
|
this.rl_tipo_cubierta.removeClass('d-none');
|
|
}
|
|
else {
|
|
this.rl_tipo_cubierta.addClass('d-none');
|
|
}
|
|
if (this.checkFormatoPersonalizado.is(':checked')) {
|
|
let ancho = parseFloat(this.anchoPersonalizado.val());
|
|
let alto = parseFloat(this.altoPersonalizado.val());
|
|
if (!isNaN(ancho) && !isNaN(alto)) {
|
|
this.rl_tamanio.text(ancho + ' x ' + alto);
|
|
this.rl_tamanio.removeClass('d-none');
|
|
menu_off = false;
|
|
}
|
|
else {
|
|
this.rl_tamanio.addClass('d-none');
|
|
}
|
|
}
|
|
|
|
else {
|
|
if (this.papelFormatoId.val() != null) {
|
|
this.rl_tamanio.text(this.papelFormatoId.find('option:selected').text());
|
|
this.rl_tamanio.removeClass('d-none');
|
|
menu_off = false;
|
|
}
|
|
else {
|
|
this.rl_tamanio.addClass('d-none');
|
|
}
|
|
}
|
|
|
|
const tiradas = this.getTiradas();
|
|
if (tiradas.length > 0) {
|
|
this.rl_tiradas.text(tiradas.join(', '));
|
|
this.rl_tiradas.removeClass('d-none');
|
|
}
|
|
else
|
|
this.rl_tiradas.addClass('d-none');
|
|
|
|
if (this.paginas.val() > 0) {
|
|
this.rl_paginas.text(this.paginas.val() + " páginas");
|
|
this.rl_paginas.removeClass('d-none');
|
|
}
|
|
else
|
|
this.rl_paginas.addClass('d-none');
|
|
|
|
if (!menu_off)
|
|
this.rl_datos_generales.removeClass('d-none');
|
|
else
|
|
this.rl_datos_generales.addClass('d-none');
|
|
|
|
// servicios extra
|
|
menu_off = true;
|
|
$('#rl-servicios-extra-items').empty();
|
|
|
|
if (this.marcapaginas.is(':checked')) {
|
|
let $ul = $('<ul>', {
|
|
class: 'list-group list-group-timeline'
|
|
});
|
|
|
|
let $li = $('<li>', {
|
|
class: 'list-group-item list-group-timeline-primary texto-resumen-lateral',
|
|
text: 'Marcapáginas'
|
|
});
|
|
|
|
$ul.append($li);
|
|
$('#rl-servicios-extra-items').append($ul);
|
|
menu_off = false;
|
|
}
|
|
|
|
if (this.retractilado.is(':checked')) {
|
|
let $ul = $('<ul>', {
|
|
class: 'list-group list-group-timeline'
|
|
});
|
|
|
|
let $li = $('<li>', {
|
|
class: 'list-group-item list-group-timeline-primary texto-resumen-lateral',
|
|
text: 'Retractilado'
|
|
});
|
|
|
|
$ul.append($li);
|
|
$('#rl-servicios-extra-items').append($ul);
|
|
menu_off = false;
|
|
}
|
|
|
|
if (this.retractilado5.is(':checked')) {
|
|
let $ul = $('<ul>', {
|
|
class: 'list-group list-group-timeline'
|
|
});
|
|
|
|
let $li = $('<li>', {
|
|
class: 'list-group-item list-group-timeline-primary texto-resumen-lateral',
|
|
text: 'Retractilado de 5'
|
|
});
|
|
|
|
$ul.append($li);
|
|
$('#rl-servicios-extra-items').append($ul);
|
|
menu_off = false;
|
|
}
|
|
|
|
const serviciosExtra = $('input[type="checkbox"][data-tarifa-tipo="extra"]:checked');
|
|
for (let i = 0; i < serviciosExtra.length; i++) {
|
|
let $ul = $('<ul>', {
|
|
class: 'list-group list-group-timeline'
|
|
});
|
|
|
|
let $li = $('<li>', {
|
|
class: 'list-group-item list-group-timeline-primary texto-resumen-lateral',
|
|
text: '' + $(serviciosExtra[i]).data('tarifa-nombre')
|
|
});
|
|
|
|
$ul.append($li);
|
|
$('#rl-servicios-extra-items').append($ul);
|
|
}
|
|
|
|
if (!menu_off) {
|
|
this.rl_servicios_extra.removeClass('d-none');
|
|
}
|
|
else {
|
|
this.rl_servicios_extra.addClass('d-none');
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
cargarDatos(datos) {
|
|
|
|
this.cargando = true;
|
|
|
|
this.titulo.val(datos.titulo);
|
|
this.autor.val(datos.autor);
|
|
this.isbn.val(datos.isbn);
|
|
this.coleccion.val(datos.coleccion);
|
|
this.referenciaCliente.val(datos.referenciaCliente);
|
|
|
|
this.cliente.setOption(datos.clienteId, datos.clienteNombre);
|
|
this.cliente.setVal(datos.clienteId);
|
|
|
|
if (datos.selectedTirada) {
|
|
this.selectedTirada = datos.selectedTirada;
|
|
}
|
|
$(this.cliente).trigger('change');
|
|
|
|
if (datos.excluirRotativa) {
|
|
this.excluirRotativa.prop('checked', true);
|
|
}
|
|
|
|
this.tirada1.val(parseInt(datos.tirada));
|
|
if (datos.tirada2)
|
|
this.tirada2.val(parseInt(datos.tirada2));
|
|
if (datos.tirada3)
|
|
this.tirada3.val(parseInt(datos.tirada3));
|
|
if (datos.tirada4)
|
|
this.tirada4.val(parseInt(datos.tirada4));
|
|
|
|
if (datos.papelFormatoPersonalizado) {
|
|
this.checkFormatoPersonalizado.prop('checked', true);
|
|
this.formatoEstandar.addClass('d-none');
|
|
this.formatoPersonalizado.removeClass('d-none');
|
|
this.altoPersonalizado.val(datos.papelFormatoAlto);
|
|
this.anchoPersonalizado.val(datos.papelFormatoAncho);
|
|
}
|
|
else {
|
|
this.formatoLibro.setOption(datos.papelFormatoId, datos.papelFormatoNombre);
|
|
this.formatoLibro.setVal(datos.papelFormatoId);
|
|
}
|
|
|
|
this.paginas.val(parseInt(datos.paginas));
|
|
this.paginasNegro.val(parseInt(datos.paginasNegro));
|
|
this.paginasColor.val(parseInt(datos.paginasColor)).trigger('change');
|
|
|
|
this.pagColorConsecutivas.prop('checked', datos.paginasColorConsecutivas);
|
|
if (datos.paginasColorConsecutivas) {
|
|
//this.divPapelDiferente.removeClass('d-none');
|
|
//this.papelDiferente.prop('checked', datos.papelInteriorDiferente).trigger('change');
|
|
}
|
|
this.posPaginasColor.val(datos.posPaginasColor);
|
|
|
|
this.paginasCuadernillo.val(datos.paginasCuadernillo);
|
|
|
|
if (datos.tipo != "") {
|
|
this.tiposLibro.removeClass('selected');
|
|
this.tiposLibro.find('.image-presupuesto').removeClass('selected');
|
|
this.domItem.find('#' + datos.tipo).addClass('selected');
|
|
|
|
if (datos.tipo == 'cosido') {
|
|
this.divPaginasCuaderillo.removeClass('d-none');
|
|
}
|
|
}
|
|
|
|
|
|
if (datos.serviciosExtra) {
|
|
|
|
let serviciosExtra = $('input[type="checkbox"][data-tarifa-tipo="extra"]');
|
|
|
|
$(serviciosExtra).each(function () {
|
|
let tarifaId = $(this).data('tarifa-id') + "";
|
|
|
|
if (datos.serviciosExtra.includes(tarifaId)) {
|
|
$(this).prop('checked', true);
|
|
$(this).trigger('change');
|
|
}
|
|
});
|
|
}
|
|
this.marcapaginas.prop('checked', datos.marcapaginas);
|
|
this.retractilado.prop('checked', datos.retractilado);
|
|
this.retractilado5.prop('checked', datos.retractilado5);
|
|
|
|
this.ivaReducido.val(datos.ivaReducido ? 1 : 0).trigger('change');
|
|
|
|
this.cargando = false;
|
|
}
|
|
|
|
getCliente() {
|
|
if ($(this.excluirRotativa).prop('hidden'))
|
|
return $('#clienteId').val();
|
|
return this.cliente.getVal();
|
|
}
|
|
|
|
getDimensionLibro() {
|
|
|
|
let ancho = 0;
|
|
let alto = 0;
|
|
|
|
if (this.checkFormatoPersonalizado.is(':checked')) {
|
|
ancho = parseFloat(this.anchoPersonalizado.val());
|
|
alto = parseFloat(this.altoPersonalizado.val());
|
|
}
|
|
else {
|
|
if (this.papelFormatoId.val() != null) {
|
|
const selectedText = this.papelFormatoId.find('option:selected').text();
|
|
if (selectedText.length > 0) {
|
|
ancho = parseFloat(selectedText.trim().split(" x ")[0]);
|
|
alto = parseFloat(selectedText.trim().split(" x ")[1]);
|
|
}
|
|
}
|
|
else
|
|
return null;
|
|
}
|
|
return {
|
|
ancho: ancho,
|
|
alto: alto
|
|
}
|
|
}
|
|
|
|
getTiradas() {
|
|
let tiradas = [];
|
|
tiradas.push(parseInt(this.tirada1.val()));
|
|
if (this.tirada2.val().length > 0)
|
|
tiradas.push(parseInt(this.tirada2.val()));
|
|
if (this.tirada3.val().length > 0)
|
|
tiradas.push(parseInt(this.tirada3.val()));
|
|
if (this.tirada4.val().length > 0)
|
|
tiradas.push(parseInt(this.tirada4.val()));
|
|
return tiradas;
|
|
}
|
|
|
|
|
|
getIsColor() {
|
|
if (this.paginasColor.val() > 0) {
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
|
|
#handleFormatoLibro() {
|
|
|
|
if (this.checkFormatoPersonalizado.is(':checked')) {
|
|
this.formatoEstandar.addClass('d-none');
|
|
this.formatoPersonalizado.removeClass('d-none');
|
|
}
|
|
else {
|
|
this.formatoEstandar.removeClass('d-none');
|
|
this.formatoPersonalizado.addClass('d-none');
|
|
}
|
|
const dimensionLibro = this.getDimensionLibro();
|
|
if (dimensionLibro && dimensionLibro.alto) {
|
|
|
|
$('#altoFaja').closest('.config-faja').find('.form-text').text('Entre 50 y ' + dimensionLibro.alto + ' mm');
|
|
}
|
|
}
|
|
|
|
#checkValue(event) {
|
|
let target = event.target;
|
|
if (target.value < target.min) {
|
|
target.value = target.min;
|
|
}
|
|
if (this.validateFormatoLibro()) {
|
|
this.removeError(window.translations["validation"].papelFormatoAncho);
|
|
this.removeError(window.translations["validation"].papelFormatoAlto);
|
|
}
|
|
else {
|
|
this.addErrors();
|
|
}
|
|
}
|
|
|
|
#eventRetractilado(event) {
|
|
let target = event.target;
|
|
if (target.id == 'retractilado') {
|
|
if (this.retractilado5.is(':checked')) {
|
|
this.retractilado5.prop('checked', false);
|
|
}
|
|
}
|
|
else {
|
|
if (this.retractilado.is(':checked')) {
|
|
this.retractilado.prop('checked', false);
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
#handleTipolibro(event) {
|
|
|
|
// Accede al ID del elemento que disparó el evento
|
|
const element = $(event.target);
|
|
|
|
let containers = $('#divTipoLibro').find('.tipo-libro');
|
|
for (let container of containers) {
|
|
if (container != element.closest('.tipo-libro')[0]) {
|
|
$(container).removeClass('selected');
|
|
$(container).find('.image-presupuesto').removeClass('selected');
|
|
}
|
|
}
|
|
|
|
element.closest('.tipo-libro').toggleClass('selected');
|
|
element.closest('.image-presupuesto').toggleClass('selected');
|
|
|
|
if (this.fresado.hasClass('selected') || this.cosido.hasClass('selected')) {
|
|
$('#tapaDuraLomoRedondo').removeClass('d-none');
|
|
if (this.cosido.hasClass('selected')) {
|
|
//$('#tapaDuraLomoRedondo').addClass('selected');
|
|
this.divPaginasCuaderillo.removeClass('d-none');
|
|
}
|
|
else {
|
|
this.divPaginasCuaderillo.addClass('d-none');
|
|
}
|
|
}
|
|
else {
|
|
$('#tapaDuraLomoRedondo').addClass('d-none');
|
|
$('#tapaDuraLomoRedondo').removeClass('selected');
|
|
this.divPaginasCuaderillo.addClass('d-none');
|
|
}
|
|
|
|
if (this.grapado.hasClass('selected') || this.espiral.hasClass('selected') || this.wireo.hasClass('selected')) {
|
|
$('#addSobrecubierta').prop('checked', false).trigger('change');
|
|
$(".sobrecubierta-items").addClass('d-none');
|
|
|
|
if (this.grapado.hasClass('selected')) {
|
|
|
|
$("#tapaBlanda").addClass('selected');
|
|
$("#tapaBlanda").removeClass('d-none');
|
|
$("#tapaDura").addClass('d-none');
|
|
$("#tapaDura").removeClass('selected');
|
|
$("#tapaDuraLomoRedondo").addClass('d-none');
|
|
$("#tapaDuraLomoRedondo").addClass('selected');
|
|
}
|
|
}
|
|
else {
|
|
if ($('#addSobrecubierta').hasClass('d-none')) {
|
|
$('#addSobrecubierta').removeClass('d-none');
|
|
}
|
|
}
|
|
|
|
if (this.validateTipoLibro()) {
|
|
this.removeError(window.translations["validation"].tipo_libro);
|
|
this.removeError(window.translations["validation"].paginas_multiplo_4);
|
|
}
|
|
else {
|
|
this.addErrors();
|
|
}
|
|
|
|
// Para recalcular el presupuesto
|
|
$('.input-paginas').trigger('change');
|
|
}
|
|
|
|
#handlePaginas() {
|
|
|
|
let paginasNegro = this.paginasNegro.val();
|
|
let paginasColor = this.paginasColor.val();
|
|
|
|
if (paginasNegro == '' || isNaN(paginasNegro)) {
|
|
paginasNegro = 0;
|
|
}
|
|
if (paginasColor == '' || isNaN(paginasColor)) {
|
|
paginasColor = 0;
|
|
}
|
|
|
|
let totalPaginas = parseInt(paginasNegro) + parseInt(paginasColor);
|
|
this.paginas.val(totalPaginas);
|
|
|
|
let tipos = [this.domItem.find('#fresado'), this.domItem.find('#cosido')];
|
|
if (totalPaginas < 32) {
|
|
for (let tipo of tipos) {
|
|
tipo.removeClass('selected');
|
|
tipo.find('.image-presupuesto').removeClass('selected');
|
|
|
|
tipo.hide();
|
|
}
|
|
}
|
|
else {
|
|
for (let tipo of tipos) {
|
|
tipo.show();
|
|
}
|
|
}
|
|
|
|
if (totalPaginas < 12 || totalPaginas > 40) {
|
|
this.domItem.find('#grapado').removeClass('selected');
|
|
this.domItem.find('#grapado').find('.image-presupuesto').removeClass('selected');
|
|
this.domItem.find('#grapado').hide();
|
|
}
|
|
else {
|
|
this.domItem.find('#grapado').show();
|
|
}
|
|
|
|
if (totalPaginas < 20) {
|
|
this.domItem.find('#espiral').removeClass('selected');
|
|
this.domItem.find('#espiral').find('.image-presupuesto').removeClass('selected');
|
|
this.domItem.find('#espiral').hide();
|
|
this.domItem.find('#wireo').removeClass('selected');
|
|
this.domItem.find('#wireo').find('.image-presupuesto').removeClass('selected');
|
|
this.domItem.find('#wireo').hide();
|
|
}
|
|
else {
|
|
this.domItem.find('#espiral').show();
|
|
this.domItem.find('#wireo').show();
|
|
}
|
|
|
|
// Se configura dependiento si hay color o no
|
|
const lastLayoutColor = $('#negroEstandar').hasClass('d-none');
|
|
if (paginasColor == 0) {
|
|
|
|
this.#handleInteriorLayout('negro');
|
|
this.divPaginasColorConsecutivas.addClass('d-none');
|
|
this.divPosPaginasColor.addClass('d-none');
|
|
this.posPaginasColor.val("");
|
|
this.pagColorConsecutivas.prop('checked', false);
|
|
|
|
if (lastLayoutColor && !this.cargando) {
|
|
|
|
$('#divPapelInterior').empty();
|
|
$('#divGramajeInterior').empty();
|
|
$('#negroEstandar').trigger('click');
|
|
$(".divTiradasPrecio").empty();
|
|
}
|
|
}
|
|
else {
|
|
if (this.papelDiferente.is(":checked"))
|
|
this.#handleInteriorLayout('mixto');
|
|
else
|
|
this.#handleInteriorLayout('color');
|
|
this.divPaginasColorConsecutivas.removeClass('d-none');
|
|
this.divPosPaginasColor.removeClass('d-none');
|
|
|
|
if (!lastLayoutColor && !this.cargando) {
|
|
|
|
$('#divPapelInterior').empty();
|
|
$('#divGramajeInterior').empty();
|
|
$('#colorEstandar').trigger('click');
|
|
}
|
|
}
|
|
|
|
$('.calcular-lomo').trigger('change');
|
|
if (this.validatePaginas()) {
|
|
this.removeError(window.translations["validation"].paginas);
|
|
this.removeError(window.translations["validation"].paginasColor);
|
|
this.removeError(window.translations["validation"].paginasNegro);
|
|
this.removeError(window.translations["validation"].paginas_pares);
|
|
}
|
|
else {
|
|
this.addErrors();
|
|
}
|
|
}
|
|
|
|
|
|
#handPaginasConsecutivas() {
|
|
if (this.pagColorConsecutivas.is(':checked')) {
|
|
//this.divPapelDiferente.removeClass('d-none');
|
|
}
|
|
else {
|
|
/*this.divPapelDiferente.addClass('d-none');
|
|
this.papelDiferente.prop('checked', false);*/
|
|
}
|
|
}
|
|
|
|
|
|
#handlePapelDiferente() {
|
|
if (this.papelDiferente.is(':checked')) {
|
|
$(".papel-interior").removeClass('selected');
|
|
$(".interior-color").removeClass('d-none');
|
|
this.#handleInteriorLayout('mixto');
|
|
$("#divPapelInterior").empty();
|
|
$("#divGramajeInterior").empty();
|
|
$("#divPapelInteriorColor").empty();
|
|
$("#divGramajeInteriorColor").empty();
|
|
}
|
|
else {
|
|
$(".interior-color").addClass('d-none');
|
|
$("#divPapelInterior").empty();
|
|
$("#divGramajeInterior").empty();
|
|
$("#divPapelInteriorColor").empty();
|
|
$("#divGramajeInteriorColor").empty();
|
|
this.#handlePaginas();
|
|
}
|
|
}
|
|
|
|
|
|
#handleInteriorLayout(layout) {
|
|
switch (layout) {
|
|
case 'negro':
|
|
case 'mixto':
|
|
$('#negroEstandar').removeClass('d-none');
|
|
$('#negroPremium').removeClass('d-none');
|
|
$('#colorEstandar').addClass('d-none');
|
|
$('#colorPremium').addClass('d-none');
|
|
break;
|
|
case 'color':
|
|
$('#negroEstandar').addClass('d-none');
|
|
$('#negroPremium').addClass('d-none');
|
|
$('#colorEstandar').removeClass('d-none');
|
|
$('#colorPremium').removeClass('d-none');
|
|
break;
|
|
default:
|
|
break;
|
|
}
|
|
}
|
|
|
|
#handleCheckFormatoPersonalizado() {
|
|
|
|
const minAncho = this.anchoPersonalizado.min;
|
|
const minAlto = this.altoPersonalizado.min;
|
|
|
|
if (this.anchoPersonalizado.val() < minAncho || this.anchoPersonalizado.val() == '' || isNaN(this.anchoPersonalizado.val())) {
|
|
this.anchoPersonalizado.val(minAncho);
|
|
}
|
|
|
|
if (this.altoPersonalizado.val() < minAlto || this.altoPersonalizado.val() == '' || isNaN(this.altoPersonalizado.val())) {
|
|
this.altoPersonalizado.val(minAlto);
|
|
}
|
|
}
|
|
|
|
getServiciosExtra() {
|
|
|
|
let serviciosExtra = $('input[type="checkbox"][data-tarifa-tipo="extra"]:checked');
|
|
|
|
if (serviciosExtra.length === 0) {
|
|
return [];
|
|
}
|
|
|
|
let servicios = [];
|
|
|
|
$(serviciosExtra).each(function () {
|
|
let tarifaId = $(this).data('tarifa-id');
|
|
if (tarifaId) {
|
|
servicios.push(tarifaId);
|
|
}
|
|
});
|
|
|
|
return servicios;
|
|
}
|
|
|
|
removeError(error) {
|
|
const hasError = this.errores.filter(err => err === error).length > 0;
|
|
if (hasError) {
|
|
// remove the item from this.errores
|
|
this.errores = this.errores.filter(err => err !== error);
|
|
}
|
|
if (this.errores.length == 0) {
|
|
document.getElementById('sk-alert').innerHTML = '';
|
|
}
|
|
else {
|
|
document.getElementById('sk-alert').innerHTML = document.getElementById('sk-alert').innerHTML
|
|
.replace(`<li>${error}</li>`, '').replace(error, '');
|
|
}
|
|
}
|
|
|
|
addErrors() {
|
|
|
|
const skAlert = document.getElementById('sk-alert');
|
|
skAlert.innerHTML = '';
|
|
this.errores = [...new Set(this.errores)];
|
|
|
|
if (this.errores.length > 0) {
|
|
const message = window.translations["validation"].fix_errors +
|
|
`<ul class="mb-0">
|
|
${this.errores.map(err => `<li>${err}</li>`).join('')}
|
|
</ul>`;
|
|
popErrorAlert(message, 'sk-alert', false);
|
|
}
|
|
else {
|
|
skAlert.innerHTML = '';
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
export default DatosGenerales; |