<form method="POST" id="formTable" >
    <div class="pull-right">
        <div class="btn-group" style="margin: 20px">
            {{ boton( 'tabla', "mostrarTodosBeneficiosAfiliados", "cargarTablaBeneficios()") }}
            {{ boton('nuevo',"gestionActividadesPreconfiguradas") }}
            {{ boton('editar','','editar_frm()') }}
            {{ boton('eliminar','', "eliminar_selection();" ) }}
            {{ boton('ver','', "activarModal('verCotizacion');" ) }}
        </div>  
    </div>
    <table id="tablaOperaciones" class="table table-striped table-bordered" cellspacing="0" width="100%">
        <thead>
            <tr>
                <th><input type="checkbox" id="chk-seleccionarTodosBeneficios" ></th>
                <th>Código</th>
                <th>Título</th>
                <th>Descripción</th>
                <th>Detalles</th>
            </tr>
        </thead>
        <tfoot>
        <th></th>
        <th>Código</th>
        <th>Título</th>
        <th>Descripción</th>
        <th>Detalles</th>
        </tfoot>
        <tbody>
            {% for actividadP in ActividadesPredefinidas  %}

            <tr>
                <td><input class="checkTable checkActividades" type="checkbox" id="checkb{{ actividadP.tipoActividadID }}" name="checkb[]" value="{{ actividadP.tipoActividadID }}"></td>
                <td>{{ actividadP.tipoActividadCODIGO }}</td>
                <td>{{ actividadP.tipoActividadTITULO }}</td>
                <td>{{ actividadP.tipoActividadDESCRIPCION }}</td>
                <th></th>
            </tr>
            {% endfor %}

        </tbody>
    </table>
</form>
<script type="text/javascript" >
    $(document).ready(function () {

        $('#tablaOperaciones').DataTable();
        activarSeleccionarTodos("chk-seleccionarTodosBeneficios", "checkb");
    });
    function eliminar_selection() {

        alert($("#formTable").serialize());
        var conteo = 0;
        $("input:checkbox:checked").each(
                function () {
                    conteo++;
                    //break;
                }
        );

        alert(conteo);
        if (conteo > 0) {
            ejecutarOperacion(
                    "planeador",
                    "ActividadesPreconfiguradas",
                    "eliminar",
                    $("#formTable").serialize(),
                    function (response) {
                        console.log(response);
                        //var respuesta = JSON.parse(response);
                        if (response.RESPUESTA == 'EXITO') {
                            alert("Operación reazalida con Exito!");
                            $("#formTable")[0].reset();
                        } else {
                            alert(response['RESPONSE']);
                        }
                    }
            );
        }
    }

    /*Editar campo*/
    function editar_frm() {
        var seleccionados = checkSelecionados('tablaOperaciones');
        validacionCheckbox(seleccionados, function () {
            var json = JSON.stringify(seleccionados);
            json = JSON.parse(json);
            var consecutivo = json[0]['value'];
            cargarVista('planeador', 'ActividadesPreconfiguradas', 'gestionActividadesPreconfiguradas', 'ActividadesPreconfiguradaCONSECUTIVO=' + consecutivo);
            /*,'Editar Operación Predefinida '+consecutivo, 'crearOperacionesPredefinidas'*/
        }, true);
        $("#formTable")[0].reset();

    }
    /**************/
</script> 
