<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@ include file="validar.jsp" %>
<!DOCTYPE html>
<html lang="es">
    <head>
        <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1" />
        <meta charset="utf-8" />
        <title>:::SISTEMA DE HORARIOS:::</title>

        <meta name="description" content="overview &amp; stats" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0" />

        <link rel="stylesheet" href="../assets/css/bootstrap.css" />
        <link rel="stylesheet" href="../assets/css/font-awesome.css" />
        <link rel="stylesheet" href="../assets/css/jquery-ui.css" />
        <link rel="stylesheet" href="../assets/css/ace-fonts.css" />
        <link rel="stylesheet" href="../assets/css/ace.css" class="ace-main-stylesheet" id="main-ace-style" />
        <script src="../assets/js/ace-extra.js"></script>
        <link href="css/success.css" rel="stylesheet" type="text/css"/>

        <!-- inline scripts related to this page -->
        <script type="text/javascript" language="javascript">

            /*$(document).ready( function() {
             jQuery("#registroEncuesta").validationEngine();
             });*/
        </script>
    </head>

    <body class="no-skin page-sound" onLoad="cargar();">
        <!-- #section:basics/navbar.layout -->
        <div id="navbar" class="navbar navbar-default">
            <script type="text/javascript">
                try {
                    ace.settings.check('navbar', 'fixed')
                } catch (e) {
                }
            </script>

            <div class="navbar-container" id="navbar-container">
                <%@ include file="banner.jsp" %>
            </div><!-- /.navbar-container -->
        </div>

        <!-- /section:basics/navbar.layout -->
        <div class="main-container" id="main-container">
            <script type="text/javascript">
                try {
                    ace.settings.check('main-container', 'fixed')
                } catch (e) {
                }
            </script>

            <!-- #section:basics/sidebar -->
            <div id="sidebar" class="sidebar                  responsive">
                <script type="text/javascript">
                    try {
                        ace.settings.check('sidebar', 'fixed')
                    } catch (e) {
                    }
                </script>
                <input id="codModulo" type="hidden" value="<%=menu!=null?menu.getCodModulo():""%>">
                <input id="codCategoria" type="hidden" value="<%=menu!=null?menu.getCodCategoria():""%>">
                <%@ include file="menu.jsp" %>
                <!-- #section:basics/sidebar.layout.minimize -->
                <div class="sidebar-toggle sidebar-collapse" id="sidebar-collapse">
                    <i class="ace-icon fa fa-angle-double-left" data-icon1="ace-icon fa fa-angle-double-left" data-icon2="ace-icon fa fa-angle-double-right"></i>
                </div>
                <!-- /section:basics/sidebar.layout.minimize -->
                <script type="text/javascript">
                    try {
                        ace.settings.check('sidebar', 'collapsed')
                    } catch (e) {
                    }
                </script>
            </div>

            <!-- /section:basics/sidebar -->
            <div class="main-content">
                <div class="main-content-inner">
                    <!-- #section:basics/content.breadcrumbs -->
                    <div class="breadcrumbs" id="breadcrumbs">
                        <script type="text/javascript">
                            try {
                                ace.settings.check('breadcrumbs', 'fixed')
                            } catch (e) {
                            }
                        </script>

                        <ul class="breadcrumb">
                            <li>
                                <i class="ace-icon fa fa-home home-icon"></i>
                                <a href="principal.jsp">INICIO</a>
                            </li>
                            <li >TABLA DE MÉRITO</li>
                            <li class="active">REGISTRO</li>
                        </ul><!-- /.breadcrumb -->
                    </div>

                    <!-- /section:basics/content.breadcrumbs -->
                    <div class="page-content">

                        <div class="page-header">
                            <h1>
                                Tabla de mérito
                                <small>
                                    <i class="ace-icon fa fa-angle-double-right"></i>
                                    Registro
                                </small>
                            </h1>
                        </div><!-- /.page-header -->

                        <div class="row">
                            <div class="col-sm-3"></div>
                            <div class="col-sm-6">
                                <div class="widget-box widget-color-blue">
                                    <div class="widget-header">
                                        <h4 class="widget-title">Búsqueda de docentes</h4>
                                    </div>
                                    <div class="widget-body">
                                        <div class="widget-main no-padding">
                                            <form id="formulario" method="post">
                                                <fieldset>
                                                    <div class="col-sm-6">
                                                        <label>Área <span style="color:red;">*</span></label>
                                                        <div id="divArea">
                                                            <select id="cmbArea" class="form-control validate[required]" >
                                                                <option value="">[SELECCIONE]</option>
                                                            </select>
                                                        </div>
                                                    </div>
                                                    <div class="col-sm-6">
                                                        <label>Apellidos del docente </label>
                                                        <input type="text" id="txtApeDoc" class="form-control">
                                                    </div>
                                                    <div class="col-sm-12" style="height: 10px;"></div>
                                                    <div class="col-sm-12 text-right">
                                                        <span style="color:red;">*</span>:Campo obligatorio
                                                    </div>
                                                </fieldset>
                                                <div class="form-actions center">
                                                    <button class="btn btn-sm btn-info" type="button" onclick="validar();">
                                                        <i class="ace-icon fa fa-search icon-on-right bigger-110"></i>
                                                        Buscar
                                                    </button>
                                                    <button class="btn btn-sm btn-success" type="button" onclick="limpiar();">
                                                        <i class="ace-icon fa fa-eraser icon-on-right bigger-110"></i>
                                                        Limpiar
                                                    </button>
                                                </div>
                                            </form>
                                        </div>
                                    </div>
                                </div>
                            </div>
                            <div class="col-sm-3"></div>




                            <!-- ----------- CONTENEDOR DE FORMULARIOS--------INI----- -->
                            <div class="col-sm-12" style="width:100%; height: 40px;"></div>
                            <div  class="col-sm-2"></div>
                            <div  class="col-sm-8">
                                <!--Cadena a buscar <input id="searchTerm" type="text" onkeyup="doSearch()" />-->
                                <!-- -------------TABLA---INI------------ -->
                                <form method="POST" id="listado">
                                    <div id='divListado' class="hidden">
                                        <div class="widget-box widget-color-blue ui-sortable-handle">
                                            <!-- #section:custom/widget-box.options -->
                                            <div class="widget-header">
                                                <h5 class="widget-title bigger lighter">
                                                    <i class="ace-icon fa fa-table"></i>
                                                    Lista de docentes
                                                </h5>
                                            </div>

                                            <!-- /section:custom/widget-box.options -->
                                            <div class="widget-body">
                                                <div class="widget-main no-padding" id="listadoBody">
                                                </div>
                                            </div>
                                        </div>
                                    </div> 
                                </form>

                                <!-- -------------TABLA---FIN------------ -->
                            </div>
                            <div  class="col-sm-2"></div>
                            <!-- ----------- CONTENEDOR DE FORMULARIOS--------FIN----- -->




                            <!-- ::::::::::-ALERTAS-::::::::::::::: -->

                            <div id="dialog-edit" class="hide">
                                <br>
                                <form name="disponibilidad" id="disponibilidad" class="formular" method="post">
                                    <div id="divFormulario"></div>
                                </form>
                                <br><br>
                            </div>



                            <!-- ::::::::::-ALERTAS-::::::::::::::: -->


                        </div><!-- /.row -->
                    </div><!-- /.page-content -->
                </div>
            </div><!-- /.main-content -->

            <div class="footer">
                <%@ include file="footer.jsp" %>
            </div>

            <a href="#" id="btn-scroll-up" class="btn-scroll-up btn btn-sm btn-inverse">
                <i class="ace-icon fa fa-angle-double-up icon-only bigger-110"></i>
            </a>
        </div><!-- /.main-container -->

        <!-- basic scripts -->

        <!--[if !IE]> -->
        <script type="text/javascript">
            window.jQuery || document.write("<script src='../assets/js/jquery.js'>" + "<" + "/script>");
        </script>

        <!-- <![endif]-->

        <!--[if IE]>
