diff --git a/index.html b/index.html index 3d80329..e5543ca 100644 --- a/index.html +++ b/index.html @@ -469,6 +469,7 @@ + diff --git a/js/timelaps.js b/js/timelaps.js index 33f9422..8b7dde9 100644 --- a/js/timelaps.js +++ b/js/timelaps.js @@ -1,42 +1,3 @@ -var api_url = 'http://timelaps.local:8000/api/v1/'; - -function getParams() { - -} - -function showKarts() { - $.ajax({ - type: 'GET', - crossDomain: true, - url: api_url + 'karts/', - dataType: 'json', - success: function (data, status) { - console.log(data); - $('#dataTable_kart_list').DataTable({ - data: data, - columns: [ - { - data: "id", - render: function (data, type, row, meta) { - return ' '; - } - }, - { - data: "name" - }, - { - data: "autonomy" - } - ] - }); - }, - error: function (xhr) { - $.notify("APIs unreachable!", "error"); - console.log('Request Status: ' + xhr.status + ' Status Text: ' + xhr.statusText + ' ' + xhr.responseText); - }, - }); -} - function getKartsMenu() { $.ajax({ type: 'GET', @@ -136,3 +97,195 @@ function getPilotsByKart() { }, }); } + +function getParams() { + + $.ajax({ + type: 'GET', + crossDomain: true, + url: api_url + 'params/1/', + dataType: 'json', + success: function (data, status) { + $('#id').val(data.id); + $('#autonomy').val(data.autonomy); + $('#stand_minimum_time').val(data.stand_minimum_time); + $('#default_relay').val(data.default_relay); + $('#comment').val(data.comment); + }, + error: function (xhr) { + $.notify("APIs unreachable!", "error"); + console.log('Request Status: ' + xhr.status + ' Status Text: ' + xhr.statusText + ' ' + xhr.responseText); + }, + }); +} + +function editParams(data) { + $.ajax({ + type: 'PUT', + crossDomain: true, + url: api_url + 'params/1/', + dataType: 'json', + data: data, + success: function (data, status) { + $.notify("Update done!", "success"); + getParams(); + }, + error: function (xhr) { + $.notify("APIs unreachable!", "error"); + console.log('Request Status: ' + xhr.status + ' Status Text: ' + xhr.statusText + ' ' + xhr.responseText); + }, + }); +} + +function getKarts(id) { + + $.ajax({ + type: 'GET', + crossDomain: true, + url: api_url + 'karts/'+id+'/', + dataType: 'json', + success: function (data, status) { + $('#id').val(data.id); + $('#autonomy').val(data.autonomy); + $('#stand_minimum_time').val(data.stand_minimum_time); + $('#default_relay').val(data.default_relay); + $('#comment').val(data.comment); + }, + error: function (xhr) { + $.notify("APIs unreachable!", "error"); + console.log('Request Status: ' + xhr.status + ' Status Text: ' + xhr.statusText + ' ' + xhr.responseText); + }, + }); +} + +function listKarts() { + $.ajax({ + type: 'GET', + crossDomain: true, + url: api_url + 'karts/', + dataType: 'json', + success: function (data, status) { + console.log(data); + $('#dataTable_kart_list').DataTable({ + data: data, + columns: [ + { + data: "id", + render: function (data, type, row, meta) { + return '' + + '' + + '' + + ' ' + + '' + + '' + + ''; + } + }, + { + data: "name" + }, + { + data: "autonomy" + } + ] + }); + }, + error: function (xhr) { + $.notify("APIs unreachable!", "error"); + console.log('Request Status: ' + xhr.status + ' Status Text: ' + xhr.statusText + ' ' + xhr.responseText); + }, + }); +} + +function deleteKarts(id) { + $.ajax({ + type: 'DELETE', + crossDomain: true, + url: api_url + 'karts/'+id+'/', + dataType: 'json', + data: data, + success: function (data, status) { + $.notify("Delete done!", "success"); + showKarts(); + }, + error: function (xhr) { + $.notify("APIs unreachable!", "error"); + console.log('Request Status: ' + xhr.status + ' Status Text: ' + xhr.statusText + ' ' + xhr.responseText); + }, + }); +} + +function addKarts(data) { + $.ajax({ + type: 'POST', + crossDomain: true, + url: api_url + 'karts/', + dataType: 'json', + data: data, + success: function (data, status) { + $.notify("Update done!", "success"); + //showKarts(); + }, + error: function (xhr) { + $.notify("APIs unreachable!", "error"); + console.log('Request Status: ' + xhr.status + ' Status Text: ' + xhr.statusText + ' ' + xhr.responseText); + }, + }); +} + +function editKarts(data) { + $.ajax({ + type: 'PUT', + crossDomain: true, + url: api_url + 'karts/1/', + dataType: 'json', + data: data, + success: function (data, status) { + $.notify("Update done!", "success"); + showKarts(); + }, + error: function (xhr) { + $.notify("APIs unreachable!", "error"); + console.log('Request Status: ' + xhr.status + ' Status Text: ' + xhr.statusText + ' ' + xhr.responseText); + }, + }); +} + +function getDriver(id) { + + $.ajax({ + type: 'GET', + crossDomain: true, + url: api_url + 'drivers/'+id+'/', + dataType: 'json', + success: function (data, status) { + $('#id').val(data.id); + $('#autonomy').val(data.autonomy); + $('#stand_minimum_time').val(data.stand_minimum_time); + $('#default_relay').val(data.default_relay); + $('#comment').val(data.comment); + }, + error: function (xhr) { + $.notify("APIs unreachable!", "error"); + console.log('Request Status: ' + xhr.status + ' Status Text: ' + xhr.statusText + ' ' + xhr.responseText); + }, + }); +} + +function editDriver(data) { + $.ajax({ + type: 'PUT', + crossDomain: true, + url: api_url + 'drivers/1/', + dataType: 'json', + data: data, + success: function (data, status) { + $.notify("Update done!", "success"); + getPilotsByKart(); + }, + error: function (xhr) { + $.notify("APIs unreachable!", "error"); + console.log('Request Status: ' + xhr.status + ' Status Text: ' + xhr.statusText + ' ' + xhr.responseText); + }, + }); +} diff --git a/js/var_conf.js b/js/var_conf.js new file mode 100644 index 0000000..9a19e33 --- /dev/null +++ b/js/var_conf.js @@ -0,0 +1 @@ +var api_url = 'http://timelaps.local:8000/api/v1/'; \ No newline at end of file diff --git a/karts.html b/karts.html index 3a80647..637a378 100644 --- a/karts.html +++ b/karts.html @@ -195,7 +195,8 @@
Karting list - - +
@@ -215,42 +216,6 @@ -
@@ -264,7 +229,8 @@ -