1
0
Fork 0
forked from s3lph/matemat

feat: improve "logout after purchase" ui representation

This commit is contained in:
s3lph 2024-12-08 00:21:11 +01:00
parent ddf5ed01a2
commit 1669ef4c1e
Signed by untrusted user: s3lph
GPG key ID: 0AA29A52FB33CFB5
6 changed files with 13 additions and 31 deletions

View file

@ -24,8 +24,6 @@ def buy():
# Fetch the authenticated user from the database # Fetch the authenticated user from the database
uid: int = session.get(session_id, 'authenticated_user') uid: int = session.get(session_id, 'authenticated_user')
user = db.get_user(uid) 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 # Read the product from the database, identified by the product ID passed as request argument
if 'pid' in request.params: if 'pid' in request.params:
pid = int(str(request.params.pid)) pid = int(str(request.params.pid))

View file

@ -23,8 +23,6 @@ def deposit():
# Fetch the authenticated user from the database # Fetch the authenticated user from the database
uid: int = session.get(session_id, 'authenticated_user') uid: int = session.get(session_id, 'authenticated_user')
user = db.get_user(uid) 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: if 'n' in request.params:
# Read the amount of cash to deposit from the request arguments # Read the amount of cash to deposit from the request arguments
n = int(str(request.params.n)) n = int(str(request.params.n))

View file

@ -55,6 +55,8 @@ def main_page():
# Fetch the user object from the database (for name display, price calculation and admin check) # Fetch the user object from the database (for name display, price calculation and admin check)
users = db.list_users() users = db.list_users()
user = db.get_user(uid) 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 # Prepare a response with a jinja2 template
return template.render('productlist.html', return template.render('productlist.html',
authuser=user, users=users, products=products, authlevel=authlevel, authuser=user, users=users, products=products, authlevel=authlevel,

View file

@ -21,8 +21,6 @@ def transfer():
# Fetch the authenticated user from the database # Fetch the authenticated user from the database
uid: int = session.get(session_id, 'authenticated_user') uid: int = session.get(session_id, 'authenticated_user')
user = db.get_user(uid) 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: if 'target' not in request.params or 'n' not in request.params:
redirect('/') redirect('/')
return return

View file

@ -10,8 +10,6 @@ const Mode = {
Transfer: 2, Transfer: 2,
} }
var append_query_string = '';
let mode = Mode.Deposit; let mode = Mode.Deposit;
let product_id = null; let product_id = null;
let target_user = null; let target_user = null;
@ -129,9 +127,10 @@ deposit_key = (k) => {
} }
}; };
let list = document.getElementById("depositlist"); let oldbuttons = document.getElementsByClassName("deposit-to-remove");
for (let i = 0; i < list.children.length; ++i) { while (oldbuttons.length > 0) {
list.removeChild(list.children[0]); oldbuttons[0].remove();
} }
let list = document.getElementById("depositlist");
list.insertBefore(button_transfer, list.children[0]); list.insertBefore(button_transfer, list.children[0]);
list.insertBefore(button, list.children[0]); list.insertBefore(button, list.children[0]);

View file

@ -9,11 +9,13 @@
Your balance: <strong>{{ authuser.balance|chf }}</strong> Your balance: <strong>{{ authuser.balance|chf }}</strong>
</p> </p>
<div id="depositlist"> <div id="depositlist">
<a class="btn btn-primary me-2" href="/deposit?n=100">Deposit CHF 1</a> <a class="deposit-to-remove btn btn-primary me-2" href="/deposit?n=100">Deposit CHF 1</a>
<a class="btn btn-primary me-2" href="/deposit?n=1000">Deposit CHF 10</a> <a class="deposit-to-remove btn btn-primary me-2" href="/deposit?n=1000">Deposit CHF 10</a>
<div class="form-check"> {% if authuser.logout_after_purchase %}
<input class="form-check-input" id="productlist-logout-after-purchase" type="checkbox"{% if authuser.logout_after_purchase %} checked="checked"{% endif %}> <a class="btn btn-primary me-2" href="/?logout_after_purchase=0">Logout after purchase</a>
<label class="form-check-label" for="productlist-logout-after-purchase">Logout after purchase</label> {% else %}
<a class="btn btn-outline-primary me-2" href="/?logout_after_purchase=1">Logout after purchase</a>
{% endif %}
</div> </div>
</div> </div>
<div id="deposit-wrapper"> <div id="deposit-wrapper">
@ -76,21 +78,6 @@
{% endfor %} {% endfor %}
</div> </div>
<script>
document.getElementById("productlist-logout-after-purchase").onchange = (e) => {
var append_query_string = "&logout_after_purchase=" + (e.target.checked ? "1" : "0");
[].forEach.call(document.getElementsByClassName("card"), (a) => {
console.log(a.href);
if (a.href) {
let url = new URL(a.href);
url.searchParams.delete("logout_after_purchase");
url.searchParams.append("logout_after_purchase", e.target.checked ? "1" : "0");
a.href = url.href;
}
});
};
</script>
{{ super() }} {{ super() }}
{% endblock %} {% endblock %}