lunes, 2 de mayo de 2016

SweetAlert no muestra diálogo de confirmación después de grabar

Mi error fue no haber establecido a false la propiedad closeOnConfirm de la primera alerta, que desencadena en la segunda.

Debe ser así:

Javascript
=========

$(Contenedor + 'btnGuardar').click(function () {
Controles_Validar_Reiniciar();

if (!Controles_Validar()) {
return false;
}

Dialogo_ConfirmarRegistro();   //1° Alerta

return false;
});

function Dialogo_ConfirmarRegistro() {
    swal({
        title: "Confirmar registro de notas",
        text: "Las notas ingresadas van a ser registradas. ¿Desea continuar?",
        type: "warning",
        showCancelButton: true,
        confirmButtonClass: "btn-danger",
        confirmButtonText: "Sí",
        cancelButtonText: "No",
        closeOnConfirm: false,
        allowEscapeKey: true
    },
        function () {
            Registrar_Notas();            
        }
    );

    return false;
}

function Registrar_Notas() {
    var Contenedor = '#ContentPlaceHolder1_';
    var CodSemestre = $(Contenedor + 'ddlSemestre').val();
    var CodCompetencia = $(Contenedor + 'ddlCompetencia').val();
    var CodCarga = $(Contenedor + 'hdnCodCarga').val();
    var CodCurso = $(Contenedor + 'hdnCodCurso').val();  
    var CodNota = $(Contenedor + 'hdnNota').val();
    var CodFecha = $(Contenedor + 'txtFecSesion').val();
    var IdControl = '_txt' + CodNota + '_';
    var IdCheck = '_chkSinNota_';
    var arrNotas = new Array();
 
    $(Contenedor + 'dtgNotas .css' + CodNota).each(function (index) {
        var objNotas = {
            CodAlumno: '',
            CodNota: 0.00
        };

        objNotas.CodAlumno = $('#' + this.id.replace(IdControl, '_lblCodAlumno_')).text();

        if ($('#' + this.id.replace(IdControl, IdCheck)).is(':checked')) {          
            objNotas.CodNota = -1.00;
        }
        else {
            objNotas.CodNota = parseFloat(this.value);
        }

        arrNotas.push(objNotas);
    });

    var objParams = {
        Semestre: CodSemestre,
        CodCarga: CodCarga,
        CodCurso: CodCurso,
        CodCompetencia: CodCompetencia,
        NumNota: CodNota,
        FecSesion: CodFecha,
        arrNotas: arrNotas      
    };  

    var arg = Sys.Serialization.JavaScriptSerializer.serialize(objParams);

    MostrarEspera(true);

    Registrar_Notas_Call(arg, function (result) {
        var Entity = Sys.Serialization.JavaScriptSerializer.deserialize(result.split('~')[0]);

        MostrarEspera(false);

        if (Entity.Resultado == "1") {
            //2° Alerta: Success
            swal({
                title: 'Operación completada',
                text: 'Las notas ingresadas han sido registradas correctamente.',
                type: 'success',
                showCancelButton: false,
                confirmButtonClass: 'btn-info',
                confirmButtonText: 'Aceptar',
                closeOnConfirm: false,
                allowEscapeKey: false
            },
                function () {
                    Reiniciar_Formulario();   
                }
            );
        }
        else {
            Dialogo_Error(Entity.MsgError);   //2° Alerta: Error
        }

        $(Contenedor + 'hdnMsgError').val(Entity.MsgError);
        $(Contenedor + 'hdnMsgErrorBD').val(Entity.MsgBD);

        return false;
    });

    return false;
}

function Dialogo_Error(MsgError) {
    swal({
        title: 'Operación no completada',
        text: MsgError,
        type: "warning",
        showConfirmButton: false,
        showCancelButton: true,
        cancelButtonText: "Aceptar",
        closeOnConfirm: false,
        allowEscapeKey: true
    });

    return false;
}

No hay comentarios:

Publicar un comentario