mirror of
https://git.imnavajas.es/jjimenez/erp-imprimelibros.git
synced 2026-01-21 08:10:20 +00:00
trabajando en el delete
This commit is contained in:
@ -1,20 +1,24 @@
|
||||
$('.imagen-container-group').on('click', '.image-container', function (e) {
|
||||
e.preventDefault(); // <- evita que el label dispare el cambio nativo (2º change)
|
||||
e.stopPropagation();
|
||||
|
||||
$('.imagen-container-group').on('click', '.image-container', function () {
|
||||
const clicked = $(this);
|
||||
const group = clicked.closest('.imagen-container-group');
|
||||
|
||||
// Limpiar selección anterior
|
||||
// Si ya está seleccionado, no hagas nada
|
||||
const $radio = clicked.find('input[type="radio"]');
|
||||
if ($radio.prop('checked')) return;
|
||||
|
||||
// Limpiar selección anterior (solo clases/animación)
|
||||
group.find('.image-container').removeClass('selected')
|
||||
.find('.image-presupuesto').removeClass('zoom-anim');
|
||||
|
||||
// Marcar nuevo seleccionado
|
||||
// Marcar nuevo seleccionado (clases/animación)
|
||||
clicked.addClass('selected');
|
||||
|
||||
// Aplicar animación de zoom
|
||||
const img = clicked.find('.image-presupuesto');
|
||||
void img[0].offsetWidth; // Forzar reflow
|
||||
void img[0].offsetWidth;
|
||||
img.addClass('zoom-anim');
|
||||
|
||||
|
||||
clicked.find('input[type="radio"]').prop('checked', true).trigger('change');
|
||||
// Marca el radio y dispara UN único change
|
||||
$radio.prop('checked', true).trigger('change');
|
||||
});
|
||||
|
||||
@ -173,6 +173,9 @@ export default class PresupuestoWizard {
|
||||
this.summaryTableSobrecubierta = $('#summary-sobrecubierta');
|
||||
this.summaryTableFaja = $('#summary-faja');
|
||||
this.summaryTableExtras = $('#summary-servicios-extras');
|
||||
|
||||
// variable para evitar disparar eventos al cargar datos
|
||||
this._hydrating = false;
|
||||
}
|
||||
|
||||
async init() {
|
||||
@ -181,9 +184,10 @@ export default class PresupuestoWizard {
|
||||
const mode = root?.dataset.mode || 'public';
|
||||
const presupuestoId = root?.dataset.id || null;
|
||||
|
||||
this.opts = { mode, presupuestoId };
|
||||
|
||||
const stored = sessionStorage.getItem("formData");
|
||||
let stored = null;
|
||||
if(this.opts.useSessionCache) {
|
||||
stored = sessionStorage.getItem("formData");
|
||||
}
|
||||
|
||||
this.#initDatosGenerales();
|
||||
|
||||
@ -261,18 +265,11 @@ export default class PresupuestoWizard {
|
||||
});
|
||||
}
|
||||
|
||||
// Limpiar el sessionStorage al salir de la página
|
||||
window.addEventListener('beforeunload', () => {
|
||||
sessionStorage.removeItem('formData');
|
||||
});
|
||||
}
|
||||
|
||||
#cacheFormData() {
|
||||
if (!this.opts.useSessionCache) return;
|
||||
const key = this.opts.mode === 'edit' && this.opts.presupuestoId
|
||||
? `formData:edit:${this.opts.presupuestoId}`
|
||||
: `formData:${this.opts.mode}`;
|
||||
sessionStorage.setItem(key, JSON.stringify(this.formData));
|
||||
sessionStorage.setItem('formData', JSON.stringify(this.formData));
|
||||
}
|
||||
|
||||
#changeTab(idContenidoTab) {
|
||||
@ -382,8 +379,9 @@ export default class PresupuestoWizard {
|
||||
|
||||
// Eventos para el resumen
|
||||
$(document).on('change', 'input[name="tipoEncuadernacion"]', (e) => {
|
||||
|
||||
if ($(e.target).is(':checked')) {
|
||||
// Actualizar el resumen
|
||||
|
||||
Summary.updateEncuadernacion();
|
||||
}
|
||||
});
|
||||
@ -474,7 +472,7 @@ export default class PresupuestoWizard {
|
||||
paginasNegro: this.paginasNegro.val(),
|
||||
paginasColor: this.paginasColor.val(),
|
||||
posicionPaginasColor: this.posicionPaginasColor.val(),
|
||||
tipoEncuadernacion: ($('.tipo-libro.selected').length > 0) ? $('.tipo-libro.selected').attr('id') : 'fresado',
|
||||
tipoEncuadernacion: $('.tipo-libro input:checked').val() || 'fresado',
|
||||
};
|
||||
}
|
||||
|
||||
@ -519,7 +517,6 @@ export default class PresupuestoWizard {
|
||||
this.alto.val(this.formData.datosGenerales.alto);
|
||||
}
|
||||
|
||||
$('.tipo-libro').removeClass('selected');
|
||||
$('input[name="tipoEncuadernacion"][value="' + this.formData.datosGenerales.tipoEncuadernacion + '"]')
|
||||
.prop('checked', true);
|
||||
this.#updateTipoEncuadernacion();
|
||||
@ -565,7 +562,7 @@ export default class PresupuestoWizard {
|
||||
#updateTipoEncuadernacion() {
|
||||
|
||||
const paginas = parseInt($('#paginas').val());
|
||||
const selectedTipo = $('.tipo-libro.selected').attr('id');
|
||||
const selectedTipo = $('.tipo-libro input:checked').val();
|
||||
$('.tipo-libro').removeClass('selected');
|
||||
|
||||
if (paginas < 32) {
|
||||
@ -591,19 +588,17 @@ export default class PresupuestoWizard {
|
||||
$('.tipo-libro#grapado').removeClass('d-none');
|
||||
}
|
||||
|
||||
if (selectedTipo && $('.tipo-libro#' + selectedTipo).length > 0 && !$('.tipo-libro#' + selectedTipo).hasClass('d-none')) {
|
||||
$('.tipo-libro#' + selectedTipo).addClass('selected');
|
||||
}
|
||||
else {
|
||||
if (!(selectedTipo && $('.tipo-libro#' + selectedTipo).length > 0 && !$('.tipo-libro#' + selectedTipo).hasClass('d-none'))) {
|
||||
|
||||
let firstVisible = $('.tipo-libro').not('.d-none').first();
|
||||
|
||||
if (firstVisible.length) {
|
||||
firstVisible.addClass('selected');
|
||||
firstVisible.trigger('click');
|
||||
}
|
||||
}
|
||||
|
||||
if ($('.tipo-libro.selected').length > 0) {
|
||||
this.formData.datosGenerales.tipoEncuadernacion = $('.tipo-libro.selected').attr('id');
|
||||
if ($('.tipo-libro input:checked').length > 0) {
|
||||
this.formData.datosGenerales.tipoEncuadernacion = $('.tipo-libro input:checked').val();
|
||||
Summary.updateEncuadernacion();
|
||||
}
|
||||
else {
|
||||
@ -629,6 +624,8 @@ export default class PresupuestoWizard {
|
||||
|
||||
|
||||
$(document).on('change', 'input[name="tipoImpresion"]', (e) => {
|
||||
if (!$(e.target).is(':checked'))
|
||||
return;
|
||||
|
||||
const data = this.#getPresupuestoData();
|
||||
Summary.updateTipoImpresion();
|
||||
@ -681,6 +678,10 @@ export default class PresupuestoWizard {
|
||||
|
||||
|
||||
$(document).on('change', 'input[name="papelInterior"]', (e) => {
|
||||
|
||||
if (!$(e.target).is(':checked'))
|
||||
return;
|
||||
|
||||
const data = this.#getPresupuestoData();
|
||||
|
||||
Summary.updatePapelInterior();
|
||||
@ -951,6 +952,12 @@ export default class PresupuestoWizard {
|
||||
|
||||
$(document).on('change', 'input[name="tipoCubierta"]', (e) => {
|
||||
|
||||
if (!$(e.target).is(':checked'))
|
||||
return;
|
||||
|
||||
if(this._hydrating)
|
||||
return;
|
||||
|
||||
$('.tapa-dura-options').eq(0).removeClass('animate-fadeInUpBounce');
|
||||
$('.tapa-blanda-options').eq(0).removeClass('animate-fadeInUpBounce');
|
||||
|
||||
@ -971,6 +978,9 @@ export default class PresupuestoWizard {
|
||||
|
||||
$(document).on('change', 'input[name="solapasCubierta"]', (e) => {
|
||||
|
||||
if (!$(e.target).is(':checked'))
|
||||
return;
|
||||
|
||||
if (e.currentTarget.closest('.image-container').id === 'sin-solapas') {
|
||||
this.divSolapasCubierta.addClass('d-none');
|
||||
}
|
||||
@ -986,7 +996,7 @@ export default class PresupuestoWizard {
|
||||
});
|
||||
|
||||
|
||||
$(document).on('click', '.papel-cubierta', (e) => {
|
||||
$(document).on('change', 'input[name="papel-cubierta"]', (e) => {
|
||||
|
||||
const data = this.#getPresupuestoData();
|
||||
|
||||
@ -1026,6 +1036,9 @@ export default class PresupuestoWizard {
|
||||
|
||||
$(document).on('change', '.datos-cubierta', (e) => {
|
||||
|
||||
if(this._hydrating)
|
||||
return;
|
||||
|
||||
const dataToStore = this.#getCubiertaData();
|
||||
this.#updateCubiertaData(dataToStore);
|
||||
this.#cacheFormData();
|
||||
@ -1165,13 +1178,13 @@ export default class PresupuestoWizard {
|
||||
if (item.extraData["sk-id"] == this.formData.cubierta.papelCubiertaId) {
|
||||
item.setSelected(true);
|
||||
}
|
||||
item.group='papel-cubierta';
|
||||
this.divPapelCubierta.append(item.render());
|
||||
}
|
||||
|
||||
if (this.divPapelCubierta.find('.image-container.selected').length === 0) {
|
||||
this.divPapelCubierta.find('.image-container').first().addClass('selected');
|
||||
this.formData.cubierta.papelCubiertaId =
|
||||
this.divPapelCubierta.find('.image-container').first().data('sk-id') || 3;
|
||||
if (this.divPapelCubierta.find('input[name="papel-cubierta"]:checked').length === 0) {
|
||||
|
||||
this.divPapelCubierta.find('input[name="papel-cubierta"]').first().prop('checked', true).trigger('change');
|
||||
}
|
||||
|
||||
this.#addGramajesCubierta(data.opciones_gramaje_cubierta);
|
||||
@ -1192,13 +1205,13 @@ export default class PresupuestoWizard {
|
||||
|
||||
#getCubiertaData() {
|
||||
|
||||
const tipoCubierta = $('.tapa-cubierta.selected').attr('id') || 'tapaBlanda';
|
||||
const solapas = $('.solapas-cubierta.selected').id == 'sin-solapas' ? 0 : 1 || 0;
|
||||
const tipoCubierta = $('.tapa-cubierta input:checked').val() || 'tapaBlanda';
|
||||
const solapas = $('.solapas-cubierta input:checked').val() == 'sin-solapas' ? 0 : 1 || 0;
|
||||
const tamanioSolapasCubierta = $('#tamanio-solapas-cubierta').val() || '80';
|
||||
const cubiertaCaras = parseInt(this.carasImpresionCubierta.val()) || 2;
|
||||
const papelGuardasId = parseInt($('#papel-guardas option:selected').data('papel-id')) || 3;
|
||||
const gramajeGuardas = parseInt($('#papel-guardas option:selected').data('gramaje')) || 170;
|
||||
const guardasImpresas = parseInt(this.guardasImpresas) || 0;
|
||||
const guardasImpresas = parseInt(this.guardasImpresas.val()) || 0;
|
||||
const cabezada = this.cabezada.val() || 'WHI';
|
||||
const papelCubiertaId = $('#div-papel-cubierta .image-container input:checked').parent().data('sk-id') || this.formData.cubierta.papelCubiertaId || 3;
|
||||
const gramajeCubierta = $('input[name="gramaje-cubierta"]:checked').data('gramaje') || this.formData.cubierta.gramajeCubierta || 170;
|
||||
@ -1279,7 +1292,7 @@ export default class PresupuestoWizard {
|
||||
|
||||
for (let i = 0; i < gramajes.length; i++) {
|
||||
const gramaje = gramajes[i];
|
||||
this.#addGramaje(this.divGramajeCubierta, 'gramaje-cubierta datos-cubierta', gramaje, 'gramaje-cubierta');
|
||||
this.#addGramaje(this.divGramajeCubierta, 'gramaje-cubierta', gramaje, 'gramaje-cubierta');
|
||||
|
||||
// Seleccionar el gramaje por defecto
|
||||
if (this.formData.cubierta.gramajeCubierta === '' && i === 0) {
|
||||
@ -1298,9 +1311,11 @@ export default class PresupuestoWizard {
|
||||
|
||||
#loadCubiertaData() {
|
||||
|
||||
this._hydrating = true;
|
||||
|
||||
$('input[name="tipoCubierta"][value="' + this.formData.cubierta.tipoCubierta + '"]')
|
||||
.prop('checked', true);
|
||||
|
||||
|
||||
if (this.formData.cubierta.tipoCubierta === 'tapaBlanda') {
|
||||
$('.tapa-blanda-options').removeClass('d-none');
|
||||
$('.tapa-dura-options').addClass('d-none');
|
||||
@ -1315,15 +1330,16 @@ export default class PresupuestoWizard {
|
||||
this.cabezada.val(this.formData.cubierta.cabezada);
|
||||
}
|
||||
|
||||
this._hydrating = false;
|
||||
|
||||
$('input[name="tipoCubierta"][value="' + this.formData.cubierta.tipoCubierta + '"]').trigger('change');
|
||||
|
||||
if (this.formData.cubierta.solapasCubierta === 0) {
|
||||
$('.solapas-cubierta#sin-solapas').addClass('selected');
|
||||
$('.solapas-cubierta#sin-solapas input').prop('checked', true);
|
||||
this.divSolapasCubierta.addClass('d-none');
|
||||
}
|
||||
else {
|
||||
$('.solapas-cubierta').removeClass('selected');
|
||||
$(`.solapas-cubierta#con-solapas`).addClass('selected');
|
||||
$('.solapas-cubierta#con-solapas input').prop('checked', true);
|
||||
this.divSolapasCubierta.removeClass('d-none');
|
||||
this.carasImpresionCubierta.val(this.formData.cubierta.cubiertaCaras);
|
||||
this.tamanioSolapasCubierta.val(this.formData.cubierta.tamanioSolapasCubierta);
|
||||
|
||||
@ -67,6 +67,7 @@
|
||||
});
|
||||
|
||||
$('#presupuestos-anonimos-datatable').on('click', '.btn-edit-anonimo', function (e) {
|
||||
|
||||
e.preventDefault();
|
||||
const id = $(this).data('id');
|
||||
if (id) {
|
||||
@ -74,5 +75,48 @@
|
||||
}
|
||||
});
|
||||
|
||||
$('#presupuestos-anonimos-datatable').on('click', '.btn-delete-anonimo', function (e) {
|
||||
|
||||
e.preventDefault();
|
||||
const id = $(this).data('id');
|
||||
|
||||
Swal.fire({
|
||||
title: window.languageBundle.get(['presupuesto.delete.title']) || 'Eliminar presupuesto',
|
||||
html: window.languageBundle.get(['presupuesto.delete.text']) || 'Esta acción no se puede deshacer.',
|
||||
icon: 'warning',
|
||||
showCancelButton: true,
|
||||
buttonsStyling: false,
|
||||
customClass: {
|
||||
confirmButton: 'btn btn-danger w-xs mt-2',
|
||||
cancelButton: 'btn btn-light w-xs mt-2'
|
||||
},
|
||||
confirmButtonText: window.languageBundle.get(['presupuesto.delete.button']) || 'Eliminar',
|
||||
cancelButtonText: window.languageBundle.get(['app.cancelar']) || 'Cancelar',
|
||||
}).then((result) => {
|
||||
if (!result.isConfirmed) return;
|
||||
|
||||
$.ajax({
|
||||
url: '/presupuesto/' + id,
|
||||
type: 'DELETE',
|
||||
success: function () {
|
||||
Swal.fire({
|
||||
icon: 'success', title: window.languageBundle.get(['presupuesto.delete.ok.title']) || 'Eliminado',
|
||||
text: window.languageBundle.get(['presupuesto.delete.ok.text']) || 'El presupuesto ha sido eliminado con éxito.',
|
||||
showConfirmButton: true,
|
||||
customClass: {
|
||||
confirmButton: 'btn btn-secondary w-xs mt-2',
|
||||
},
|
||||
});
|
||||
$('#presupuestos-anonimos-datatable').DataTable().ajax.reload(null, false);
|
||||
},
|
||||
error: function (xhr) {
|
||||
// usa el mensaje del backend; fallback genérico por si no llega JSON
|
||||
const msg = (xhr.responseJSON && xhr.responseJSON.message)
|
||||
|| 'Error al eliminar el presupuesto.';
|
||||
Swal.fire({ icon: 'error', title: 'No se pudo eliminar', text: msg });
|
||||
}
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user