trabajando en la vista del carro de la compra

This commit is contained in:
2025-10-14 21:52:25 +02:00
parent a33ba3256b
commit 9f33db4055
12 changed files with 528 additions and 76 deletions

View File

@ -49,9 +49,118 @@
location.replace(url); // alinea y no deja historial extra
}
if (document.getElementById("topnav-hamburger-icon")) {
document.getElementById("topnav-hamburger-icon").addEventListener("click", toggleHamburgerMenu);
}
window.addEventListener("resize", windowResizeHover);
windowResizeHover();
initsAlert();
}
function windowResizeHover() {
feather.replace();
var windowSize = document.documentElement.clientWidth;
if (windowSize < 1025 && windowSize > 767) {
document.body.classList.remove("twocolumn-panel");
if (sessionStorage.getItem("data-layout") == "twocolumn") {
document.documentElement.setAttribute("data-layout", "twocolumn");
if (document.getElementById("customizer-layout03")) {
document.getElementById("customizer-layout03").click();
}
twoColumnMenuGenerate();
initTwoColumnActiveMenu();
isCollapseMenu();
}
if (sessionStorage.getItem("data-layout") == "vertical") {
document.documentElement.setAttribute("data-sidebar-size", "sm");
}
if (document.querySelector(".hamburger-icon")) {
document.querySelector(".hamburger-icon").classList.add("open");
}
} else if (windowSize >= 1025) {
document.body.classList.remove("twocolumn-panel");
if (sessionStorage.getItem("data-layout") == "twocolumn") {
document.documentElement.setAttribute("data-layout", "twocolumn");
if (document.getElementById("customizer-layout03")) {
document.getElementById("customizer-layout03").click();
}
twoColumnMenuGenerate();
initTwoColumnActiveMenu();
isCollapseMenu();
}
if (sessionStorage.getItem("data-layout") == "vertical") {
document.documentElement.setAttribute(
"data-sidebar-size",
sessionStorage.getItem("data-sidebar-size")
);
}
if (document.querySelector(".hamburger-icon")) {
document.querySelector(".hamburger-icon").classList.remove("open");
}
} else if (windowSize <= 767) {
document.body.classList.remove("vertical-sidebar-enable");
document.body.classList.add("twocolumn-panel");
if (sessionStorage.getItem("data-layout") == "twocolumn") {
document.documentElement.setAttribute("data-layout", "vertical");
hideShowLayoutOptions("vertical");
isCollapseMenu();
}
if (sessionStorage.getItem("data-layout") != "horizontal") {
document.documentElement.setAttribute("data-sidebar-size", "lg");
}
if (document.querySelector(".hamburger-icon")) {
document.querySelector(".hamburger-icon").classList.add("open");
}
}
var isElement = document.querySelectorAll("#navbar-nav > li.nav-item");
Array.from(isElement).forEach(function (item) {
item.addEventListener("click", menuItem.bind(this), false);
item.addEventListener("mouseover", menuItem.bind(this), false);
});
}
function menuItem(e) {
if (e.target && e.target.matches("a.nav-link span")) {
if (elementInViewport(e.target.parentElement.nextElementSibling) == false) {
e.target.parentElement.nextElementSibling.classList.add("dropdown-custom-right");
e.target.parentElement.parentElement.parentElement.parentElement.classList.add("dropdown-custom-right");
var eleChild = e.target.parentElement.nextElementSibling;
Array.from(eleChild.querySelectorAll(".menu-dropdown")).forEach(function (item) {
item.classList.add("dropdown-custom-right");
});
} else if (elementInViewport(e.target.parentElement.nextElementSibling) == true) {
if (window.innerWidth >= 1848) {
var elements = document.getElementsByClassName("dropdown-custom-right");
while (elements.length > 0) {
elements[0].classList.remove("dropdown-custom-right");
}
}
}
}
if (e.target && e.target.matches("a.nav-link")) {
if (elementInViewport(e.target.nextElementSibling) == false) {
e.target.nextElementSibling.classList.add("dropdown-custom-right");
e.target.parentElement.parentElement.parentElement.classList.add("dropdown-custom-right");
var eleChild = e.target.nextElementSibling;
Array.from(eleChild.querySelectorAll(".menu-dropdown")).forEach(function (item) {
item.classList.add("dropdown-custom-right");
});
} else if (elementInViewport(e.target.nextElementSibling) == true) {
if (window.innerWidth >= 1848) {
var elements = document.getElementsByClassName("dropdown-custom-right");
while (elements.length > 0) {
elements[0].classList.remove("dropdown-custom-right");
}
}
}
}
}
function initsAlert() {
var alerts = document.querySelectorAll('.alert.alert-dismissible');
alerts.forEach(function (el) {
@ -67,4 +176,61 @@
}
document.addEventListener("DOMContentLoaded", initLanguage);
function toggleHamburgerMenu() {
var windowSize = document.documentElement.clientWidth;
if (windowSize > 767)
document.querySelector(".hamburger-icon").classList.toggle("open");
//For collapse horizontal menu
if (document.documentElement.getAttribute("data-layout") === "horizontal") {
document.body.classList.contains("menu") ? document.body.classList.remove("menu") : document.body.classList.add("menu");
}
//For collapse vertical menu
if (document.documentElement.getAttribute("data-layout") === "vertical") {
if (windowSize <= 1025 && windowSize > 767) {
document.body.classList.remove("vertical-sidebar-enable");
document.documentElement.getAttribute("data-sidebar-size") == "sm" ?
document.documentElement.setAttribute("data-sidebar-size", "") :
document.documentElement.setAttribute("data-sidebar-size", "sm");
} else if (windowSize > 1025) {
document.body.classList.remove("vertical-sidebar-enable");
document.documentElement.getAttribute("data-sidebar-size") == "lg" ?
document.documentElement.setAttribute("data-sidebar-size", "sm") :
document.documentElement.setAttribute("data-sidebar-size", "lg");
} else if (windowSize <= 767) {
document.body.classList.add("vertical-sidebar-enable");
document.documentElement.setAttribute("data-sidebar-size", "lg");
}
}
// semibox menu
if (document.documentElement.getAttribute("data-layout") === "semibox") {
if (windowSize > 767) {
// (document.querySelector(".hamburger-icon").classList.contains("open")) ? document.documentElement.setAttribute('data-sidebar-visibility', "show"): '';
if (document.documentElement.getAttribute('data-sidebar-visibility') == "show") {
document.documentElement.getAttribute("data-sidebar-size") == "lg" ?
document.documentElement.setAttribute("data-sidebar-size", "sm") :
document.documentElement.setAttribute("data-sidebar-size", "lg");
} else {
document.getElementById("sidebar-visibility-show").click();
document.documentElement.setAttribute("data-sidebar-size", document.documentElement.getAttribute("data-sidebar-size"));
}
} else if (windowSize <= 767) {
document.body.classList.add("vertical-sidebar-enable");
document.documentElement.setAttribute("data-sidebar-size", "lg");
}
}
//Two column menu
if (document.documentElement.getAttribute("data-layout") == "twocolumn") {
document.body.classList.contains("twocolumn-panel") ?
document.body.classList.remove("twocolumn-panel") :
document.body.classList.add("twocolumn-panel");
}
}
})();

