basic track deletion working

ref #11
This commit is contained in:
Philipp Dormann 2021-01-05 18:31:26 +01:00
parent 17e7778d15
commit 35a9aa40cb

View File

@ -23,8 +23,25 @@
renderdatatable();
}, 100);
});
if (trackscache.length > 0) {
table_visible = true;
}
});
window.track__delete_handler = () => {
const trackid = parseInt(window.event.target.getAttribute("data-trackid"));
// const track = trackscache.find((e) => e.id == trackid);
// console.log(track);
// -----
// TODO: modal or double click confirmation?
TrackService.trackControllerRemove(trackid)
.then((resp) => {
const newStoreVal = trackscache.filter((obj) => obj.id !== trackid);
tracksstore.set(newStoreVal);
})
.catch((err) => {
console.log(err);
});
};
function renderdatatable() {
let tabledata = [];
trackscache.forEach((track) => {
@ -34,10 +51,11 @@
track.minimumLapTime || 0,
html(`
<button class="w-full inline-flex justify-center rounded-md border border-transparent shadow-sm px-4 py-2 bg-gray-400 text-base font-medium text-white sm:w-auto sm:text-sm">Edit</button>
<button class="w-full inline-flex justify-center rounded-md border border-transparent shadow-sm px-4 py-2 bg-red-500 text-base font-medium text-white sm:w-auto sm:text-sm">Delete</button>
<button class="w-full inline-flex justify-center rounded-md border border-transparent shadow-sm px-4 py-2 bg-red-500 text-base font-medium text-white sm:w-auto sm:text-sm" data-trackid="${track.id}" onclick="track__delete_handler()">Delete</button>
`),
]);
});
if (trackscache.length > 0) {
if (datatable_inited === false) {
datatable = new Grid({
columns: [
@ -61,6 +79,7 @@
datatable.updateConfig({ data: tabledata }).forceRender();
}
}
}
let table_visible = false;
</script>