diff --git a/files/assets/js/award_modal.js b/files/assets/js/award_modal.js index dae944c93..79ab1457c 100644 --- a/files/assets/js/award_modal.js +++ b/files/assets/js/award_modal.js @@ -178,3 +178,12 @@ function buy(mb) { xhr.send(form); } + +function giveaward(t) { + post_toast_callback(t.dataset.action, + { + "kind": document.getElementById('kind').value, + "note": document.getElementById('note').value + } + ); +} diff --git a/files/assets/js/bootstrap.js b/files/assets/js/bootstrap.js index e043fc642..f783981f4 100644 --- a/files/assets/js/bootstrap.js +++ b/files/assets/js/bootstrap.js @@ -248,7 +248,8 @@ function post_toast_callback(url, data, callback) { form.append("formkey", formkey()); xhr.onload = function() { - let result = callback(xhr); + let result + if (callback) result = callback(xhr); if (xhr.status >= 200 && xhr.status < 300) { var myToast = bootstrap.Toast.getOrCreateInstance(document.getElementById('toast-post-error')); myToast.hide(); diff --git a/files/routes/awards.py b/files/routes/awards.py index 7f91ceaba..e892c32fa 100644 --- a/files/routes/awards.py +++ b/files/routes/awards.py @@ -117,10 +117,10 @@ def buy(v, award): g.db.add(v) if CARP_ID and v.id != CARP_ID and og_price >= 10000: - send_repeatable_notification(CARP_ID, f"@{v.username} has bought a `{award}` award!") + send_repeatable_notification(CARP_ID, f"@{v.username} has bought a `{AWARDS[award]['title']}` award!") - return {"message": f"{award} award bought!"} + return {"message": f"{AWARDS[award]['title']} award bought!"} @app.post("/award//") @limiter.limit("1/second;30/minute;200/hour;1000/day") @@ -133,7 +133,7 @@ def award_thing(v, thing_type, id): if thing_type == 'post': thing = get_post(id) else: thing = get_comment(id) - if v.shadowbanned: return render_template('errors/500.html', err=True, v=v), 500 + if v.shadowbanned: abort(500) kind = request.values.get("kind", "").strip() @@ -186,10 +186,7 @@ def award_thing(v, thing_type, id): g.db.delete(award) - if request.referrer and len(request.referrer) > 1: - if request.referrer == f'{SITE_FULL}/submit': return redirect(thing.permalink) - elif request.referrer.startswith(f'{SITE_FULL}/'): return redirect(request.referrer) - return redirect(SITE_FULL) + return {"message": f"{AWARDS[kind]['title']} award given to {thing_type} successfully!"} if author.deflector and v.id != AEVANN_ID and (AWARDS[kind]['price'] > 500 or kind == 'marsify' or kind.istitle()) and kind not in ('pin','unpin','benefactor'): msg = f"@{v.username} has tried to give your [{thing_type}]({thing.shortlink}) the {AWARDS[kind]['title']} Award but it was deflected and applied to them :marseytroll:" @@ -431,7 +428,4 @@ def award_thing(v, thing_type, id): else: author.received_award_count = 1 g.db.add(author) - if request.referrer and len(request.referrer) > 1: - if request.referrer == f'{SITE_FULL}/submit': return redirect(thing.permalink) - elif request.referrer.startswith(f'{SITE_FULL}/'): return redirect(request.referrer) - return redirect(SITE_FULL) + return {"message": f"{AWARDS[kind]['title']} award given to {thing_type} successfully!"} diff --git a/files/templates/award_modal.html b/files/templates/award_modal.html index a05e86e58..93f6b9a1a 100644 --- a/files/templates/award_modal.html +++ b/files/templates/award_modal.html @@ -1,3 +1,5 @@ + + @@ -54,5 +54,3 @@ - - diff --git a/files/templates/comments.html b/files/templates/comments.html index 118f6ffb6..1a6c8d46d 100644 --- a/files/templates/comments.html +++ b/files/templates/comments.html @@ -408,7 +408,7 @@ {% if FEATURES['AWARDS'] -%} - + {%- endif %} @@ -623,7 +623,7 @@ Report {% if FEATURES['AWARDS'] -%} - Give Award + Give Award {%- endif %} Save diff --git a/files/templates/post_actions.html b/files/templates/post_actions.html index a81197709..b7d9254d5 100644 --- a/files/templates/post_actions.html +++ b/files/templates/post_actions.html @@ -9,7 +9,7 @@ {% if v and ((not p.ghost and v.admin_level >= PERMS['VOTES_VISIBLE']) or v.id == AEVANN_ID) %}Votes{% endif %} {% if v and FEATURES['AWARDS'] %} - Give Award + Give Award {% endif %} Copy link diff --git a/files/templates/post_actions_mobile.html b/files/templates/post_actions_mobile.html index 472e02acb..4048c6784 100644 --- a/files/templates/post_actions_mobile.html +++ b/files/templates/post_actions_mobile.html @@ -13,7 +13,7 @@ {% if FEATURES['AWARDS'] -%} - + {%- endif %}