1214 lines
39 KiB
HTML
1214 lines
39 KiB
HTML
|
|
<section class="py-md-4 py-2">
|
||
|
|
<div class="container-fluid">
|
||
|
|
<div class="row">
|
||
|
|
<div class="col-12">
|
||
|
|
<h1 class="text-secondary font-weight-bolder">Usuarios</h1>
|
||
|
|
<p>Sistema de gestión de usuarios, se pueden agregar usuarios, desactivar usuarios y modificar usuarios.</p>
|
||
|
|
<p>Existen dos roles en el sistema administradores y estudiantes, por defecto se agrega un usuario con el rol de estudiante.</p>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</section>
|
||
|
|
<section class="py-md-4 py-2 controller">
|
||
|
|
<div class="container-fluid">
|
||
|
|
<div class="row align-items-center align-self-center">
|
||
|
|
<div class="col-12">
|
||
|
|
<div id="dvjson"></div>
|
||
|
|
</div>
|
||
|
|
<div class="col-12">
|
||
|
|
<table id="datatable" class="display table table-striped table-bordered" cellspacing="0" width="100%">
|
||
|
|
<thead>
|
||
|
|
<tr>
|
||
|
|
<th>id</th>
|
||
|
|
<th>Número de empleado</th>
|
||
|
|
<th>Correo electrónico</th>
|
||
|
|
<th>Nombres (s)</th>
|
||
|
|
<th>Apellidos</th>
|
||
|
|
<th>Centro de trabajo</th>
|
||
|
|
<th>Distrito</th>
|
||
|
|
<th>Posición</th>
|
||
|
|
<th>Sociedad</th>
|
||
|
|
<th>División</th>
|
||
|
|
<th>Unidad organizativa</th>
|
||
|
|
<th>CeCo</th>
|
||
|
|
<th>Supervisor</th>
|
||
|
|
<th>Habilitado</th>
|
||
|
|
<th>IP</th>
|
||
|
|
<th>Ultimo ingreso</th>
|
||
|
|
<th>Creación</th>
|
||
|
|
<th>Actualización</th>
|
||
|
|
<th>Rol</th>
|
||
|
|
</tr>
|
||
|
|
</thead>
|
||
|
|
<tfoot>
|
||
|
|
<tr>
|
||
|
|
<th>id</th>
|
||
|
|
<th>Número de empleado</th>
|
||
|
|
<th>Correo electrónico</th>
|
||
|
|
<th>Nombres (s)</th>
|
||
|
|
<th>Apellidos</th>
|
||
|
|
<th>Centro de trabajo</th>
|
||
|
|
<th>Distrito</th>
|
||
|
|
<th>Posición</th>
|
||
|
|
<th>Sociedad</th>
|
||
|
|
<th>División</th>
|
||
|
|
<th>Unidad organizativa</th>
|
||
|
|
<th>CeCo</th>
|
||
|
|
<th>Supervisor</th>
|
||
|
|
<th>Habilitado</th>
|
||
|
|
<th>IP</th>
|
||
|
|
<th>Ultimo ingreso</th>
|
||
|
|
<th>Creación</th>
|
||
|
|
<th>Actualización</th>
|
||
|
|
<th>Rol</th>
|
||
|
|
</tr>
|
||
|
|
</tfoot>
|
||
|
|
</table>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
<section class="py-md-4 py-2">
|
||
|
|
<hr>
|
||
|
|
<div class="container-fluid">
|
||
|
|
<div class="row align-items-center align-self-center">
|
||
|
|
<div class="col-12">
|
||
|
|
<h2>Carga masiva de usuarios</h2>
|
||
|
|
</div>
|
||
|
|
<div class="col-12">Esta función sólo creará usuarios con rol de estudiante, el número de empleado es obligatorio.
|
||
|
|
</div>
|
||
|
|
<div class="col-12 my-3"><a class="btn btn-secondary" href="../data/template_users.xlsx" download target="_blank">Descargar template carga de usuarios</a></div>
|
||
|
|
</div>
|
||
|
|
<div class="row align-items-center align-self-center">
|
||
|
|
<div class="col-12 col-md-6 colform">
|
||
|
|
<form name="masiveusers" method="post" enctype="multipart/form-data" id="masiveusers">
|
||
|
|
<div class="custom-file">
|
||
|
|
<input type="file" class="custom-file-input" id="customFile" name="customFile" required accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet">
|
||
|
|
<label class="custom-file-label" for="customFile">Subir archivo</label>
|
||
|
|
</div>
|
||
|
|
<div class="form-group row justify-content-end my-3">
|
||
|
|
<div class="col-12 col-md-6 text-right">
|
||
|
|
<button name="Enviar" type="submit" value="Enviar" class="btn btn-primary">Enviar</button>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</form>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
<div class="row align-items-center align-self-center">
|
||
|
|
<div class="col-12 col-md-6 ">
|
||
|
|
<div class="card h-100 bg-transparent rounded-0 border-0 ">
|
||
|
|
<div class="card-body resutadosmasivos"></div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</section>
|
||
|
|
<section class="actualizacion py-md-4 py-2">
|
||
|
|
<hr>
|
||
|
|
<div class="container-fluid">
|
||
|
|
<div class="row align-items-center align-self-center">
|
||
|
|
<div class="col-12">
|
||
|
|
<h2>Actualización masiva de usuarios</h2>
|
||
|
|
</div>
|
||
|
|
<div class="legend col-12">Actualizara todos los campos siempre que existan y concuerden con el nombre asignado siempre debe tener la columna de número de empleado para realizar la actualización o baja de usuarios.</div>
|
||
|
|
<div class="col-12 my-3"><a class="btn btn-secondary admin" href="../data/template_update.xlsx" download target="_blank">Descargar template actualización de usuarios</a></div>
|
||
|
|
<div class="col-12 my-3"><a class="btn btn-secondary" href="../data/template_users_baja.xlsx" download target="_blank">Descargar template para baja de usuarios</a></div>
|
||
|
|
</div>
|
||
|
|
<div class="row align-items-center align-self-center">
|
||
|
|
<div class="col-12 col-md-6 colform">
|
||
|
|
<form name="updatemasiveusers" method="post" enctype="multipart/form-data" id="updatemasiveusers">
|
||
|
|
<div class="custom-file">
|
||
|
|
<input type="file" class="custom-file-input" id="customFileUpdate" name="customFileUpdate" required accept="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet">
|
||
|
|
<label class="custom-file-label" for="customFileUpdate">Subir archivo</label>
|
||
|
|
</div>
|
||
|
|
<div class="form-group row justify-content-end my-3">
|
||
|
|
<div class="col-12 col-md-6 text-right">
|
||
|
|
<button name="Enviar" type="submit" value="Enviar" class="btn btn-primary">Actualizar</button>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</form>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
<div class="row align-items-center align-self-center">
|
||
|
|
<div class="col-12 col-md-6 ">
|
||
|
|
<div class="card h-100 bg-transparent rounded-0 border-0 ">
|
||
|
|
<div class="card-body resultadosmasivos"></div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
|
||
|
|
</section>
|
||
|
|
|
||
|
|
</section>
|
||
|
|
<section class="py-md-4 py-2 editor" style="display: none;">
|
||
|
|
<div class="container-fluid">
|
||
|
|
<div class="row align-items-center justify-content-start">
|
||
|
|
<div class="col-12 text-left my-4">
|
||
|
|
<h3 class="title-cat edit" style="display: none;">Editar usuario</h3>
|
||
|
|
<h3 class="title-cat crear" style="display: none;">Crear usuario</h3>
|
||
|
|
</div>
|
||
|
|
<div class="col-12 col-md-10">
|
||
|
|
<form class="formcontroller" autocomplete="off">
|
||
|
|
<input type="hidden" name="iduser" id="iduser" value="">
|
||
|
|
<div class="form-group row">
|
||
|
|
<label for="rolname" class="col-md-2 col-12 col-form-label">Rol</label>
|
||
|
|
<div class="col-lg-8 col-md-8 col-12">
|
||
|
|
<select id="rolname" name="rolname" class="custom-select" required="required">
|
||
|
|
</select>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
<div class="form-group row">
|
||
|
|
<label class="col-md-2 col-12 col-form-label" for="email">Email</label>
|
||
|
|
<div class="col-lg-8 col-md-8 col-12">
|
||
|
|
<input id="email" name="email" placeholder="Email" type="text" class="form-control">
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
<div class="form-group row">
|
||
|
|
<label class="col-md-2 col-12 col-form-label" for="numempl">Número de empleado</label>
|
||
|
|
<div class="col-lg-8 col-md-8 col-12">
|
||
|
|
<input id="numempl" name="numempl" placeholder="Número de empleado" type="text" class="form-control" required="required">
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
<div class="form-group row">
|
||
|
|
<label class="col-md-2 col-12 col-form-label" for="nombre">Nombre (s)</label>
|
||
|
|
<div class="col-lg-8 col-md-8 col-12">
|
||
|
|
<input id="nombre" name="nombre" placeholder="Nombre (s)" type="text" class="form-control">
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
<div class="form-group row d-none">
|
||
|
|
<label class="col-md-2 col-12 col-form-label" for="password">
|
||
|
|
<span style="display: none;" class="crear">Contraseña</span>
|
||
|
|
<span style="display: none;" class="edit">Nueva contraseña</span>
|
||
|
|
</label>
|
||
|
|
<div class="col-8">
|
||
|
|
<input id="password" autocomplete="off" autocomplete="new-password" name="password" placeholder="Contraseña" type="text" class="form-control">
|
||
|
|
<!-- An element to toggle between password visibility -->
|
||
|
|
<div class="d-inline-block py-2"><input type="checkbox" checked id="mostrarpassword"> Mostrar contraseña</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
<div class="form-group row">
|
||
|
|
<label class="col-md-2 col-12 col-form-label" for="Apellidos">Apellidos</label>
|
||
|
|
<div class="col-lg-8 col-md-8 col-12">
|
||
|
|
<input id="apellidos" name="apellidos" placeholder="Apellidos" type="text" class="form-control">
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
<div class="form-group row">
|
||
|
|
<label for="catcentrotrab" class="col-md-2 col-12 col-form-label">Centro de trabajo</label>
|
||
|
|
<div class="col-lg-8 col-md-8 col-12">
|
||
|
|
<select id="catcentrotrab" name="catcentrotrab" class="custom-select" required="required">
|
||
|
|
</select>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
<div class="form-group row">
|
||
|
|
<label for="catdistrito" class="col-md-2 col-12 col-form-label">Distrito</label>
|
||
|
|
<div class="col-lg-8 col-md-8 col-12">
|
||
|
|
<select id="catdistrito" name="catdistrito" class="custom-select" required="required">
|
||
|
|
</select>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
<div class="form-group row">
|
||
|
|
<label for="catposicion" class="col-md-2 col-12 col-form-label">Posición</label>
|
||
|
|
<div class="col-lg-8 col-md-8 col-12">
|
||
|
|
<select id="catposicion" name="catposicion" class="custom-select">
|
||
|
|
</select>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
<div class="form-group row">
|
||
|
|
<label for="catsociedad" class="col-md-2 col-12 col-form-label">Sociedad</label>
|
||
|
|
<div class="col-lg-8 col-md-8 col-12">
|
||
|
|
<select id="catsociedad" name="catsociedad" class="custom-select">
|
||
|
|
</select>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
<div class="form-group row">
|
||
|
|
<label for="catdivision" class="col-md-2 col-12 col-form-label">División</label>
|
||
|
|
<div class="col-lg-8 col-md-8 col-12">
|
||
|
|
<select id="catdivision" name="catdivision" class="custom-select">
|
||
|
|
</select>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
<div class="form-group row">
|
||
|
|
<label for="catunidad" class="col-md-2 col-12 col-form-label">Unidad organizativa</label>
|
||
|
|
<div class="col-lg-8 col-md-8 col-12">
|
||
|
|
<select id="catunidad" name="catunidad" class="custom-select">
|
||
|
|
</select>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
<div class="form-group row">
|
||
|
|
<label for="catceco" class="col-md-2 col-12 col-form-label">CeCo</label>
|
||
|
|
<div class="col-lg-8 col-md-8 col-12">
|
||
|
|
<select id="catceco" name="catceco" class="custom-select">
|
||
|
|
</select>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
<div class="form-group row">
|
||
|
|
<label for="catsupervisor" class="col-md-2 col-12 col-form-label">Supervisor</label>
|
||
|
|
<div class="col-lg-8 col-md-8 col-12">
|
||
|
|
<select id="catsupervisor" name="catsupervisor" class="custom-select">
|
||
|
|
</select>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
<div class="form-group row">
|
||
|
|
<label for="habilitado" class="col-md-2 col-12 col-form-label">Habilitado</label>
|
||
|
|
<div class="col-lg-8 col-md-8 col-12">
|
||
|
|
<select id="habilitado" name="habilitado" class="custom-select">
|
||
|
|
<option value="1">ACTIVO</option>
|
||
|
|
<option value="0">BAJA</option>
|
||
|
|
</select>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
<div class="form-group row justify-content-center">
|
||
|
|
<div class="col-12 col-md-6 text-right">
|
||
|
|
<div class="btn btn-warning btn_cancelar">Cancelar</div>
|
||
|
|
<button name="Enviar" type="submit" value="Enviar" class="btn btn-primary">Enviar</button>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</form>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</section>
|
||
|
|
<script type="text/javascript">
|
||
|
|
|
||
|
|
|
||
|
|
$(".layer-load").show();
|
||
|
|
var table;
|
||
|
|
var query;
|
||
|
|
|
||
|
|
window.alert = (function() {
|
||
|
|
var nativeAlert = window.alert;
|
||
|
|
return function(message) {
|
||
|
|
window.alert = nativeAlert;
|
||
|
|
message.indexOf("DataTables warning") === 0 ?
|
||
|
|
console.warn(message) :
|
||
|
|
nativeAlert(message);
|
||
|
|
}
|
||
|
|
})();
|
||
|
|
|
||
|
|
jQuery(document).ready(function ($) {
|
||
|
|
/**********************************************************************/
|
||
|
|
/****************** administración ************************************/
|
||
|
|
/**********************************************************************/
|
||
|
|
admin();
|
||
|
|
validateForm();
|
||
|
|
|
||
|
|
function admin(){
|
||
|
|
var rol = $('#roladmin').val();
|
||
|
|
if(rol != 2){
|
||
|
|
$('.admin').remove();
|
||
|
|
|
||
|
|
$('.actualizacion h2').html('Baja masiva de usuarios');
|
||
|
|
$('.actualizacion .legend').html('Se debe de colocar el número de empleado y en la columna de habilitado colocar <b>0</b> para dar de baja ó <b>1</b> para activar nuevamente usuarios ya previamente registrados.');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
function validateCreate(){
|
||
|
|
|
||
|
|
|
||
|
|
if($('#roladmin').val() != 2){
|
||
|
|
|
||
|
|
$.ajax({
|
||
|
|
url: 'usuarios_statistical.php'
|
||
|
|
})
|
||
|
|
.done(function (response) {
|
||
|
|
var _data = parseJSON(response);
|
||
|
|
|
||
|
|
if (_data.code == "200" && _data.codelimite == "200") {
|
||
|
|
//console.log(_data.conteo.estadisticos,_data.limite.limite);
|
||
|
|
if (parseInt(_data.conteo.estadisticos) >= parseInt(_data.limite.limite)) {
|
||
|
|
Swal.fire({
|
||
|
|
html: 'Se alcanzado el límite de usuarios para dar de alta.',
|
||
|
|
icon: "warning",
|
||
|
|
onBeforeOpen: function () {},
|
||
|
|
onOpen: function () {},
|
||
|
|
onRender: function () {},
|
||
|
|
onClose: function () {
|
||
|
|
$(".preview").hide();
|
||
|
|
$(".controller").show();
|
||
|
|
$(".editor").hide();
|
||
|
|
//reloadData();
|
||
|
|
},
|
||
|
|
onAfterClose: function () {}
|
||
|
|
});
|
||
|
|
}else{
|
||
|
|
crear();
|
||
|
|
}
|
||
|
|
|
||
|
|
}else{
|
||
|
|
Swal.fire({
|
||
|
|
html: 'Hubo un error al intentar procesar los datos.',
|
||
|
|
icon: "error",
|
||
|
|
onBeforeOpen: function () {},
|
||
|
|
onOpen: function () {},
|
||
|
|
onRender: function () {},
|
||
|
|
onClose: function () {
|
||
|
|
$(".preview").hide();
|
||
|
|
$(".controller").show();
|
||
|
|
$(".editor").hide();
|
||
|
|
reloadData();
|
||
|
|
},
|
||
|
|
onAfterClose: function () {}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
})
|
||
|
|
.fail(function () {
|
||
|
|
//console.log("error");
|
||
|
|
})
|
||
|
|
.always(function () {
|
||
|
|
//console.log("complete");
|
||
|
|
});
|
||
|
|
|
||
|
|
}else{
|
||
|
|
crear();
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
function validateForm(){
|
||
|
|
if($('#roladmin').val() != 2){
|
||
|
|
$.ajax({
|
||
|
|
url: 'usuarios_statistical.php'
|
||
|
|
})
|
||
|
|
.done(function (response) {
|
||
|
|
var _data = parseJSON(response);
|
||
|
|
|
||
|
|
if (_data.code == "200" && _data.codelimite == "200") {
|
||
|
|
if (parseInt(_data.conteo.estadisticos) >= parseInt(_data.limite.limite)) {
|
||
|
|
$('#customFile').prop('disabled',true);
|
||
|
|
$('#masiveusers button').prop('disabled',true);
|
||
|
|
}else{
|
||
|
|
$('#customFile').prop('disabled',false);
|
||
|
|
$('#masiveusers button').prop('disabled',false);
|
||
|
|
}
|
||
|
|
}
|
||
|
|
})
|
||
|
|
.fail(function () {
|
||
|
|
//console.log("error");
|
||
|
|
})
|
||
|
|
.always(function () {
|
||
|
|
//console.log("complete");
|
||
|
|
});
|
||
|
|
|
||
|
|
}else{
|
||
|
|
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
/**********************************************************************/
|
||
|
|
/****************** masiveusers *****************************************/
|
||
|
|
/**********************************************************************/
|
||
|
|
$("#masiveusers").validate({
|
||
|
|
rules: {
|
||
|
|
customFile: {
|
||
|
|
required: true,
|
||
|
|
extension: "xlsx"
|
||
|
|
}
|
||
|
|
},
|
||
|
|
invalidHandler: function (event, validator) {
|
||
|
|
$(".custom-file-label").removeClass('selected').html('Subir archivo');
|
||
|
|
},
|
||
|
|
submitHandler: function () {
|
||
|
|
var data = new FormData();
|
||
|
|
|
||
|
|
if ($('#roladmin').val() != 2) {
|
||
|
|
url = "usuarios_masive_upload_manager.php";
|
||
|
|
}else{
|
||
|
|
url = "usuarios_masive_upload.php";
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
//File data
|
||
|
|
var file_data = $('input[name="customFile"]')[0].files;
|
||
|
|
for (var i = 0; i < file_data.length; i++) {
|
||
|
|
data.append("customFile[]", file_data[i]);
|
||
|
|
}
|
||
|
|
$(".layer-load").show();
|
||
|
|
$.ajax({
|
||
|
|
url: url,
|
||
|
|
method: "post",
|
||
|
|
processData: false,
|
||
|
|
contentType: false,
|
||
|
|
data: data,
|
||
|
|
success: function (response) {
|
||
|
|
//success
|
||
|
|
var _data = parseJSON(response);
|
||
|
|
console.log(_data);
|
||
|
|
if (_data.error > 0) {
|
||
|
|
Swal.fire({
|
||
|
|
html: _data.msg,
|
||
|
|
icon: "error",
|
||
|
|
onBeforeOpen: function () {},
|
||
|
|
onOpen: function () {},
|
||
|
|
onRender: function () {},
|
||
|
|
onClose: function () {
|
||
|
|
$('#masiveusers').trigger("reset");
|
||
|
|
$(".custom-file-label").removeClass('selected').html('Subir archivo');
|
||
|
|
},
|
||
|
|
onAfterClose: function () {}
|
||
|
|
});
|
||
|
|
} else {
|
||
|
|
$(".resutadosmasivos").html("");
|
||
|
|
$(".resutadosmasivos").html('<h3>Resultado</h3><ul class="list-group listresult"></ul>')
|
||
|
|
$.each(_data.results, function (index, val) {
|
||
|
|
$(".listresult").append('<li class="list-group-item">' + val + '</li>');
|
||
|
|
});
|
||
|
|
$(".resutadosmasivos").append('<p class="my-2 pl-2">Procesados: ' + _data.procesados + ' Correctos: ' + _data.correctos + '</p>');
|
||
|
|
$('#masiveusers').trigger("reset");
|
||
|
|
$(".custom-file-label").removeClass('selected').html('Subir archivo');
|
||
|
|
reloadData();
|
||
|
|
}
|
||
|
|
$(".layer-load").hide();
|
||
|
|
},
|
||
|
|
error: function (e) {
|
||
|
|
//error
|
||
|
|
$(".layer-load").hide();
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
// Add the following code if you want the name of the file appear on select
|
||
|
|
$(".custom-file-input").on("change", function () {
|
||
|
|
var fileName = $(this).val().split("\\").pop();
|
||
|
|
$(this).siblings(".custom-file-label").addClass("selected").html(fileName);
|
||
|
|
});
|
||
|
|
/**********************************************************************/
|
||
|
|
/********************* update masiveusers *****************************/
|
||
|
|
/**********************************************************************/
|
||
|
|
$("#updatemasiveusers").validate({
|
||
|
|
rules: {
|
||
|
|
customFileUpdate: {
|
||
|
|
required: true,
|
||
|
|
extension: "xlsx"
|
||
|
|
}
|
||
|
|
},
|
||
|
|
invalidHandler: function (event, validator) {
|
||
|
|
$(".custom-file-label").removeClass('selected').html('Subir archivo');
|
||
|
|
},
|
||
|
|
submitHandler: function () {
|
||
|
|
var data = new FormData();
|
||
|
|
//File data
|
||
|
|
var file_data = $('input[name="customFileUpdate"]')[0].files;
|
||
|
|
for (var i = 0; i < file_data.length; i++) {
|
||
|
|
data.append("customFileUpdate[]", file_data[i]);
|
||
|
|
}
|
||
|
|
|
||
|
|
$(".layer-load").show();
|
||
|
|
$('html, body').animate({
|
||
|
|
scrollTop: $(".layer-load").offset().top
|
||
|
|
}, 2000);
|
||
|
|
|
||
|
|
|
||
|
|
$.ajax({
|
||
|
|
url: "usuarios_update_masive_upload.php",
|
||
|
|
method: "post",
|
||
|
|
processData: false,
|
||
|
|
contentType: false,
|
||
|
|
data: data,
|
||
|
|
success: function (response) {
|
||
|
|
//success
|
||
|
|
var _data = parseJSON(response);
|
||
|
|
console.log(_data);
|
||
|
|
if (_data.error > 0) {
|
||
|
|
Swal.fire({
|
||
|
|
html: _data.msg,
|
||
|
|
icon: "error",
|
||
|
|
onBeforeOpen: function () {},
|
||
|
|
onOpen: function () {},
|
||
|
|
onRender: function () {},
|
||
|
|
onClose: function () {
|
||
|
|
$('#updatemasiveusers').trigger("reset");
|
||
|
|
$(".custom-file-label").removeClass('selected').html('Subir archivo');
|
||
|
|
},
|
||
|
|
onAfterClose: function () {}
|
||
|
|
});
|
||
|
|
} else {
|
||
|
|
$(".resultadosmasivos").html("");
|
||
|
|
$(".resultadosmasivos").html('<h3>Resultado</h3><ul class="list-group listresult"></ul>')
|
||
|
|
$.each(_data.results, function (index, val) {
|
||
|
|
$(".listresult").append('<li class="list-group-item">' + val + '</li>');
|
||
|
|
});
|
||
|
|
$(".resultadosmasivos").append('<p class="my-2 pl-2">Procesados: ' + _data.procesados + ' Correctos: ' + _data.correctos + '</p>');
|
||
|
|
$('#updatemasiveusers').trigger("reset");
|
||
|
|
$(".custom-file-label").removeClass('selected').html('Subir archivo');
|
||
|
|
$('html, body').animate({
|
||
|
|
scrollTop: $(".resultadosmasivos").offset().top
|
||
|
|
}, 2000);
|
||
|
|
reloadData();
|
||
|
|
}
|
||
|
|
$(".layer-load").hide();
|
||
|
|
},
|
||
|
|
error: function (e) {
|
||
|
|
//error
|
||
|
|
$(".layer-load").hide();
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
// Add the following code if you want the name of the file appear on select
|
||
|
|
$(".custom-file-input").on("change", function () {
|
||
|
|
var fileName = $(this).val().split("\\").pop();
|
||
|
|
$(this).siblings(".custom-file-label").addClass("selected").html(fileName);
|
||
|
|
});
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
/**********************************************************************/
|
||
|
|
/****************** DATATABLE *****************************************/
|
||
|
|
/**********************************************************************/
|
||
|
|
function parseJSON(resp) {
|
||
|
|
if (resp == null) return null;
|
||
|
|
if (typeof resp === 'object') return resp;
|
||
|
|
try { return JSON.parse(resp); }
|
||
|
|
catch (e) {
|
||
|
|
console.error('Respuesta no-JSON del servidor:', String(resp).substring(0, 300));
|
||
|
|
return null;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
function getData() {
|
||
|
|
|
||
|
|
listadoDeRoles();
|
||
|
|
listadoCentros();
|
||
|
|
listadoDistritos();
|
||
|
|
listadoPosiciones();
|
||
|
|
listadoSociedades();
|
||
|
|
listadoDivisiones();
|
||
|
|
listadoUnidades();
|
||
|
|
listadoCeCo();
|
||
|
|
listadoSupervisores();
|
||
|
|
$(".layer-load").show();
|
||
|
|
|
||
|
|
var urlusuarios;
|
||
|
|
if($('#roladmin').val() != 2){
|
||
|
|
urlusuarios = "usuarios_manager.php";
|
||
|
|
}else{
|
||
|
|
urlusuarios = "usuarios.php";
|
||
|
|
}
|
||
|
|
|
||
|
|
table = $('#datatable').DataTable({
|
||
|
|
dom: "Bfrtip",
|
||
|
|
responsive: true,
|
||
|
|
"drawCallback": function (settings) {
|
||
|
|
|
||
|
|
$("#btn_edit, #btn_habilitar").addClass('disabled');
|
||
|
|
addEventsCheck();
|
||
|
|
|
||
|
|
window.alert = (function() {
|
||
|
|
var nativeAlert = window.alert;
|
||
|
|
return function(message) {
|
||
|
|
window.alert = nativeAlert;
|
||
|
|
message.indexOf("DataTables warning") === 0 ?
|
||
|
|
console.warn(message) :
|
||
|
|
nativeAlert(message);
|
||
|
|
}
|
||
|
|
})();
|
||
|
|
|
||
|
|
},
|
||
|
|
buttons: [{
|
||
|
|
text: 'Exportar',
|
||
|
|
action: function (e, dt, node, config) {
|
||
|
|
exportar(e, dt, node, config);
|
||
|
|
},
|
||
|
|
attr: {
|
||
|
|
id: 'btn_export'
|
||
|
|
}
|
||
|
|
},
|
||
|
|
{
|
||
|
|
text: 'Editar',
|
||
|
|
action: function (e, dt, node, config) {
|
||
|
|
editar(e, dt, node, config);
|
||
|
|
},
|
||
|
|
attr: {
|
||
|
|
id: 'btn_edit'
|
||
|
|
}
|
||
|
|
},
|
||
|
|
{
|
||
|
|
text: 'Alternar habilitar',
|
||
|
|
action: function (e, dt, node, config) {
|
||
|
|
deshabilitar(e, dt, node, config)
|
||
|
|
},
|
||
|
|
attr: {
|
||
|
|
id: 'btn_habilitar'
|
||
|
|
}
|
||
|
|
},
|
||
|
|
{
|
||
|
|
text: 'Crear',
|
||
|
|
action: function (e, dt, node, config) {
|
||
|
|
//crear();
|
||
|
|
validateCreate();
|
||
|
|
},
|
||
|
|
attr: {
|
||
|
|
id: 'btn_crear'
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
],
|
||
|
|
'columnDefs': [{
|
||
|
|
'targets': 0,
|
||
|
|
'checkboxes': { 'selectRow': true }
|
||
|
|
}],
|
||
|
|
|
||
|
|
'order': [
|
||
|
|
[1, 'asc']
|
||
|
|
],
|
||
|
|
"processing": true,
|
||
|
|
"serverSide": true,
|
||
|
|
"ajax":{
|
||
|
|
"url": urlusuarios
|
||
|
|
},
|
||
|
|
"language": {
|
||
|
|
"url": "../json/Spanish.json"
|
||
|
|
},
|
||
|
|
"initComplete": function( settings, json ) {
|
||
|
|
$(".layer-load").hide();
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
function reloadData() {
|
||
|
|
validateForm();
|
||
|
|
listadoDeRoles();
|
||
|
|
listadoCentros();
|
||
|
|
listadoDistritos();
|
||
|
|
listadoPosiciones();
|
||
|
|
listadoSociedades();
|
||
|
|
listadoDivisiones();
|
||
|
|
listadoUnidades();
|
||
|
|
listadoCeCo();
|
||
|
|
listadoSupervisores();
|
||
|
|
|
||
|
|
|
||
|
|
setTimeout(function(){
|
||
|
|
$('#datatable').DataTable().ajax.reload(null, false);
|
||
|
|
}, 500);
|
||
|
|
table.column(0).checkboxes.deselectAll();
|
||
|
|
}
|
||
|
|
|
||
|
|
function addEventsCheck() {
|
||
|
|
$("#datatable_wrapper input[type='checkbox']").on('change', function (e) {
|
||
|
|
console.log('clic checkbox');
|
||
|
|
setTimeout(function (){
|
||
|
|
console.log($("#datatable_wrapper input[type='checkbox']:checked").length);
|
||
|
|
if (table.column(0).checkboxes.selected().length == 0) {
|
||
|
|
$("#btn_edit, #btn_habilitar").addClass('disabled');
|
||
|
|
} else if (table.column(0).checkboxes.selected().length == 1) {
|
||
|
|
$("#btn_edit, #btn_habilitar").removeClass('disabled');
|
||
|
|
} else if (table.column(0).checkboxes.selected().length > 1) {
|
||
|
|
$("#btn_edit").addClass('disabled');
|
||
|
|
$("#btn_habilitar").removeClass('disabled');
|
||
|
|
}
|
||
|
|
}, 150);
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
/**********************************************************************/
|
||
|
|
/****************** Editar, Deshabilitar, Crear ***********************/
|
||
|
|
/**********************************************************************/
|
||
|
|
|
||
|
|
function exportar(){
|
||
|
|
window.open('exportUsers.php?roladmin=' + encodeURIComponent($('#roladmin').val()), '_blank');
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
function listadoDeRoles() {
|
||
|
|
var urllist = "";
|
||
|
|
if($('#roladmin').val() != 2){
|
||
|
|
urllist = "usuarios_rol_list_manager.php";
|
||
|
|
}else{
|
||
|
|
urllist = "usuarios_rol_list.php";
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
$(".layer-load").show();
|
||
|
|
$.ajax({
|
||
|
|
url: urllist,
|
||
|
|
type: 'POST'
|
||
|
|
})
|
||
|
|
.done(function (response) {
|
||
|
|
var _data = parseJSON(response);
|
||
|
|
if (_data.code == "1") {
|
||
|
|
$("#rolname").html("");
|
||
|
|
|
||
|
|
$.each(_data.datos, function (index, val) {
|
||
|
|
$("#rolname").append('<option value="' + val.id + '">' + val.nombre + '</option>');
|
||
|
|
});
|
||
|
|
} else {
|
||
|
|
$("#rolname").html('<option value="2">Administrador</option>');
|
||
|
|
}
|
||
|
|
$(".layer-load").hide();
|
||
|
|
})
|
||
|
|
.fail(function () {
|
||
|
|
|
||
|
|
})
|
||
|
|
.always(function () {
|
||
|
|
|
||
|
|
});
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
function listadoCentros(){
|
||
|
|
$(".layer-load").show();
|
||
|
|
$.ajax({
|
||
|
|
url: 'usuarios_centros_list.php',
|
||
|
|
type: 'POST'
|
||
|
|
})
|
||
|
|
.done(function (response) {
|
||
|
|
var _data = parseJSON(response);
|
||
|
|
if (_data.code == "1") {
|
||
|
|
$("#catcentrotrab").html("");
|
||
|
|
|
||
|
|
//$("#catcentrotrab").append('<option selected disabled>Selecciona un centro de trabajo</option>');
|
||
|
|
$.each(_data.datos, function (index, val) {
|
||
|
|
$("#catcentrotrab").append('<option value="' + val.nombrecentro + '">' + val.nombrecentro + '</option>');
|
||
|
|
});
|
||
|
|
} else {
|
||
|
|
$("#catcentrotrab").html('<option value="0">Sin centros</option>');
|
||
|
|
}
|
||
|
|
$(".layer-load").hide();
|
||
|
|
})
|
||
|
|
.fail(function () {
|
||
|
|
|
||
|
|
})
|
||
|
|
.always(function () {
|
||
|
|
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
function listadoDistritos(){
|
||
|
|
$(".layer-load").show();
|
||
|
|
$.ajax({
|
||
|
|
url: 'usuarios_distritos_list.php',
|
||
|
|
type: 'POST'
|
||
|
|
})
|
||
|
|
.done(function (response) {
|
||
|
|
var _data = parseJSON(response);
|
||
|
|
if (_data.code == "1") {
|
||
|
|
$("#catdistrito").html("");
|
||
|
|
|
||
|
|
//$("#catdistrito").append('<option selected disabled>Selecciona un distrito</option>');
|
||
|
|
$.each(_data.datos, function (index, val) {
|
||
|
|
$("#catdistrito").append('<option value="' + val.nombredistrito + '">' + val.nombredistrito + '</option>');
|
||
|
|
});
|
||
|
|
} else {
|
||
|
|
$("#catdistrito").html('<option value="0">Sin distritos</option>');
|
||
|
|
}
|
||
|
|
$(".layer-load").hide();
|
||
|
|
})
|
||
|
|
.fail(function () {
|
||
|
|
|
||
|
|
})
|
||
|
|
.always(function () {
|
||
|
|
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
function listadoPosiciones(){
|
||
|
|
$(".layer-load").show();
|
||
|
|
$.ajax({
|
||
|
|
url: 'usuarios_posiciones_list.php',
|
||
|
|
type: 'POST'
|
||
|
|
})
|
||
|
|
.done(function (response) {
|
||
|
|
var _data = parseJSON(response);
|
||
|
|
if (_data.code == "1") {
|
||
|
|
$("#catposicion").html("");
|
||
|
|
|
||
|
|
//$("#catdistrito").append('<option selected disabled>Selecciona un distrito</option>');
|
||
|
|
$.each(_data.datos, function (index, val) {
|
||
|
|
$("#catposicion").append('<option value="' + val.posicion+ '">' + val.posicion + '</option>');
|
||
|
|
});
|
||
|
|
} else {
|
||
|
|
$("#catposicion").html('<option value="0">Sin posiciones</option>');
|
||
|
|
}
|
||
|
|
$(".layer-load").hide();
|
||
|
|
})
|
||
|
|
.fail(function () {
|
||
|
|
|
||
|
|
})
|
||
|
|
.always(function () {
|
||
|
|
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
function listadoSociedades(){
|
||
|
|
$(".layer-load").show();
|
||
|
|
$.ajax({
|
||
|
|
url: 'usuarios_sociedades_list.php',
|
||
|
|
type: 'POST'
|
||
|
|
})
|
||
|
|
.done(function (response) {
|
||
|
|
var _data = parseJSON(response);
|
||
|
|
if (_data.code == "1") {
|
||
|
|
$("#catsociedad").html("");
|
||
|
|
|
||
|
|
//$("#catdistrito").append('<option selected disabled>Selecciona un distrito</option>');
|
||
|
|
$.each(_data.datos, function (index, val) {
|
||
|
|
$("#catsociedad").append('<option value="' + val.sociedad+ '">' + val.sociedad + '</option>');
|
||
|
|
});
|
||
|
|
} else {
|
||
|
|
$("#catsociedad").html('<option value="0">Sin sociedades</option>');
|
||
|
|
}
|
||
|
|
$(".layer-load").hide();
|
||
|
|
})
|
||
|
|
.fail(function () {
|
||
|
|
|
||
|
|
})
|
||
|
|
.always(function () {
|
||
|
|
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
function listadoDivisiones(){
|
||
|
|
$(".layer-load").show();
|
||
|
|
$.ajax({
|
||
|
|
url: 'usuarios_divisiones_list.php',
|
||
|
|
type: 'POST'
|
||
|
|
})
|
||
|
|
.done(function (response) {
|
||
|
|
var _data = parseJSON(response);
|
||
|
|
if (_data.code == "1") {
|
||
|
|
$("#catdivision").html("");
|
||
|
|
|
||
|
|
//$("#catdistrito").append('<option selected disabled>Selecciona un distrito</option>');
|
||
|
|
$.each(_data.datos, function (index, val) {
|
||
|
|
$("#catdivision").append('<option value="' + val.division+ '">' + val.division + '</option>');
|
||
|
|
});
|
||
|
|
} else {
|
||
|
|
$("#catdivision").html('<option value="0">Sin divisiones</option>');
|
||
|
|
}
|
||
|
|
$(".layer-load").hide();
|
||
|
|
})
|
||
|
|
.fail(function () {
|
||
|
|
|
||
|
|
})
|
||
|
|
.always(function () {
|
||
|
|
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
function listadoUnidades(){
|
||
|
|
$(".layer-load").show();
|
||
|
|
$.ajax({
|
||
|
|
url: 'usuarios_unidades_list.php',
|
||
|
|
type: 'POST'
|
||
|
|
})
|
||
|
|
.done(function (response) {
|
||
|
|
var _data = parseJSON(response);
|
||
|
|
if (_data.code == "1") {
|
||
|
|
$("#catunidad").html("");
|
||
|
|
|
||
|
|
//$("#catdistrito").append('<option selected disabled>Selecciona un distrito</option>');
|
||
|
|
$.each(_data.datos, function (index, val) {
|
||
|
|
$("#catunidad").append('<option value="' + val.unidad+ '">' + val.unidad + '</option>');
|
||
|
|
});
|
||
|
|
} else {
|
||
|
|
$("#catunidad").html('<option value="0">Sin unidades</option>');
|
||
|
|
}
|
||
|
|
$(".layer-load").hide();
|
||
|
|
})
|
||
|
|
.fail(function () {
|
||
|
|
|
||
|
|
})
|
||
|
|
.always(function () {
|
||
|
|
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
function listadoCeCo(){
|
||
|
|
$(".layer-load").show();
|
||
|
|
$.ajax({
|
||
|
|
url: 'usuarios_ceco_list.php',
|
||
|
|
type: 'POST'
|
||
|
|
})
|
||
|
|
.done(function (response) {
|
||
|
|
var _data = parseJSON(response);
|
||
|
|
if (_data.code == "1") {
|
||
|
|
$("#catceco").html("");
|
||
|
|
|
||
|
|
//$("#catdistrito").append('<option selected disabled>Selecciona un distrito</option>');
|
||
|
|
$.each(_data.datos, function (index, val) {
|
||
|
|
$("#catceco").append('<option value="' + val.ceco+ '">' + val.ceco + '</option>');
|
||
|
|
});
|
||
|
|
} else {
|
||
|
|
$("#catceco").html('<option value="0">Sin Ceco</option>');
|
||
|
|
}
|
||
|
|
$(".layer-load").hide();
|
||
|
|
})
|
||
|
|
.fail(function () {
|
||
|
|
|
||
|
|
})
|
||
|
|
.always(function () {
|
||
|
|
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
function listadoSupervisores(){
|
||
|
|
$(".layer-load").show();
|
||
|
|
$.ajax({
|
||
|
|
url: 'usuarios_supervisores_list.php',
|
||
|
|
type: 'POST'
|
||
|
|
})
|
||
|
|
.done(function (response) {
|
||
|
|
var _data = parseJSON(response);
|
||
|
|
if (_data.code == "1") {
|
||
|
|
$("#catsupervisor").html("");
|
||
|
|
|
||
|
|
//$("#catdistrito").append('<option selected disabled>Selecciona un distrito</option>');
|
||
|
|
$.each(_data.datos, function (index, val) {
|
||
|
|
$("#catsupervisor").append('<option value="' + val.supervisor+ '">' + val.supervisor + '</option>');
|
||
|
|
});
|
||
|
|
} else {
|
||
|
|
$("#catsupervisor").html('<option value="0">Sin supervisores</option>');
|
||
|
|
}
|
||
|
|
$(".layer-load").hide();
|
||
|
|
})
|
||
|
|
.fail(function () {
|
||
|
|
|
||
|
|
})
|
||
|
|
.always(function () {
|
||
|
|
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
function editar(e, dt, node, config) {
|
||
|
|
var $table = table.table().node();
|
||
|
|
var $chkbox_checked = $('tbody input[type="checkbox"]:checked', $table);
|
||
|
|
$($chkbox_checked).closest('tr')
|
||
|
|
var data = table.row($($chkbox_checked).closest('tr')).data();
|
||
|
|
$("#iduser").val(data[0]);
|
||
|
|
$("#numempl").val(data[1]);
|
||
|
|
$("#email").val(data[2]);
|
||
|
|
$("#nombre").val(data[3]);
|
||
|
|
$("#apellidos").val(data[4]);
|
||
|
|
|
||
|
|
$("#catcentrotrab").find('option').each(function (index, el) {
|
||
|
|
if ($(this).text() == data[5]) {
|
||
|
|
$("#catcentrotrab").val($(this).attr('value'));
|
||
|
|
}
|
||
|
|
});
|
||
|
|
$("#catdistrito").find('option').each(function (index, el) {
|
||
|
|
if ($(this).text() == data[6]) {
|
||
|
|
$("#catdistrito").val($(this).attr('value'));
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
var str = data[7];
|
||
|
|
//console.log(data[7]);
|
||
|
|
if (str == null) {
|
||
|
|
posicion = data[7];
|
||
|
|
}else{
|
||
|
|
var res = str.replace("'", "'");
|
||
|
|
var posicion = res.replace("'", "'");
|
||
|
|
}
|
||
|
|
|
||
|
|
$("#catposicion").find('option').each(function (index, el) {
|
||
|
|
if ($(this).text() == posicion) {
|
||
|
|
$("#catposicion").val($(this).attr('value'));
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
|
||
|
|
//$("#catposicion").val(data[7]);
|
||
|
|
$("#catsociedad").val(data[8]);
|
||
|
|
$("#catdivision").val(data[9]);
|
||
|
|
$("#catunidad").val(data[10]);
|
||
|
|
$("#catceco").val(data[11]);
|
||
|
|
$("#catsupervisor").val(data[12]);
|
||
|
|
|
||
|
|
|
||
|
|
$("#habilitado").find('option').each(function (index, el) {
|
||
|
|
if ($(this).text() == data[13]) {
|
||
|
|
$("#habilitado").val($(this).attr('value'));
|
||
|
|
}
|
||
|
|
});
|
||
|
|
//$("#habilitado").val(data[13]);
|
||
|
|
|
||
|
|
$("#rolname").find('option').each(function (index, el) {
|
||
|
|
if ($(this).text() == data[18]) {
|
||
|
|
$("#rolname").val($(this).attr('value'));
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
$(".controller").hide();
|
||
|
|
$(".editor").show();
|
||
|
|
$(".edit").show();
|
||
|
|
$(".crear").hide();
|
||
|
|
$("#password").rules("remove", 'required');
|
||
|
|
$("#password").rules("remove", 'minlength');
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
function deshabilitar(e, dt, node, config) {
|
||
|
|
var rows_selected = table.column(0).checkboxes.selected();
|
||
|
|
|
||
|
|
var ids = new Array();
|
||
|
|
$.each(rows_selected, function (index, rowId) {
|
||
|
|
ids.push(rowId);
|
||
|
|
});
|
||
|
|
|
||
|
|
var urldelete;
|
||
|
|
if ($('#roladmin').val() != 2) {
|
||
|
|
urldelete = "usuarios_delete_manager.php";
|
||
|
|
}else{
|
||
|
|
urldelete = "usuarios_delete.php";
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
$(".layer-load").show();
|
||
|
|
$.ajax({
|
||
|
|
url: urldelete,
|
||
|
|
type: 'POST',
|
||
|
|
data: { ids: ids },
|
||
|
|
})
|
||
|
|
.done(function (response) {
|
||
|
|
Swal.fire({
|
||
|
|
html: response,
|
||
|
|
icon: "success",
|
||
|
|
onBeforeOpen: function () {},
|
||
|
|
onOpen: function () {},
|
||
|
|
onRender: function () {},
|
||
|
|
onClose: function () {
|
||
|
|
reloadData();
|
||
|
|
},
|
||
|
|
onAfterClose: function () {}
|
||
|
|
});
|
||
|
|
})
|
||
|
|
.fail(function () {
|
||
|
|
|
||
|
|
})
|
||
|
|
.always(function () {
|
||
|
|
$(".layer-load").hide();
|
||
|
|
});
|
||
|
|
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
function crear() {
|
||
|
|
listadoDeRoles();
|
||
|
|
listadoCentros();
|
||
|
|
listadoDistritos();
|
||
|
|
listadoPosiciones();
|
||
|
|
listadoSociedades();
|
||
|
|
listadoDivisiones();
|
||
|
|
listadoUnidades();
|
||
|
|
listadoCeCo();
|
||
|
|
listadoSupervisores();
|
||
|
|
$("#iduser").val("");
|
||
|
|
$("#numempl").val("");
|
||
|
|
$("#email").val("");
|
||
|
|
$("#nombre").val("");
|
||
|
|
$("#apellidos").val("");
|
||
|
|
$("#habilitado").val(1);
|
||
|
|
$(".controller").hide();
|
||
|
|
$(".editor").show();
|
||
|
|
$(".edit").hide();
|
||
|
|
$(".crear").show();
|
||
|
|
// solo para este desarrolo
|
||
|
|
$("#password").rules("remove", 'required');
|
||
|
|
$("#password").rules("remove", 'minlength');
|
||
|
|
}
|
||
|
|
$(".btn_cancelar").click(function (event) {
|
||
|
|
$(".preview").hide();
|
||
|
|
$(".controller").show();
|
||
|
|
$(".editor").hide();
|
||
|
|
});
|
||
|
|
$(".formcontroller").validate({
|
||
|
|
submitHandler: function (form) {
|
||
|
|
|
||
|
|
var controller = 'usuarios_upadate.php';
|
||
|
|
if ($(".crear").css("display") == "block") {
|
||
|
|
controller = 'usuarios_add.php';
|
||
|
|
}
|
||
|
|
$.ajax({
|
||
|
|
url: controller,
|
||
|
|
type: 'POST',
|
||
|
|
data: $(".formcontroller").serializeArray(),
|
||
|
|
})
|
||
|
|
.done(function (response) {
|
||
|
|
//console.log("success");
|
||
|
|
Swal.fire({
|
||
|
|
html: response,
|
||
|
|
icon: "success",
|
||
|
|
onBeforeOpen: function () {},
|
||
|
|
onOpen: function () {},
|
||
|
|
onRender: function () {},
|
||
|
|
onClose: function () {
|
||
|
|
$(".preview").hide();
|
||
|
|
$(".controller").show();
|
||
|
|
$(".editor").hide();
|
||
|
|
reloadData();
|
||
|
|
},
|
||
|
|
onAfterClose: function () {}
|
||
|
|
});
|
||
|
|
})
|
||
|
|
.fail(function () {
|
||
|
|
//console.log("error");
|
||
|
|
})
|
||
|
|
.always(function () {
|
||
|
|
//console.log("complete");
|
||
|
|
});
|
||
|
|
},
|
||
|
|
rules: {
|
||
|
|
numempl: {
|
||
|
|
required: true,
|
||
|
|
maxlength: 254,
|
||
|
|
minlength: 2,
|
||
|
|
number: true
|
||
|
|
}
|
||
|
|
},
|
||
|
|
messages: {
|
||
|
|
numempl: {
|
||
|
|
required: "El número de empleado es obligatorio",
|
||
|
|
minlength: jQuery.validator.format("El número de empleado es de al menos {0} caracteres"),
|
||
|
|
maxlength: jQuery.validator.format("El número de empleado es de máximo {0} digitos")
|
||
|
|
}
|
||
|
|
}
|
||
|
|
});
|
||
|
|
$("#mostrarpassword").click(function (event) {
|
||
|
|
var x = document.getElementById("password");
|
||
|
|
if (x.type === "password") {
|
||
|
|
x.type = "text";
|
||
|
|
} else {
|
||
|
|
x.type = "password";
|
||
|
|
}
|
||
|
|
});
|
||
|
|
|
||
|
|
$("#password").keyup(function (event) {
|
||
|
|
if ($(".crear").css("display") == "block") {
|
||
|
|
$(this).rules("add", 'required');
|
||
|
|
$(this).rules("add", 'minlength');
|
||
|
|
} else {
|
||
|
|
if ($(this).val() != "") {
|
||
|
|
$(this).rules("add", 'required');
|
||
|
|
$(this).rules("add", 'minlength');
|
||
|
|
} else {
|
||
|
|
$(this).rules("remove", 'required');
|
||
|
|
$(this).rules("remove", 'minlength');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
// solo para este desarrolo
|
||
|
|
$(this).rules("remove", 'required');
|
||
|
|
$(this).rules("remove", 'minlength');
|
||
|
|
});
|
||
|
|
|
||
|
|
getData();
|
||
|
|
});
|
||
|
|
</script>
|