Fix CRUD on drivers
This commit is contained in:
245
js/timelaps.js
245
js/timelaps.js
@ -22,82 +22,6 @@ function getKartsMenu() {
|
||||
});
|
||||
}
|
||||
|
||||
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("" +
|
||||
"<div class=\"card shadow mb-4\">\n" +
|
||||
" <div class=\"card-header py-3\">\n" +
|
||||
" <h6 class=\"m-0 font-weight-bold text-primary\">\n" +
|
||||
" Pilot list - " + value.name + " \n" +
|
||||
" <a href=\"#\" class=\"btn btn-primary btn-circle\" title='Ajouter un piote au karting " + value.name + "'>\n" +
|
||||
" <i class=\"fas fa-plus\"></i>\n" +
|
||||
" </a>\n" +
|
||||
" </h6>\n" +
|
||||
" </div>\n" +
|
||||
" <div class=\"card-body\">\n" +
|
||||
" <div class=\"table-responsive\">\n" +
|
||||
" <table class=\"table table-bordered\" id=\"dataTable_pilots" + value.id + "\" width=\"100%\" cellspacing=\"0\">\n" +
|
||||
" <thead>\n" +
|
||||
" <tr>\n" +
|
||||
" <th></th>\n" +
|
||||
" <th>Order</th>\n" +
|
||||
" <th>Short Name</th>\n" +
|
||||
" <th>First Name</th>\n" +
|
||||
" <th>Last Name</th>\n" +
|
||||
" <th>Ref time (Sec)</th>\n" +
|
||||
" </tr>\n" +
|
||||
" </thead>\n" +
|
||||
" <tbody>\n" +
|
||||
" </tbody>\n" +
|
||||
" </table>\n" +
|
||||
" </div>\n" +
|
||||
" </div>\n" +
|
||||
" </div>" +
|
||||
"");
|
||||
|
||||
$('#dataTable_pilots' + value.id).DataTable({
|
||||
data: value.drivers,
|
||||
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> <a href="#" class="btn btn-danger btn-circle"><i class="fas fa-trash"></i>';
|
||||
}
|
||||
},
|
||||
{
|
||||
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({
|
||||
@ -137,19 +61,18 @@ function editParams(data) {
|
||||
});
|
||||
}
|
||||
|
||||
/***
|
||||
* Get one kart data by Id
|
||||
* @param id
|
||||
*/
|
||||
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);
|
||||
console.log(data);
|
||||
},
|
||||
error: function (xhr) {
|
||||
$.notify("APIs unreachable!", "error");
|
||||
@ -243,7 +166,7 @@ function modalEditKarts(id) {
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
crossDomain: true,
|
||||
url: api_url + 'karts/'+id+'/',
|
||||
url: api_url + 'karts/' + id + '/',
|
||||
dataType: 'json',
|
||||
success: function (data, status) {
|
||||
$('#id').val(data.id);
|
||||
@ -262,7 +185,7 @@ function editKarts(id, data) {
|
||||
$.ajax({
|
||||
type: 'PUT',
|
||||
crossDomain: true,
|
||||
url: api_url + 'karts/'+id+'/',
|
||||
url: api_url + 'karts/' + id + '/',
|
||||
dataType: 'json',
|
||||
data: data,
|
||||
success: function (data, status) {
|
||||
@ -280,6 +203,113 @@ function editKarts(id, data) {
|
||||
});
|
||||
}
|
||||
|
||||
function modalEditDriver(id) {
|
||||
$('#modal_new_driver').modal('show');
|
||||
$('#modal_new_driver').val(kart_id);
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
crossDomain: true,
|
||||
url: api_url + 'drivers/' + id + '/',
|
||||
dataType: 'json',
|
||||
success: function (data, status) {
|
||||
$('#id').val(data.id);
|
||||
$('#short_name').val(data.short_name);
|
||||
$('#first_name').val(data.first_name);
|
||||
$('#last_name').val(data.last_name);
|
||||
$('#order').val(data.order);
|
||||
$('#ref_time').val(data.ref_time);
|
||||
},
|
||||
error: function (xhr) {
|
||||
$.notify("APIs unreachable!", "error");
|
||||
console.log('Request Status: ' + xhr.status + ' Status Text: ' + xhr.statusText + ' ' + xhr.responseText);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function modalAddDriver(kart_id) {
|
||||
$('#modal_new_driver').modal('show');
|
||||
$('#kart_id').val(kart_id);
|
||||
}
|
||||
|
||||
function getDriversByKart() {
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
crossDomain: true,
|
||||
url: api_url + 'karts/',
|
||||
dataType: 'json',
|
||||
success: function (data, status) {
|
||||
$.each(data, function (index, value) {
|
||||
if ($.fn.DataTable.isDataTable("#dataTable_drivers" + value.id)) {
|
||||
$('#dataTable_drivers' + value.id).DataTable().destroy();
|
||||
} else {
|
||||
$('.container-fluid').append("" +
|
||||
"<div class=\"card shadow mb-4\">\n" +
|
||||
" <div class=\"card-header py-3\">\n" +
|
||||
" <h6 class=\"m-0 font-weight-bold text-primary\">\n" +
|
||||
" " + value.name + " \n" +
|
||||
" <a href=\"#\" onclick='modalAddDriver(" + value.id + ")' class=\"btn btn-primary btn-circle\" title='Add driver to " + value.name + "'>\n" +
|
||||
" <i class=\"fas fa-plus\"></i>\n" +
|
||||
" </a>\n" +
|
||||
" </h6>\n" +
|
||||
" </div>\n" +
|
||||
" <div class=\"card-body\">\n" +
|
||||
" <div class=\"table-responsive\">\n" +
|
||||
" <table class=\"table table-bordered\" id=\"dataTable_drivers" + value.id + "\" width=\"100%\" cellspacing=\"0\">\n" +
|
||||
" <thead>\n" +
|
||||
" <tr>\n" +
|
||||
" <th></th>\n" +
|
||||
" <th>Order</th>\n" +
|
||||
" <th>Short Name</th>\n" +
|
||||
" <th>First Name</th>\n" +
|
||||
" <th>Last Name</th>\n" +
|
||||
" <th>Ref time (Sec)</th>\n" +
|
||||
" </tr>\n" +
|
||||
" </thead>\n" +
|
||||
" <tbody>\n" +
|
||||
" </tbody>\n" +
|
||||
" </table>\n" +
|
||||
" </div>\n" +
|
||||
" </div>\n" +
|
||||
" </div>" +
|
||||
"");
|
||||
}
|
||||
|
||||
$('#dataTable_drivers' + value.id).DataTable({
|
||||
data: value.drivers,
|
||||
columns: [
|
||||
{
|
||||
data: "id",
|
||||
render: function (data, type, row, meta) {
|
||||
return '<a href="#" onclick=\'modalEditDriver(' + data + ')\' class="btn btn-primary btn-circle"><i class="fas fa-edit"></i></a> <a href="#" onclick=\'deleteDriver(' + data + ','+value.id + ',' + meta.row + ')\' class="btn btn-danger btn-circle"><i class="fas fa-trash"></i>';
|
||||
}
|
||||
},
|
||||
{
|
||||
data: "order"
|
||||
},
|
||||
{
|
||||
data: "short_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 getDriver(id) {
|
||||
|
||||
$.ajax({
|
||||
@ -301,16 +331,57 @@ function getDriver(id) {
|
||||
});
|
||||
}
|
||||
|
||||
function editDriver(data) {
|
||||
function addDriver(data) {
|
||||
$.ajax({
|
||||
type: 'POST',
|
||||
crossDomain: true,
|
||||
url: api_url + 'drivers/',
|
||||
dataType: 'json',
|
||||
data: data,
|
||||
success: function (data, status) {
|
||||
$.notify("Insert done!", "success");
|
||||
getDriversByKart();
|
||||
$("#saveDriverChanges").prop('disabled', false);
|
||||
$('#modal_new_driver').modal('hide');
|
||||
},
|
||||
error: function (xhr) {
|
||||
$.notify("APIs unreachable!", "error");
|
||||
console.log('Request Status: ' + xhr.status + ' Status Text: ' + xhr.statusText + ' ' + xhr.responseText);
|
||||
$("#saveDriverChanges").prop('disabled', false);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function editDriver(id, data) {
|
||||
$.ajax({
|
||||
type: 'PUT',
|
||||
crossDomain: true,
|
||||
url: api_url + 'drivers/1/',
|
||||
url: api_url + 'drivers/' + id + '/',
|
||||
dataType: 'json',
|
||||
data: data,
|
||||
success: function (data, status) {
|
||||
$.notify("Update done!", "success");
|
||||
getPilotsByKart();
|
||||
getDriversByKart();
|
||||
$("#saveDriverChanges").prop('disabled', false);
|
||||
$('#modal_new_driver').modal('hide');
|
||||
},
|
||||
error: function (xhr) {
|
||||
$.notify("APIs unreachable!", "error");
|
||||
console.log('Request Status: ' + xhr.status + ' Status Text: ' + xhr.statusText + ' ' + xhr.responseText);
|
||||
$("#saveDriverChanges").prop('disabled', false);
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
function deleteDriver(id, kart_id, row_index) {
|
||||
$.ajax({
|
||||
type: 'DELETE',
|
||||
crossDomain: true,
|
||||
url: api_url + 'drivers/' + id + '/',
|
||||
dataType: 'json',
|
||||
success: function (data, status) {
|
||||
$.notify("Delete done!", "success");
|
||||
$('#dataTable_drivers' + kart_id).DataTable().row(row_index).remove().draw();
|
||||
},
|
||||
error: function (xhr) {
|
||||
$.notify("APIs unreachable!", "error");
|
||||
|
Reference in New Issue
Block a user