Setting new global JS conf file.

This commit is contained in:
2019-04-18 22:08:29 +02:00
parent 0d8f112c9e
commit 2bbb8c17f8
6 changed files with 242 additions and 100 deletions

View File

@ -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 '<a href="#" class="btn btn-primary btn-circle"><i class="fas fa-edit"></i></a>&nbsp;<a href="#" class="btn btn-danger btn-circle"><i class="fas fa-trash"></i>';
}
},
{
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 '<a href="#" onclick="" class="btn btn-primary btn-circle">' +
'<i class="fas fa-edit"></i>' +
'</a>' +
'&nbsp;' +
'<a href="#" onclick="if ( confirm( \'Do you want to delete the kart\' ) ) {deleteKarts('+data+')}" class="btn btn-danger btn-circle">' +
'<i class="fas fa-trash"></i>' +
'</a>';
}
},
{
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);
},
});
}

1
js/var_conf.js Normal file
View File

@ -0,0 +1 @@
var api_url = 'http://timelaps.local:8000/api/v1/';