File "FOR-S-CCI-73.js"
Full Path: C:/wamp64/www/CALIDADWEB/CALIDADWEB/FRONTED/CONTROLTABLAS.JS/FOR-S-CCI-73.js
File size: 8.73 KB
MIME-type: text/plain
Charset: utf-8
$(document).ready(function () {
$(".btnGuacalesdesinfeccion").click(function (e) {
e.preventDefault();
swal.fire({
title: "Cargando datos...",
allowOutsideClick: false,
didOpen: () => { swal.showLoading(); }
});
if ($.fn.DataTable.isDataTable('#tblGuacalesdesinfeccion')) {
$('#tblGuacalesdesinfeccion').DataTable().destroy();
}
let tablahucales = $("#tblGuacalesdesinfeccion").DataTable({
"ajax": {
"url": "../../BACKEND/controltablas/FOR-S-CCI-73.php",
"type": "POST",
"data": { opcion: 64 },
"dataSrc": ""
},
"columns": [
{ "data": "id", "width": "50px" },
{ "data": "fecha", "width": "100px" },
{ "data": "hora", "width": "80px" },
{ data: "viaje" },
{ data: "limpieza_veh" },
{ data: "limpieza_desi" },
{ data: "verificacion" },
{ data: "acciones_corre" },
{ data: "responsable" },
{ data: "aprobosi" },
{
"data": null,
"orderable": false,
"width": "80px",
"className": "text-center",
"render": function () {
return "<button class='btn btn-danger btn-sm btnBorrar'><i class='fas fa-trash-alt'></i></button>";
}
},
{
"data": null,
"orderable": false,
"width": "80px",
"className": "text-center",
"render": function (data, type, row) {
return "<button class='btn btn-primary btn-sm btnEditar' data-id='" + row.id + "'><i class='fas fa-edit'></i></button>";
}
}
],
"language": {
"decimal": "",
"emptyTable": "No hay información",
"info": "Mostrando _START_ a _END_ de _TOTAL_ registros",
"infoEmpty": "Mostrando 0 a 0 de 0 registros",
"infoFiltered": "(Filtrado de _MAX_ total registros)",
"thousands": ",",
"lengthMenu": "Mostrar _MENU_ registros",
"loadingRecords": "Cargando...",
"processing": "Procesando...",
"search": "Buscar:",
"zeroRecords": "Sin resultados encontrados",
"paginate": {
"first": "Primero",
"last": "Último",
"next": "Siguiente",
"previous": "Anterior"
}
},
"scrollX": true,
"scrollCollapse": true,
"autoWidth": false,
"dom": "Bfrtip",
"buttons": [
{
extend: "pageLength",
className: "btn btn-warning"
},
{
extend: "excelHtml5",
autoFilter: true,
sheetName: "HIPOCLORITO SODIO (PPM) 200",
title: "HIPOCLORITO SODIO (PPM) 200",
text: '<i class="fa-lg fa-solid fa-file-excel"></i> GENERAR EXCEL',
className: "btn btn-success",
exportOptions: {
columns: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
}
}
],
"initComplete": function () {
swal.close();
}
});
// --- ELIMINAR ---
$('#tblGuacalesdesinfeccion tbody').off('click', '.btnBorrar').on('click', '.btnBorrar', function (e) {
e.preventDefault();
e.stopPropagation();
let data = tablahucales.row($(this).parents('tr')).data();
swal.fire({
title: "¿Eliminar registro?",
text: "ID: " + data.id,
icon: "warning",
showCancelButton: true,
confirmButtonColor: "#d33",
cancelButtonColor: "#3085d6",
cancelButtonText: "Cancelar",
confirmButtonText: "Sí, borrar"
}).then((result) => {
if (result.isConfirmed) {
$.ajax({
url: "../../BACKEND/controltablas/FOR-S-CCI-73.php",
type: "POST",
data: { opcion: 65, id: data.id },
success: function (response) {
tablahucales.ajax.reload(null, false);
swal.fire({
icon: "success",
title: "¡Éxito!",
text: "Registro eliminado correctamente",
showConfirmButton: false,
timer: 1500
});
},
error: function () {
swal.fire({
icon: "error",
title: "Error",
text: "No se pudo eliminar el registro",
showConfirmButton: false,
timer: 1500
});
}
});
}
});
return false;
});
// --- EDITAR ---
$('#tblGuacalesdesinfeccion tbody').off('click', '.btnEditar').on('click', '.btnEditar', function (e) {
e.preventDefault();
e.stopPropagation();
let $row = $(this).closest('tr');
let data = tablahucales.row($row).data();
$row.find('td').each(function (index) {
if (index > 0 && index < 10) {
let valorActual = $(this).text();
let nombreColumna = tablahucales.settings().init().columns[index].data;
$(this).html(`<input type="text" class="form-control form-control-sm" value="${valorActual}" data-campo="${nombreColumna}">`);
}
});
$(this).removeClass('btn-primary btnEditar')
.addClass('btn-success btnGuardar')
.html('<i class="fas fa-save"></i>');
$row.find('.btnBorrar').removeClass('btn-danger btnBorrar')
.addClass('btn-secondary btnCancelar')
.html('<i class="fas fa-times"></i>');
return false;
});
// --- GUARDAR ---
$('#tblGuacalesdesinfeccion tbody').off('click', '.btnGuardar').on('click', '.btnGuardar', function (e) {
e.preventDefault();
e.stopPropagation();
let $row = $(this).closest('tr');
let id = tablahucales.row($row).data().id;
let datosActualizados = { opcion: 66, id: id };
$row.find('input').each(function () {
let campo = $(this).data('campo');
let valor = $(this).val();
datosActualizados[campo] = valor;
});
$.ajax({
url: "../../BACKEND/controltablas/FOR-S-CCI-73.php",
type: "POST",
data: datosActualizados,
success: function (response) {
tablahucales.ajax.reload(null, false);
swal.fire({
icon: "success",
title: "¡Éxito!",
text: "Registro actualizado correctamente",
showConfirmButton: false,
timer: 1500
});
},
error: function () {
swal.fire({
icon: "error",
title: "Error",
text: "No se pudo actualizar el registro",
showConfirmButton: false,
timer: 1500
});
tablahucales.ajax.reload(null, false);
}
});
return false;
});
// --- CANCELAR ---
$('#tblGuacalesdesinfeccion tbody').off('click', '.btnCancelar').on('click', '.btnCancelar', function (e) {
e.preventDefault();
e.stopPropagation();
tablahucales.ajax.reload(null, false);
return false;
});
});
});