<%@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>
        <style>
            .dialogWide50 > .modal-dialog {
                width: 25% !important;
            }
        </style>
    </head>

    <body class="no-skin" 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 class="active">USUARIO</li>
                        </ul><!-- /.breadcrumb -->
                    </div>

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

                        <div class="page-header">
                            <h1>
                                Usuario
                                <small>
                                    <i class="ace-icon fa fa-angle-double-right"></i>
                                    Director
                                </small>
                            </h1>
                        </div><!-- /.page-header -->

                        <div class="row">





                            <!-- ----------- CONTENEDOR DE FORMULARIOS--------INI----- -->
                            <div class="col-sm-12" style="width:100%;">

                                <div  class="col-sm-4"></div>
                                <div  class="col-sm-4">
                                    <div class="widget-box widget-color-blue">
                                        <div class="widget-header">
                                            <h4 class="widget-title">Creación de Usuarios (Director)</h4>
                                        </div>

                                        <div class="widget-body">
                                            <div class="widget-main no-padding">
                                                <form id="registro"  method="post">
                                                    <fieldset>
                                                        <label>Usuario <span style='color:red;'>*</span></label><br>
                                                        <input class="form-control validate[required, custom[onlyLetterMayNumberSp]] " id="txt_new_usu" onchange="conMayusculas(this);" type="text" >
                                                        <br>
                                                        <label>Clave <span style='color:red;'>*</span></label><br>
                                                        <input class="form-control validate[required] " id="txt_new_pass" type="text" >
                                                        <br>
                                                        <label>Sede <span style='color:red;'>*</span></label><br>
                                                        <div id="divcodLoc">
                                                            <select class="form-control validate[required]" id="cmb_nom_sede" onchange="">
                                                                <option value="">[Seleccione]</option>
                                                            </select>
                                                        </div>
                                                    </fieldset>
                                                    <div class="form-actions center">
                                                        <button  class="btn btn-sm btn-info" type="button" onclick="validar_registro();">
                                                            <i class="ace-icon fa fa-pencil-square-o icon-on-right bigger-110"></i>
                                                            Registrar Usuario
                                                        </button>
                                                    </div>
                                                </form>
                                            </div>
                                        </div>
                                    </div>
                                </div>
                                <div  class="col-sm-4"></div>

                            </div>
                            <div class="col-sm-12" style="width:100%; height: 40px;"></div>
                            <div  class="col-sm-12" style="width:100%;">
                                <div  class="col-sm-2" ></div>
                                <div  class="col-sm-8">
                                    <!-- -------------TABLA---INI------------ -->
                                    <div id="divListadoUsuSede"></div>
                                    <!-- -------------TABLA---FIN------------ -->
                                </div>
                                <div  class="col-sm-2"></div>
                            </div>
                            <!-- ----------- CONTENEDOR DE FORMULARIOS--------FIN----- -->




                            <!-- ::::::::::-ALERTAS-::::::::::::::: -->
                            <input type='hidden' id='codigo'>



                            <div id="dialog-noti1" class="hide">
                                <br>
                                Se habilitó el estado con éxito. 
                                <br><br>
                            </div>

                            <div id="dialog-noti2" class="hide">
                                <br>
                                Se inhabilitó el estado con éxito.
                                <br><br>
                            </div>

                            <div id="dialog-noti3" class="hide">
                                <br>
                                Se modificó el registro con éxito.
                                <br><br>
                            </div>

                            <div id="dialog-noti4" class="hide">
                                <br>
                                Se registró con éxito.
                                <br><br>
                            </div>

                            <div id="dialog-advertencia1" class="hide">
                                <br>
                                --------------------------------
                                <br><br>
                            </div>

                            <div id="dialog-confor1" class="hide">
                                <br>
                                ¿Está seguro de inhabilitar el estado del usuario?
                                <br><br>
                            </div>

                            <div id="dialog-confor2" class="hide">
                                <br>
                                ¿Está seguro de habilitar el estado del usuario?
                                <br><br>
                            </div>

                            <div id="dialog-confor3" class="hide">
                                <br>
                                ¿Está seguro de modificar el registro?
                                <br><br>
                            </div>

                            <div id="dialog-confor4" class="hide">
                                <br>
                                ¿Está seguro de registrar un nuevo Usuario? 
                                <br><br>
                            </div>



                            <div id="dialog-cargando" class="hide">
                                <table cellpadding="0" cellspacing="0" width="100%">
                                    <tr><td align="center"><img src="imagenes/cargando.gif" border=0></td></tr>
                                </table>
                            </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="../assets/js/bootstrap.js"></script>

        <!-- page specific plugin scripts -->
        <script src="../assets/js/jquery-ui.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>
        <script src="../assets/js/jquery.easypiechart.js"></script>
        <script src="../assets/js/jquery.sparkline.js"></script>
        <script src="../assets/js/flot/jquery.flot.js"></script>
        <script src="../assets/js/flot/jquery.flot.pie.js"></script>
        <script src="../assets/js/flot/jquery.flot.resize.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">

            var variableRSVP;
            $(document).ready(function () {
                jQuery("#registroEncuesta").validationEngine();
                variableRSVP = RSVP;
            });

            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>',
                    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 conMayusculas(field) {
                field.value = field.value.toUpperCase()
            }

            function segundaCarga() {
                cargarSede();
                listarUsuarioSede();
            }

            function cargarSede() {
                var accion = "";
                $.ajax({
                    type: 'POST',
                    url: '../ServletUsuario?accion=cargarSede',
                    data: 'accion=' + accion,
                    beforeSend: function () {
                        cargando();
                    }, success: function (resultado) {
                        cerrar_cargando();
                        $("#divcodLoc").html(resultado);
                    }, complete: function () {

                    }
                });

            }

            function armarEdicion(codUsuario) {
                var cuerpo = "";
                $.ajax({
                    type: 'POST',
                    url: '../ServletUsuario?accion=armarEditarDirector',
                    data: 'codUsuario=' + codUsuario,
                    success: function (resultado) {
                        cuerpo = resultado;
                    }, complete: function () {
                        editar(codUsuario, cuerpo);
                    }
                });
            }

            function editar(codUsuario, cuerpo) {
                bootbox.dialog({
                    headerClass: "modal-bg-primary",
                    className: "dialogWide50",
                    title: "<i class='ace-icon fa fa-check-circle white'></i> <span class='white'>Actualizar usuario</span>",
                    message: cuerpo,
                    buttons: {
                        si: {
                            label: "<i class='fa fa-check bigger-110'></i>&nbsp; Actualizar",
                            className: "btn-primary  btn-sm",
                            callback: function () {
                                var nombre = $("#txt_nom_usu").val();
                                var clave = $("#txt_nom_pass").val();
                                var codSede = $("#cmbsedeEncargado").val();
                                if (!validar_actulizar()) {
                                    return false;
                                } else {

                                    popup_actualizar(codUsuario,nombre,clave,codSede);
                                }

                            }
                        }, no: {
                            label: "<i class='fa fa-times bigger-110'></i>&nbsp; Cancelar",
                            className: "btn-danger  btn-sm",
                            callback: function () {

                            }
                        }
                    }
                });

            }

            function actualizar(codUsuario,nombre,clave,codSede) {
                $.ajax({
                    type: 'POST',
                    url: '../ServletUsuario?accion=actualizarUsuarioDirector',
                    data: 'codUsuario=' + codUsuario + '&nombre=' + nombre + '&clave=' + clave + '&codSede=' + codSede,
                    beforeSend: function () {
                        cargando();
                    }, success: function (resultado) {
                        cerrar_cargando();
                    }, complete: function () {
                        popup_OK();

                    }
                });
            }

            function validar_actulizar() {
//                return new variableRSVP.Promise(function(resolve){
                var estado = $('#actulizar').validationEngine('validate');
                return estado;
//                }) 
            }

            function popup_actualizar(codUsuario,nombre,clave,codSede) {
                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 modificar el registro?",
                    buttons: {
                        si: {
                            label: "<i class='fa fa-check bigger-110'></i>&nbsp; Si",
                            className: "btn-primary  btn-sm",
                            callback: function () {
                                actualizar(codUsuario,nombre,clave,codSede);
                            }
                        }, no: {
                            label: "<i class='fa fa-times bigger-110'></i>&nbsp; No",
                            className: "btn-danger  btn-sm",
                            callback: function () {

                            }
                        }
                    }
                });
            }

            function popup_OK() {
                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 modificó el registro con éxito.",
                    buttons: {
                        si: {
                            label: "<i class='fa fa-check bigger-110'></i>&nbsp; Aceptar",
                            className: "btn-success btn-sm",
                            callback: function () {
                                listarUsuarioSede();
                            }
                        }
                    }
                });
            }

            function listarUsuarioSede() {
                $.ajax({
                    type: 'POST',
                    url: '../ServletUsuario?accion=listarUsuarioDirector',
                    data: null,
                    beforeSend: function () {
                        cargando();
                    }, success: function (resultado) {
                        cerrar_cargando();
                        $('#divListadoUsuSede').html(resultado);
                    }, complete: function () {
                    }
                });
            }

            function validar_registro() {
                var estado = jQuery('#registro').validationEngine('validate');
                if (estado) {
                    popup_0();

                }
            }

            function registrarUsuarioSede() {
                // 1: se registro normal   2: ya exista   3: error
                var usuario = $("#txt_new_usu").val();
                var clave = $("#txt_new_pass").val();
                var codLoc = $("#cmb_nom_sede").val();

                $.ajax({
                    type: 'POST',
                    url: '../ServletUsuario?accion=registrarUsuarioDirector',
                    data: 'usuario=' + usuario + '&clave=' + clave + '&codLoc=' + codLoc,
                    beforeSend: function () {
                        cargando();
                    }, success: function (resultado) {
                        cerrar_cargando();
                    }, complete: function () {
                        popup_1();
                        $("#txt_new_usu").val("");
                        $("#txt_new_pass").val("");
                        cargarSede();
                    }
                });
            }

            function estado(dato, codUsuario) {
                var mensaje;
                $.ajax({
                    type: 'POST',
                    url: '../ServletUsuario?accion=cambiarEstado',
                    data: 'dato=' + dato + '&codUsuario=' + codUsuario,
                    beforeSend: function () {
                        cargando();
                    }, success: function (resultado) {
                        cerrar_cargando();
                    }, complete: function () {
                        if (dato == 0) {
                            mensaje = "¿Está seguro de inhabilitar el estado del usuario?";
                            popup_2(mensaje, dato);
                        } else {
                            mensaje = "¿Está seguro de habilitar el estado del usuario?";
                            popup_2(mensaje, dato);
                        }
                    }
                });
            }

            function popup_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 registrar un nuevo Usuario? ",
                    buttons: {
                        si: {
                            label: "<i class='fa fa-check bigger-110'></i>&nbsp; Si",
                            className: "btn-primary  btn-sm",
                            callback: function () {
                                registrarUsuarioSede();
                            }
                        }, no: {
                            label: "<i class='fa fa-times bigger-110'></i>&nbsp; No",
                            className: "btn-danger  btn-sm",
                            callback: function () {

                            }
                        }
                    }
                });
            }

            function popup_1() {
                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 registró con éxito.",
                    buttons: {
                        si: {
                            label: "<i class='fa fa-check bigger-110'></i>&nbsp; Aceptar",
                            className: "btn-success btn-sm",
                            callback: function () {
                                listarUsuarioSede();
                            }
                        }
                    }
                });
            }

            function popup_2(mensaje, dato) {
                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: mensaje,
                    buttons: {
                        si: {
                            label: "<i class='fa fa-check bigger-110'></i>&nbsp; Si",
                            className: "btn-primary  btn-sm",
                            callback: function () {

                                popup_5(dato);
                            }
                        }, no: {
                            label: "<i class='fa fa-times bigger-110'></i>&nbsp; No",
                            className: "btn-danger  btn-sm",
                            callback: function () {

                            }
                        }
                    }
                });
            }


            function popup_5(dato) {
                if (dato == 0) {
                    mensaje = "Se inhabilitó el estado con éxito.";
                } else {
                    mensaje = "Se habilitó el estado con éxito.";
                }

                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: mensaje,
                    buttons: {
                        si: {
                            label: "<i class='fa fa-check bigger-110'></i>&nbsp; Aceptar",
                            className: "btn-success btn-sm",
                            callback: function () {
                                listarUsuarioSede();
                            }
                        }
                    }
                });
            }


        </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>
        <script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/rsvp/4.7.0/rsvp.min.js"></script>

</html>
