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