<script type="text/javascript">
window.jQuery || document.write("<script src='../assets/js/jquery1x.js'>"+"<"+"/script>");
</script>
<![endif]-->
        <script type="text/javascript">
            if ('ontouchstart' in document.documentElement)
                document.write("<script src='../assets/js/jquery.mobile.custom.js'>" + "<" + "/script>");
        </script>

        <script src="js/jquery.mask.js" type="text/javascript"></script>
        <script src="js/jquery.mask.min.js" type="text/javascript"></script>
        <!-- page specific plugin scripts -->
        <script src="../assets/js/ionsound/js/ion.sound.min.js" type="text/javascript"></script>
        <script src="../assets/js/jquery-ui.js"></script>
        <script src="../assets/js/bootstrap.js"></script>
        <script src="../assets/js/jquery.ui.touch-punch.js"></script>

        <!--[if lte IE 8]>
          <script src="../assets/js/excanvas.js"></script>
        <![endif]-->
        <script src="../assets/js/jquery-ui.custom.js"></script>
        <script src="../assets/js/jquery.ui.touch-punch.js"></script>

        <!-- ace scripts -->
        <script src="../assets/js/ace/elements.scroller.js"></script>
        <script src="../assets/js/ace/elements.colorpicker.js"></script>
        <script src="../assets/js/ace/elements.fileinput.js"></script>
        <script src="../assets/js/ace/elements.typeahead.js"></script>
        <script src="../assets/js/ace/elements.wysiwyg.js"></script>
        <script src="../assets/js/ace/elements.spinner.js"></script>
        <script src="../assets/js/ace/elements.treeview.js"></script>
        <script src="../assets/js/ace/elements.wizard.js"></script>
        <script src="../assets/js/ace/elements.aside.js"></script>
        <script src="../assets/js/ace/ace.js"></script>
        <script src="../assets/js/ace/ace.ajax-content.js"></script>
        <script src="../assets/js/ace/ace.touch-drag.js"></script>
        <script src="../assets/js/ace/ace.sidebar.js"></script>
        <script src="../assets/js/ace/ace.sidebar-scroll-1.js"></script>
        <script src="../assets/js/ace/ace.submenu-hover.js"></script>
        <script src="../assets/js/ace/ace.widget-box.js"></script>
        <script src="../assets/js/ace/ace.settings.js"></script>
        <script src="../assets/js/ace/ace.settings-rtl.js"></script>
        <script src="../assets/js/ace/ace.settings-skin.js"></script>
        <script src="../assets/js/ace/ace.widget-on-reload.js"></script>
        <script src="../assets/js/ace/ace.searchbox-autocomplete.js"></script>
        <script src="../assets/js/ace/ace.searchbox-autocomplete.js"></script>

        <script src="js/blockui.min.js" type="text/javascript"></script>
        <link rel="stylesheet" href="css/validationEngine.jquery.css" type="text/css"/>
        <!--<link rel="stylesheet" href="css/template.css" type="text/css"/>-->


        <!-- inline scripts related to this page -->
        <script type="text/javascript">

            //::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

            $(document).ready(function () {
                jQuery("#formulario").validationEngine();
            });

            function conMayuscula(field) {
                field.value = field.value.toUpperCase();
            }

            function cargando() {
                $.blockUI({
                    message: '<div class="thecube"> <div class="cube c1"></div> <div class="cube c2"></div> <div class="cube c4"></div> <div class="cube c3"></div> </div>',
//        message: '<div class="loading" id="g-spinner" style="zoom: 1;"><div class="circle c1"></div><div class="circle c2"></div><div class="circle c3"></div><div class="circle c4"></div></div>',
//        message: '<div class="js-loading-indicator triple" style="width: 192px; height: 192px; top: 64px; left: 208px;"></div>',

                    baseZ: 9000,
                    overlayCSS: {
                        backgroundColor: '#1b2024',
                        opacity: 0.8,
                        cursor: 'wait'
                    },
                    css: {
                        zindex: '9999',
                        border: 0,
                        color: '#fff',
                        padding: 0,
                        backgroundColor: 'transparent'
                    }
                });
            }

            function cerrar_cargando() {
                $.unblockUI();
            }

            function segundaCarga() {
                cargarArea();
            }

            function cargarArea() {
                var accion = "ocultarTabla();";
                $.ajax({
                    type: 'POST',
                    url: '../ServletArea?Accion=cargarArea',
                    data: 'accion=' + accion,
                    beforeSend: function () {
                        cargando();
                    }, success: function (resultado) {
                        cerrar_cargando();
                        $("#divArea").html(resultado);
                    }, complete: function () {
                    }
                });
            }
            
            function ocultarTabla(){
                $("#listadoBody").html("");
                $("#divListado").addClass("hidden");
            }
            
            function limpiar(){
                $("#txtApeDoc").val("");
                listarRegistros();
            }
            
            function validar() {
                var estado = $("#formulario").validationEngine('validate');
                if (estado) {
                    listarRegistros();
                }
            }

            function listarRegistros() {
                var codigoArea = $("#cmbArea").val();
                var codigoPeriodo = "<%=periodo!=null?periodo.getCodigoPeriodo():""%>";
                var apellidoDocente = $("#txtApeDoc").val();
                $.ajax({
                    type: 'POST',
                    url: '../ServletTablaMerito?Accion=listarDocentes',
                    data: 'codigoArea=' + codigoArea + '&codigoPeriodo=' + codigoPeriodo + '&apellidoDocente=' + apellidoDocente,
                    beforeSend: function () {
                        cargando();
                    }, success: function (resultado) {
                        cerrar_cargando();
                        $("#listadoBody").html(resultado);
                    }, complete: function () {
                        $("#divListado").removeClass("hidden");
                    }
                });
            }

            function conformidadAsignarCoordinador(codigoDocente, dato) {
                if (dato == 0) {
                    bootbox.dialog({
                        headerClass: "modal-bg-primary",
                        title: "<i class='ace-icon fa fa-check-circle white'></i> <span class='white'>Conformidad</span>",
                        size: "small",
                        message: "¿Está seguro de eliminar la asignación?",
                        buttons: {
                            si: {
                                label: "<i class='fa fa-check bigger-110'></i>&nbsp; Si",
                                className: "btn-primary  btn-sm",
                                callback: function () {
                                    quitarAsignacionCoordinador(codigoDocente);
                                }
                            }, no: {
                                label: "<i class='fa fa-times bigger-110'></i>&nbsp; No",
                                className: "btn-danger  btn-sm",
                                callback: function () {

                                }
                            }
                        }
                    });
                } else {
                    bootbox.dialog({
                        headerClass: "modal-bg-primary",
                        title: "<i class='ace-icon fa fa-check-circle white'></i> <span class='white'>Conformidad</span>",
                        size: "small",
                        message: "¿Está seguro de asignar al docente como coordinador de área?",
                        buttons: {
                            si: {
                                label: "<i class='fa fa-check bigger-110'></i>&nbsp; Si",
                                className: "btn-primary  btn-sm",
                                callback: function () {
                                    validarSiExisteCoordinador(codigoDocente);
                                }
                            }, no: {
                                label: "<i class='fa fa-times bigger-110'></i>&nbsp; No",
                                className: "btn-danger  btn-sm",
                                callback: function () {

                                }
                            }
                        }
                    });
                }

            }

            function quitarAsignacionCoordinador(codigoDocente) {
                var codigoPeriodo = "<%=periodo!=null?periodo.getCodigoPeriodo():""%>";
                var codigoArea = $("#cmbArea").val();
                $.ajax({
                    type: 'POST',
                    url: '../ServletTablaMerito?Accion=quitarAsignacionCoordinador',
                    data: 'codigoPeriodo=' + codigoPeriodo + '&codigoDocente=' + codigoDocente + '&codigoArea=' + codigoArea,
                    beforeSend: function () {
                        cargando();
                    }, success: function (resultado) {
                        cerrar_cargando();
                        if (resultado == 1) {
                            notificacionQuitarAsignacionCoordinador();
                        } else {
                            alert("error");
                        }

                    }, complete: function () {
                    }
                });
            }

            function notificacionQuitarAsignacionCoordinador() {
                bootbox.dialog({
                    headerClass: "modal-bg-success",
                    title: "<i class='ace-icon fa fa-tags white'></i> <span class='white'>Notificación</span>",
                    size: "small",
                    message: "Se eliminó la asignación con éxito.",
                    buttons: {
                        si: {
                            label: "<i class='fa fa-check bigger-110'></i>&nbsp; Aceptar",
                            className: "btn-success btn-sm",
                            callback: function () {
                                listarRegistros();
                            }
                        }
                    }
                });
            }

            function validarSiExisteCoordinador(codigoDocente) {
                var cant = $("#txtCantAsi").val();
                if (cant > 0) {
                    var mensaje = "Ya existe un coordinador asignado, debe eliminar dicha asignación para continuar."
                    advertencia(mensaje);
                } else {
                    asignarCoordinador(codigoDocente);
                }
            }
            
            function asignarCoordinador(codigoDocente){
                var codigoPeriodo = "<%=periodo!=null?periodo.getCodigoPeriodo():""%>";
                var codigoArea = $("#cmbArea").val();
                $.ajax({
                    type: 'POST',
                    url: '../ServletTablaMerito?Accion=asignarCoordinador',
                    data: 'codigoPeriodo=' + codigoPeriodo + '&codigoDocente=' + codigoDocente + '&codigoArea=' + codigoArea,
                    beforeSend: function () {
                        cargando();
                    }, success: function (resultado) {
                        cerrar_cargando();
                        if (resultado == 1) {
                            notificacionAsignarCoordinador();
                        } else {
                            alert("error");
                        }

                    }, complete: function () {
                    }
                });
            }
            
            function notificacionAsignarCoordinador(){
                bootbox.dialog({
                    headerClass: "modal-bg-success",
                    title: "<i class='ace-icon fa fa-tags white'></i> <span class='white'>Notificación</span>",
                    size: "small",
                    message: "La asignación se realizó con éxito.",
                    buttons: {
                        si: {
                            label: "<i class='fa fa-check bigger-110'></i>&nbsp; Aceptar",
                            className: "btn-success btn-sm",
                            callback: function () {
                                listarRegistros();
                            }
                        }
                    }
                });
            }
            
            function advertencia(mensaje) {
                bootbox.dialog({
                    headerClass: "modal-bg-warning",
                    title: "<i class='ace-icon fa fa-exclamation-triangle white'></i> <span class='white'>Advertencia</span>",
                    size: "small",
                    message: mensaje,
                    buttons: {
                        si: {
                            label: "<i class='fa fa-check bigger-110'></i>&nbsp; Aceptar",
                            className: "btn-warning btn-sm",
                            callback: function () {
                                
                            }
                        }
                    }
                });
            }

            // -----------------------------------------------------------------



            function conMayusculas(field) {
                field.value = field.value.toUpperCase();
            }

            $('input').keypress(function (e) {
                if (e.which == 13) {
                    return false;
                }
            });


        </script>

        <!-- the following scripts are used in demo only for onpage help and you don't need them -->

        <link rel="stylesheet" href="../assets/css/ace.onpage-help.css" />
        <link rel="stylesheet" href="../docs/assets/js/themes/sunburst.css" />

        <script type="text/javascript"> ace.vars['base'] = '..';</script>
        <script src="../assets/js/ace/elements.onpage-help.js"></script>
        <script src="../assets/js/ace/ace.onpage-help.js"></script>
        <script src="../docs/assets/js/rainbow.js"></script>
        <script src="../docs/assets/js/language/generic.js"></script>
        <script src="../docs/assets/js/language/html.js"></script>
        <script src="../docs/assets/js/language/css.js"></script>
        <script src="../docs/assets/js/language/javascript.js"></script>


        <script src="js/bootbox.min.js" type="text/javascript"></script>
        <script src="js/languages/jquery.validationEngine-es.js" type="text/javascript" charset="utf-8"></script>
        <script src="js/jquery.validationEngine.js" type="text/javascript" charset="utf-8"></script>

</html>
