Skip to content
Snippets Groups Projects
Commit 5303f809 authored by b4-sharp's avatar b4-sharp
Browse files

[Frontend] Add item to set

parent 73ae8396
No related branches found
No related tags found
No related merge requests found
......@@ -354,6 +354,7 @@ def database_management():
main_item=item,
is_item=type(item) is Item,
)
return render_template(
"userContent/database_management.html",
access_data_form=access_data_form,
......@@ -361,14 +362,32 @@ def database_management():
)
# @app.route("/add_item", methods=["POST"])
# def add_item():
# if current_user.userType != "admin":
# flash("Unauthorized access")
# return redirect(url_for("home"))
# 25701, 12522
@app.route("/add_item_to_set", methods=["GET", "POST"])
def add_item_to_set():
print("Adding Item", file=sys.stderr)
if current_user.userType != "admin":
flash("Unauthorized access")
return redirect(url_for("home"))
item_id = request.form.get("item_id")
set_id = request.form.get("set_id")
item_set = ItemSet.query.get(set_id)
item = Item.query.get(item_id)
print("Adding Item:", item_id, "To Set:", set_id, file=sys.stderr)
@app.route("/delete_item", methods=["POST"])
if item_set == None or item == None:
abort(406)
if item in item_set.items:
abort(406)
print("Adding Item:", item_id, "To Set:", set_id, file=sys.stderr)
item_set.items.append(item)
db.session.commit()
return "ok"
@app.route("/delete_item", methods=["DELETE"])
def delete_item():
if current_user.userType != "admin":
flash("Unauthorized access")
......@@ -376,6 +395,7 @@ def delete_item():
id = request.form.get("item_id")
item = Item.query.get(id)
if item == None:
print("Could not delete item:", id, file=sys.stderr)
abort(406)
print("Deleting Item:", id, file=sys.stderr)
remove_item(item)
......@@ -403,11 +423,12 @@ def delete_item_from_set():
return redirect(url_for("home"))
item_id = request.form.get("item_id")
set_id = request.form.get("set_id")
item_set = ItemSet.query.get(set_id)
item = Item.query.get(item_id)
if item_set == None or item == None:
abort(406)
print("Deleting Item:", item_id, "From Set:", set_id, file=sys.stderr)
item_set.items.remove(item)
db.session.commit()
......
......@@ -5,7 +5,7 @@
<form method="POST">
{{access_data_form.hidden_tag()}}
<dl>
<table class="loginTable">
<table>
<tr>
<td>{{ render_field(access_data_form.table) }} </td>
</tr>
......@@ -54,17 +54,33 @@
{% endfor %}
</tbody>
</table>
<label for="itemID">Item ID:</label><br>
<input type="number" id="itemID" name="itemID"><br>
<button onclick="addItemToSet({{main_item.id}})">Add</button>
</div>
{% endif %}
</div>
{% endif %}
<script>
function addItemToSet(set_id) {
console.log(set_id);
console.log($('#itemID').val());
$.ajax({
url: '/add_item_to_set',
type: 'POST',
data: { set_id: set_id, item_id: $('#itemID').val() },
success: function () {
window.location.href = window.location.href;
}
});
};
function deleteItem(id) {
if (confirm("Are you sure you want to delete this item? It is irreversible.")) {
$.ajax({
url: '/delete_item',
type: 'POST',
type: 'DELETE',
data: { item_id: id },
success: function () {
window.location.href = window.location.href;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment