trabajando en el backend

This commit is contained in:
2024-10-13 21:10:02 +02:00
parent e64022a7b7
commit 0eaac5af28
32 changed files with 1196 additions and 4746 deletions

View File

@ -6,6 +6,7 @@ class Ajax{
this.success = success;
this.error = error;
this.type = type;
this.jqXHR = null;
}
post(){
(this.type == 'default') ? this.ajax('POST'): this.ajaxForm('POST');
@ -19,8 +20,21 @@ class Ajax{
delete(){
(this.type == 'default') ? this.ajax('DELETE'): this.ajaxForm('DELETE');
}
abort() {
if (this.jqXHR) {
this.jqXHR.abort();
this.jqXHR = null; // Limpiamos la referencia a la petición
}
}
setData(data){
this.data = data;
}
ajax(method){
$.ajax({
if (this.jqXHR) {
this.jqXHR.abort();
}
this.jqXHR = $.ajax({
url : this.url,
type : method,
data: this.data,
@ -30,7 +44,11 @@ class Ajax{
})
}
ajaxForm(method){
$.ajax({
if (this.jqXHR) {
this.jqXHR.abort();
}
this.jqXHR = $.ajax({
url : this.url,
type : method,
data: this.data,

View File

@ -44,11 +44,6 @@ class ClassSelect2 {
}
});
}
setParams(params) {
this.params = params;
}
// Método para obtener el valor seleccionado
getValue() {
return this.domItem.val();
@ -59,6 +54,10 @@ class ClassSelect2 {
this.domItem.val(value).trigger('change');
}
setParams(params) {
this.params = params;
}
clear() {
this.domItem.val(null).trigger('change');
}

View File

@ -20,19 +20,18 @@ class tarjetaDireccion {
var $label = $('<label>', { class: 'form-check-label custom-option-content' });
var $header = $('<span>', { class: 'custom-option-header mb-2' });
var $name = $('<h6>', { class: 'fw-semibold mb-0', text: direccion.nombre });
var $name = $('<h6>', { class: 'fw-semibold mb-0', text: direccion.att });
var $unidades = $('<span>', { class: 'badge bg-label-primary unidades', text: direccion.unidades + ' unidades' });
var $body = $('<span>', { class: 'custom-option-body' });
var $direccion = $('<small>', { class: 'address-direccion', text: direccion.direccion });
var $cp = $('<small>', { class: 'address-cp', text: direccion.cp });
var $municipioPais = $('<small>', { class: 'address-municipio-pais', text: direccion.municipioPais });
var $municipioPais = $('<small>', { class: 'address-municipio-pais', text: direccion.municipio + ', '+ direccion.pais });
var $telefono = $('<small>', { class: 'address-telefono', text: direccion.telefono });
var $email = $('<small>', { class: 'address-email', text: direccion.email });
var $palets = $('<small>', {class: 'address-palets', html: '<i>Envío en palets</i>'});
if (!direccion.palets) $palets.addClass('d-none');
var $hr = $('<hr>', { class: 'my-2' });
var $eliminar = $('<a>', { class: 'ms-auto direccion-eliminar', href: 'javascript:void(0)', text: 'Eliminar' });
var $editar = $('<a>', { class: 'me-auto direccion-editar', href: 'javascript:void(0)', text: 'Editar' });
@ -64,6 +63,18 @@ class tarjetaDireccion {
}
setEntregaPalets(palets) {
this.card.find('.address-palets').toggleClass('d-none', !palets);
}
getEntregaPalets() {
return !this.card.find('.address-palets').hasClass('d-none');
}
setUnidades(unidades) {
this.card.find('.unidades').text(unidades + ' unidades');
}
getUnidades() {
return this.card.find('.unidades').text().split(' ')[0];
}

View File

@ -14,6 +14,12 @@ class DatosGenerales {
this.titulo = this.domItem.find("#titulo");
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.anchoPersonalizado = this.domItem.find("#papelFormatoAncho");
@ -27,6 +33,8 @@ class DatosGenerales {
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");
@ -34,6 +42,10 @@ class DatosGenerales {
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.initValidation();
}
@ -44,6 +56,9 @@ class DatosGenerales {
this.formatoLibro.init();
this.cliente.init();
// Inicializa el tipo de impresion
this.#handlePaginas();
// Eventos
this.checkFormatoPersonalizado.bind('change', this.#handleFormatoLibro.bind(this));
this.tiposLibro.on('click', this.#handleTipolibro.bind(this));
@ -318,6 +333,52 @@ class DatosGenerales {
});
}
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 && parseInt(this.tirada2.val()) > 0)
tiradas.push(parseInt(this.tirada2.val()));
if (this.tirada3.val().length > 0 && parseInt(this.tirada3.val()) > 0)
tiradas.push(parseInt(this.tirada3.val()));
if (this.tirada4.val().length > 0 && parseInt(this.tirada4.val()) > 0)
tiradas.push(parseInt(this.tirada4.val()));
return tiradas;
}
getIsColor() {
if(this.paginasColor.val() > 0) {
return true;
}
return false;
}
#handleFormatoLibro() {
@ -351,11 +412,22 @@ class DatosGenerales {
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');
}
// Para recalcular el presupuesto
element.trigger('change');
}
#handlePaginas() {
@ -431,8 +503,10 @@ class DatosGenerales {
#handlePapelDiferente() {
if (this.papelDiferente.is(':checked')) {
$(".papel-interior").removeClass('selected');
$(".interior-color").removeClass('d-none');
this.#handleInteriorLayout('mixto');
}
else {
$(".interior-color").addClass('d-none');

View File

@ -1,4 +1,5 @@
import ClassSelect from '../../components/select2.js';
import Ajax from '../../components/ajax.js';
import tarjetaDireccion from '../../components/tarjetaDireccionPresupuesto.js';
class Direcciones {
@ -9,6 +10,10 @@ class Direcciones {
this.wizardStep = wizardForm.querySelector('#direcciones-libro');
this.validatorStepper = validatorStepper;
this.unidadesAdd = this.domItem.find('#unidadesEnvio');
this.btnAdd = this.domItem.find('#insertarDireccion');
this.entregaPieCallero = this.domItem.find('#entregaPieCalle');
this.direccionesCliente = new ClassSelect($("#direcciones"), '/clientedirecciones/menuitems');
this.divDirecciones = $(this.domItem.find('#divDirecciones'));
@ -24,16 +29,8 @@ class Direcciones {
$("#clienteId").on('change', this.#handleChangeCliente.bind(this));
let direccion = {
nombre: 'Casa',
unidades: '100',
direccion: 'Calle de la Prueba, 12',
cp: '28000',
municipioPais: 'Madrid, España',
telefono: '912345678',
email: 'aaa@aa.com',
palets: false,
}
this.direccionesCliente.init();
this.btnAdd.on('click', this.#insertDireccion.bind(this));
}
@ -70,24 +67,60 @@ class Direcciones {
});
}
#insertDireccion(direccion_id) {
let tarjeta = new tarjetaDireccion();
tarjeta.setDireccion(direccion);
tarjeta.card.find('.direccion-editar').on('click', this.#editUnits.bind(this));
tarjeta.card.find('.direccion-eliminar').on('click', this.#deleteDireccion.bind(this));
this.divDirecciones.append(tarjeta.card);
this.direcciones.push(direccion);
#insertDireccion() {
self = this;
try {
let id = this.direccionesCliente.getValue();
let unidades = this.unidadesAdd.val();
let entregaPalets = this.entregaPieCallero.is(':checked');
let dirId = "dirEnvio-1";
let direccionesActuales = this.divDirecciones.find('.direccion-cliente');
if (direccionesActuales.length > 0) {
// the the lass item
let last = direccionesActuales[direccionesActuales.length - 1];
dirId = "dirEnvio-" + (parseInt(last.id.split('-')[1]) + 1);
}
if (id == null || id <= 0 || id == undefined)
return;
if (unidades == null || unidades <= 0 || unidades == undefined)
return;
$('#loader').show();
let peticion = new Ajax('/misdirecciones/get/' + id, {}, {},
(response) => {
let tarjeta = new tarjetaDireccion(this.divDirecciones, dirId, response.data[0]);
tarjeta.setUnidades(unidades);
tarjeta.setEntregaPalets(entregaPalets);
tarjeta.card.find('.direccion-editar').on('click', this.#editUnits.bind(self));
tarjeta.card.find('.direccion-eliminar').on('click', this.#deleteDireccion.bind(self));
this.divDirecciones.append(tarjeta.card);
this.direcciones.push({ "id": dirId, "unidades": unidades, "enPallets": entregaPalets, "direccion": response.data[0] });
self.divDirecciones.trigger('change');
$('#loader').hide();
},
() => {
console.error('Error getting address');
$('#loader').hide();
});
peticion.get();
} catch (e) {
console.error(e);
$('#loader').hide();
}
}
#handleChangeCliente() {
this.direccionesCliente.setParams({ 'cliente_id': $("#clienteId").select2('data')[0].id })
this.direccionesCliente.clear();
this.domItem.find('.direccion-cliente').remove();
this.direcciones = [];
}
@ -103,12 +136,13 @@ class Direcciones {
modal.modal('show');
modal.find('.btn-primary').off('click');
modal.find('.btn-primary').on('click', function () {
modal.find('.btn-primary').on('click', () => {
try {
let nuevo_valor = parseInt(modal.find('.modal-body input').val());
if (nuevo_valor > 0) {
tarjeta.find('.unidades').text(nuevo_valor + ' unidades');
this.divDirecciones.trigger('change');
}
} catch (error) {
console.error('Units must be a number');
@ -123,7 +157,8 @@ class Direcciones {
let id = tarjeta.id;
tarjeta.remove();
this.divDirecciones.trigger('change');
this.direcciones = this.direcciones.filter(direccion => direccion.id != id);
}
}

View File

@ -11,8 +11,11 @@ class DisenioCubierta {
this.papelCubierta = this.domItem.find(".papel-cubierta");
this.divSolapas = this.domItem.find("#divSolapasCubierta");
this.divCarasImpresion = this.domItem.find("#divCarasImpresion");
this.divConfigTapaDura = 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");
@ -26,6 +29,7 @@ class DisenioCubierta {
this.estucadoMate = this.domItem.find("#estucadoMate");
this.divGramajeCubierta = this.domItem.find("#divGramajeCubierta");
this.gramaje = this.domItem.find(".check-gramaje-cubierta");
this.gramaje170 = $(this.domItem.find("#divGramaje170Cubierta"));
this.gramaje250 = $(this.domItem.find("#divGramaje250Cubierta"));
this.gramaje270 = $(this.domItem.find("#divGramaje270Cubierta"));
@ -37,7 +41,7 @@ class DisenioCubierta {
this.configuracionSobrecubierta = this.domItem.find(".config-sobrecubierta");
this.sobrecubierta = this.domItem.find("#addSobrecubierta");
this.configuracionFaja = this.domItem.find(".config-faja");
this.faja = this.domItem.find("#addFaja");
this.faja = this.domItem.find("#addFaja");
this.solapasSobrecubierta = this.domItem.find("#solapasSobrecubierta");
this.solapasFaja = this.domItem.find("#solapasFaja");
@ -79,11 +83,15 @@ class DisenioCubierta {
this.solapasSobrecubierta.on('blur', this.#handleInputs);
this.solapasFaja.on('blur', this.#handleInputs);
this.sobrecubierta.on('change', () => {
this.sobrecubierta.is(":checked") ? this.configuracionSobrecubierta.removeClass("d-none") : this.configuracionSobrecubierta.addClass("d-none") }
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") }
this.faja.is(":checked") ? this.configuracionFaja.removeClass("d-none") : this.configuracionFaja.addClass("d-none")
}
);
@ -97,7 +105,7 @@ class DisenioCubierta {
this.observer.observe(this.sinSolapas[0], { attributes: true });
this.checksGramaje.each(function () {
const customOptionEL = $(this);
customOptionEL.on('click', function () {
self.#handleClickGramaje(customOptionEL);
@ -139,7 +147,7 @@ class DisenioCubierta {
validators: {
callback: {
callback: function (input) {
const div = $('#divSolapasCubierta');
const div = $('#divSolapasCubierta');
if (div.hasClass("d-none")) return true;
div.find('.fv-plugins-message-container').remove();
@ -164,7 +172,7 @@ class DisenioCubierta {
validators: {
callback: {
callback: function (input) {
const div = $('#divPapelCubierta');
const div = $('#divPapelCubierta');
if (div.hasClass("d-none")) return true;
div.find('.fv-plugins-message-container').remove();
@ -190,7 +198,7 @@ class DisenioCubierta {
callback: {
callback: function (input) {
const div = $('#divGramajeCubierta'); // Selecciona el div
div.find('.fv-plugins-message-container').remove();
if ($('.check-gramaje-cubierta:checked').length > 0) {
return true;
@ -239,6 +247,159 @@ class DisenioCubierta {
}
getSolapasCubierta() {
try {
if (this.solapasCubierta.hasClass("selected").length == 0)
return null;
else {
if (this.solapasCubierta.hasClass("selected").attr("id") == "solapasCubiertaNo")
return false;
else
parseInt(this.tamanioSolapasCubierta.val());
}
}
catch (error) {
return null;
}
}
getPapel() {
try {
if (this.papelCubierta.filter('.selected').length > 0) {
return this.papelCubierta.filter('.selected').attr('cod');
}
return null;
}
catch (e) {
return null;
}
}
getGramaje() {
try {
if(this.divGramajeCubierta.hasClass("d-none"))
return null;
if (this.gramaje.filter(':checked').length > 0)
return this.gramaje.filter(':checked').attr('data-value');
else
return null;
} catch (e) {
return null;
}
}
getAcabados() {
try {
let acabados = {};
acabados.plastificado = this.domItem.find("#plastificado ").children("option:selected").val();
acabados.barniz = this.domItem.find("#barniz").children("option:selected").val();
acabados.estampado = this.domItem.find("#estampado").children("option:selected").val();
acabados.retractilado = this.domItem.find("#retractilado").hasClass('selected') ? true : false;
return acabados;
} catch (e) {
return null;
}
}
getCabezada() {
try {
if (this.tapaBlanda.hasClass("selected"))
return false;
else
return this.domItem.find("#cabezada").children("option:selected").val();
} catch (e) {
return null;
}
}
getGuardas() {
try {
if (this.tapaBlanda.hasClass("selected")) {
return false;
}
else {
let guardas = {};
let papelGuardas = this.domItem.find("#papelGuardas").children("option:selected").val();
guardas.papel = papelGuardas.split('_')[0];
guardas.gramaje = papelGuardas.split('_')[1];
guardas.guardasImpresas = this.domItem.find("#guardasImpresas").children("option:selected").val();
return guardas;
}
} catch (e) {
return null;
}
}
getSobrecubierta() {
try {
if (!this.sobrecubierta.is(":checked")) {
return false;
}
else {
let sobrecubierta = {};
let papel = this.domItem.find("#papelSobrecubierta").children("option:selected").val();
sobrecubierta.papel = papel.split('_')[0];
sobrecubierta.gramaje = papel.split('_')[1];
sobrecubierta.solapas = this.domItem.find("#solapasSobrecubierta").val();
sobrecubierta.plastificado = this.domItem.find("#plastificadoSobrecubierta").children("option:selected").val();
return sobrecubierta;
}
} catch (e) {
return null;
}
}
getFaja() {
try {
if (!this.faja.is(":checked")) {
return false;
}
else {
let faja = {};
faja.alto = this.domItem.find("#altoFaja").val();
let papel = this.domItem.find("#papelFaja").children("option:selected").val();
faja.papel = papel.split('_')[0];
faja.gramaje = papel.split('_')[1];
faja.solapas = this.domItem.find("#solapasFaja").val();
faja.plastificado = this.domItem.find("#plastificadoFaja").children("option:selected").val();
return faja;
}
} catch (e) {
return null;
}
}
#handleCarasCubierta(){
// Si es a dos caras
if(this.carasCubierta.val() == 4){
this.cartulinaEstucada.addClass("d-none");
}
else{
this.cartulinaEstucada.removeClass("d-none");
}
}
#handleDisenioCubierta(event) {
// Accede al ID del elemento que disparó el evento
const element = $(event.target);
@ -259,7 +420,9 @@ class DisenioCubierta {
$(".papel-cubierta").removeClass("selected");
if (this.tapaBlanda.hasClass("selected")) {
this.cartulinaEstucada.removeClass("d-none");
if(this.carasCubierta.val() == 2){
this.cartulinaEstucada.removeClass("d-none");
}
this.divGramajeCubierta.addClass("d-none");
}
else {
@ -273,6 +436,8 @@ class DisenioCubierta {
this.gramaje300.addClass("d-none");
this.gramaje350.addClass("d-none");
}
element.trigger('change');
}
@ -292,6 +457,8 @@ class DisenioCubierta {
element.closest(class2Find).toggleClass('selected');
element.closest('.image-presupuesto').toggleClass('selected');
element.trigger('change');
}
@ -311,23 +478,28 @@ class DisenioCubierta {
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.divConfigTapaDura.addClass("d-none");
}
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.divConfigTapaDura.removeClass("d-none");
this.#handleMenuPapel();
}
else {
this.divSolapas.addClass("d-none");
this.divCarasImpresion.addClass("d-none");
this.divConfigTapaDura.addClass("d-none");
this.#handleMenuPapel();
}
@ -348,7 +520,7 @@ class DisenioCubierta {
$(".check-gramaje-cubierta").prop("checked", false);
if(!this.tapaBlanda.hasClass("selected") && !this.tapaDuraLomoRecto.hasClass("selected") && !this.tapaDuraLomoRedondo.hasClass("selected")) {
if (!this.tapaBlanda.hasClass("selected") && !this.tapaDuraLomoRecto.hasClass("selected") && !this.tapaDuraLomoRedondo.hasClass("selected")) {
this.divGramajeCubierta.addClass("d-none");
this.estucadoMate.removeClass("selected");
this.cartulinaEstucada.removeClass("selected");
@ -363,8 +535,8 @@ class DisenioCubierta {
this.gramaje300.removeClass("d-none");
this.gramaje350.removeClass("d-none");
}
else if(this.estucadoMate.hasClass("selected")) {
if(this.tapaBlanda.hasClass("selected")) {
else if (this.estucadoMate.hasClass("selected")) {
if (this.tapaBlanda.hasClass("selected")) {
this.divGramajeCubierta.removeClass("d-none");
this.gramaje170.addClass("d-none");
this.gramaje250.removeClass("d-none");
@ -372,7 +544,7 @@ class DisenioCubierta {
this.gramaje300.removeClass("d-none");
this.gramaje350.removeClass("d-none");
}
else{
else {
this.divGramajeCubierta.removeClass("d-none");
this.gramaje170.removeClass("d-none");
this.gramaje250.addClass("d-none");

View File

@ -19,6 +19,7 @@ class DisenioInterior {
this.offsetAhuesadoVolumen = this.domItem.find("#offsetAhuesadoVolumen");
this.estucadoMate = this.domItem.find("#estucadoMate");
this.gramaje = this.domItem.find(".check-interior-gramaje");
this.gramaje70 = this.domItem.find("#interiorGramaje70");
this.gramaje80 = this.domItem.find("#interiorGramaje80");
this.gramaje90 = this.domItem.find("#interiorGramaje90");
@ -29,6 +30,7 @@ class DisenioInterior {
this.gramaje150 = this.domItem.find("#interiorGramaje150");
this.gramaje170 = this.domItem.find("#interiorGramaje170");
this.interiorColor = this.domItem.find(".interior-color");
this.disenioInterior_color = this.domItem.find(".disenio-interior-color");
this.papelInterior_color = this.domItem.find(".papel-interior-color");
@ -40,6 +42,7 @@ class DisenioInterior {
this.offsetAhuesadoVolumen_color = this.domItem.find("#offsetAhuesadoVolumenColor");
this.estucadoMate_color = this.domItem.find("#estucadoMateColor");
this.gramaje_color = this.domItem.find(".check-interior-color-gramaje");
this.gramaje70_color = this.domItem.find("#interiorGramaje70Color");
this.gramaje80_color = this.domItem.find("#interiorGramaje80Color");
this.gramaje90_color = this.domItem.find("#interiorGramaje90Color");
@ -96,7 +99,7 @@ class DisenioInterior {
this.observer.observe(this.estucadoMate_color[0], { attributes: true });
this.checksGramaje.each(function () {
const customOptionEL = $(this);
customOptionEL.on('click', function () {
self.#handleClickGramaje(customOptionEL);
@ -291,6 +294,76 @@ class DisenioInterior {
}
getIsHq() {
try {
if (this.interiorColor.filter('.d-none').length > 0) {
return this.disenioInterior.filter('.selected').attr('id').includes('Premium');
}
else if (this.disenioInterior_color.filter('.selected').length > 0) {
return {
negro: this.disenioInterior.filter('.selected').attr('id').includes('Premium'),
color: this.disenioInterior_color.filter('.selected').attr('id').includes('Premium')
}
}
return null;
} catch (e) {
return null;
}
}
getPapel() {
try {
if (this.papelInterior.filter('.selected').length > 0) {
if (this.papelInterior_color.filter('.selected').length > 0) {
return {
negro: this.papelInterior.filter('.selected').attr('cod'),
color: this.papelInterior_color.filter('.selected').attr('cod')
}
}
if (this.interiorColor.filter('.d-none').length > 0)
return this.papelInterior.filter('.selected').attr('cod')
else
return null;
}
return null;
}
catch (e) {
return null;
}
}
getGramaje() {
try {
if (this.interiorColor.filter('.d-none').length == 0){
let values = {
negro: this.gramaje.filter(':checked') .attr('data-value'),
color: this.gramaje_color.filter(':checked').attr('data-value')
}
if (values.negro && values.color) {
return values;
}
else return null;
}
else{
return this.gramaje.filter(':checked').attr('data-value');
}
} catch (e) {
return null;
}
}
#handleClickGramaje(customOption) {
const el = customOption[0];
@ -328,6 +401,9 @@ class DisenioInterior {
element.closest(class2Find).toggleClass('selected');
element.closest('.image-presupuesto').toggleClass('selected');
// Para recalcular el presupuesto
element.trigger('change');
}
@ -358,6 +434,9 @@ class DisenioInterior {
$('#tapaDuraLomoRedondo').removeClass('d-none');
}
}
// Para recalcular el presupuesto
element.trigger('change');
}
#handleUpdateGramaje() {
@ -366,7 +445,7 @@ class DisenioInterior {
$(".check-interior-gramaje ").prop("checked", false);
$(".check-interior-color-gramaje ").prop("checked", false);
if (this.negroEstandar.hasClass("selected") || this.colorEstandar.hasClass("selected")) {
if (this.offsetBlanco.hasClass("selected")) {

View File

@ -4,6 +4,9 @@ import DisenioCubierta from './disenioCubierta.js';
import Direcciones from './direcciones.js';
import Ajax from '../../components/ajax.js';
import tarjetaTiradasPrecio from './tarjetaTiradasPrecio.js';
class PresupuestoCliente {
constructor() {
@ -23,6 +26,12 @@ class PresupuestoCliente {
this.disenioInterior = new DisenioInterior($("#interior-libro"), this.clientePresupuestoWizard, this.validationStepper);
this.disenioCubierta = new DisenioCubierta($("#cubierta-libro"), this.clientePresupuestoWizard, this.validationStepper);
this.direcciones = new Direcciones($("#direcciones-libro"), this.clientePresupuestoWizard, this.validationStepper);
this.datos = {};
this.ajax_calcular = new Ajax('/presupuestocliente/calcular',
{}, this.datos,
this.#procesarPresupuesto,
() => { $('#loader').hide(); console.log("Error") });
}
@ -31,6 +40,8 @@ class PresupuestoCliente {
this.btnNext.on('click', this.#nextStep.bind(this));
this.btnPrev.on('click', this.#prevtStep.bind(this));
$(".calcular-presupuesto").on('change', this.checkForm.bind(this));
// Fuerza el foco en el campo de búsqueda de select2
$(document).on('select2:open', () => {
document.querySelector('.select2-search__field').focus();
@ -48,6 +59,29 @@ class PresupuestoCliente {
}
checkForm() {
this.#getDatos();
if (Object.values(this.datos).every(this.#isValidDataForm)) {
try {
$('#loader').show();
// Si se está ejecutando la petición, abortar la petición anterior
this.ajax_calcular.abort();
this.ajax_calcular.setData(this.datos);
this.ajax_calcular.post();
}
catch (e) {
console.log(e);
$('#loader').hide();
}
}
}
RELLENAR_PRESUPUESTO() {
$("#titulo").val("Titulo del libro");
@ -58,7 +92,7 @@ class PresupuestoCliente {
clienteId.append(newOption).trigger('change');
const papelFormatoId = $("#papelFormatoId");
const newOption2 = new Option("Formato 1", "1", true, true);
const newOption2 = new Option("148 x 210", "1", true, true);
papelFormatoId.append(newOption2).trigger('change');
$("#paginasColor").val("6");
@ -66,18 +100,33 @@ class PresupuestoCliente {
$("#fresado").trigger("click");
$("#colorEstandar").trigger("click");
$("#offsetBlanco").trigger("click");
setTimeout(function() {
$("#offsetBlanco").trigger("click");
setTimeout(function () {
$("#gramaje80").trigger("click");
}, 0);
setTimeout(function() {
setTimeout(function () {
$("#tapaDura").trigger("click");
}, 0);
}, 0);
/*
setTimeout(function () {
$("#btnNext").trigger("click");
}, 0);
setTimeout(function () {
$("#btnNext").trigger("click");
}, 0);
setTimeout(function () {
$("#btnNext").trigger("click");
}, 0);
setTimeout(function () {
$("#unidadesEnvio").val("100");
}, 0);*/
}
@ -102,6 +151,14 @@ class PresupuestoCliente {
}
#procesarPresupuesto(response) {
$('#loader').hide();
console.log("Success");
console.log(response);
}
#nextStep() {
switch (this.validationStepper._currentIndex) {
@ -112,27 +169,113 @@ class PresupuestoCliente {
case 1:
this.disenioInterior.formValidation.validate();
break;
case 2:
this.disenioCubierta.formValidation.validate();
break;
/*
case 3:
FormValidation5.validate();
this.direcciones.formValidation.validate();
break;
*/
default:
break;
}
}
#prevtStep() {
if(this.validationStepper._currentIndex >= 1 && this.validationStepper._currentIndex <= 4)
if (this.validationStepper._currentIndex >= 1 && this.validationStepper._currentIndex <= 4)
this.validationStepper.previous();
}
#getDatos() {
this.datos = {
clienteId: this.datosGenerales.cliente.getValue(),
tamanio: this.datosGenerales.getDimensionLibro(),
tirada: this.datosGenerales.getTiradas(),
paginas: this.datosGenerales.paginas.val(),
paginasColor: this.datosGenerales.paginasColor.val(),
tipo: this.datosGenerales.tiposLibro.filter('.selected').attr('id'),
isColor: this.datosGenerales.getIsColor(),
isHq: this.disenioInterior.getIsHq(),
interior: {
papelInterior: this.disenioInterior.getPapel(),
gramajeInterior: this.disenioInterior.getGramaje(),
},
cubierta: {
tipoCubierta: this.disenioCubierta.disenioCubierta.filter('.selected').attr('id'),
papelCubierta: this.disenioCubierta.getPapel(),
gramajeCubierta: this.disenioCubierta.getGramaje(),
cabezada: this.disenioCubierta.getCabezada(),
acabados: this.disenioCubierta.getAcabados(),
carasImpresion: this.disenioCubierta.carasCubierta.val(),
},
guardas: this.disenioCubierta.getGuardas(),
sobrecubierta: this.disenioCubierta.getSobrecubierta(),
faja: this.disenioCubierta.getFaja(),
excluirRotativa: this.datosGenerales.excluirRotativa.is(':checked'),
ivaReducido: this.datosGenerales.ivaReducido.find('option:selected').val(),
servicios: {
'prototipo' : this.datosGenerales.servicios.prototipo.is(':checked'),
},
};
if(this.datos.tipo == "cosido"){
this.datos.paginasCuadernillo = this.datosGenerales.paginasCuadernillo.val();
}
let solapasCubierta = this.disenioCubierta.getSolapasCubierta();
if (solapasCubierta !== null && solapasCubierta !== undefined) {
if (solapasCubierta === false)
this.datos.cubierta.solapas = false;
else {
this.datos.cubierta.solapas = true;
this.datos.cubierta.tamanioSolapas = solapasCubierta;
}
}
else{
this.datos.cubierta.solapas = false;
}
}
#isValidDataForm(value) {
if (value === null || value === undefined || value === '') {
return false;
}
if (typeof value === 'object' && value !== null) {
return Object.values(value).every(isValid);
}
return true;
}
}
function isValid(value) {
if (value === null || value === undefined || value === '') {
return false;
}
if (typeof value === 'object' && value !== null) {
return Object.values(value).every(isValid);
}
return true;
}
function initialize(translations) {
window.translations = JSON.parse(translations);

View File

@ -0,0 +1,60 @@
class tarjetaTiradasPrecio {
constructor(domItem, id, tirada, precio, precio_unidad) {
this.domItem = domItem;
this.id = id;
this.tirada = tirada;
this.precio = precio;
this.precio_unidad = precio_unidad;
this.card = this.#generateHTML(id, tirada, precio, precio_unidad);
this.domItem.append(this.card);
}
#generateHTML(id, tirada, precio, precio_unidad) {
let $html = $('<div>', {
id: id,
class: 'list-group'
});
let $link = $('<a>', {
href: 'javascript:void(0);',
class: 'list-group-item list-group-item-action'
});
let $liWrapper = $('<div>', {
class: 'li-wrapper d-flex justify-content-start align-items-center'
});
let $listContent = $('<div>', {
class: 'list-content'
});
$listContent.append($('<h7>', {
id: 'ud_' + id,
class: 'mb-1',
text: tirada + ' ud.'
}));
$listContent.append($('<h6>', {
id: 'tot_' + id,
class: 'mb-1',
text: 'Total: ' + precio + '€'
}));
$listContent.append($('<h7>', {
id: 'pu_' + id,
class: 'mb-1',
text: precio_unidad + '€/ud'
}));
$liWrapper.append($listContent);
$link.append($liWrapper);
$html.append($link);
return $html;
}
}
export default tarjetaTiradasPrecio;