crearRolPolicia.js 10.3 KB
Newer Older
1
function init() {
2
    listarTipoRoles();
3 4 5
    listarFrecuenciaRol();
    listarSedes();
    listarPolicias();
6
    listarRolesPolicias();
7 8
}

9
function listarRolesPolicias() {
Billy Larru committed
10
    axios.get(URI_ROL_POLICIA).then((result) => {
11 12 13
        let columns = [
            {
                title: `N°`,
14 15
//                data: `numeroFila`
                data: `id`
16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42
            },
            {
                title: `APELLIDOS Y NOMBRES`,
                data: `policia_nombres`
            },
            {
                title: `SEDE`,
                data: `sede_descripcion`
            },
            {
                title: `FECHA INICIO`,
                data: `fecha_inicio`
            },
            {
                title: `FECHA FIN`,
                data: `fecha_fin`
            },
            {
                title: `TIPO`,
                data: `tiporol_descripcion`
            },
            {
                title: `FRECUENCIA`,
                data: `frecuencia_descripcion`
            },
            {
                title: `ESTADO`,
43 44
                data: `estado`,
                render: (data) => {
45
                    if (Object.is(data, 1)) {
46
                        return `<span class="label label-success">ACTIVO</span>`;
47
                    } else {
48 49 50
                        return `<span class="label label-danger">INACTIVO</span>`;
                    }
                }
51
            },
52 53 54 55 56 57 58
            {
                title: `ACCIONES`,
                data: `estado`,
                className: 'text-center',
                render: (data) => {
                    console.log(data);
                    if (Object.is(data, 1)) {
59
                        return `   <span data-placement="left" title="Ver detalle" data-toggle="modal" data-target="#modal_tombo_remote" style="cursor: pointer"> <i class='ver icon-calendar2 text-primary-700'></i>&nbsp;&nbsp; </span>
60 61 62 63 64 65 66 67
                                    <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 {
                        return null;
                    }

                }
            }
68
        ];
69

70 71 72 73 74 75 76 77 78 79
        let columnDefs = [
            {orderable: false, width: '5%', targets: 0, className: "text-center"},
            {orderable: false, width: '5%', targets: 1},
            {orderable: false, width: '30%', targets: 2, className: "text-center"},
            {orderable: false, width: '7%', targets: 3, className: "text-center"},
            {orderable: false, width: '7%', targets: 4, 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: 7, className: "text-center"}
        ];
80

81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97
        let wrapsNameDatatable = `divRoles`;
        let classNameForDatatable = `display table table-bordered`;
        let footer = false

        makeDatatable({
            data: result.data,
            columns: columns,
            columnDefs: columnDefs,
            wrapsNameDatatable: wrapsNameDatatable,
            classNameForDatatable: classNameForDatatable,
            footer: footer
        });

    });
}

function listarTipoRoles() {
Billy Larru committed
98
    axios.get(URI_TIPOROL_POLICIA).then((result) => {
99 100 101
        let roles = result.data;
        let html = "<option>[SELECCIONE]</option>";
        roles.forEach(rol => html += `<option value="${rol.codigo}">${rol.descripcion}</option>`);
102
        $("#cboTipoRol").html(html);
103 104 105 106 107
    });
}


function listarFrecuenciaRol() {
Billy Larru committed
108
    axios.get(URI_FRECUENCIA_ROL_POLICIA).then((result) => {
109 110 111 112 113 114 115 116
        let frecuenciasRol = result.data;
        let html = "<option>[SELECCIONE]</option>";
        frecuenciasRol.forEach(f => html += `<option value="${f.codigo}">${f.descripcion}</option>`);
        $("#cboFrecuenciaRol").html(html);
    });
}

function listarSedes() {
Billy Larru committed
117
    axios.get(URI_SEDES).then((result) => {
118
        let sedes = result.data;
Billy Larru committed
119
        sedes = _.orderBy(sedes, s => s.descripcion);
120 121 122 123 124 125 126
        let html = "<option>[SELECCIONE]</option>";
        sedes.forEach(sede => html += `<option value="${sede.codigo}">${sede.descripcion}</option>`);
        $("#cboSedes").html(html);
    });
}

function listarPolicias() {
Billy Larru committed
127
    axios.get(URI_POLICIAS).then((result) => {
128
        let policias = result.data;
Billy Larru committed
129
        policias = _.orderBy(policias, p => p.nombres);
130 131 132 133 134 135 136
        let html = "<option>[SELECCIONE]</option>";
        policias.forEach(p => html += `<option value="${p.id}">${p.nombres}</option>`);
        $("#cboPolicias").html(html);
    });
}


137 138 139 140 141 142 143 144 145
function modificarServicio() {
//    debugger
    $("#detalle_rol").addClass("hidden");
    $("#editar_rol").removeClass("hidden");
    $("#modal-title").html('Cambiar servicio');
    $("#modal-header").removeClass('bg-primary');
    $("#modal-header").addClass('bg-jade');
    $("#botones-editar").removeClass('hidden');
    $("#btnCerrar").addClass("hidden");
146

147
    animar();
148
//    e.preventDefault();
Billy Larru committed
149
}
150

Billy Larru committed
151
function registrarRolPolicia() {
152 153 154 155 156 157 158 159 160 161 162 163 164
    let policia_nombres = $("#cboPolicias option:selected").text();
    let policia_id = $("#cboPolicias").val();
    let tiporol_id = $("#cboTipoRol").val();
    let tiporol_descripcion = $("#cboTipoRol option:selected").text();
    let rango_fechas = $("#dpRangoFechas").val();
    let split_fechas = rango_fechas.split("-").map(f => f.trim());
    let fecha_inicio = split_fechas[0];
    let fecha_fin = split_fechas[1];
    let frecuencia_id = $("#cboFrecuenciaRol").val();
    let frecuencia_descripcion = $("#cboFrecuenciaRol option:selected").text();
    let sede_id = $("#cboSedes").val();
    let sede_descripcion = $("#cboSedes option:selected").text();
    let estado = 1;
165 166 167 168 169 170 171 172 173 174 175 176 177
    debugger
    let fechas = generarFechas(fecha_inicio, fecha_fin);
    let detalles_rol = [];
    let numero = 1;
    fechas.forEach((f) => {
        let detalle_rol = {
            id: numero++,
            fecha_entrada: f,
            fecha_salida: f,
            estado: 1
        };
        detalles_rol.push(detalle_rol);
    });
178 179

    let params = {
180
        numeroFila: policia_id,
181 182 183 184 185 186 187 188 189 190
        policia_id,
        policia_nombres,
        sede_id,
        sede_descripcion,
        fecha_inicio,
        fecha_fin,
        tiporol_id,
        tiporol_descripcion,
        frecuencia_id,
        frecuencia_descripcion,
191
        detalles_rol,
192 193
        estado
    };
Billy Larru committed
194

195
    axios.post(URI_ROL_POLICIA, params)
196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215
            .then((result) => {

                debugger;
                function formatSo(resultAxios) {
                    return {
                        status: resultAxios.data.status || true,
                        message: resultAxios.data.message || `Operación exitosa`,
                        data: resultAxios.data.data || result.data
                    };
                }

                debugger;
                result.data = formatSo(result);
                debugger;
                if (result.data.status) {
                    listarRolesPolicias();
                    console.log(result.data);
                } else {

                }
Billy Larru committed
216
            })
217
            .catch(error => {
Billy Larru committed
218 219
                console.log(error);
            });
220 221
}

222 223 224 225 226 227 228 229 230 231 232 233 234 235 236
function generarFechas(desde, hasta) {
    let reverseDesde = desde.split("/").reverse().join("/");
    let reverseHasta = hasta.split("/").reverse().join("/");
    desde = moment(reverseDesde);
    hasta = moment(reverseHasta);
    let diaActual = desde;

    let fechas = [];
    while (diaActual.isSameOrBefore(hasta)) {
        fechas.push(diaActual.format('DD/MM/YYYY'));
        diaActual.add(1, 'days');
    }
    return fechas;
}

237
function cancelar() {
238 239 240 241 242 243 244
    $("#detalle_rol").removeClass("hidden");
    $("#editar_rol").addClass("hidden");
    $("#modal-title").html('Ver detalle rol');
    $("#modal-header").addClass('bg-primary');
    $("#modal-header").removeClass('bg-jade');
    $("#botones-editar").addClass('hidden');
    $("#btnCerrar").removeClass("hidden");
245 246 247
    animar();
}

248 249
function animar() {
    let animation = `fadeIn`;
250 251 252 253 254 255 256

    $("#modal_body_tombo2").addClass(`animated ${animation}`).one("webkitAnimationEnd mozAnimationEnd MSAnimationEnd oanimationend animationend", function () {
        $(this).removeClass(`animated ${animation}`);
    });
}


257
function guardarCambios() {
258 259
    cancelar();
    $("#servicio13").css("background-color", "lightpink");
260 261 262 263
}



264
$().ready(function () {
265
    init();
266
    defaultConfigDataTable();
267 268 269 270
    $('.selectpicker').selectpicker({
        style: 'btn-info',
        size: 4
    });
271 272


273
    $('.select-search').select2();
274 275


276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307
    $(".btn.dropdown-toggle.bs-placeholder").removeClass("btn-info");
    $(".btn.dropdown-toggle.bs-placeholder").css({
        border: "1px solid #ddd",
        backgroundColor: "#fff"
    });

    $("#dpFechaInicio").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',
        onSelect: function () {
//        $(this).valid();
        }
    });
    $("#dpFechaInicio").datepicker('setDate', 'now');

    $("#dpFechaFin").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',
        onSelect: function () {
//        $(this).valid();
        }
    });
    $("#dpFechaFin").datepicker('setDate', 'now');

308
    defaultConfigDatePicker();
309
    defaultConfigDateRangePicker();
310 311
    $('#servicio13').click(modificarServicio);
    $("#btnCancelar").click(cancelar);
312
    $("#btnGuardarCambios").click(guardarCambios);
Billy Larru committed
313
    $("#btnRegistrar").click(registrarRolPolicia);
314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329
    axios.get("modals/policias/mantenimientoRol/detalleRol.jspf").then((response) => {
        swal({
            title: '<strong>Detalle de rol</strong>',
//            type: 'info',
            html: response.data,
            showCloseButton: true,
            showCancelButton: true,
            focusConfirm: false,
            confirmButtonText: '<i class="fa fa-thumbs-up"></i> Great!',
            confirmButtonAriaLabel: 'Thumbs up, great!',
            cancelButtonText: 'Cancelar',
            cancelButtonAriaLabel: 'Thumbs down',
            width: '30%'
        })

    });
330
});