From 804b80bbf5371383320b0db8f00ed0976f68307e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mateusz=20Gruszczy=C5=84ski?= Date: Fri, 18 Jul 2025 10:45:51 +0200 Subject: [PATCH] nowa funckcja i male zmiany w js --- app.py | 15 +++++++++++ static/js/confirm_delete.js | 20 +++++++++++++++ static/js/live.js | 13 +++++++++- templates/edit_my_list.html | 49 +++++++++++++++++++++++++++++++++--- templates/user_expenses.html | 2 +- 5 files changed, 94 insertions(+), 5 deletions(-) create mode 100644 static/js/confirm_delete.js diff --git a/app.py b/app.py index 0a338ed..51d8e95 100644 --- a/app.py +++ b/app.py @@ -610,6 +610,21 @@ def edit_my_list(list_id): return render_template("edit_my_list.html", list=l) +@app.route("/delete_user_list/", methods=["POST"]) +@login_required +def delete_user_list(list_id): + l = db.session.get(ShoppingList, list_id) + if l is None or l.owner_id != current_user.id: + abort(403) + delete_receipts_for_list(list_id) + Item.query.filter_by(list_id=list_id).delete() + Expense.query.filter_by(list_id=list_id).delete() + db.session.delete(l) + db.session.commit() + flash("Lista została usunięta", "success") + return redirect(url_for("main_page")) + + @app.route("/toggle_visibility/", methods=["GET", "POST"]) @login_required def toggle_visibility(list_id): diff --git a/static/js/confirm_delete.js b/static/js/confirm_delete.js new file mode 100644 index 0000000..edb0a69 --- /dev/null +++ b/static/js/confirm_delete.js @@ -0,0 +1,20 @@ +document.addEventListener("DOMContentLoaded", function () { + const input = document.getElementById('confirm-delete-input'); + const button = document.getElementById('confirm-delete-btn'); + let timer = null; + + input.addEventListener('input', function () { + button.disabled = true; + if (timer) clearTimeout(timer); + + if (input.value.trim().toLowerCase() === 'usuń') { + timer = setTimeout(() => { + button.disabled = false; + }, 2000); + } + }); + + button.addEventListener('click', function () { + document.getElementById('delete-form').submit(); + }); +}); \ No newline at end of file diff --git a/static/js/live.js b/static/js/live.js index 9cc05c3..40be454 100644 --- a/static/js/live.js +++ b/static/js/live.js @@ -155,8 +155,19 @@ function setupList(listId, username) { `; - document.getElementById('items').prepend(li); + // góra listy + //document.getElementById('items').prepend(li); + + // dół listy + document.getElementById('items').appendChild(li); toggleEmptyPlaceholder(); + + setTimeout(() => { + if (window.LIST_ID) { + socket.emit('request_full_list', { list_id: window.LIST_ID }); + } + }, 15000); + }); socket.on('item_deleted', data => { diff --git a/templates/edit_my_list.html b/templates/edit_my_list.html index 62892b3..1adf2b9 100644 --- a/templates/edit_my_list.html +++ b/templates/edit_my_list.html @@ -1,7 +1,8 @@ {% extends 'base.html' %} -{% block content %} +{% block content %}

Edytuj listę: {{ list.title }}

+
@@ -40,9 +41,51 @@
- - Anuluj +
+ + Anuluj +
+
+
+ +
+ +
+ + + +
+ + + +
+{% endblock %} + +{% block scripts %} + {% endblock %} \ No newline at end of file diff --git a/templates/user_expenses.html b/templates/user_expenses.html index d3ebb1a..ad103fe 100644 --- a/templates/user_expenses.html +++ b/templates/user_expenses.html @@ -3,7 +3,7 @@ {% block content %}
-

📊 Statystyki wydatków

+

Statystyki wydatków

← Powrót