forked from MarseyWorld/MarseyWorld
make giving awards not refresh the page
parent
a2600767d1
commit
2d2a35d7ca
|
@ -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
|
||||
}
|
||||
);
|
||||
}
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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/<thing_type>/<id>")
|
||||
@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!"}
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
<script defer src="{{'js/award_modal.js' | asset}}"></script>
|
||||
|
||||
<div class="modal fade" id="awardModal" tabindex="-1" role="dialog" aria-labelledby="awardModalTitle" aria-hidden="true">
|
||||
<div class="modal-dialog modal-dialog-scrollable modal-dialog-centered awardmodal pt-5" role="document">
|
||||
<div class="modal-content">
|
||||
|
@ -8,37 +10,35 @@
|
|||
</button>
|
||||
</div>
|
||||
<div id="awardModalBody" class="modal-body mb-3">
|
||||
<form id="awardTarget" class="pt-3 pb-0" method="post">
|
||||
<input type="hidden" name="formkey", value="{{v.formkey}}">
|
||||
<div class="card-columns award-columns awards-wrapper">
|
||||
{% for award in v.user_awards %}
|
||||
<a data-bs-toggle="tooltip" data-bs-placement="bottom" title="{{award.description}}" role="button" id="{{award.kind}}" class="card" onclick="pick('{{award.kind}}', {{award.price}}*{{v.discount}} <= {{v.procoins}}, {{award.price}}*{{v.discount}} <= {{v.coins}})">
|
||||
<i class="{{award.icon}} {{award.color}}"></i>
|
||||
<div class="pt-2" style="font-weight: bold; font-size: 14px; color:#E1E1E1">{{award.title}}</div>
|
||||
<div class="text-muted"><span id="{{award.kind}}-owned">{{award.owned}}</span> owned</div>
|
||||
</a>
|
||||
{% endfor %}
|
||||
{% if v.user_awards|length % 2 %}
|
||||
<a class="card disabled d-md-none" style="border:none">
|
||||
<i class="fas fa-volume-mute" style="opacity:0"></i>
|
||||
<div class="pt-2" style="font-weight: bold; font-size: 14px; color:#E1E1E1"> </div>
|
||||
<div class="text-muted"> </div>
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
<label id="notelabel" for="note" class="pt-4">Note (optional):</label>
|
||||
<input autocomplete="off" id="kind" name="kind" value="" hidden>
|
||||
<textarea autocomplete="off" id="note" maxlength="200" name="note" class="form-control" placeholder="Note to include in award notification..."></textarea>
|
||||
<input autocomplete="off" id="giveaward" class="awardbtn btn btn-primary mt-3" style="float:right" type="submit" onclick="disable(this)" value="Give Award" disabled>
|
||||
<div class="card-columns award-columns awards-wrapper">
|
||||
{% for award in v.user_awards %}
|
||||
<a data-bs-toggle="tooltip" data-bs-placement="bottom" title="{{award.description}}" role="button" id="{{award.kind}}" class="card" onclick="pick('{{award.kind}}', {{award.price}}*{{v.discount}} <= {{v.procoins}}, {{award.price}}*{{v.discount}} <= {{v.coins}})">
|
||||
<i class="{{award.icon}} {{award.color}}"></i>
|
||||
<div class="pt-2" style="font-weight: bold; font-size: 14px; color:#E1E1E1">{{award.title}}</div>
|
||||
<div class="text-muted"><span id="{{award.kind}}-owned">{{award.owned}}</span> owned</div>
|
||||
</a>
|
||||
{% endfor %}
|
||||
{% if v.user_awards|length % 2 %}
|
||||
<a class="card disabled d-md-none" style="border:none">
|
||||
<i class="fas fa-volume-mute" style="opacity:0"></i>
|
||||
<div class="pt-2" style="font-weight: bold; font-size: 14px; color:#E1E1E1"> </div>
|
||||
<div class="text-muted"> </div>
|
||||
</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
<label id="notelabel" for="note" class="pt-4">Note (optional):</label>
|
||||
<input autocomplete="off" id="kind" value="" hidden>
|
||||
<textarea autocomplete="off" id="note" maxlength="200" class="form-control" placeholder="Note to include in award notification..."></textarea>
|
||||
|
||||
<button id="buy1" class="awardbtn btn btn-primary mt-3 mx-3 {% if SITE_NAME == 'WPD' %}d-none{% endif %}" type="button" disabled style="float:right" onclick="this.classList.add('d-none');document.getElementById('buy1-go').classList.remove('d-none')">Buy with marseybux</button>
|
||||
<button id="buy1-go" class="awardbtn btn btn-primary mt-3 mx-3 d-none" type="button" disabled style="float:right" onclick="buy(true)">Are you sure?</button>
|
||||
<input autocomplete="off" id="giveaward" class="awardbtn btn btn-primary mt-3" style="float:right" type="submit" onclick="giveaward(this)" value="Give Award" data-bs-dismiss="modal" disabled>
|
||||
|
||||
<button id="buy2" class="awardbtn btn btn-primary mt-3" type="button" disabled style="float:right" onclick="this.classList.add('d-none');document.getElementById('buy2-go').classList.remove('d-none')">Buy</button>
|
||||
<button id="buy2-go" class="awardbtn btn btn-primary mt-3 d-none" type="button" disabled style="float:right" onclick="buy()">Are you sure?</button>
|
||||
<pre>
|
||||
</pre>
|
||||
</form>
|
||||
<button id="buy1" class="awardbtn btn btn-primary mt-3 mx-3 {% if SITE_NAME == 'WPD' %}d-none{% endif %}" type="button" disabled style="float:right" onclick="this.classList.add('d-none');document.getElementById('buy1-go').classList.remove('d-none')">Buy with marseybux</button>
|
||||
<button id="buy1-go" class="awardbtn btn btn-primary mt-3 mx-3 d-none" type="button" disabled style="float:right" onclick="buy(true)">Are you sure?</button>
|
||||
|
||||
<button id="buy2" class="awardbtn btn btn-primary mt-3" type="button" disabled style="float:right" onclick="this.classList.add('d-none');document.getElementById('buy2-go').classList.remove('d-none')">Buy</button>
|
||||
<button id="buy2-go" class="awardbtn btn btn-primary mt-3 d-none" type="button" disabled style="float:right" onclick="buy()">Are you sure?</button>
|
||||
<pre>
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -54,5 +54,3 @@
|
|||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script defer src="{{'js/award_modal.js' | asset}}"></script>
|
||||
|
|
|
@ -408,7 +408,7 @@
|
|||
<button class="btn caction py-0 nobackground px-1 text-muted" data-bs-toggle="modal" data-bs-target="#reportCommentModal" onclick="report_commentModal('{{c.id}}','{{c.author_name}}',)"><i class="fas fa-flag fa-fw"></i>Report</button>
|
||||
|
||||
{% if FEATURES['AWARDS'] -%}
|
||||
<button class="btn caction py-0 nobackground px-1 text-muted" role="button" data-bs-toggle="modal" data-bs-target="#awardModal" data-url="/award/comment/{{c.id}}" onclick="document.getElementById('awardTarget').action = this.dataset.url"><i class="fas fa-gift" aria-hidden="true"></i>Give Award</button>
|
||||
<button class="btn caction py-0 nobackground px-1 text-muted" role="button" data-bs-toggle="modal" data-bs-target="#awardModal" data-url="/award/comment/{{c.id}}" onclick="document.getElementById('giveaward').dataset.action = this.dataset.url"><i class="fas fa-gift" aria-hidden="true"></i>Give Award</button>
|
||||
{%- endif %}
|
||||
|
||||
<button id="unsave-{{c.id}}" class="btn caction py-0 nobackground px-1 {% if c.id in v.saved_comment_idlist %}d-md-inline-block{% endif %} text-muted d-none" role="button" onclick="post_toast(this,'/unsave_comment/{{c.id}}','save-{{c.id}}','unsave-{{c.id}}','d-md-inline-block')"><i class="fas fa-save"></i>Unsave</button>
|
||||
|
@ -623,7 +623,7 @@
|
|||
<a role="button" data-bs-toggle="modal" data-bs-dismiss="modal" data-bs-target="#reportCommentModal" onclick="report_commentModal('{{c.id}}','{{c.author_name}}')" class="list-group-item"><i class="fas fa-flag mr-2"></i>Report</a>
|
||||
|
||||
{% if FEATURES['AWARDS'] -%}
|
||||
<a class="list-group-item" role="button" data-bs-toggle="modal" data-bs-target="#awardModal" data-url="/award/comment/{{c.id}}" onclick="document.getElementById('awardTarget').action = this.dataset.url"><i class="fas fa-gift mr-2" aria-hidden="true"></i>Give Award</a>
|
||||
<a class="list-group-item" role="button" data-bs-toggle="modal" data-bs-target="#awardModal" data-url="/award/comment/{{c.id}}" onclick="document.getElementById('giveaward').dataset.action = this.dataset.url"><i class="fas fa-gift mr-2" aria-hidden="true"></i>Give Award</a>
|
||||
{%- endif %}
|
||||
|
||||
<a id="save2-{{c.id}}" class="list-group-item {% if c.id in v.saved_comment_idlist %}d-none{% endif %}" role="button" data-bs-dismiss="modal" onclick="post_toast(this,'/save_comment/{{c.id}}','save2-{{c.id}}','unsave2-{{c.id}}','d-none')"><i class="fas fa-save mr-2"></i>Save</a>
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
{% if v and ((not p.ghost and v.admin_level >= PERMS['VOTES_VISIBLE']) or v.id == AEVANN_ID) %}<a class="list-inline-item" href="/votes/{{p.fullname}}"><i class="fas fa-arrows-v"></i>Votes</a>{% endif %}
|
||||
|
||||
{% if v and FEATURES['AWARDS'] %}
|
||||
<a class="list-inline-item text-muted d-none d-md-inline-block" role="button" data-bs-toggle="modal" data-bs-target="#awardModal" data-url='/award/post/{{p.id}}' onclick="document.getElementById('awardTarget').action = this.dataset.url"><i class="fas fa-gift fa-fw"></i>Give Award</a>
|
||||
<a class="list-inline-item text-muted d-none d-md-inline-block" role="button" data-bs-toggle="modal" data-bs-target="#awardModal" data-url='/award/post/{{p.id}}' onclick="document.getElementById('giveaward').dataset.action = this.dataset.url"><i class="fas fa-gift fa-fw"></i>Give Award</a>
|
||||
{% endif %}
|
||||
|
||||
<a class="list-inline-item copy-link" role="button" data-clipboard-text="{% if SITE == 'rdrama.net' %}https://rdrama.org{{p.shortlink}}{% else %}{{p.permalink}}{% endif %}"><i class="fas fa-copy"></i>Copy link</a>
|
||||
|
|
|
@ -13,7 +13,7 @@
|
|||
<button class="nobackground btn btn-link btn-block btn-lg text-left text-muted" data-bs-toggle="modal" data-bs-dismiss="modal" data-bs-target="#reportPostModal" onclick="report_postModal('{{p.id}}')"><i class="far fa-flag text-center text-muted mr-2"></i>Report</button>
|
||||
|
||||
{% if FEATURES['AWARDS'] -%}
|
||||
<button class="nobackground btn btn-link btn-block btn-lg text-left text-muted" data-bs-toggle="modal" data-bs-dismiss="modal" data-bs-target="#awardModal" data-url='/award/post/{{p.id}}' onclick="document.getElementById('awardTarget').action = this.dataset.url"><i class="fas fa-gift text-center text-muted mr-2"></i>Give Award</button>
|
||||
<button class="nobackground btn btn-link btn-block btn-lg text-left text-muted" data-bs-toggle="modal" data-bs-dismiss="modal" data-bs-target="#awardModal" data-url='/award/post/{{p.id}}' onclick="document.getElementById('giveaward').dataset.action = this.dataset.url"><i class="fas fa-gift text-center text-muted mr-2"></i>Give Award</button>
|
||||
{%- endif %}
|
||||
|
||||
<button id="subscribe2-{{p.id}}" class="{% if p.id in v.subscribed_idlist %}d-none{% endif %} nobackground btn btn-link btn-block btn-lg text-left text-muted" role="button" onclick="post_toast(this,'/subscribe/{{p.id}}','subscribe2-{{p.id}}','unsubscribe2-{{p.id}}','d-none')" data-bs-dismiss="modal"><i class="fas fa-eye text-center text-muted mr-2"></i>Subscribe</button>
|
||||
|
|
Loading…
Reference in New Issue