From 1669ef4c1ef3cf633a15b3b96e684645b7ba96ef Mon Sep 17 00:00:00 2001 From: s3lph Date: Sun, 8 Dec 2024 00:21:11 +0100 Subject: [PATCH] feat: improve "logout after purchase" ui representation --- matemat/webserver/pagelets/buy.py | 2 -- matemat/webserver/pagelets/deposit.py | 2 -- matemat/webserver/pagelets/main.py | 2 ++ matemat/webserver/pagelets/transfer.py | 2 -- static/js/depositlist.js | 9 ++++----- templates/productlist.html | 27 +++++++------------------- 6 files changed, 13 insertions(+), 31 deletions(-) diff --git a/matemat/webserver/pagelets/buy.py b/matemat/webserver/pagelets/buy.py index 2257cb2..5ce27ba 100644 --- a/matemat/webserver/pagelets/buy.py +++ b/matemat/webserver/pagelets/buy.py @@ -24,8 +24,6 @@ def buy(): # Fetch the authenticated user from the database uid: int = session.get(session_id, 'authenticated_user') user = db.get_user(uid) - if 'logout_after_purchase' in request.params: - db.change_user(user, agent=user, logout_after_purchase=request.params.logout_after_purchase != '0') # Read the product from the database, identified by the product ID passed as request argument if 'pid' in request.params: pid = int(str(request.params.pid)) diff --git a/matemat/webserver/pagelets/deposit.py b/matemat/webserver/pagelets/deposit.py index b608a5e..cd19b26 100644 --- a/matemat/webserver/pagelets/deposit.py +++ b/matemat/webserver/pagelets/deposit.py @@ -23,8 +23,6 @@ def deposit(): # Fetch the authenticated user from the database uid: int = session.get(session_id, 'authenticated_user') user = db.get_user(uid) - if 'logout_after_purchase' in request.params: - db.change_user(user, agent=user, logout_after_purchase=request.params.logout_after_purchase != '0') if 'n' in request.params: # Read the amount of cash to deposit from the request arguments n = int(str(request.params.n)) diff --git a/matemat/webserver/pagelets/main.py b/matemat/webserver/pagelets/main.py index a756d87..58da2b6 100644 --- a/matemat/webserver/pagelets/main.py +++ b/matemat/webserver/pagelets/main.py @@ -55,6 +55,8 @@ def main_page(): # Fetch the user object from the database (for name display, price calculation and admin check) users = db.list_users() user = db.get_user(uid) + if 'logout_after_purchase' in request.params: + db.change_user(user, agent=user, logout_after_purchase=request.params.logout_after_purchase != '0') # Prepare a response with a jinja2 template return template.render('productlist.html', authuser=user, users=users, products=products, authlevel=authlevel, diff --git a/matemat/webserver/pagelets/transfer.py b/matemat/webserver/pagelets/transfer.py index d522560..a0d0695 100644 --- a/matemat/webserver/pagelets/transfer.py +++ b/matemat/webserver/pagelets/transfer.py @@ -21,8 +21,6 @@ def transfer(): # Fetch the authenticated user from the database uid: int = session.get(session_id, 'authenticated_user') user = db.get_user(uid) - if 'logout_after_purchase' in request.params: - db.change_user(user, agent=user, logout_after_purchase=request.params.logout_after_purchase != '0') if 'target' not in request.params or 'n' not in request.params: redirect('/') return diff --git a/static/js/depositlist.js b/static/js/depositlist.js index 4044457..6e463dc 100644 --- a/static/js/depositlist.js +++ b/static/js/depositlist.js @@ -10,8 +10,6 @@ const Mode = { Transfer: 2, } -var append_query_string = ''; - let mode = Mode.Deposit; let product_id = null; let target_user = null; @@ -129,9 +127,10 @@ deposit_key = (k) => { } }; -let list = document.getElementById("depositlist"); -for (let i = 0; i < list.children.length; ++i) { - list.removeChild(list.children[0]); +let oldbuttons = document.getElementsByClassName("deposit-to-remove"); +while (oldbuttons.length > 0) { + oldbuttons[0].remove(); } +let list = document.getElementById("depositlist"); list.insertBefore(button_transfer, list.children[0]); list.insertBefore(button, list.children[0]); diff --git a/templates/productlist.html b/templates/productlist.html index 075d950..b751697 100644 --- a/templates/productlist.html +++ b/templates/productlist.html @@ -9,11 +9,13 @@ Your balance: {{ authuser.balance|chf }}

- Deposit CHF 1 - Deposit CHF 10 -
- - + Deposit CHF 1 + Deposit CHF 10 + {% if authuser.logout_after_purchase %} + Logout after purchase + {% else %} + Logout after purchase + {% endif %}
@@ -76,21 +78,6 @@ {% endfor %}
- - {{ super() }} {% endblock %}