<?php use_helper( 'UrlFunctions' ); ?>
<?php use_helper( 'UtilFunctions' ); ?>
<?php use_helper( 'IncludePartial' ); ?>

<script type="text/javascript">
showAlertBootStrap = function( elm_id_content, class_default, message_alert )
{
    var html_alert = '<div class="alert ' + class_default + ' alert-dismissible fade show" role="alert"> ' +
            '' + message_alert +
            '<button type="button" class="close" data-dismiss="alert" aria-label="Close">' +
                '<span aria-hidden="true">&times;</span>' +
            '</button>' +
        '</div>';
    $( "#" + elm_id_content ).append( html_alert );
}

saveForm = function()
{
    //mostrarCargaImg();
    var strFormSerialize = $( 'form' ).serialize();
    
    executeAjaxJson
    ( 
        "<?php echo buildUrl( 'estadoshab/saveAddEdit', "" ) ?>", 
        strFormSerialize,
        function( o_json )
        {
            //console.log( o_json );
            //ocultarCargaImg();
            if( o_json.error )
            {
                showAlertBootStrap( 'content_alert', 'alert-danger', o_json.mensaje_error );
                //mostrarMensajeError( o_json.mensaje_error );
                return false;
            }
            //return false;
            switch ( o_json.type_sub )
            {
                case "0":
                    location.href = "<?=buildUrl( 'estadoshab/addedit', "s_TipoProc=upd&i_Id="  )?>" + o_json.id;
                break;
                case "1":
                    location.href = "<?=buildUrl( 'estadoshab/list', "" )?>";
                break;
            }
        } 
    );
    return false;
}
</script>

<div class="shadow-sm p-3 mb-2 bg-white rounded card card-body">
    <div class="row">
        <div class="col mb-1">
            <h4 class="text-info text-nowrap mb-0"><?=$s_Titulo?></h4>
        </div>
    </div>
</div>

<div id="content_alert" style=""></div>

<div class="card">
    <div class="container">
        <form class="was-validated" name="form1" id="form1" method="POST" action="" onsubmit="return saveForm();">
            <input type="hidden" name="i_Id" id="i_Id" value="<?=$o_ObjectBN->getIdEstados()?>">
            <input type="hidden" name="s_TipoProc" id="s_TipoProc" value="<?=$s_TipoProc?>">
            <input type="hidden" name="TypeSub" id="TypeSub" value="0">

            <?php include_partial( "addedit", array( "o_ObjectBN" => $o_ObjectBN ) ); ?>

            <div class="form-row mx-0">
                <div class="col-md-6 mb-1">
                    <button type="button" class="btn btn-primary btn-lg btn-block" onclick="location.href='<?php echo buildUrl( 'estadoshab/list', '' ) ?>'">CANCELAR</button>
                </div>
                <div class="col-md-6 mb-1">
                    <button type="submit" class="btn btn-primary btn-lg btn-block" onclick="$( '#TypeSub' ).val( '1' );">GRABAR Y SALIR</button>
                </div>
            </div>
        </form>
    </div>
</div>