function getKartsMenu() {
$.ajax({
type: 'GET',
crossDomain: true,
url: api_url + 'karts/',
dataType: 'json',
success: function (data, status) {
$.each(data, function (index, value) {
$('#link_all').after("" +
" \n" +
" \n" +
" \n" +
"\n" +
" " + value.name + "" +
" ");
});
},
error: function (xhr) {
$.notify("APIs unreachable!", "error");
console.log('Request Status: ' + xhr.status + ' Status Text: ' + xhr.statusText + ' ' + xhr.responseText);
},
});
}
function getPilotsByKart() {
$.ajax({
type: 'GET',
crossDomain: true,
url: api_url + 'karts/',
dataType: 'json',
success: function (data, status) {
$.each(data, function (index, value) {
$('.container-fluid').append("" +
"
\n" +
" \n" +
"
\n" +
"
\n" +
"
\n" +
" \n" +
" \n" +
" | \n" +
" Order | \n" +
" Short Name | \n" +
" First Name | \n" +
" Last Name | \n" +
" Ref time (Sec) | \n" +
"
\n" +
" \n" +
" \n" +
" \n" +
"
\n" +
"
\n" +
"
\n" +
"
" +
"");
$('#dataTable_pilots'+value.id).DataTable({
data: value.drivers,
columns: [
{
data: "id",
render: function (data, type, row, meta) {
return ' ';
}
},
{
data: "order"
},
{
data: "first_name"
},
{
data: "first_name"
},
{
data: "last_name"
},
{
data: "ref_time"
}
]
});
});
},
error: function (xhr) {
$.notify("APIs unreachable!", "error");
console.log('Request Status: ' + xhr.status + ' Status Text: ' + xhr.statusText + ' ' + xhr.responseText);
},
});
}
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) {
if(tableListKart instanceof $.fn.dataTable.Api){
tableListKart.destroy();
}
tableListKart = $('#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, index) {
$.ajax({
type: 'DELETE',
crossDomain: true,
url: api_url + 'karts/'+id+'/',
dataType: 'json',
success: function (data, status) {
$.notify("Delete done!", "success");
tableListKart.row(index).remove().draw();
},
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");
$('#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);
},
});
}
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);
},
});
}