timelapsStorage = localStorage; if (typeof timelapsStorage.current_kart_id === "undefined") { timelapsStorage.setItem('current_kart_id', null); } if (typeof timelapsStorage.params_max_relay_time === "undefined") { timelapsStorage.setItem('params_max_relay_time', null); } if (typeof timelapsStorage.params_min_stand_time === "undefined") { timelapsStorage.setItem('params_min_stand_time', null); } if (typeof timelapsStorage.params_max_fuel_autonomy === "undefined") { timelapsStorage.setItem('params_max_fuel_autonomy', null); } function getKartsMenu() { $.ajax({ type: 'GET', crossDomain: true, url: api_url + 'karts/', dataType: 'json', success: function (data, status) { actual_kart = timelapsStorage.current_kart_id; $.each(data.reverse(), function (index, value) { btn_class = 'btn-light'; if (actual_kart == value.id) { btn_class = 'btn-primary'; } $('#link_all').after("" + " \n \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 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); }, }); } /*** * 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) { console.log(data); }, 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 ($.fn.DataTable.isDataTable("#dataTable_kart_list")) { $('#dataTable_kart_list').DataTable().destroy(); } $('#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); $("#saveKartChanges").closest('form').find("input, textarea").val(""); 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 modalEditKarts(id) { $('#modal_newkart').modal('show'); $.ajax({ type: 'GET', crossDomain: true, url: api_url + 'karts/' + id + '/', dataType: 'json', success: function (data, status) { $('#id').val(data.id); $('#name').val(data.name); $('#autonomy').val(data.autonomy); $('#comment').val(data.comment); }, error: function (xhr) { $.notify("APIs unreachable!", "error"); console.log('Request Status: ' + xhr.status + ' Status Text: ' + xhr.statusText + ' ' + xhr.responseText); }, }); } function editKarts(id, data) { $.ajax({ type: 'PUT', crossDomain: true, url: api_url + 'karts/' + id + '/', dataType: 'json', data: data, success: function (data, status) { $.notify("Update done!", "success"); $('#modal_newkart').modal('hide'); $("#saveKartChanges").prop('disabled', false); $("#saveKartChanges").closest('form').find("input, textarea").val(""); 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 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("" + "
\n" + " | Order | \n" + "Short Name | \n" + "First Name | \n" + "Last Name | \n" + "Ref time (Sec) | \n" + "
---|
Total : 03:39:36
\n" +
" Tps de repos : 14:05:26
\n" +
" \n" +
"