diff --git a/js/timelaps.js b/js/timelaps.js index 8b7dde9..c04a262 100644 --- a/js/timelaps.js +++ b/js/timelaps.js @@ -165,8 +165,10 @@ function listKarts() { url: api_url + 'karts/', dataType: 'json', success: function (data, status) { - console.log(data); - $('#dataTable_kart_list').DataTable({ + if(tableListKart instanceof $.fn.dataTable.Api){ + tableListKart.destroy(); + } + tableListKart = $('#dataTable_kart_list').DataTable({ data: data, columns: [ { @@ -176,7 +178,7 @@ function listKarts() { '' + '' + ' ' + - '' + + '' + '' + ''; } @@ -197,16 +199,15 @@ function listKarts() { }); } -function deleteKarts(id) { +function deleteKarts(id, index) { $.ajax({ type: 'DELETE', crossDomain: true, url: api_url + 'karts/'+id+'/', dataType: 'json', - data: data, success: function (data, status) { $.notify("Delete done!", "success"); - showKarts(); + tableListKart.row(index).remove().draw(); }, error: function (xhr) { $.notify("APIs unreachable!", "error"); @@ -224,11 +225,14 @@ function addKarts(data) { data: data, success: function (data, status) { $.notify("Update done!", "success"); - //showKarts(); + $('#modal_newkart').modal('hide'); + $("#saveKartChanges").prop('disabled', false); + listKarts() }, error: function (xhr) { $.notify("APIs unreachable!", "error"); console.log('Request Status: ' + xhr.status + ' Status Text: ' + xhr.statusText + ' ' + xhr.responseText); + $("#saveKartChanges").prop('disabled', false); }, }); } diff --git a/js/var_conf.js b/js/var_conf.js index 9a19e33..19831c1 100644 --- a/js/var_conf.js +++ b/js/var_conf.js @@ -1 +1,2 @@ -var api_url = 'http://timelaps.local:8000/api/v1/'; \ No newline at end of file +var api_url = 'http://timelaps.local:8000/api/v1/'; +var tableListKart = ''; \ No newline at end of file diff --git a/karts.html b/karts.html index 637a378..156a171 100644 --- a/karts.html +++ b/karts.html @@ -200,10 +200,8 @@ - - - +