Fix CRUD on karts
This commit is contained in:
parent
e04074843a
commit
ee2bd88f93
@ -174,7 +174,7 @@ function listKarts() {
|
||||
{
|
||||
data: "id",
|
||||
render: function (data, type, row, meta) {
|
||||
return '<a href="#" onclick="" class="btn btn-primary btn-circle">' +
|
||||
return '<a href="#" onclick="modalEditKarts(' + data + ')" class="btn btn-primary btn-circle">' +
|
||||
'<i class="fas fa-edit"></i>' +
|
||||
'</a>' +
|
||||
' ' +
|
||||
@ -227,6 +227,7 @@ function addKarts(data) {
|
||||
$.notify("Update done!", "success");
|
||||
$('#modal_newkart').modal('hide');
|
||||
$("#saveKartChanges").prop('disabled', false);
|
||||
$("#saveKartChanges").closest('form').find("input, textarea").val("");
|
||||
listKarts()
|
||||
},
|
||||
error: function (xhr) {
|
||||
@ -237,16 +238,18 @@ function addKarts(data) {
|
||||
});
|
||||
}
|
||||
|
||||
function editKarts(data) {
|
||||
function modalEditKarts(id) {
|
||||
$('#modal_newkart').modal('show');
|
||||
$.ajax({
|
||||
type: 'PUT',
|
||||
type: 'GET',
|
||||
crossDomain: true,
|
||||
url: api_url + 'karts/1/',
|
||||
url: api_url + 'karts/'+id+'/',
|
||||
dataType: 'json',
|
||||
data: data,
|
||||
success: function (data, status) {
|
||||
$.notify("Update done!", "success");
|
||||
showKarts();
|
||||
$('#id').val(data.id);
|
||||
$('#name').val(data.name);
|
||||
$('#autonomy').val(data.autonomy);
|
||||
$('#comment').val(data.comment);
|
||||
},
|
||||
error: function (xhr) {
|
||||
$.notify("APIs unreachable!", "error");
|
||||
@ -255,6 +258,28 @@ function editKarts(data) {
|
||||
});
|
||||
}
|
||||
|
||||
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 getDriver(id) {
|
||||
|
||||
$.ajax({
|
||||
|
@ -307,9 +307,17 @@
|
||||
$("#kartForm").submit(function (event) {
|
||||
$("#saveKartChanges").prop('disabled', true);
|
||||
event.preventDefault();
|
||||
if($('#id').val() == ""){
|
||||
addKarts($( this ).serialize())
|
||||
}else{
|
||||
editKarts($('#id').val(), $( this ).serialize())
|
||||
}
|
||||
});
|
||||
|
||||
$('#modal_newkart').on('hide.bs.modal', function () {
|
||||
$("#saveKartChanges").closest('form').find("input, textarea").val("");
|
||||
})
|
||||
|
||||
});
|
||||
|
||||
</script>
|
||||
|
Loading…
x
Reference in New Issue
Block a user