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);
|
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());
|
form.append("formkey", formkey());
|
||||||
xhr.onload = function() {
|
xhr.onload = function() {
|
||||||
let result = callback(xhr);
|
let result
|
||||||
|
if (callback) result = callback(xhr);
|
||||||
if (xhr.status >= 200 && xhr.status < 300) {
|
if (xhr.status >= 200 && xhr.status < 300) {
|
||||||
var myToast = bootstrap.Toast.getOrCreateInstance(document.getElementById('toast-post-error'));
|
var myToast = bootstrap.Toast.getOrCreateInstance(document.getElementById('toast-post-error'));
|
||||||
myToast.hide();
|
myToast.hide();
|
||||||
|
|
|
@ -117,10 +117,10 @@ def buy(v, award):
|
||||||
g.db.add(v)
|
g.db.add(v)
|
||||||
|
|
||||||
if CARP_ID and v.id != CARP_ID and og_price >= 10000:
|
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>")
|
@app.post("/award/<thing_type>/<id>")
|
||||||
@limiter.limit("1/second;30/minute;200/hour;1000/day")
|
@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)
|
if thing_type == 'post': thing = get_post(id)
|
||||||
else: thing = get_comment(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()
|
kind = request.values.get("kind", "").strip()
|
||||||
|
|
||||||
|
@ -186,10 +186,7 @@ def award_thing(v, thing_type, id):
|
||||||
|
|
||||||
g.db.delete(award)
|
g.db.delete(award)
|
||||||
|
|
||||||
if request.referrer and len(request.referrer) > 1:
|
return {"message": f"{AWARDS[kind]['title']} award given to {thing_type} successfully!"}
|
||||||
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)
|
|
||||||
|
|
||||||
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'):
|
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:"
|
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
|
else: author.received_award_count = 1
|
||||||
g.db.add(author)
|
g.db.add(author)
|
||||||
|
|
||||||
if request.referrer and len(request.referrer) > 1:
|
return {"message": f"{AWARDS[kind]['title']} award given to {thing_type} successfully!"}
|
||||||
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)
|
|
||||||
|
|
|
@ -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 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-dialog modal-dialog-scrollable modal-dialog-centered awardmodal pt-5" role="document">
|
||||||
<div class="modal-content">
|
<div class="modal-content">
|
||||||
|
@ -8,37 +10,35 @@
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div id="awardModalBody" class="modal-body mb-3">
|
<div id="awardModalBody" class="modal-body mb-3">
|
||||||
<form id="awardTarget" class="pt-3 pb-0" method="post">
|
<div class="card-columns award-columns awards-wrapper">
|
||||||
<input type="hidden" name="formkey", value="{{v.formkey}}">
|
{% for award in v.user_awards %}
|
||||||
<div class="card-columns award-columns awards-wrapper">
|
<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}})">
|
||||||
{% for award in v.user_awards %}
|
<i class="{{award.icon}} {{award.color}}"></i>
|
||||||
<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}})">
|
<div class="pt-2" style="font-weight: bold; font-size: 14px; color:#E1E1E1">{{award.title}}</div>
|
||||||
<i class="{{award.icon}} {{award.color}}"></i>
|
<div class="text-muted"><span id="{{award.kind}}-owned">{{award.owned}}</span> owned</div>
|
||||||
<div class="pt-2" style="font-weight: bold; font-size: 14px; color:#E1E1E1">{{award.title}}</div>
|
</a>
|
||||||
<div class="text-muted"><span id="{{award.kind}}-owned">{{award.owned}}</span> owned</div>
|
{% endfor %}
|
||||||
</a>
|
{% if v.user_awards|length % 2 %}
|
||||||
{% endfor %}
|
<a class="card disabled d-md-none" style="border:none">
|
||||||
{% if v.user_awards|length % 2 %}
|
<i class="fas fa-volume-mute" style="opacity:0"></i>
|
||||||
<a class="card disabled d-md-none" style="border:none">
|
<div class="pt-2" style="font-weight: bold; font-size: 14px; color:#E1E1E1"> </div>
|
||||||
<i class="fas fa-volume-mute" style="opacity:0"></i>
|
<div class="text-muted"> </div>
|
||||||
<div class="pt-2" style="font-weight: bold; font-size: 14px; color:#E1E1E1"> </div>
|
</a>
|
||||||
<div class="text-muted"> </div>
|
{% endif %}
|
||||||
</a>
|
</div>
|
||||||
{% endif %}
|
<label id="notelabel" for="note" class="pt-4">Note (optional):</label>
|
||||||
</div>
|
<input autocomplete="off" id="kind" value="" hidden>
|
||||||
<label id="notelabel" for="note" class="pt-4">Note (optional):</label>
|
<textarea autocomplete="off" id="note" maxlength="200" class="form-control" placeholder="Note to include in award notification..."></textarea>
|
||||||
<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>
|
|
||||||
|
|
||||||
<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>
|
<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="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="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="buy2-go" class="awardbtn btn btn-primary mt-3 d-none" type="button" disabled style="float:right" onclick="buy()">Are you sure?</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>
|
||||||
<pre>
|
|
||||||
</pre>
|
<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>
|
||||||
</form>
|
<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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@ -54,5 +54,3 @@
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</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>
|
<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'] -%}
|
{% 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 %}
|
{%- 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>
|
<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>
|
<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'] -%}
|
{% 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 %}
|
{%- 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>
|
<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 ((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'] %}
|
{% 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 %}
|
{% 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>
|
<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>
|
<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'] -%}
|
{% 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 %}
|
{%- 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>
|
<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