Commit 893ca942 by Billy Larru

crear rol policias arreglado

parent 1055284d
function initDatePicker(selectorName) {
$(selectorName).datepicker({
minDate: new Date(2000, 1 - 1, 1), maxDate: new Date(),
dateFormat: 'dd/mm/yy',
defaultDate: new Date(),
changeMonth: true,
changeYear: true,
yearRange: '-18:+0',
zIndexOffset: 3000,
onSelect: function () {
// $(this).valid();
}
});
$(selectorName).datepicker('setDate', 'now');
}
function listarRolesPolicias(objParams = {}) { function listarRolesPolicias(objParams = {}) {
ajaxWebService.get(URI_ROL_POLICIA, objParams).then((response) => { ajaxWebService.get(URI_ROL_POLICIA, objParams).then((response) => {
debugger debugger
let columns = [ let columns = [
{ {
title: `N°`, title: `N°`,
// data: `numeroFila` // data: `numeroFila`
data: `id` data: `id`
}, },
{ {
title: `APELLIDOS Y NOMBRES`, title: `APELLIDOS Y NOMBRES`,
data: `policia_nombres` data: `policia_nombres`
}, },
{ {
title: `SEDE`, title: `SEDE`,
data: `sede_descripcion` data: `sede_descripcion`
}, },
{ {
title: `FECHA INICIO`, title: `FECHA INICIO`,
data: `fecha_inicio` data: `fecha_inicio`
}, },
{ {
title: `FECHA FIN`, title: `FECHA FIN`,
data: `fecha_fin` data: `fecha_fin`
}, },
{ {
title: `TIPO`, title: `TIPO`,
data: `tiporol_descripcion` data: `tiporol_descripcion`
}, },
{ {
title: `FRECUENCIA`, title: `FRECUENCIA`,
data: `frecuencia_descripcion` data: `frecuencia_descripcion`
}, },
{ {
title: `ESTADO`, title: `ESTADO`,
data: `estado`, data: `estado`,
render: (data) => { render: (data) => {
if (Object.is(data, 1)) { if (Object.is(data, 1)) {
return `<span class="label label-success">ACTIVO</span>`; return `<span class="label label-success">ACTIVO</span>`;
} else { } else {
return `<span class="label label-danger">INACTIVO</span>`; return `<span class="label label-danger">INACTIVO</span>`;
} }
} }
}, },
{ {
title: `ACCIONES`, title: `ACCIONES`,
data: `estado`, data: `estado`,
className: 'text-center', className: 'text-center',
render: (data) => { render: (data) => {
console.log(data); console.log(data);
if (Object.is(data, 1)) { if (Object.is(data, 1)) {
return ` <span data-placement="left" title="Ver detalle" data-toggle="tooltip" style="cursor: pointer"> <i class='ver-detalle icon-calendar2 text-primary-700'></i>&nbsp;&nbsp; </span> return ` <span data-placement="left" title="Ver detalle" data-toggle="tooltip" style="cursor: pointer"> <i class='ver-detalle icon-calendar2 text-primary-700'></i>&nbsp;&nbsp; </span>
<span data-toggle="tooltip" data-placement="left" title="Desactivar Rol" style="cursor: pointer"> <i class='anular icon-cancel-circle2 text-danger-700'></i>&nbsp;&nbsp; </span> <span data-toggle="tooltip" data-placement="left" title="Desactivar Rol" style="cursor: pointer"> <i class='anular icon-cancel-circle2 text-danger-700'></i>&nbsp;&nbsp; </span>
`; `;
} else { } else {
return null; return null;
} }
} }
} }
]; ];
let columnDefs = [ let columnDefs = [
{orderable: false, width: '5%', targets: 0, className: "text-center"}, {orderable: false, width: '1%', targets: 0, className: "text-center"},
{orderable: false, width: '5%', targets: 1}, {orderable: false, width: '8%', targets: 1},
{orderable: false, width: '30%', targets: 2, className: "text-center"}, {orderable: false, width: '10%', targets: 2, className: "text-center"},
{orderable: false, width: '7%', targets: 3, className: "text-center"}, {orderable: false, width: '7%', targets: 3, className: "text-center"},
{orderable: false, width: '7%', targets: 4, className: "text-center"}, {orderable: false, width: '7%', targets: 4, className: "text-center"},
{orderable: false, width: '10%', targets: 5, className: "text-center"}, {orderable: false, width: '10%', targets: 5, className: "text-center"},
{orderable: false, width: '8%', targets: 6, className: "text-center"}, {orderable: false, width: '8%', targets: 6, className: "text-center"},
{orderable: false, width: '8%', targets: 7, className: "text-center"} {orderable: false, width: '8%', targets: 7, className: "text-center"}
]; ];
let wrapsNameDatatable = `divRoles`; let wrapsNameDatatable = `divRoles`;
let classNameForDatatable = `display table table-bordered`; let classNameForDatatable = `display table table-bordered`;
let footer = false
makeDatatable(wrapsNameDatatable,
makeDatatable({ {
data: response.data, data: response.data,
columns, columns,
columnDefs, columnDefs,
wrapsNameDatatable, },
classNameForDatatable, classNameForDatatable).then((nodes) => {
footer nodes.container.off().on("click", ".ver-detalle", function () {
}).then((nodes) => { let data = nodes.datatable.DataTable().row($(this).parents("tr")).data();
nodes.container.off().on("click", ".ver-detalle", function () { console.log(data);
let data = nodes.datatable.DataTable().row($(this).parents("tr")).data();
console.log(data); ajaxModal.get("policias/mantenimientoRol/detalleRol.jspf").then((response) => {
debugger
ajaxModal.get("policias/mantenimientoRol/detalleRol.jspf").then((response) => { swal({
debugger title: '<strong>Detalle de rol</strong>',
swal({ html: response.data,
title: '<strong>Detalle de rol</strong>', showCloseButton: true,
html: response.data, showCancelButton: true,
showCloseButton: true, focusConfirm: false,
showCancelButton: true, confirmButtonText: '<i class="fa fa-thumbs-up"></i> Great!',
focusConfirm: false, confirmButtonAriaLabel: 'Thumbs up, great!',
confirmButtonText: '<i class="fa fa-thumbs-up"></i> Great!', cancelButtonText: 'Cancelar',
confirmButtonAriaLabel: 'Thumbs up, great!', cancelButtonAriaLabel: 'Thumbs down',
cancelButtonText: 'Cancelar', width: '30%',
cancelButtonAriaLabel: 'Thumbs down', onOpen: () => {
width: '30%', $("#spanNombres").html(data.policia_nombres);
onOpen: () => { $("#spanSede").html(data.sede_descripcion);
$("#spanNombres").html(data.policia_nombres); $("#spanHorario").html(`${data.tiporol_descripcion} ${data.frecuencia_descripcion}`);
$("#spanSede").html(data.sede_descripcion); $("#spanRangoFechas").html(`${data.fecha_inicio} - ${data.fecha_fin}`);
$("#spanHorario").html(`${data.tiporol_descripcion} ${data.frecuencia_descripcion}`); let htmlList = ``;
$("#spanRangoFechas").html(`${data.fecha_inicio} - ${data.fecha_fin}`); data.detalles_rol.forEach(x => htmlList += `<li class="list-group-item" id="${x.id}">${x.fecha_entrada}</li>`);
let htmlList = ``; $("#listaDias").html(htmlList);
data.detalles_rol.forEach(x => htmlList += `<li class="list-group-item" id="${x.id}">${x.fecha_entrada}</li>`); }
$("#listaDias").html(htmlList); });
}
}); });
});
}); });
});
}); });
});
} }
function listarTipoRoles() { function listarTipoRoles() {
ajaxWebService.get(URI_TIPOROL_POLICIA).then((response) => { ajaxWebService.get(URI_TIPOROL_POLICIA).then((response) => {
let tipoRoles = response.data; let tipoRoles = response.data;
let html = "<option>[SELECCIONE]</option>"; let html = "<option>[SELECCIONE]</option>";
tipoRoles.forEach(tp => html += `<option data-hora-entrada="${tp.hora_entrada}" data-hora-salida="${tp.hora_salida}" value="${tp.codigo}">${tp.descripcion}</option>`); tipoRoles.forEach(tp => html += `<option data-hora-entrada="${tp.hora_entrada}" data-hora-salida="${tp.hora_salida}" value="${tp.codigo}">${tp.descripcion}</option>`);
$("#cboTipoRol").html(html); $("#cboTipoRol").html(html);
}); });
} }
function listarFrecuenciaRol() { function listarFrecuenciaRol() {
ajaxWebService.get(URI_FRECUENCIA_ROL_POLICIA).then((result) => { ajaxWebService.get(URI_FRECUENCIA_ROL_POLICIA).then((result) => {
let frecuenciasRol = result.data; let frecuenciasRol = result.data;
let html = "<option>[SELECCIONE]</option>"; let html = "<option>[SELECCIONE]</option>";
frecuenciasRol.forEach(f => html += `<option value="${f.codigo}">${f.descripcion}</option>`); frecuenciasRol.forEach(f => html += `<option value="${f.codigo}">${f.descripcion}</option>`);
$("#cboFrecuenciaRol").html(html); $("#cboFrecuenciaRol").html(html);
}); });
} }
function listarSedes(selectorName) { function listarSedes(selectorName) {
ajaxWebService.get(URI_SEDES).then((result) => { ajaxWebService.get(URI_SEDES).then((result) => {
let sedes = result.data; let sedes = result.data;
sedes = _.orderBy(sedes, s => s.descripcion); sedes = _.orderBy(sedes, s => s.descripcion);
let html = `<option value="">[SELECCIONE]</option>`; let html = `<option value="">[SELECCIONE]</option>`;
sedes.forEach(sede => html += `<option value="${sede.codigo}">${sede.descripcion}</option>`); sedes.forEach(sede => html += `<option value="${sede.codigo}">${sede.descripcion}</option>`);
$(`${selectorName}`).html(html); $(`${selectorName}`).html(html);
}); });
} }
function listarPolicias(selectorName) { function listarPolicias(selectorName) {
ajaxWebService.get(URI_POLICIAS).then((result) => { ajaxWebService.get(URI_POLICIAS).then((result) => {
let policias = result.data; let policias = result.data;
policias = _.orderBy(policias, p => p.nombres); policias = _.orderBy(policias, p => p.nombres);
let html = `<option value="">[SELECCIONE]</option>`; let html = `<option value="">[SELECCIONE]</option>`;
policias.forEach(p => html += `<option documento_identidad="${p.dni}" value="${p.id}">${p.nombres}</option>`); policias.forEach(p => html += `<option documento_identidad="${p.dni}" value="${p.id}">${p.nombres}</option>`);
$(`${selectorName}`).html(html); $(`${selectorName}`).html(html);
$('.select-search').select2(); $('.select-search').select2();
}); });
} }
function modificarServicio() { function modificarServicio() {
// debugger // debugger
$("#detalle_rol").addClass("hidden"); $("#detalle_rol").addClass("hidden");
$("#editar_rol").removeClass("hidden"); $("#editar_rol").removeClass("hidden");
$("#modal-title").html('Cambiar servicio'); $("#modal-title").html('Cambiar servicio');
$("#modal-header").removeClass('bg-primary'); $("#modal-header").removeClass('bg-primary');
$("#modal-header").addClass('bg-jade'); $("#modal-header").addClass('bg-jade');
$("#botones-editar").removeClass('hidden'); $("#botones-editar").removeClass('hidden');
$("#btnCerrar").addClass("hidden"); $("#btnCerrar").addClass("hidden");
animar(); animar();
// e.preventDefault(); // e.preventDefault();
} }
function registrarRolPolicia() { function registrarRolPolicia() {
let policia_nombres = $("#cboPolicias option:selected").text(); let policia_nombres = $("#cboPolicias option:selected").text();
let policia_id = $("#cboPolicias").val(); let policia_id = $("#cboPolicias").val();
let tiporol_id = $("#cboTipoRol").val(); let tiporol_id = $("#cboTipoRol").val();
let tiporol_descripcion = $("#cboTipoRol option:selected").text(); let tiporol_descripcion = $("#cboTipoRol option:selected").text();
let rango_fechas = $("#dpRangoFechas").val(); let rango_fechas = $("#dpRangoFechas").val();
let split_fechas = rango_fechas.split("-").map(f => f.trim()); let split_fechas = rango_fechas.split("-").map(f => f.trim());
let fecha_inicio = split_fechas[0]; let fecha_inicio = split_fechas[0];
let fecha_fin = split_fechas[1]; let fecha_fin = split_fechas[1];
let frecuencia_id = $("#cboFrecuenciaRol").val(); let frecuencia_id = $("#cboFrecuenciaRol").val();
let frecuencia_descripcion = $("#cboFrecuenciaRol option:selected").text(); let frecuencia_descripcion = $("#cboFrecuenciaRol option:selected").text();
let sede_id = $("#cboSedesModal").val(); let sede_id = $("#cboSedesModal").val();
let sede_descripcion = $("#cboSedesModal option:selected").text(); let sede_descripcion = $("#cboSedesModal option:selected").text();
let estado = 1; let estado = 1;
let policia_dni = $("#cboPolicias option:selected").attr("documento_identidad"); let policia_dni = $("#cboPolicias option:selected").attr("documento_identidad");
let hora_entrada = $("#cboTipoRol option:selected").data('hora-entrada'); let hora_entrada = $("#cboTipoRol option:selected").data('hora-entrada');
let hora_salida = $("#cboTipoRol option:selected").data('hora-salida'); let hora_salida = $("#cboTipoRol option:selected").data('hora-salida');
debugger debugger
let fechas = generarFechas(fecha_inicio, fecha_fin); let fechas = generarFechas(fecha_inicio, fecha_fin);
let detalles_rol = []; let detalles_rol = [];
let numero = 1; let numero = 1;
fechas fechas
.map((f) => { .map((f) => {
let obj = { let obj = {
fecha_entrada: `${f} ${hora_entrada}`, fecha_entrada: `${f} ${hora_entrada}`,
fecha_salida: `${f} ${hora_salida}` fecha_salida: `${f} ${hora_salida}`
} }
return obj; return obj;
}) })
.forEach((f) => { .forEach((f) => {
debugger debugger
let detalle_rol = { let detalle_rol = {
id: numero++, id: numero++,
fecha_entrada: f.fecha_entrada, fecha_entrada: f.fecha_entrada,
fecha_salida: f.fecha_salida, fecha_salida: f.fecha_salida,
estado: 1 estado: 1
}; };
detalles_rol.push(detalle_rol); detalles_rol.push(detalle_rol);
}); });
let params = { let params = {
numeroFila: policia_id, numeroFila: policia_id,
policia_id, policia_id,
policia_dni, policia_dni,
policia_nombres, policia_nombres,
sede_id, sede_id,
sede_descripcion, sede_descripcion,
fecha_inicio, fecha_inicio,
fecha_fin, fecha_fin,
tiporol_id, tiporol_id,
tiporol_descripcion, tiporol_descripcion,
frecuencia_id, frecuencia_id,
frecuencia_descripcion, frecuencia_descripcion,
detalles_rol, detalles_rol,
estado estado
}; };
ajaxWebService.post(URI_ROL_POLICIA, params) ajaxWebService.post(URI_ROL_POLICIA, params)
.then((result) => { .then((result) => {
result.data = formatResponse(result); result.data = formatResponse(result);
debugger; debugger;
if (result.data.status) { if (result.data.status) {
listarRolesPolicias(); listarRolesPolicias();
console.log(result.data); console.log(result.data);
} else { } else {
} }
}) })
.catch(error => { .catch(error => {
console.log(error); console.log(error);
}); });
} }
function generarFechas(desde, hasta) { function generarFechas(desde, hasta) {
let reverseDesde = desde.split("/").reverse().join("/"); let reverseDesde = desde.split("/").reverse().join("/");
let reverseHasta = hasta.split("/").reverse().join("/"); let reverseHasta = hasta.split("/").reverse().join("/");
desde = moment(reverseDesde); desde = moment(reverseDesde);
hasta = moment(reverseHasta); hasta = moment(reverseHasta);
let diaActual = desde; let diaActual = desde;
let fechas = []; let fechas = [];
while (diaActual.isSameOrBefore(hasta)) { while (diaActual.isSameOrBefore(hasta)) {
fechas.push(diaActual.format('DD/MM/YYYY')); fechas.push(diaActual.format('DD/MM/YYYY'));
diaActual.add(1, 'days'); diaActual.add(1, 'days');
} }
return fechas; return fechas;
} }
function cancelar() { function cancelar() {
$("#detalle_rol").removeClass("hidden"); $("#detalle_rol").removeClass("hidden");
$("#editar_rol").addClass("hidden"); $("#editar_rol").addClass("hidden");
$("#modal-title").html('Ver detalle rol'); $("#modal-title").html('Ver detalle rol');
$("#modal-header").addClass('bg-primary'); $("#modal-header").addClass('bg-primary');
$("#modal-header").removeClass('bg-jade'); $("#modal-header").removeClass('bg-jade');
$("#botones-editar").addClass('hidden'); $("#botones-editar").addClass('hidden');
$("#btnCerrar").removeClass("hidden"); $("#btnCerrar").removeClass("hidden");
animar(); animar();
} }
function animar() { function animar() {
let animation = `fadeIn`; let animation = `fadeIn`;
$("#modal_body_tombo2").addClass(`animated ${animation}`).one("webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend", function () { $("#modal_body_tombo2").addClass(`animated ${animation}`).one("webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend", function () {
$(this).removeClass(`animated ${animation}`); $(this).removeClass(`animated ${animation}`);
}); });
} }
function guardarCambios() { function guardarCambios() {
cancelar(); cancelar();
$("#servicio13").css("background-color", "lightpink"); $("#servicio13").css("background-color", "lightpink");
} }
function mostrarModalNuevoRol() { function mostrarModalNuevoRol() {
ajaxModal.get("policias/mantenimientoRol/crearRol.jspf").then((response) => { ajaxModal.get("policias/mantenimientoRol/crearRol.jspf").then((response) => {
swal({ swal({
title: '<strong>Nuevo Rol</strong>', title: '<strong>Nuevo Rol</strong>',
// type: 'info', // type: 'info',
html: response.data, html: response.data,
showCloseButton: true, showCloseButton: true,
showCancelButton: true, showCancelButton: true,
focusConfirm: false, focusConfirm: false,
confirmButtonText: '<i class="fa fa-thumbs-up"></i> Registrar rol', confirmButtonText: '<i class="fa fa-thumbs-up"></i> Registrar rol',
confirmButtonAriaLabel: 'Registrar rol', confirmButtonAriaLabel: 'Registrar rol',
cancelButtonText: 'Cancelar', cancelButtonText: 'Cancelar',
cancelButtonAriaLabel: 'Thumbs down', cancelButtonAriaLabel: 'Thumbs down',
width: '30%', width: '30%',
customClass: 'swal2-overflow', customClass: 'swal2-overflow',
onOpen: () => { onOpen: () => {
listarTipoRoles(); listarTipoRoles();
listarFrecuenciaRol(); listarFrecuenciaRol();
listarSedes("#cboSedesModal"); listarSedes("#cboSedesModal");
listarPolicias("#cboPolicias"); listarPolicias("#cboPolicias");
$('.selectpicker').selectpicker({ $('.selectpicker').selectpicker({
style: 'btn-info', style: 'btn-info',
size: 4 size: 4
}); });
$('.select-search').select2(); $('.select-search').select2();
$(".btn.dropdown-toggle.bs-placeholder").removeClass("btn-info"); $(".btn.dropdown-toggle.bs-placeholder").removeClass("btn-info");
$(".btn.dropdown-toggle.bs-placeholder").css({ $(".btn.dropdown-toggle.bs-placeholder").css({
border: "1px solid #ddd", border: "1px solid #ddd",
backgroundColor: "#fff" backgroundColor: "#fff"
}); });
$("#dpRangoFechas").daterangepicker({ $("#dpRangoFechas").daterangepicker({
"autoApply": true, "autoApply": true,
"locale": { "locale": {
"format": "DD/MM/YYYY", "format": "DD/MM/YYYY",
"separator": " - ", "separator": " - ",
"applyLabel": "Apply", "applyLabel": "Apply",
"cancelLabel": "Cancel", "cancelLabel": "Cancel",
"fromLabel": "From", "fromLabel": "From",
"toLabel": "To", "toLabel": "To",
"customRangeLabel": "Custom", "customRangeLabel": "Custom",
"weekLabel": "W", "weekLabel": "W",
"daysOfWeek": [ "daysOfWeek": [
"Do", "Do",
"Lu", "Lu",
"Ma", "Ma",
"Mi", "Mi",
"Ju", "Ju",
"Vi", "Vi",
"Sa" "Sa"
], ],
"monthNames": [ "monthNames": [
"Enero", "Enero",
"Febrero", "Febrero",
"Marzo", "Marzo",
"Abril", "Abril",
"Mayo", "Mayo",
"Junio", "Junio",
"Julio", "Julio",
"Agosto", "Agosto",
"Setiembre", "Setiembre",
"Octubre", "Octubre",
"Noviembre", "Noviembre",
"Diciembre" "Diciembre"
], ],
"firstDay": 1 "firstDay": 1
}, },
"startDate": "17/08/2018", "startDate": "17/08/2018",
"endDate": "23/08/2018" "endDate": "23/08/2018"
}, function (start, end, label) { }, function (start, end, label) {
// console.log('New date range selected: ' + start.format('YYYY-MM-DD') + ' to ' + end.format('YYYY-MM-DD') + ' (predefined range: ' + label + ')'); // console.log('New date range selected: ' + start.format('YYYY-MM-DD') + ' to ' + end.format('YYYY-MM-DD') + ' (predefined range: ' + label + ')');
}); });
$("#dpRangoFechas").datepicker('setDate', 'now'); $("#dpRangoFechas").datepicker('setDate', 'now');
defaultConfigDatePicker(); defaultConfigDatePicker();
} }
}).then((result) => { }).then((result) => {
if (result.value) { if (result.value) {
registrarRolPolicia(); registrarRolPolicia();
} }
}); });
}); });
} }
function buscarRoles() { function buscarRoles() {
let policia_id = $("#cboPoliciasFiltro").val(); let policia_id = $("#cboPoliciasFiltro").val();
let sede_id = $("#cboSedesFiltro").val(); let sede_id = $("#cboSedesFiltro").val();
let fecha_inicio = $("#dpFechaInicio").val(); let fecha_inicio = $("#dpFechaInicio").val();
let fecha_fin = $("#dpFechaFin").val(); let fecha_fin = $("#dpFechaFin").val();
let params = cleanQueryParams({ let params = cleanQueryParams({
policia_id, policia_id,
sede_id, sede_id,
fecha_inicio fecha_inicio
}); });
console.log(params); console.log(params);
listarRolesPolicias({params}); listarRolesPolicias({params});
} }
$().ready(function () { $().ready(function () {
initDatePicker("#dpFechaInicio"); initDatePicker("#dpFechaInicio", "#dpFechaFin");
initDatePicker("#dpFechaFin"); listarSedes("#cboSedesFiltro");
listarSedes("#cboSedesFiltro"); listarPolicias("#cboPoliciasFiltro");
listarPolicias("#cboPoliciasFiltro"); $('#servicio13').click(modificarServicio);
$('#servicio13').click(modificarServicio); $("#btnCancelar").click(cancelar);
$("#btnCancelar").click(cancelar); $("#btnGuardarCambios").click(guardarCambios);
$("#btnGuardarCambios").click(guardarCambios); $("#btnNuevoRol").click(mostrarModalNuevoRol);
$("#btnNuevoRol").click(mostrarModalNuevoRol); $("#btnVerRoles").click(buscarRoles);
$("#btnVerRoles").click(buscarRoles); $("#btnVerTodos").click(listarRolesPolicias);
$("#btnVerTodos").click(listarRolesPolicias);
}); });
\ No newline at end of file
...@@ -64,7 +64,7 @@ ...@@ -64,7 +64,7 @@
</div> </div>
<div class="col-md-10 col-md-offset-1"> <div class="col-md-8 col-md-offset-2">
<div class="panel panel-primary card-3" style="margin-top: 30px"> <div class="panel panel-primary card-3" style="margin-top: 30px">
<div class="panel-heading" style="padding: 8px 15px"> <div class="panel-heading" style="padding: 8px 15px">
<h6 class="panel-title" style="font-size: 15px; font-family: inherit">LISTADO DE ROLES</h6> <h6 class="panel-title" style="font-size: 15px; font-family: inherit">LISTADO DE ROLES</h6>
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment