delete function
This commit is contained in:
parent
6cef184f2b
commit
04c0d69cb3
@ -79,6 +79,7 @@ async function generateUser() {
|
||||
}
|
||||
}
|
||||
|
||||
//get shoppinglist content
|
||||
async function displayShoppinglist(sl_id) {
|
||||
try {
|
||||
let groups = await query('SELECT row_to_json("Group") AS obj FROM "Group" JOIN "Shoppinglist" USING (sl_id) WHERE sl_id = $1;', [sl_id]);
|
||||
@ -93,6 +94,21 @@ async function displayShoppinglist(sl_id) {
|
||||
}
|
||||
}
|
||||
|
||||
//delete shoppinglist
|
||||
|
||||
async function deleteShoppinglist(sl_id) {
|
||||
|
||||
try {
|
||||
await nonQuery('DELETE FROM "Shoppinglist_admin" WHERE sl_id = $1', [sl_id]);
|
||||
await nonQuery('DELETE FROM "Shoppinglist_member" WHERE sl_id = $1', [sl_id]);
|
||||
await nonQuery('DELETE FROM "Shoppinglist" WHERE sl_id = $1', [sl_id]);
|
||||
}
|
||||
|
||||
catch (error) {
|
||||
console.error(error);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//sl_id generieren
|
||||
function generate_sl_id() {
|
||||
@ -124,5 +140,5 @@ function items_in_groups(groups, items) {
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
getShoppinglistsAdmin, getShoppinglistsShared, newShoppinglist, displayShoppinglist
|
||||
getShoppinglistsAdmin, getShoppinglistsShared, newShoppinglist, displayShoppinglist, deleteShoppinglist
|
||||
}
|
||||
|
@ -1,27 +1,60 @@
|
||||
$(document).ready(function() {
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: "/myshoppinglists",
|
||||
success(data) {
|
||||
for(let item of data) {
|
||||
$(".tb_myshoppinglists").append("<tr id='" + item.sl_id +"'><td>" + item.name + "</td><td>" + item.description +
|
||||
"</td><td> <a class='btn-floating btn-large waves-effect waves-light red btn_detail'><i class='material-icons'>forward</i></a></td></tr>");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: "/sharedshoppinglists",
|
||||
success(data) {
|
||||
for(let item of data) {
|
||||
$(".tb_sharedshoppinglists").append("<tr id='" + item.sl_id +"'><td>" + item.name + "</td><td>" + item.description +
|
||||
"</td><td> <a class='btn-floating btn-large waves-effect waves-light red btn_detail'><i class='material-icons'>forward</i></a></td></tr>");
|
||||
}
|
||||
}
|
||||
});
|
||||
refresh();
|
||||
|
||||
$(document).on("click", ".btn_detail", function() {
|
||||
window.location.replace("/shoppinglist/" + $(this).closest("tr").attr("id"));
|
||||
});
|
||||
|
||||
$(".btn_add").click(function() {
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
url: "/shoppinglist",
|
||||
data: {
|
||||
name: $(".name").val(),
|
||||
description: $(".description").val()
|
||||
}, success(result) {
|
||||
refresh();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$(document).on("click", ".btn_delete", function() {
|
||||
$.ajax({
|
||||
type: "DELETE",
|
||||
url: "/shoppinglist",
|
||||
data: {
|
||||
sl_id: $(this).closest("tr").attr("id")
|
||||
}, success(result) {
|
||||
refresh();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
function refresh() {
|
||||
|
||||
$("tbody").empty();
|
||||
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: "/myshoppinglists",
|
||||
success(data) {
|
||||
for(let item of data) {
|
||||
$(".tb_myshoppinglists").append("<tr id='" + item.sl_id +"'><td>" + item.name + "</td><td>" + item.description +
|
||||
"</td><td> <a class='btn-floating btn-large waves-effect waves-light red btn_detail'><i class='material-icons'>forward</i></a></td>"
|
||||
+ "<td><a class='btn-floating btn-large waves-effect waves-light red btn_delete'><i class='material-icons'>clear</i></a></td></tr>");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$.ajax({
|
||||
type: "GET",
|
||||
url: "/sharedshoppinglists",
|
||||
success(data) {
|
||||
for(let item of data) {
|
||||
$(".tb_sharedshoppinglists").append("<tr id='" + item.sl_id +"'><td>" + item.name + "</td><td>" + item.description +
|
||||
"</td><td> <a class='btn-floating btn-large waves-effect waves-light red btn_detail'><i class='material-icons'>forward</i></a></td></tr>");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
@ -110,6 +110,18 @@ router.get("/shoppinglist/:sl_id", async (req, res) => {
|
||||
}
|
||||
});
|
||||
|
||||
//DELETE Shoppinglist
|
||||
|
||||
router.delete("/shoppinglist", async (req, res) => {
|
||||
try {
|
||||
res.status(200).send(await postgres.deleteShoppinglist(req.body.sl_id));
|
||||
}
|
||||
|
||||
catch(err) {
|
||||
res.status(400).send(await err);
|
||||
}
|
||||
});
|
||||
|
||||
router.get("/test1", (req, res) => {
|
||||
res.render("index1");
|
||||
});
|
||||
|
@ -12,7 +12,21 @@
|
||||
<body>
|
||||
|
||||
<div class="container">
|
||||
<p>Logged in as: testuser1</p>
|
||||
<p>Logged in as: testuser1</p>
|
||||
<br><br>
|
||||
<div class="row">
|
||||
<div class="input-field col s6">
|
||||
<input id="name" type="text" class="validate name">
|
||||
<label class="active" for="name">Name</label>
|
||||
</div>
|
||||
<div class="input-field col s6">
|
||||
<input id="description" type="text" class="validate description">
|
||||
<label class="active" for="description">Description</label>
|
||||
</div>
|
||||
<div class="col s6">
|
||||
<a class="waves-effect waves-light btn btn_add">add</a>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col s12 m12 l6">
|
||||
<p>My Shoppinglists</p>
|
||||
@ -21,6 +35,7 @@
|
||||
<th>Name</th>
|
||||
<th>Description</th>
|
||||
<th>Open</th>
|
||||
<th>Delete</th>
|
||||
</thead>
|
||||
<tbody class="tb_myshoppinglists"></tbody>
|
||||
</table>
|
||||
|
Loading…
x
Reference in New Issue
Block a user