usuarios.tabela-itens.js
1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
var Protocolo = Protocolo || {};
Protocolo.TabelaUsuarios = (function () {
function TabelaUsuarios() {
this.btnExcluir = $('.js-btn-excluir-usuario');
}
TabelaUsuarios.prototype.iniciar = function () {
this.btnExcluir.on('click', onExcluirUsuario.bind(this));
};
function onExcluirUsuario(event) {
event.preventDefault();
var url = $(event.currentTarget).data('url');
console.log(url);
swal({
title: 'Confirma a Exclusão ?',
text: 'Você não poderá recuperar depois.',
showCancelButton: true,
confirmButtonColor: '#DD6B55',
confirmButtonText: 'SIM',
cancelButtonText: 'CANCELAR',
closeOnConfirm: false
}, onExcluirConfirmado.bind(this, url));
}
function onExcluirConfirmado(url) {
$.ajax({
url: url,
method: 'DELETE',
contentType: 'application/json',
success: onExclusaoConcluido.bind(this),
error: onErroExclusao.bind(this)
});
}
function onExclusaoConcluido() {
window.location.reload();
}
function onErroExclusao() {
$.jAlert({
'title': 'Erro',
'content': 'Erro ao excluir o usuário.',
'theme': 'dark_red',
'btns': {'text': 'FECHAR'}
});
}
return TabelaUsuarios;
})();
$(function () {
var tabelaUsuarios = new Protocolo.TabelaUsuarios();
tabelaUsuarios.iniciar();
});