make shadowbanned, banning, chudding from the userpage work without refreshing the page
parent
5ee7eac502
commit
ce6998bd6e
|
@ -369,3 +369,53 @@ function prepare_to_pause(audio) {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function sendFormXHR(e, extraActionsOnSuccess) {
|
||||||
|
const form = e.target;
|
||||||
|
const xhr = new XMLHttpRequest();
|
||||||
|
e.preventDefault();
|
||||||
|
|
||||||
|
formData = new FormData(form);
|
||||||
|
|
||||||
|
formData.append("formkey", formkey());
|
||||||
|
actionPath = form.getAttribute("action");
|
||||||
|
|
||||||
|
xhr.open("POST", actionPath);
|
||||||
|
xhr.setRequestHeader('xhr', 'xhr');
|
||||||
|
|
||||||
|
xhr.onload = function() {
|
||||||
|
if (xhr.status >= 200 && xhr.status < 300) {
|
||||||
|
let data = JSON.parse(xhr.response);
|
||||||
|
showToast(true, getMessageFromJsonData(true, data));
|
||||||
|
if (extraActionsOnSuccess) extraActionsOnSuccess(xhr);
|
||||||
|
return true
|
||||||
|
} else {
|
||||||
|
document.getElementById('toast-post-error-text').innerText = "Error, please try again later."
|
||||||
|
try {
|
||||||
|
let data=JSON.parse(xhr.response);
|
||||||
|
var myToast = bootstrap.Toast.getOrCreateInstance(document.getElementById('toast-post-error'));
|
||||||
|
myToast.show();
|
||||||
|
document.getElementById('toast-post-error-text').innerText = data["error"];
|
||||||
|
if (data && data["details"]) document.getElementById('toast-post-error-text').innerText = data["details"];
|
||||||
|
} catch(e) {
|
||||||
|
var myToast = bootstrap.Toast.getOrCreateInstance(document.getElementById('toast-post-success'));
|
||||||
|
myToast.hide();
|
||||||
|
var myToast = bootstrap.Toast.getOrCreateInstance(document.getElementById('toast-post-error'));
|
||||||
|
myToast.show();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
xhr.send(formData);
|
||||||
|
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
function sendFormXHRSwitch(t, e) {
|
||||||
|
sendFormXHR(e,
|
||||||
|
() => {
|
||||||
|
t.previousElementSibling.classList.remove('d-none');
|
||||||
|
t.classList.add('d-none');
|
||||||
|
}
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
|
@ -80,44 +80,10 @@ function sendMessage(e) {
|
||||||
document.getElementById('message-mobile').classList.add('d-none');
|
document.getElementById('message-mobile').classList.add('d-none');
|
||||||
document.getElementById('message-preview').classList.add('d-none');
|
document.getElementById('message-preview').classList.add('d-none');
|
||||||
document.getElementById('message-preview-mobile').classList.add('d-none');
|
document.getElementById('message-preview-mobile').classList.add('d-none');
|
||||||
|
sendFormXHR(e,
|
||||||
const form = e.target;
|
() => {
|
||||||
const xhr = new XMLHttpRequest();
|
|
||||||
e.preventDefault();
|
|
||||||
|
|
||||||
formData = new FormData(form);
|
|
||||||
|
|
||||||
formData.append("formkey", formkey());
|
|
||||||
actionPath = form.getAttribute("action");
|
|
||||||
|
|
||||||
xhr.open("POST", actionPath);
|
|
||||||
xhr.setRequestHeader('xhr', 'xhr');
|
|
||||||
|
|
||||||
xhr.onload = function() {
|
|
||||||
if (xhr.status >= 200 && xhr.status < 300) {
|
|
||||||
let data = JSON.parse(xhr.response);
|
|
||||||
showToast(true, getMessageFromJsonData(true, data));
|
|
||||||
document.getElementById('input-message').value = ''
|
document.getElementById('input-message').value = ''
|
||||||
document.getElementById('input-message-mobile').value = ''
|
document.getElementById('input-message-mobile').value = ''
|
||||||
return true
|
|
||||||
} else {
|
|
||||||
document.getElementById('toast-post-error-text').innerText = "Error, please try again later."
|
|
||||||
try {
|
|
||||||
let data=JSON.parse(xhr.response);
|
|
||||||
var myToast = bootstrap.Toast.getOrCreateInstance(document.getElementById('toast-post-error'));
|
|
||||||
myToast.show();
|
|
||||||
document.getElementById('toast-post-error-text').innerText = data["error"];
|
|
||||||
if (data && data["details"]) document.getElementById('toast-post-error-text').innerText = data["details"];
|
|
||||||
} catch(e) {
|
|
||||||
var myToast = bootstrap.Toast.getOrCreateInstance(document.getElementById('toast-post-success'));
|
|
||||||
myToast.hide();
|
|
||||||
var myToast = bootstrap.Toast.getOrCreateInstance(document.getElementById('toast-post-error'));
|
|
||||||
myToast.show();
|
|
||||||
}
|
}
|
||||||
}
|
)
|
||||||
};
|
|
||||||
|
|
||||||
xhr.send(formData);
|
|
||||||
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -863,7 +863,7 @@ def shadowban(user_id, v):
|
||||||
|
|
||||||
cache.delete_memoized(frontlist)
|
cache.delete_memoized(frontlist)
|
||||||
|
|
||||||
return redirect(user.url)
|
return {"message": f"@{user.username} has been shadowbanned!"}
|
||||||
|
|
||||||
@app.post("/unshadowban/<user_id>")
|
@app.post("/unshadowban/<user_id>")
|
||||||
@limiter.limit("1/second;30/minute;200/hour;1000/day")
|
@limiter.limit("1/second;30/minute;200/hour;1000/day")
|
||||||
|
@ -992,8 +992,7 @@ def ban_user(user_id, v):
|
||||||
comment.bannedfor = f'{duration} by @{v.username}'
|
comment.bannedfor = f'{duration} by @{v.username}'
|
||||||
g.db.add(comment)
|
g.db.add(comment)
|
||||||
|
|
||||||
if 'redir' in request.values: return redirect(user.url)
|
return {"message": f"@{user.username} has been banned!"}
|
||||||
else: return {"message": f"@{user.username} has been banned!"}
|
|
||||||
|
|
||||||
|
|
||||||
@app.post("/agendaposter/<user_id>")
|
@app.post("/agendaposter/<user_id>")
|
||||||
|
@ -1058,8 +1057,7 @@ def agendaposter(user_id, v):
|
||||||
comment.chuddedfor = f'{duration} by @{v.username}'
|
comment.chuddedfor = f'{duration} by @{v.username}'
|
||||||
g.db.add(comment)
|
g.db.add(comment)
|
||||||
|
|
||||||
if 'redir' in request.values: return redirect(user.url)
|
return {"message": f"@{user.username} has been chudded!"}
|
||||||
else: return {"message": f"@{user.username} has been chudded!"}
|
|
||||||
|
|
||||||
|
|
||||||
@app.post("/unban_user/<user_id>")
|
@app.post("/unban_user/<user_id>")
|
||||||
|
|
|
@ -44,7 +44,7 @@
|
||||||
{% if v.admin_level >= PERMS['USER_BAN'] %}
|
{% if v.admin_level >= PERMS['USER_BAN'] %}
|
||||||
<button type="button" id="unban-{{deviceType}}" class="mt-1 mb-3 {% if not u.is_suspended %}d-none{% endif %} btn btn-success" 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 mb-3 {% if not u.is_suspended %}d-none{% endif %} btn btn-success" onclick="postToastSwitch(this,'/unban_user/{{u.id}}','ban-{{deviceType}}','unban-{{deviceType}}','d-none')">Unban user</button>
|
||||||
|
|
||||||
<form id="ban-{{deviceType}}" class="mb-3 {% if u.is_suspended %}d-none{% endif %}" action="/ban_user/{{u.id}}" method="post">
|
<form id="ban-{{deviceType}}" class="mb-3 {% if u.is_suspended %}d-none{% endif %}" action="/ban_user/{{u.id}}" method="post" onsubmit="sendFormXHRSwitch(this, event)">
|
||||||
<input type="hidden" name="formkey" value="{{v.formkey}}">
|
<input type="hidden" name="formkey" value="{{v.formkey}}">
|
||||||
<input type="hidden" name="redir" value="true">
|
<input type="hidden" name="redir" value="true">
|
||||||
<input autocomplete="off" style="font-size:11px" type="text" class="form-control" maxlength="256" name="reason" placeholder="Ban Reason" oninput="document.getElementById('user-ban-submit-{{deviceType}}').disabled=false" required>
|
<input autocomplete="off" style="font-size:11px" type="text" class="form-control" maxlength="256" name="reason" placeholder="Ban Reason" oninput="document.getElementById('user-ban-submit-{{deviceType}}').disabled=false" required>
|
||||||
|
@ -57,9 +57,9 @@
|
||||||
</form>
|
</form>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if v.admin_level >= PERMS['USER_SHADOWBAN'] %}
|
{% if v.admin_level >= PERMS['USER_SHADOWBAN'] %}
|
||||||
<button type="button" id="unshadowban-{{deviceType}}" class="mt-1 mb-3 {% if not u.shadowbanned %}d-none{% endif %} btn btn-success" onclick="postToastSwitch(this,'/unshadowban/{{u.id}}','shadowban-{{deviceType}}','unshadowban-{{deviceType}}','d-none')">Unshadowban user</button>
|
<button type="button" id="unshadowban-{{deviceType}}" class="mt-1 {% if not u.shadowbanned %}d-none{% endif %} btn btn-success" onclick="postToastSwitch(this,'/unshadowban/{{u.id}}','shadowban-{{deviceType}}','unshadowban-{{deviceType}}','d-none')">Unshadowban user</button>
|
||||||
|
|
||||||
<form id="shadowban-{{deviceType}}" class="mb-3 {% if u.shadowbanned %}d-none{% endif %}" action="/shadowban/{{u.id}}" method="post">
|
<form id="shadowban-{{deviceType}}" class="mb-3 {% if u.shadowbanned %}d-none{% endif %}" action="/shadowban/{{u.id}}" method="post" onsubmit="sendFormXHRSwitch(this, event)">
|
||||||
<input type="hidden" name="formkey" value="{{v.formkey}}">
|
<input type="hidden" name="formkey" value="{{v.formkey}}">
|
||||||
<input autocomplete="off" style="font-size:11px" type="text" class="form-control" maxlength="256" name="reason" placeholder="Shadowban Reason" oninput="document.getElementById('user-shadowban-submit-{{deviceType}}').disabled=false" required>
|
<input autocomplete="off" style="font-size:11px" type="text" class="form-control" maxlength="256" name="reason" placeholder="Shadowban Reason" oninput="document.getElementById('user-shadowban-submit-{{deviceType}}').disabled=false" required>
|
||||||
<div class="custom-control custom-checkbox mb-1">
|
<div class="custom-control custom-checkbox mb-1">
|
||||||
|
@ -70,13 +70,14 @@
|
||||||
</form>
|
</form>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
{% if v.admin_level >= PERMS['USER_AGENDAPOSTER'] %}
|
{% if v.admin_level >= PERMS['USER_AGENDAPOSTER'] %}
|
||||||
<form id="agendaposter-{{deviceType}}" class="{% if u.agendaposter %}d-none{% endif %}" action="/agendaposter/{{u.id}}" method="post">
|
<button type="button" id="unagendaposter-{{deviceType}}" class="mt-1 {% if not u.agendaposter %}d-none{% endif %} btn btn-success" onclick="postToastSwitch(this,'/unagendaposter/{{u.id}}','agendaposter-{{deviceType}}','unagendaposter-{{deviceType}}','d-none')">Unchud</button>
|
||||||
|
|
||||||
|
<form id="agendaposter-{{deviceType}}" class="{% if u.agendaposter %}d-none{% endif %}" action="/agendaposter/{{u.id}}" method="post" onsubmit="sendFormXHRSwitch(this, event)">
|
||||||
<input type="hidden" name="formkey", value="{{v.formkey}}">
|
<input type="hidden" name="formkey", value="{{v.formkey}}">
|
||||||
<input type="hidden" name="redir" value="true">
|
<input type="hidden" name="redir" value="true">
|
||||||
<input autocomplete="off" type="number" step="any" name="days" class="form-control" placeholder="Days (0 or blank = permanent)">
|
<input autocomplete="off" type="number" step="any" name="days" class="form-control" placeholder="Days (0 or blank = permanent)">
|
||||||
<input type="submit" onclick="disable(this)" class="btn btn-danger" value="Chud">
|
<input type="submit" onclick="disable(this)" class="btn btn-danger" value="Chud">
|
||||||
</form>
|
</form>
|
||||||
<button type="button" id="unagendaposter-{{deviceType}}" class="mt-1 {% if not u.agendaposter %}d-none{% endif %} btn btn-success" onclick="postToastSwitch(this,'/unagendaposter/{{u.id}}','agendaposter-{{deviceType}}','unagendaposter-{{deviceType}}','d-none')">Unchud</button>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<div class="actionbtns mt-3">
|
<div class="actionbtns mt-3">
|
||||||
|
|
Loading…
Reference in New Issue