443 lines
15 KiB
HTML
443 lines
15 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">Asignaciones</h1>
|
||
|
|
<p>Sistema de asignación de usuarios a categorías principales, al momento de crear la asignación, el usuario tendrá acceso a todos los recursos de dicha categoría, sino se le asigna ninguna categoría el usuario no podrá acceder a ningún recurso.</p>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</section>
|
||
|
|
<section class="py-md-4 py-2 controller">
|
||
|
|
<div class="container-fluid">
|
||
|
|
<div class="row">
|
||
|
|
<div class="col-12 text-left py-2 py-md-0 cat_disponibles">
|
||
|
|
<p>Selecciona la categoría<p>
|
||
|
|
<select id="catsuperior" class="col-12 col-md-6 selectpicker" data-live-search="true">
|
||
|
|
</select>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
<div class="row my-3">
|
||
|
|
<div class="col-12 text-left">
|
||
|
|
<h3 class="catname">Bienvenido a bordo de Estafeta</h3>
|
||
|
|
</div>
|
||
|
|
<div class="col-12 col-md-6 py-2 py-md-0">
|
||
|
|
<div class="card h-100 bg-transparent freecardasignaciones">
|
||
|
|
<div class="card-header bg-transparent">
|
||
|
|
<h5 class="text-primary font-weight-bold">Asignados</h5>
|
||
|
|
</div>
|
||
|
|
<div class="card-body">
|
||
|
|
<select class="custom-select" multiple id="lista_asignaciones">
|
||
|
|
</select>
|
||
|
|
</div>
|
||
|
|
<div class="card-footer bg-transparent">
|
||
|
|
<input class="form-control w-100" id="busqueda_asignados" type="text" placeholder="Buscar..">
|
||
|
|
<div class="row align-items-center text-center my-3">
|
||
|
|
<div class="col-6 text-center">
|
||
|
|
<div class="btn btn-primary btn_quitar">Quitar seleccionados</div>
|
||
|
|
</div>
|
||
|
|
<div class="col-6 text-center">
|
||
|
|
<div class="btn btn-primary btn_quitar_des">Limpiar selección</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
<div class="col-12 col-md-6 py-2 py-md-0">
|
||
|
|
<div class="card h-100 bg-transparent freecardasignaciones">
|
||
|
|
<div class="card-header bg-transparent">
|
||
|
|
<h5 class="text-primary font-weight-bold">Disponibles</h5>
|
||
|
|
</div>
|
||
|
|
<div class="card-body">
|
||
|
|
<select class="custom-select" multiple id="lista_disponibles">
|
||
|
|
</select>
|
||
|
|
</div>
|
||
|
|
<div class="card-footer bg-transparent">
|
||
|
|
<input class="form-control w-100" id="busqueda_disponibles" type="text" placeholder="Buscar..">
|
||
|
|
<div class="row align-items-center text-center my-3">
|
||
|
|
<div class="col-6 text-center">
|
||
|
|
<div class="btn btn-primary btn_agregar">Agregar seleccionados</div>
|
||
|
|
</div>
|
||
|
|
<div class="col-6 text-center">
|
||
|
|
<div class="btn btn-primary btn_agregar_des">Limpiar selección</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</section>
|
||
|
|
<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>Asignación masiva de usuarios</h2>
|
||
|
|
</div>
|
||
|
|
<div class="col-12">Para asignar un usuario a una categoría coloca el número <b>1</b> para quitar la asignación a dicha categoría coloca el número <b>0</b>.
|
||
|
|
</div>
|
||
|
|
<div class="col-12 my-3"><a class="btn btn-secondary" href="asignacion_template.php" download target="_blank">Descargar template asignación 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_asignacion" method="post" enctype="multipart/form-data" id="masiveusers_asignacion">
|
||
|
|
<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 resultadosmasivos_asignacion"></div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</div>
|
||
|
|
</section>
|
||
|
|
<script type="text/javascript">
|
||
|
|
jQuery(document).ready(function ($) {
|
||
|
|
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; }
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
/**********************************************************************/
|
||
|
|
/***************** masiveusers ****************************************/
|
||
|
|
/**********************************************************************/
|
||
|
|
$("#masiveusers_asignacion").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();
|
||
|
|
|
||
|
|
url = 'asignacion_masive_upload.php';
|
||
|
|
|
||
|
|
console.log(url);
|
||
|
|
|
||
|
|
//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_asignacion').trigger("reset");
|
||
|
|
$(".custom-file-label").removeClass('selected').html('Subir archivo');
|
||
|
|
},
|
||
|
|
onAfterClose: function () {}
|
||
|
|
});
|
||
|
|
} else {
|
||
|
|
$(".resultadosmasivos_asignacion").html("");
|
||
|
|
$(".resultadosmasivos_asignacion").html('<h3>Resultado</h3><ul class="list-group listresult_asignacion"></ul>')
|
||
|
|
$.each(_data.results, function (index, val) {
|
||
|
|
$(".listresult_asignacion").append('<li class="list-group-item">' + val + '</li>');
|
||
|
|
});
|
||
|
|
//$(".resultadosmasivos_asignacion").append('<p class="my-2 pl-2">Procesados: ' + _data.procesados + ' Correctos: ' + _data.correctos + '</p>');
|
||
|
|
$('#masiveusers_asignacion').trigger("reset");
|
||
|
|
$(".custom-file-label").removeClass('selected').html('Subir archivo');
|
||
|
|
verAsiganaciones($('#catsuperior').val());
|
||
|
|
$(".layer-load").show();
|
||
|
|
}
|
||
|
|
$(".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);
|
||
|
|
});
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
function listadoDeCategorias() {
|
||
|
|
$(".layer-load").show();
|
||
|
|
$.ajax({
|
||
|
|
url: 'categorias_list.php',
|
||
|
|
type: 'POST'
|
||
|
|
})
|
||
|
|
.done(function (response) {
|
||
|
|
var _data = parseJSON(response);
|
||
|
|
if (_data.code == "1") {
|
||
|
|
$("#catsuperior").html("");
|
||
|
|
var _padres = _.filter(_data.datos, function (n) {
|
||
|
|
return n.padre == 0;
|
||
|
|
});
|
||
|
|
/*
|
||
|
|
var _datos = _.groupBy(_data.datos, function (n) {
|
||
|
|
return n.padre;
|
||
|
|
});
|
||
|
|
$.each(_padres, function (index, val1) {
|
||
|
|
$("#catsuperior").append('<optgroup label="' + val1.nombre + '"></optgroup>');
|
||
|
|
$.each(_datos, function (index, cats) {
|
||
|
|
$.each(cats, function (index, val) {
|
||
|
|
if (val.padre == val1.id || val.nombre == val1.nombre) {
|
||
|
|
if (val.nombre == val1.nombre) {
|
||
|
|
$("[label='" + val1.nombre + "']").append('<option class="font-weight-bold" value="' + val.id + '">' + val.nombre + '</option>');
|
||
|
|
} else {
|
||
|
|
$("[label='" + val1.nombre + "']").append('<option value="' + val.id + '">' + val.nombre + '</option>');
|
||
|
|
}
|
||
|
|
}
|
||
|
|
});
|
||
|
|
});
|
||
|
|
});*/
|
||
|
|
$.each(_padres, function (index, val) {
|
||
|
|
$("#catsuperior").append('<option value="' + val.id + '">' + val.nombre + '</option>');
|
||
|
|
});
|
||
|
|
$('#catsuperior').selectpicker('render');
|
||
|
|
$('#catsuperior').change(function (event) {
|
||
|
|
event.preventDefault();
|
||
|
|
/* Act on the event */
|
||
|
|
verAsiganaciones($(this).val());
|
||
|
|
});
|
||
|
|
$('#catsuperior').trigger('change');
|
||
|
|
} else {
|
||
|
|
$(".controller").html('<h1>No existen categorias</h1>');
|
||
|
|
}
|
||
|
|
|
||
|
|
$(".layer-load").hide();
|
||
|
|
})
|
||
|
|
.fail(function () {
|
||
|
|
|
||
|
|
})
|
||
|
|
.always(function () {
|
||
|
|
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
|
||
|
|
function verAsiganaciones(indexofcat) {
|
||
|
|
$(".layer-load").show();
|
||
|
|
$.ajax({
|
||
|
|
url: 'asignaciones.php',
|
||
|
|
type: 'POST',
|
||
|
|
data: { indexofcat: indexofcat },
|
||
|
|
})
|
||
|
|
.done(function (reponse) {
|
||
|
|
var _data = JSON.parse(reponse);
|
||
|
|
if (_data.code == 0) {
|
||
|
|
Swal.fire({
|
||
|
|
html: _data.msg,
|
||
|
|
icon: 'error',
|
||
|
|
onBeforeOpen: function () {},
|
||
|
|
onOpen: function () {},
|
||
|
|
onRender: function () {},
|
||
|
|
onClose: function () {},
|
||
|
|
onAfterClose: function () {}
|
||
|
|
});
|
||
|
|
} else {
|
||
|
|
$("#lista_asignaciones").html("");
|
||
|
|
$("#lista_disponibles").html("");
|
||
|
|
|
||
|
|
$(".catname").html("Asignaciones en la categoría: <span class='text-secondary'>" + _data.catdata[0].nombre + "</span>");
|
||
|
|
$.each(_data.asignados, function (index, val) {
|
||
|
|
$("#lista_asignaciones").append('<option class="user_listado" value="' + val.userid + '">' + val.numempl + '</option>');
|
||
|
|
});
|
||
|
|
|
||
|
|
$.each(_data.disponibles, function (index, val) {
|
||
|
|
$("#lista_disponibles").append('<option class="user_listado" value="' + val.userid + '">' + val.numempl + '</option>');
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
})
|
||
|
|
.fail(function () {
|
||
|
|
|
||
|
|
})
|
||
|
|
.always(function () {
|
||
|
|
$(".layer-load").hide();
|
||
|
|
});
|
||
|
|
|
||
|
|
}
|
||
|
|
|
||
|
|
$("#busqueda_disponibles").on("keyup", function () {
|
||
|
|
var value = $(this).val().toLowerCase();
|
||
|
|
$("#lista_disponibles option").filter(function () {
|
||
|
|
$(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
|
||
|
|
});
|
||
|
|
});
|
||
|
|
$("#busqueda_asignados").on("keyup", function () {
|
||
|
|
var value = $(this).val().toLowerCase();
|
||
|
|
$("#lista_asignaciones option").filter(function () {
|
||
|
|
$(this).toggle($(this).text().toLowerCase().indexOf(value) > -1)
|
||
|
|
});
|
||
|
|
});
|
||
|
|
|
||
|
|
$(".btn_quitar").click(function (event) {
|
||
|
|
var asignados = $('#lista_asignaciones').val();
|
||
|
|
if (asignados.length == 0) {
|
||
|
|
Swal.fire({
|
||
|
|
html: "No hay usuarios seleccionados",
|
||
|
|
icon: 'error',
|
||
|
|
onBeforeOpen: function () {},
|
||
|
|
onOpen: function () {},
|
||
|
|
onRender: function () {},
|
||
|
|
onClose: function () {},
|
||
|
|
onAfterClose: function () {}
|
||
|
|
});
|
||
|
|
} else {
|
||
|
|
$(".layer-load").show();
|
||
|
|
$.ajax({
|
||
|
|
url: 'asignaciones_remove.php',
|
||
|
|
type: 'POST',
|
||
|
|
data: { id: asignados, idcat: $('#catsuperior').val() }
|
||
|
|
})
|
||
|
|
.done(function (response) {
|
||
|
|
var _data = parseJSON(response);
|
||
|
|
if (_data.code == 0) {
|
||
|
|
Swal.fire({
|
||
|
|
html: _data.msg,
|
||
|
|
icon: 'error',
|
||
|
|
onBeforeOpen: function () {},
|
||
|
|
onOpen: function () {},
|
||
|
|
onRender: function () {},
|
||
|
|
onClose: function () {
|
||
|
|
verAsiganaciones($('#catsuperior').val());
|
||
|
|
},
|
||
|
|
onAfterClose: function () {}
|
||
|
|
});
|
||
|
|
} else {
|
||
|
|
Swal.fire({
|
||
|
|
html: _data.msg,
|
||
|
|
icon: 'success',
|
||
|
|
onBeforeOpen: function () {},
|
||
|
|
onOpen: function () {},
|
||
|
|
onRender: function () {},
|
||
|
|
onClose: function () {
|
||
|
|
verAsiganaciones($('#catsuperior').val());
|
||
|
|
},
|
||
|
|
onAfterClose: function () {}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
})
|
||
|
|
.fail(function () {
|
||
|
|
|
||
|
|
})
|
||
|
|
.always(function () {
|
||
|
|
$(".layer-load").hide();
|
||
|
|
});
|
||
|
|
}
|
||
|
|
});
|
||
|
|
$(".btn_agregar").click(function (event) {
|
||
|
|
var disponibles = $('#lista_disponibles').val();
|
||
|
|
if (disponibles.length == 0) {
|
||
|
|
Swal.fire({
|
||
|
|
html: "No hay usuarios seleccionados",
|
||
|
|
icon: 'error',
|
||
|
|
onBeforeOpen: function () {},
|
||
|
|
onOpen: function () {},
|
||
|
|
onRender: function () {},
|
||
|
|
onClose: function () {},
|
||
|
|
onAfterClose: function () {}
|
||
|
|
});
|
||
|
|
} else {
|
||
|
|
$(".layer-load").show();
|
||
|
|
$.ajax({
|
||
|
|
url: 'asignaciones_add.php',
|
||
|
|
type: 'POST',
|
||
|
|
data: { id: disponibles, idcat: $('#catsuperior').val() }
|
||
|
|
})
|
||
|
|
.done(function (response) {
|
||
|
|
var _data = parseJSON(response);
|
||
|
|
if (_data.code == 0) {
|
||
|
|
Swal.fire({
|
||
|
|
html: _data.msg,
|
||
|
|
icon: 'error',
|
||
|
|
onBeforeOpen: function () {},
|
||
|
|
onOpen: function () {},
|
||
|
|
onRender: function () {},
|
||
|
|
onClose: function () {
|
||
|
|
verAsiganaciones($('#catsuperior').val());
|
||
|
|
},
|
||
|
|
onAfterClose: function () {}
|
||
|
|
});
|
||
|
|
} else {
|
||
|
|
Swal.fire({
|
||
|
|
html: _data.msg,
|
||
|
|
icon: 'success',
|
||
|
|
onBeforeOpen: function () {},
|
||
|
|
onOpen: function () {},
|
||
|
|
onRender: function () {},
|
||
|
|
onClose: function () {
|
||
|
|
verAsiganaciones($('#catsuperior').val());
|
||
|
|
},
|
||
|
|
onAfterClose: function () {}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
})
|
||
|
|
.fail(function () {
|
||
|
|
|
||
|
|
})
|
||
|
|
.always(function () {
|
||
|
|
$(".layer-load").hide();
|
||
|
|
});
|
||
|
|
|
||
|
|
}
|
||
|
|
});
|
||
|
|
$(".btn_quitar_des, .btn_agregar_des").click(function (event) {
|
||
|
|
$(this).closest('.freecardasignaciones').find('option').prop("selected", false);
|
||
|
|
});
|
||
|
|
listadoDeCategorias();
|
||
|
|
});
|
||
|
|
</script>
|