You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
407 lines
12 KiB
407 lines
12 KiB
|
|
$(function () { |
|
|
|
$(document).ajaxStart(function(){ |
|
$.blockUI({ |
|
message: '<i class="fas fa-spin fa-sync text-white"></i>', |
|
overlayCSS: { |
|
backgroundColor: "#000", |
|
opacity: 0.5, |
|
cursor: "wait", |
|
}, |
|
css: { |
|
border: 0, |
|
padding: 0, |
|
color: "#333", |
|
backgroundColor: "transparent", |
|
} |
|
}); |
|
}); |
|
|
|
$(document).ajaxStop($.unblockUI); |
|
|
|
|
|
$("#formNuevoUsuario").on("submit", function(e){ |
|
|
|
e.preventDefault(); |
|
|
|
|
|
var check = document.getElementsByClassName('formNuevoUsuario')[0].reportValidity(); |
|
|
|
|
|
if (check) { |
|
|
|
var formData = new FormData(this); |
|
|
|
Swal.fire({ |
|
title: "¿Esta seguro que desea agregar un nuevo usuario?", |
|
type: "warning", |
|
showCancelButton: true, |
|
confirmButtonColor: "#3085d6", |
|
cancelButtonColor: "#d33", |
|
cancelButtonText: "Cancelar", |
|
confirmButtonText: "Aceptar", |
|
}).then((result) => { |
|
if (result.value) { |
|
|
|
$('#cerrarModalNuevoUsuario').trigger("click"); |
|
|
|
$.ajax({ |
|
type:'POST', |
|
url:'nuevo_usuario', |
|
headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')}, |
|
data: formData, |
|
processData:false, |
|
contentType: false, |
|
success:function(data){ |
|
|
|
cargarListaUsuarios(); |
|
$(".formNuevoUsuario")[0].reset(); |
|
$('#formNuevoUsuario').removeClass('was-validated'); |
|
Swal.fire("¡Éxito!", "Se agrego un nuevo usuario.", "success"); |
|
|
|
}, |
|
error: function (e) { |
|
mensajeError(); |
|
} |
|
}); |
|
} |
|
}); |
|
}else{ |
|
errorFaltanCampos(); |
|
} |
|
}); |
|
|
|
$("#formEditarUsuario").on("submit", function(e){ |
|
|
|
e.preventDefault(); |
|
|
|
var check = document.getElementsByClassName('formEditarUsuario')[0].reportValidity(); |
|
|
|
if (check) { |
|
|
|
|
|
var formData = new FormData(this); |
|
|
|
Swal.fire({ |
|
title: "¿Esta seguro que desea editar los datos del usuario?", |
|
type: "warning", |
|
showCancelButton: true, |
|
confirmButtonColor: "#3085d6", |
|
cancelButtonColor: "#d33", |
|
cancelButtonText: "Cancelar", |
|
confirmButtonText: "Aceptar", |
|
}).then((result) => { |
|
if (result.value) { |
|
|
|
$('#cerrarModalEditarUsuario').trigger("click"); |
|
|
|
$.ajax({ |
|
type:'POST', |
|
url:'editar_usuario', |
|
headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')}, |
|
data: formData, |
|
processData:false, |
|
contentType: false, |
|
success:function(data){ |
|
|
|
cargarListaUsuarios(); |
|
$("#formEditarUsuario")[0].reset(); |
|
$('#formEditarUsuario').removeClass('was-validated'); |
|
Swal.fire("¡Éxito!", "Se editaron los datos del usuario.", "success"); |
|
|
|
}, |
|
error: function (e) { |
|
mensajeError(); |
|
} |
|
}); |
|
} |
|
}); |
|
}else{ |
|
errorFaltanCampos(); |
|
} |
|
}); |
|
|
|
|
|
$("#formCargarUsuarios").on("submit", function(e){ |
|
|
|
e.preventDefault(); |
|
|
|
var formData = new FormData(this); |
|
|
|
Swal.fire({ |
|
title: "¿Esta seguro que deseas cargar la lista de nuevos usuarios?", |
|
type: "warning", |
|
showCancelButton: true, |
|
confirmButtonColor: "#3085d6", |
|
cancelButtonColor: "#d33", |
|
cancelButtonText: "Cancelar", |
|
confirmButtonText: "Aceptar", |
|
}).then((result) => { |
|
if (result.value) { |
|
|
|
$('#cerrarModalNuevo').trigger("click"); |
|
|
|
$.ajax({ |
|
type:'POST', |
|
url:'cargar_lista_usuarios', |
|
headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')}, |
|
data: formData, |
|
processData:false, |
|
contentType: false, |
|
success:function(data){ |
|
|
|
cargarListaUsuarios(); |
|
Swal.fire("¡Éxito!", "Se agrego la lista de nuevos usuarios.", "success"); |
|
|
|
}, |
|
error: function (e) { |
|
mensajeError(); |
|
} |
|
}); |
|
} |
|
}); |
|
|
|
|
|
}); |
|
|
|
$('#expirarContrasena').click(function(){ |
|
|
|
Swal.fire({ |
|
title: "¿Esta seguro que deseas expirar la contraseña del usuario?", |
|
type: "warning", |
|
showCancelButton: true, |
|
confirmButtonColor: "#3085d6", |
|
cancelButtonColor: "#d33", |
|
cancelButtonText: "Cancelar", |
|
confirmButtonText: "Aceptar", |
|
}).then((result) => { |
|
if (result.value) { |
|
|
|
$.ajax({ |
|
type:'POST', |
|
url:'expirar_contrasena', |
|
headers: {'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')}, |
|
data: { id:$('#editar_id').val() }, |
|
success:function(data){ |
|
|
|
cargarListaUsuarios(); |
|
Swal.fire("¡Éxito!", "Se agrego la lista de nuevos usuarios.", "success"); |
|
|
|
}, |
|
error: function (e) { |
|
mensajeError(); |
|
} |
|
}); |
|
} |
|
}); |
|
|
|
|
|
|
|
}); |
|
|
|
}); |
|
|
|
cargarListaUsuarios(); |
|
|
|
function cargarListaUsuarios(){ |
|
|
|
$('#listaUsuarios').empty(); |
|
$('#listaUsuarios').DataTable({ |
|
searchDelay: 400, |
|
ajax: { |
|
url: 'api/obtener_lista_tareas_usuarios', |
|
dataSrc: function(json){ |
|
console.log(json); |
|
return json; |
|
|
|
} |
|
}, |
|
// order: [[0, 'asc']], |
|
// ordering:true, |
|
columns:[ |
|
// { data: "id", defaultContent: "---", title: "#2" }, |
|
{data:function(row, type){ |
|
const id = row.id; |
|
let botonAcciones = '<ul class="dropdown-menu" aria-labelledby="dropdownMenuButton" style="">'+ |
|
'<li>'+ |
|
'<a class="dropdown-item" data-bs-toggle="modal" data-bs-target="#modal_editar_form" onclick="cargarEditarForm('+id+')">Editar</a>'+ |
|
'</li>'+ |
|
'<li>'+ |
|
'<a class="dropdown-item" onclick="eliminarUsuario('+ id +')">Eliminar</a>'+ |
|
'</li>'+ |
|
'</ul>'; |
|
return '<div class="dropdown dropstart">'+ |
|
'<a href="table-basic.html#" class="link" id="dropdownMenuButton" data-bs-toggle="dropdown" aria-expanded="false">'+ |
|
'<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" class="feather feather-more-horizontal feather-sm">'+ |
|
'<circle cx="12" cy="12" r="1"></circle>'+ |
|
'<circle cx="19" cy="12" r="1"></circle>'+ |
|
'<circle cx="5" cy="12" r="1"></circle>'+ |
|
'</svg>'+ |
|
'</a>'+ |
|
botonAcciones+ |
|
'</div>'; |
|
}, |
|
title: "Acciones"}, |
|
// { data: "id", defaultContent: "---", title: "#" }, |
|
{ data: "datos_empleado.nombre_completo", defaultContent: "---", title: "Nombre completo" }, |
|
{ data: "name", defaultContent: "---", title: "Nombre de usuario" }, |
|
|
|
// { data: "email", defaultContent: "---", title: "Correo" }, |
|
{ data: "datos_empleado.clave_contpaq", defaultContent: "---", title: "Clave contpaq" }, |
|
{ data: "roles.rol", defaultContent: "---", title: "Rol" }, |
|
{data:function(row, type){ |
|
const activo = row.activo; |
|
console.log(activo); |
|
return (row.activo == 1) ? 'Activo' : 'Inactivo' ; |
|
|
|
}, |
|
title: "Estado"} |
|
|
|
|
|
], |
|
aLengthMenu: [ |
|
[25, 50, 100, 200, -1], |
|
[25, 50, 100, 200, 'All'] |
|
], |
|
destroy: true, |
|
paging:true, |
|
info:true, |
|
// responsive: true, |
|
// dom: "Bfrtip", |
|
// buttons: ["copy", "csv", "excel", "pdf", "print"], |
|
"language": { |
|
"url": "//cdn.datatables.net/plug-ins/1.10.19/i18n/Spanish.json" |
|
} |
|
}); |
|
} |
|
|
|
cargarListaRoles(); |
|
|
|
function cargarListaRoles(){ |
|
|
|
$.get('api/lista_roles',function(data){ |
|
|
|
let opciones = ''; |
|
$('.roles').empty(); |
|
|
|
$.each(data,function(i,ele){ |
|
|
|
opciones += '<option value="'+ ele.id +'" >'+ ele.rol +'</option>'; |
|
|
|
}); |
|
|
|
$('.roles').append(opciones); |
|
|
|
}); |
|
|
|
} |
|
|
|
|
|
function cargarEditarForm(id){ |
|
$.get('api/detalle_usuario',{id:id},function(data){ |
|
|
|
$.each(data,function(i,ele){ |
|
|
|
$('#editar_'+i).val(ele).change; |
|
if( i == 'datos_empleado' ){ |
|
|
|
$.each(ele,function(j,datos_empleado){ |
|
|
|
// if( j == 'id' ){ |
|
// $('#editar_empleado_'+j).val(datos_empleado); |
|
// } |
|
|
|
$('#editar_empleado_'+j).val(datos_empleado); |
|
|
|
}); |
|
|
|
} |
|
|
|
}); |
|
}); |
|
} |
|
|
|
function eliminarUsuario(id){ |
|
|
|
|
|
Swal.fire({ |
|
title: "¿Esta seguro que desea eliminar el usuario?", |
|
type: "warning", |
|
showCancelButton: true, |
|
confirmButtonColor: "#3085d6", |
|
cancelButtonColor: "#d33", |
|
cancelButtonText: "Cancelar", |
|
confirmButtonText: "Aceptar", |
|
}).then((result) => { |
|
if (result.value) { |
|
|
|
$.get('eliminar_usuario',{id:id},function(data){ |
|
|
|
cargarListaUsuarios(); |
|
Swal.fire("¡Éxito!", "Se editaron los datos del usuario.", "success"); |
|
|
|
}); |
|
|
|
} |
|
}); |
|
|
|
|
|
|
|
} |
|
|
|
function errorFaltanCampos(){ |
|
|
|
Swal.fire({ |
|
title: "Alerta!", |
|
text: "Faltan campos por llenar.", |
|
type: "warning", |
|
timer: 3000, |
|
showConfirmButton: false, |
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
function mensajeError(){ |
|
|
|
Swal.fire({ |
|
type: "error", |
|
title: "Oops...", |
|
text: "¡Lo siento, ocurrió un error!", |
|
}); |
|
|
|
} |
|
|
|
|
|
|
|
(function () { |
|
"use strict"; |
|
window.addEventListener( |
|
"load", |
|
function () { |
|
// Fetch all the forms we want to apply custom Bootstrap validation styles to |
|
var forms = document.getElementsByClassName("needs-validation"); |
|
// Loop over them and prevent submission |
|
var validation = Array.prototype.filter.call( |
|
forms, |
|
function (form) { |
|
form.addEventListener( |
|
"submit", |
|
function (event) { |
|
if (form.checkValidity() === false) { |
|
event.preventDefault(); |
|
event.stopPropagation(); |
|
} |
|
form.classList.add("was-validated"); |
|
}, |
|
false |
|
); |
|
} |
|
); |
|
}, |
|
false |
|
); |
|
})(); |
|
|
|
|