rework "are you sure?" and make it work on subscribing to posts and reverting admin actions

remotes/1693176582716663532/tmp_refs/heads/watchparty
Aevann1 2022-10-08 08:06:46 +02:00
parent b515b8bd15
commit acbfbb07ce
11 changed files with 35 additions and 43 deletions

View File

@ -97,30 +97,16 @@ function vote(type, id, dir) {
function pick(kind, canbuy1, canbuy2) { function pick(kind, canbuy1, canbuy2) {
const buy1 = document.getElementById('buy1') const buy1 = document.getElementById('buy1')
const buy1go = document.getElementById('buy1-go')
if (canbuy1 && kind != "grass") if (canbuy1 && kind != "grass")
{
buy1.disabled=false; buy1.disabled=false;
buy1go.disabled=false;
}
else else
{
buy1.disabled=true; buy1.disabled=true;
buy1go.disabled=true;
}
const buy2 = document.getElementById('buy2') const buy2 = document.getElementById('buy2')
const buy2go = document.getElementById('buy2-go')
if (canbuy2 && kind != "benefactor") if (canbuy2 && kind != "benefactor")
{
buy2.disabled=false; buy2.disabled=false;
buy2go.disabled=false;
}
else else
{
buy2.disabled=true; buy2.disabled=true;
buy2go.disabled=true;
}
let ownednum = Number(document.getElementById(`${kind}-owned`).textContent); let ownednum = Number(document.getElementById(`${kind}-owned`).textContent);
document.getElementById('giveaward').disabled = (ownednum == 0); document.getElementById('giveaward').disabled = (ownednum == 0);

View File

@ -338,3 +338,18 @@ function timestamp(str, ti) {
const date = new Date(ti*1000); const date = new Date(ti*1000);
document.getElementById(str).setAttribute("data-bs-original-title", formatDate(date)); document.getElementById(str).setAttribute("data-bs-original-title", formatDate(date));
}; };
function areyousure(t) {
if (t.value) {
t.type = 'submit';
t.value = 'Are you sure?'
}
else
{
t.innerHTML = t.innerHTML.replace(t.textContent, 'Are you sure?')
}
t.setAttribute("onclick", t.dataset.click);
if (t.dataset.dismiss)
t.setAttribute("data-bs-dismiss", t.dataset.dismiss);
}

View File

@ -374,7 +374,7 @@ class Submission(Base):
body += " - <b>WINNER!</b>" body += " - <b>WINNER!</b>"
if not winner and v and v.admin_level >= PERMS['POST_BETS_DISTRIBUTE']: if not winner and v and v.admin_level >= PERMS['POST_BETS_DISTRIBUTE']:
body += f'''<button class="btn btn-primary distribute" onclick="this.nextElementSibling.classList.remove('d-none');this.classList.add('d-none')">Declare winner</button><button class="btn btn-primary distribute d-none" onclick="post_toast(this,'/distribute/{o.id}',true)">Are you sure?</button>''' body += f'''<button class="btn btn-primary distribute" data-click="post_toast(this,'/distribute/{o.id}',true)" onclick="areyousure(this)">Declare winner</button>'''
body += "</div>" body += "</div>"
else: else:
input_type = 'radio' if o.exclusive else 'checkbox' input_type = 'radio' if o.exclusive else 'checkbox'

View File

@ -32,11 +32,9 @@
<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> <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" 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" class="awardbtn btn btn-primary mt-3 mx-3 {% if SITE_NAME == 'WPD' %}d-none{% endif %}" type="button" disabled style="float:right" data-click="buy(true)" onclick="areyousure(this)">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" class="awardbtn btn btn-primary mt-3" type="button" disabled style="float:right" data-click="buy()" onclick="areyousure(this)">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>
</pre> </pre>
</div> </div>

View File

@ -642,9 +642,9 @@
{% endif %} {% endif %}
{% if not c.ghost %} {% if not c.ghost %}
<a id="unblock2-{{c.id}}" data-bs-dismiss="modal" class="text-success list-group-item {% if not c.is_blocking %}d-none{% endif %}" role="button" onclick="post_toast(this,'/settings/unblock?username={{c.author.username}}','block2-{{c.id}}','unblock2-{{c.id}}','d-none')" data-bs-dismiss="modal"><i class="fas fa-eye-slash text-success mr-2"></i>Unblock user</a> <a id="unblock2-{{c.id}}" data-bs-dismiss="modal" class="text-success list-group-item {% if not c.is_blocking %}d-none{% endif %}" role="button" onclick="post_toast(this,'/settings/unblock?username={{c.author.username}}','block2-{{c.id}}','unblock2-{{c.id}}','d-none')"><i class="fas fa-eye-slash text-success mr-2"></i>Unblock user</a>
<a id="prompt2-{{c.id}}" data-bs-dismiss="modal" class="blockuser list-group-item d-none text-danger" role="button" onclick="post_toast(this,'/settings/block?username={{c.author.username}}','prompt2-{{c.id}}','unblock2-{{c.id}}','d-none')"><i class="fas fa-eye-slash fa-fw text-danger mr-2"></i>Are you sure?</a>
<a id="block2-{{c.id}}" class="{% if c.is_blocking %}d-none{% endif %} list-group-item text-danger" role="button" onclick="document.getElementById('block2-{{c.id}}').classList.toggle('d-none');document.getElementById('prompt2-{{c.id}}').classList.toggle('d-none');"><i class="fas fa-eye-slash fa-fw text-danger mr-2"></i>Block user</a> <a id="block2-{{c.id}}" class="{% if c.is_blocking %}d-none{% endif %} list-group-item text-danger" role="button" data-click="post_toast(this,'/settings/block?username={{c.author.username}}','block2-{{c.id}}','unblock2-{{c.id}}','d-none')" onclick="areyousure(this)" data-dismiss="modal"><i class="fas fa-eye-slash fa-fw text-danger mr-2"></i>Block user</a>
{% endif %} {% endif %}
{% endif %} {% endif %}

View File

@ -124,14 +124,10 @@
<td class="shop-table-actions" style="width:unset"> <td class="shop-table-actions" style="width:unset">
{% if hat.id not in owned_hat_ids %} {% if hat.id not in owned_hat_ids %}
<div id="if-not-owned-{{hat.id}}"> <div id="if-not-owned-{{hat.id}}">
<a id="buy1-{{hat.id}}" class="btn btn-success {% if v.coins < hat.price %}disabled{% endif %}" role="button" onclick="this.classList.add('d-none');document.getElementById('buy1-go-{{hat.id}}').classList.remove('d-none')"><span class="m-auto">Buy</span></a> <a id="buy1-{{hat.id}}" class="btn btn-success {% if v.coins < hat.price %}disabled{% endif %}" role="button" data-click="post_toast(this, '/buy_hat/{{hat.id}}', 'if-not-owned-{{hat.id}}', 'if-owned-{{hat.id}}', 'd-none', (xhr)=>{if(xhr.status == 200)document.getElementById('user-coins-amount').innerHTML-={{hat.price}}})" onclick="areyousure(this)"><span class="m-auto">Buy</span></a>
<a id="buy1-go-{{hat.id}}" class="d-none btn btn-success {% if v.coins < hat.price %}disabled{% endif %}" role="button" onclick="post_toast(this, '/buy_hat/{{hat.id}}', 'if-not-owned-{{hat.id}}', 'if-owned-{{hat.id}}', 'd-none', (xhr)=>{if(xhr.status == 200)document.getElementById('user-coins-amount').innerHTML-={{hat.price}}})"><span class="m-auto">Are you sure?</span></a>
{% if FEATURES['PROCOINS'] %} {% if FEATURES['PROCOINS'] %}
<a id="buy2-{{hat.id}}" class="marseybux btn btn-success {% if v.procoins < hat.price %}disabled{% endif %}" role="button" onclick="this.classList.add('d-none');document.getElementById('buy2-go-{{hat.id}}').classList.remove('d-none')"><span class="m-auto">MBux</span></a> <a id="buy2-{{hat.id}}" class="marseybux btn btn-success {% if v.procoins < hat.price %}disabled{% endif %}" role="button" data-click="post_toast(this, '/buy_hat/{{hat.id}}?mb=true', 'if-not-owned-{{hat.id}}', 'if-owned-{{hat.id}}', 'd-none', (xhr)=>{if(xhr.status == 200)document.getElementById('user-bux-amount').innerHTML-={{hat.price}}})" onclick="areyousure(this)"><span class="m-auto">MBux</span></a>
<a id="buy2-go-{{hat.id}}" class="d-none marseybux btn btn-success {% if v.procoins < hat.price %}disabled{% endif %}" role="button" onclick="post_toast(this, '/buy_hat/{{hat.id}}?mb=true', 'if-not-owned-{{hat.id}}', 'if-owned-{{hat.id}}', 'd-none', (xhr)=>{if(xhr.status == 200)document.getElementById('user-bux-amount').innerHTML-={{hat.price}}})"><span class="m-auto">Are you sure?</span></a>
{% endif %} {% endif %}
</div> </div>
{% endif %} {% endif %}

View File

@ -59,8 +59,8 @@
<form action="/live/remove" method="post"> <form action="/live/remove" method="post">
<input type="hidden" name="formkey" value="{{v.formkey}}"> <input type="hidden" name="formkey" value="{{v.formkey}}">
<input type="hidden" name="id" value="{{id}}"> <input type="hidden" name="id" value="{{id}}">
<input autocomplete="off" class="btn btn-primary ml-auto donttrigger" onclick="this.nextElementSibling.classList.remove('d-none');this.classList.add('d-none')" value="Remove" style="width:75px">
<input autocomplete="off" class="btn btn-primary ml-auto d-none donttrigger" type="submit" onclick="disable(this)" value="Are you sure?"> <input autocomplete="off" class="btn btn-primary ml-auto donttrigger" data-click="disable(this)" onclick="areyousure(this)" value="Remove">
</form> </form>
</td> </td>
{% endif %} {% endif %}
@ -85,8 +85,7 @@
<form action="/live/remove" method="post"> <form action="/live/remove" method="post">
<input type="hidden" name="formkey" value="{{v.formkey}}"> <input type="hidden" name="formkey" value="{{v.formkey}}">
<input type="hidden" name="id" value="{{id}}"> <input type="hidden" name="id" value="{{id}}">
<input autocomplete="off" class="btn btn-primary ml-auto donttrigger" onclick="this.nextElementSibling.classList.remove('d-none');this.classList.add('d-none')" value="Remove" style="width:75px"> <input autocomplete="off" class="btn btn-primary ml-auto donttrigger" data-click="disable(this)" onclick="areyousure(this)" value="Remove">
<input autocomplete="off" class="btn btn-primary ml-auto d-none donttrigger" type="submit" onclick="disable(this)" value="Are you sure?">
</form> </form>
</td> </td>
{% endif %} {% endif %}

View File

@ -15,7 +15,7 @@
<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>
{% if v %} {% if v %}
<a id="subscribe-{{p.id}}" class="{% if p.id in v.subscribed_idlist %}d-none{% endif %} list-inline-item" role="button" onclick="post_toast(this,'/subscribe/{{p.id}}','subscribe-{{p.id}}','unsubscribe-{{p.id}}','d-none')"><i class="fas fa-eye"></i>Subscribe</a> <a id="subscribe-{{p.id}}" class="{% if p.id in v.subscribed_idlist %}d-none{% endif %} list-inline-item" role="button" data-click="post_toast(this,'/subscribe/{{p.id}}','subscribe-{{p.id}}','unsubscribe-{{p.id}}','d-none')" onclick="areyousure(this)"><i class="fas fa-eye"></i>Subscribe</a>
<a id="unsubscribe-{{p.id}}" class="{% if p.id not in v.subscribed_idlist %}d-none{% endif %} list-inline-item" role="button" onclick="post_toast(this,'/unsubscribe/{{p.id}}','subscribe-{{p.id}}','unsubscribe-{{p.id}}','d-none')"><i class="fas fa-eye-slash"></i>Unsubscribe</a> <a id="unsubscribe-{{p.id}}" class="{% if p.id not in v.subscribed_idlist %}d-none{% endif %} list-inline-item" role="button" onclick="post_toast(this,'/unsubscribe/{{p.id}}','subscribe-{{p.id}}','unsubscribe-{{p.id}}','d-none')"><i class="fas fa-eye-slash"></i>Unsubscribe</a>
{% endif %} {% endif %}

View File

@ -16,7 +16,8 @@
<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> <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" data-click="post_toast(this,'/subscribe/{{p.id}}','subscribe2-{{p.id}}','unsubscribe2-{{p.id}}','d-none')" onclick="areyousure(this)" data-dismiss="modal"><i class="fas fa-eye text-center text-muted mr-2"></i>Subscribe</button>
<button id="unsubscribe2-{{p.id}}" class="{% if not 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,'/unsubscribe/{{p.id}}','subscribe2-{{p.id}}','unsubscribe2-{{p.id}}','d-none')" data-bs-dismiss="modal"><i class="fas fa-eye-slash text-center text-muted mr-2"></i>Unsubscribe</button> <button id="unsubscribe2-{{p.id}}" class="{% if not 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,'/unsubscribe/{{p.id}}','subscribe2-{{p.id}}','unsubscribe2-{{p.id}}','d-none')" data-bs-dismiss="modal"><i class="fas fa-eye-slash text-center text-muted mr-2"></i>Unsubscribe</button>
<button id="save2-{{p.id}}" class="{% if p.id in v.saved_idlist %}d-none{% endif %} nobackground btn btn-link btn-block btn-lg text-left text-muted" role="button" onclick="post_toast(this,'/save_post/{{p.id}}','save2-{{p.id}}','unsave2-{{p.id}}','d-none')" data-bs-dismiss="modal"><i class="fas fa-save text-center text-muted mr-2"></i>Save</button> <button id="save2-{{p.id}}" class="{% if p.id in v.saved_idlist %}d-none{% endif %} nobackground btn btn-link btn-block btn-lg text-left text-muted" role="button" onclick="post_toast(this,'/save_post/{{p.id}}','save2-{{p.id}}','unsave2-{{p.id}}','d-none')" data-bs-dismiss="modal"><i class="fas fa-save text-center text-muted mr-2"></i>Save</button>
@ -46,8 +47,7 @@
{% else %} {% else %}
{% if not p.ghost %} {% if not p.ghost %}
<button id="unblock2-{{p.id}}" class="nobackground btn btn-link btn-block btn-lg text-success text-left{% if not p.is_blocking %} d-none{% endif %}" data-bs-dismiss="modal" onclick="post_toast(this,'/settings/unblock?username={{p.author.username}}','block2-{{p.id}}','unblock2-{{p.id}}','d-none')"><i class="fas fa-eye mr-2 text-success"></i>Unblock user</button> <button id="unblock2-{{p.id}}" class="nobackground btn btn-link btn-block btn-lg text-success text-left{% if not p.is_blocking %} d-none{% endif %}" data-bs-dismiss="modal" onclick="post_toast(this,'/settings/unblock?username={{p.author.username}}','block2-{{p.id}}','unblock2-{{p.id}}','d-none')"><i class="fas fa-eye mr-2 text-success"></i>Unblock user</button>
<button id="prompt2-{{p.id}}" class="blockuser nobackground btn btn-link btn-block btn-lg text-danger text-left d-none" data-bs-dismiss="modal" onclick="post_toast(this,'/settings/block?username={{p.author.username}}','prompt2-{{p.id}}','unblock2-{{p.id}}','d-none')"><i class="fas fa-eye-slash mr-2 text-danger"></i>Are you sure?</button> <button id="block2-{{p.id}}" class="blockuser nobackground btn btn-link btn-block btn-lg text-danger text-left" data-click="post_toast(this,'/settings/block?username={{p.author.username}}','block2-{{p.id}}','unblock2-{{p.id}}','d-none')" onclick="areyousure(this)" data-dismiss="modal"><i class="fas fa-eye-slash mr-2 text-danger"></i>Block user</button>
<button id="block2-{{p.id}}" class="blockuser nobackground btn btn-link btn-block btn-lg text-danger text-left{% if p.is_blocking %} d-none{% endif %}" onclick="document.getElementById('block2-{{p.id}}').classList.toggle('d-none');document.getElementById('prompt2-{{p.id}}').classList.toggle('d-none');"><i class="fas fa-eye-slash mr-2 text-danger"></i>Block user</button>
{% endif %} {% endif %}
{% endif %} {% endif %}

View File

@ -102,13 +102,11 @@
{% set kind = a['kind'] %} {% set kind = a['kind'] %}
<td class="shop-table-actions"> <td class="shop-table-actions">
{% if kind != "benefactor" %} {% if kind != "benefactor" %}
<a id="buy1-{{loop.index}}" class="btn btn-success {% if v.coins < a['price'] %}disabled{% endif %}" role="button" onclick="this.classList.add('d-none');document.getElementById('buy1-go-{{loop.index}}').classList.remove('d-none')"><span class="m-auto">Buy</span></a> <a id="buy1-{{loop.index}}" class="btn btn-success {% if v.coins < a['price'] %}disabled{% endif %}" role="button" data-click="post_toast(this,'/buy/{{kind}}')" onclick="areyousure(this)"><span class="m-auto">Buy</span></a>
<a id="buy1-go-{{loop.index}}" class="d-none btn btn-success {% if v.coins < a['price'] %}disabled{% endif %}" role="button" onclick="post_toast(this,'/buy/{{kind}}')"><span class="m-auto">Are you sure?</span></a>
{% endif %} {% endif %}
{% if FEATURES['PROCOINS'] %} {% if FEATURES['PROCOINS'] %}
{% if kind != "grass" %} {% if kind != "grass" %}
<a id="buy2-{{loop.index}}" class="marseybux btn btn-success {% if v.procoins < a['price'] %}disabled{% endif %}" role="button" onclick="this.classList.add('d-none');document.getElementById('buy2-go-{{loop.index}}').classList.remove('d-none')"><span class="m-auto">Buy with MBux</span></a> <a id="buy2-{{loop.index}}" class="marseybux btn btn-success {% if v.procoins < a['price'] %}disabled{% endif %}" role="button" data-click="post_toast(this,'/buy/{{kind}}?mb=true')" onclick="areyousure(this)"><span class="m-auto">Buy with MBux</span></a>
<a id="buy2-go-{{loop.index}}" class="d-none marseybux btn btn-success {% if v.procoins < a['price'] %}disabled{% endif %}" role="button" onclick="post_toast(this,'/buy/{{kind}}?mb=true')"><span class="m-auto">Are you sure?</span></a>
{% endif %} {% endif %}
{% endif %} {% endif %}
</td> </td>

View File

@ -227,7 +227,7 @@
<a id="unadmin" class="{% if u.admin_level < 1 %}d-none{% endif %} btn btn-primary" href="javascript:void(0)" onclick="post_toast(this,'/@{{u.username}}/remove_admin','admin','unadmin','d-none')">Remove admin</a> <a id="unadmin" class="{% if u.admin_level < 1 %}d-none{% endif %} btn btn-primary" href="javascript:void(0)" onclick="post_toast(this,'/@{{u.username}}/remove_admin','admin','unadmin','d-none')">Remove admin</a>
{% endif %} {% endif %}
{% if v.admin_level >= PERMS['ADMIN_ACTIONS_REVERT'] %} {% if v.admin_level >= PERMS['ADMIN_ACTIONS_REVERT'] %}
<a class="btn btn-primary" role="button" onclick="post_toast(this,'/@{{u.username}}/revert_actions')">Revert admin actions</a> <a class="btn btn-primary" role="button" data-click="post_toast(this,'/@{{u.username}}/revert_actions')" onclick="areyousure(this)">Revert admin actions</a>
{% endif %} {% endif %}
</div> </div>
@ -498,7 +498,7 @@
{% endif %} {% endif %}
{% if v.admin_level >= PERMS['ADMIN_ACTIONS_REVERT'] %} {% if v.admin_level >= PERMS['ADMIN_ACTIONS_REVERT'] %}
<a class="btn btn-primary" role="button" onclick="post_toast(this,'/@{{u.username}}/revert_actions')">Revert admin actions</a> <a class="btn btn-primary" role="button" data-click="post_toast(this,'/@{{u.username}}/revert_actions')" onclick="areyousure(this)">Revert admin actions</a>
{% endif %} {% endif %}
<form class="d-none toggleable" id='message-mobile' action="/@{{u.username}}/message" onsubmit="submitFormAjax(event)"> <form class="d-none toggleable" id='message-mobile' action="/@{{u.username}}/message" onsubmit="submitFormAjax(event)">