Files
safekat/httpdocs/assets/js/safekat/pages/presupuestoAdmin/presupuestoAdminEdit.js

162 lines
5.1 KiB
JavaScript

import { getToken } from '../../common/common.js';
import Ajax from '../../components/ajax.js';
import DatosGenerales from './sections/datosGenerales.js';
import DatosLibro from './sections/datosLibro.js';
class PresupuestoAdminEdit {
constructor() {
this.domItem = $('#presupuestoForm');
this.csrf_token = getToken();
this.csrf_hash = $('#presupuestoForm').find('input[name="' + this.csrf_token + '"]').val();
this.lc = $("#lomo_cubierta");
this.lsc = $("#lomo_sobrecubierta");
this.cosido = $("#isCosido");
this.tipo_impresion = $("#tipo_impresion_id");
this.cosido = $("#isCosido");
this.datosGenerales = new DatosGenerales(this.domItem.find('#accordionDatosPresupuestoTip'));
this.datosLibro = new DatosLibro(this.domItem.find('#accordionDatosPresupuestoTip'));
this.calcularPresupuesto = false;
}
init() {
// Fuerza el foco en el campo de búsqueda de select2
$(document).on('select2:open', () => {
document.querySelector('.select2-search__field').focus();
});
this.datosGenerales.init();
if (window.location.href.includes("edit")) {
setTimeout(() => {
this.#cargarPresupuesto();
}, 0);
const successMessage = sessionStorage.getItem('message');
if (successMessage) {
popSuccessAlert(successMessage);
sessionStorage.removeItem('message');
}
}
}
#cargarPresupuesto() {
const self = this;
$('#loader').modal('show');
let id = window.location.href.split("/").pop()
new Ajax('/presupuestoadmin/cargar/' + id,
{},
{},
(response) => {
if (response.status === 1) {
self.lc.val(parseFloat(response.data.lc).toFixed(2));
self.lsc.val(parseFloat(response.data.lsc).toFixed(2));
self.cosido.val(response.data.cosido);
self.tipo_impresion.val(response.data.tipo_impresion);
self.calcularPresupuesto = false;
self.datosGenerales.cargarDatos(response.data.datosGenerales);
/*self.direcciones.handleChangeCliente();
self.direcciones.cargarDatos(response.data.direcciones, response.data.datosGenerales);
self.disenioInterior.cargarDatos(response.data.interior, response.data.datosGenerales.papelInteriorDiferente);
self.disenioCubierta.cargarDatos(response.data.cubierta, response.data.guardas, response.data.sobrecubierta);
*/
setTimeout(() => {
$('#loader').modal('hide');
if (response.data.state != 2) {
self.calcularPresupuesto = true;
}
}, 0);
// Funciones para detectar cambios en el formulario
this.#checkChangesPresupuesto();
$('#bc-save').on("click", function () {
showBreadCrumbSaveButton(false);
$('#saveForm').trigger('click');
});
}
},
() => {
$('#loader').modal('hide');
this.calcularPresupuesto = true;
}
).get();
}
#checkChangesPresupuesto() {
// Detectar cambios en inputs de texto
$('input[type="text"]').on('change', function () {
showBreadCrumbSaveButton(true);
});
// Detectar cambios en inputs de texto
$('input[type="number"]').on('change', function () {
showBreadCrumbSaveButton(true);
});
// Detectar cambios en select
$('select').on('change', function () {
showBreadCrumbSaveButton(true);
});
$('.select2bs').on('change', function (e) {
showBreadCrumbSaveButton(true);
});
// Detectar cambios en checkboxes
$('input[type="checkbox"]').change(function () {
showBreadCrumbSaveButton(true);
});
// Detectar cambios en textareas
$('textarea').on('input', function () {
showBreadCrumbSaveButton(true);
});
// Detectar cambios en otros tipos de input
$('input[type="radio"]').change(function () {
showBreadCrumbSaveButton(true);
});
// Detectar cambios en otros tipos de input
$('input:not([type])').on('input', function () {
showBreadCrumbSaveButton(true);
});
}
}
document.addEventListener('DOMContentLoaded', function () {
const locale = document.querySelector('meta[name="locale"]').getAttribute('content');
new Ajax('/translate/getTranslation', { locale: locale, translationFile: ['Maquinas'] }, {},
function (translations) {
window.language = JSON.parse(translations);
new PresupuestoAdminEdit().init();
},
function (error) {
console.log("Error getting translations:", error);
}
).post();
});