delete item interactivity

This commit is contained in:
2024-02-01 23:27:39 +01:00
parent 8761a6c5ad
commit 550848b4ff
3 changed files with 56 additions and 7 deletions

View File

@@ -319,9 +319,7 @@ fetch_history().then(async function(data) {
document.getElementById("addbutton").addEventListener("click", addItem);
async function addItem() {
const apiUrl = `${currentUrl}app/add`;
const postData = {
itemid: document.getElementById("additemid").value,
attributes: document.getElementById("addattributes").value
@@ -344,16 +342,41 @@ async function addItem() {
console.error('Error during POST request:', error);
});
if (response.ok) {
console.log(response);
// reload window to display new item
location.reload();
} else {
throw new Error('Error in server response');
}
}
async function delItem(uuid) {
const apiUrl = `${currentUrl}app/delete`;
const postData = {
uuid: uuid
};
const requestOptions = {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify(postData)
};
const response = await fetch(apiUrl, requestOptions)
.catch(error => {
console.error('Error during POST request:', error);
});
if (response.ok) {
console.log(response);
// reload window to stop displaying deleted item
location.reload();
} else {
throw new Error('Error in server response');
}
}
@@ -363,13 +386,11 @@ document.addEventListener('DOMContentLoaded', function () {
const noBtn = document.getElementById('noBtn');
yesBtn.addEventListener('click', function () {
// Add your function to execute on 'Yes' click
console.log('Yes clicked');
console.log(del_key);
delItem(del_key);
confirmationPopup.style.display = 'none';
});
noBtn.addEventListener('click', function () {
// Add your function to execute on 'No' click
console.log('No clicked');
confirmationPopup.style.display = 'none';
});
});