When updating the library SweetAlert it stopped working, debugging the error saw that it had many modifications that made version 1.x incompatible with the new version, so I would like help transcribing my deletarRegistro()
function.
Function code with sweetalert 1.x
function deletarRegistro() {
if (id_row > 0) {
swal({
title: "Você tem certeza disso?",
text: "Uma vez deletado, não há como desfazer!",
type: "warning",
showCancelButton: true,
confirmButtonColor: "#DD6B55",
confirmButtonText: "Sim, delete isto!",
showLoaderOnConfirm: true,
closeOnConfirm: false
},
function () {
$.post('/api/tdocumentos/delete', {id: id_row})
.done(function () {
tbl_api.row('.info').remove().draw(false);
swal("Deletado!", "Seu registro foi deletado.", "success");
id_row = null;
formulario.reset();
$(tab_lista).click();
})
.fail(function (response) {
console.log(response.responseText);
swal("Erro!", response.responseText, "error");
})
;
})
;
} else {
tbl_dependentes.effect('shake');
return false;
}
}
The SweetAlert 2.0 documentation for this example:
swal({
title: "Are you sure?",
text: "Once deleted, you will not be able to recover this imaginary
file!",
icon: "warning",
buttons: true,
dangerMode: true,
})
.then((willDelete) => {
if (willDelete) {
swal("Poof! Your imaginary file has been deleted!", {
icon: "success",
});
} else {
swal("Your imaginary file is safe!");
}
});
Question: I would like to know how I can transcribe the function using promisses, and know what promisses use improves function.