View File

@ -33,7 +33,7 @@ export default class PresupuestoWizard {
paginasColor: 0,
posicionPaginasColor: '',
tipoEncuadernacion: 'fresado',
entregaTipo: 'peninsula',
entregaTipo: 'peninsula',
ivaReducido: true,
},
interior: {
@ -254,67 +254,32 @@ export default class PresupuestoWizard {
if (this.opts.canSave) {
$('.guardar-presupuesto').on('click', async () => {
const alert = $('#form-errors');
const servicios = [];
const payload = {
id: this.opts.presupuestoId,
mode: this.opts.mode,
presupuesto: this.#getPresupuestoData(),
servicios: this.formData.servicios.servicios,
datosMaquetacion: this.formData.servicios.datosMaquetacion,
datosMarcapaginas: this.formData.servicios.datosMarcapaginas,
cliente_id: $('#cliente_id').val() || null,
};
try {
alert.addClass('d-none').find('ul').empty();
$.ajax({
url: '/presupuesto/api/save',
type: 'POST',
contentType: 'application/json',
data: JSON.stringify(payload)
}).then((data) => {
Swal.fire({
icon: 'success',
title: window.languageBundle?.get('presupuesto.exito.guardado') || 'Guardado',
timer: 1800,
buttonsStyling: false,
customClass: {
confirmButton: 'btn btn-secondary me-2', // clases para el botón confirmar
cancelButton: 'btn btn-light' // clases para cancelar
},
showConfirmButton: false
});
// opcional: actualizar window.PRESUPUESTO_ID/resumen con el id devuelto
if (data.id) this.opts.presupuestoId = data.id;
}).catch((xhr, status, error) => {
const errors = xhr.responseJSON;
if (errors && typeof errors === 'object') {
if (!this.DEBUG && xhr.responseJSON.error && xhr.responseJSON.error == 'Internal Server Error') {
console.error("Error al validar los datos generales. Internal Server Error");
return;
}
Object.values(errors).forEach(errorMsg => {
alert.find('ul').append(`<li>${errorMsg}</li>`);
});
alert.removeClass('d-none');
} else {
alert.find('ul').append('<li>Error desconocido. Por favor, inténtelo de nuevo más tarde.</li>');
$(window).scrollTop(0);
alert.removeClass('d-none');
}
window.scrollTo({ top: 0, behavior: 'smooth' });
});
} catch (e) {
const success = await this.#guardarPresupuesto();
if (success) {
Swal.fire({
icon: 'error',
title: window.languageBundle?.get('presupuesto.add.error.save.title') || 'Error',
text: e?.message || '',
icon: 'success',
title: window.languageBundle?.get('presupuesto.exito.guardado') || 'Guardado',
timer: 1800,
buttonsStyling: false,
customClass: {
confirmButton: 'btn btn-secondary me-2', // clases para el botón confirmar
cancelButton: 'btn btn-light' // clases para cancelar
},
showConfirmButton: false
});
}
});
$('.add-cart-btn').on('click', async () => {
const success = await this.#guardarPresupuesto();
if (success) {
await $.ajax({
url: `/cart/add/${this.opts.presupuestoId}`,
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
});
}
});
@ -322,6 +287,68 @@ export default class PresupuestoWizard {
}
async #guardarPresupuesto() {
const alert = $('#form-errors');
const servicios = [];
const payload = {
id: this.opts.presupuestoId,
mode: this.opts.mode,
presupuesto: this.#getPresupuestoData(),
servicios: this.formData.servicios.servicios,
datosMaquetacion: this.formData.servicios.datosMaquetacion,
datosMarcapaginas: this.formData.servicios.datosMarcapaginas,
cliente_id: $('#cliente_id').val() || null,
};
try {
alert.addClass('d-none').find('ul').empty();
return await $.ajax({
url: '/presupuesto/api/save',
type: 'POST',
contentType: 'application/json',
data: JSON.stringify(payload)
}).then((data) => {
if (data.id) this.opts.presupuestoId = data.id;
return true;
}).catch((xhr, status, error) => {
const errors = xhr.responseJSON;
if (errors && typeof errors === 'object') {
if (!this.DEBUG && xhr.responseJSON.error && xhr.responseJSON.error == 'Internal Server Error') {
console.error("Error al validar los datos generales. Internal Server Error");
return;
}
Object.values(errors).forEach(errorMsg => {
alert.find('ul').append(`<li>${errorMsg}</li>`);
});
alert.removeClass('d-none');
} else {
alert.find('ul').append('<li>Error desconocido. Por favor, inténtelo de nuevo más tarde.</li>');
$(window).scrollTop(0);
alert.removeClass('d-none');
}
window.scrollTo({ top: 0, behavior: 'smooth' });
return false;
});
} catch (e) {
Swal.fire({
icon: 'error',
title: window.languageBundle?.get('presupuesto.add.error.save.title') || 'Error',
text: e?.message || '',
buttonsStyling: false,
customClass: {
confirmButton: 'btn btn-secondary me-2', // clases para el botón confirmar
cancelButton: 'btn btn-light' // clases para cancelar
},
});
return false;
}
}
#cacheFormData() {
if (!this.opts.useSessionCache) return;
sessionStorage.setItem('formData', JSON.stringify(this.formData));
@ -1633,7 +1660,6 @@ export default class PresupuestoWizard {
if ($target.prop('checked')) {
this.formData.servicios.servicios.push(
$target.val(),
{
id: $target.attr('id') ?? $(`label[for="${$target.attr('id')}"] .service-title`).text().trim(),
label: $(`label[for="${$target.attr('id')}"] .service-title`).text().trim(),
@ -1675,6 +1701,14 @@ export default class PresupuestoWizard {
this.divExtras.append(item.render());
}
if(!this.formData.servicios.servicios.includes(s => s.id === "ferro-digital")) {
this.formData.servicios.servicios.push({
id: "ferro-digital",
label: "Ferro Digital",
units: 1,
price: 0
});
}
this.#cacheFormData();
Summary.updateExtras();
}
@ -1813,15 +1847,15 @@ export default class PresupuestoWizard {
}
$('#resumen-base').text(formateaMoneda(data.base_imponible, 2, locale));
if(data.iva_importe_4 > 0) {
if (data.iva_importe_4 > 0) {
$('#tr-resumen-iva4').removeClass('d-none');
$('#resumen-iva4').text(formateaMoneda(data.iva_importe_4, 2, locale));
}
else{
else {
$('#tr-resumen-iva4').addClass('d-none');
$('#resumen-iva4').text(formateaMoneda(0, 2, locale));
}
if(data.iva_importe_21 > 0) {
if (data.iva_importe_21 > 0) {
$('#tr-resumen-iva21').removeClass('d-none');
$('#resumen-iva21').text(formateaMoneda(data.iva_importe_21, 2, locale));
} else {