make chudding and banning in profiles more seamless

pull/142/head
Aevann 2023-03-17 16:23:42 +02:00
parent 2102fb1de1
commit f66fcdc6ce
4 changed files with 19 additions and 6 deletions

View File

@ -0,0 +1,9 @@
function unchud_or_unban(t, url) {
postToast(t, url,
{
},
() => {
t.classList.add('d-none');
t.nextElementSibling.classList.remove('d-none');
});
}

View File

@ -325,11 +325,12 @@ function sendFormXHR(form, extraActionsOnSuccess) {
xhr.send(formData);
}
function sendFormXHRSwitch(form, donthideself) {
function sendFormXHRSwitch(form) {
sendFormXHR(form,
() => {
form.previousElementSibling.classList.remove('d-none');
if (!donthideself)
const days = form.querySelector("input[name=days]")
if (!days || !days.value)
form.classList.add('d-none');
}
)

View File

@ -42,9 +42,9 @@
</div>
{% endif %}
{% if v.admin_level >= PERMS['USER_BAN'] %}
<button type="button" id="unban-{{deviceType}}" class="mt-1 {% if not u.is_suspended %}d-none{% endif %} btn btn-success" data-nonce="{{g.nonce}}" data-onclick="postToastSwitch(this,'/unban_user/{{u.id}}','ban-{{deviceType}}','unban-{{deviceType}}','d-none')">Unban user</button>
<button type="button" id="unban-{{deviceType}}" class="mt-1 {% if not u.is_suspended %}d-none{% endif %} btn btn-success" data-nonce="{{g.nonce}}" data-onclick="unchud_or_unban(this,'/unban_user/{{u.id}}')">Unban user</button>
<form class="my-3" action="/ban_user/{{u.id}}" method="post" data-nonce="{{g.nonce}}" data-onsubmit="sendFormXHRSwitch(this, true)">
<form class="my-3 {% if u.is_suspended_permanently %}d-none{% endif %}" action="/ban_user/{{u.id}}" method="post" data-nonce="{{g.nonce}}" data-onsubmit="sendFormXHRSwitch(this)">
<input hidden name="formkey" value="{{v|formkey}}">
<input autocomplete="off" style="font-size:11px" type="text" class="form-control" maxlength="256" name="reason" placeholder="Ban Reason" data-nonce="{{g.nonce}}" data-undisable_element="user-ban-submit-{{deviceType}}" required>
<input autocomplete="off" style="font-size:11px" type="number" step="any" class="form-control" name="days" max="{{max_days()}}" placeholder="Days (blank = permanent)">
@ -65,9 +65,9 @@
</form>
{% endif %}
{% if v.admin_level >= PERMS['USER_AGENDAPOSTER'] %}
<button type="button" id="unagendaposter-{{deviceType}}" class="mt-1 {% if not u.agendaposter %}d-none{% endif %} btn btn-success" data-nonce="{{g.nonce}}" data-onclick="postToastSwitch(this,'/unagendaposter/{{u.id}}','agendaposter-{{deviceType}}','unagendaposter-{{deviceType}}','d-none')">Unchud</button>
<button type="button" id="unagendaposter-{{deviceType}}" class="mt-1 {% if not u.agendaposter %}d-none{% endif %} btn btn-success" data-nonce="{{g.nonce}}" data-onclick="unchud_or_unban(this,'/unagendaposter/{{u.id}}')">Unchud</button>
<form class="my-3" action="/agendaposter/{{u.id}}" method="post" data-nonce="{{g.nonce}}" data-onsubmit="sendFormXHRSwitch(this, true)">
<form class="my-3 {% if u.agendaposter == 1 %}d-none{% endif %}" action="/agendaposter/{{u.id}}" method="post" data-nonce="{{g.nonce}}" data-onsubmit="sendFormXHRSwitch(this)">
<input hidden name="formkey" value="{{v|formkey}}">
<input autocomplete="off" type="number" step="any" name="days" max="{{max_days()}}" class="form-control" placeholder="Days (0 or blank = permanent)">
<input type="submit" class="btn btn-danger" value="Chud">

View File

@ -9,6 +9,9 @@
{% macro javascript() %}
<script defer src="{{'js/vendor/bootstrap.js' | asset}}"></script>
<script defer src="{{'js/core.js' | asset}}"></script>
{% if v and v.admin_level %}
<script defer src="{{'js/admin/core.js' | asset}}"></script>
{% endif %}
{% endmacro %}
{% macro page_meta(title=none) %}