[UserWarnable] Add confirmation to "mark for" buttons (#537)

* [UserWarnable] Add confirmation to "mark for" buttons

* tweak message, better formatting

---------

Co-authored-by: Earlopain <earlopain@protonmail.com>
This commit is contained in:
Donovan Daniels 2023-08-01 13:47:10 -05:00 committed by GitHub
parent 49fb99b0ac
commit b029997aa9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 4 deletions

View File

@ -11,8 +11,16 @@ class UserWarnable {
const target = $(evt.target);
const type = target.data('item-route');
const id = target.data('item-id');
const item_type = target.data('item-type');
const record_type = target.data('record-type');
const message = record_type === "unmark"
? `Are you sure you want to unmark this ${item_type}?`
: `Are you sure you want to mark this ${item_type} for having received ${record_type}?`
if(!confirm(message)) {
return;
}
$.ajax({
type: "POST",
url: `/${type}/${id}/warning.json`,

View File

@ -1,8 +1,8 @@
<% if model.was_warned? %>
<li><%= tag.a "Unmark", href: "#", class: "item-mark-user-warned", data: { "item-route": model.model_name.route_key, "item-id": model.id, "record-type": "unmark" } %></li>
<li><%= tag.a "Unmark", href: "#", class: "item-mark-user-warned", data: { "item-route": model.model_name.route_key, "item-id": model.id, "record-type": "unmark", "item-type": model.model_name.human.downcase } %></li>
<% else %>
<li>Mark for:</li>
<li><%= tag.a "Warning", href: "#", class: "item-mark-user-warned", data: { "item-route": model.model_name.route_key, "item-id": model.id, "record-type": "warning" } %></li>
<li><%= tag.a "Record", href: "#", class: "item-mark-user-warned", data: { "item-route": model.model_name.route_key, "item-id": model.id, "record-type": "record" } %></li>
<li><%= tag.a "Ban", href: "#", class: "item-mark-user-warned", data: { "item-route": model.model_name.route_key, "item-id": model.id, "record-type": "ban" } %></li>
<li><%= tag.a "Warning", href: "#", class: "item-mark-user-warned", data: { "item-route": model.model_name.route_key, "item-id": model.id, "record-type": "warning", "item-type": model.model_name.human.downcase } %></li>
<li><%= tag.a "Record", href: "#", class: "item-mark-user-warned", data: { "item-route": model.model_name.route_key, "item-id": model.id, "record-type": "record", "item-type": model.model_name.human.downcase } %></li>
<li><%= tag.a "Ban", href: "#", class: "item-mark-user-warned", data: { "item-route": model.model_name.route_key, "item-id": model.id, "record-type": "ban", "item-type": model.model_name.human.downcase } %></li>
<% end %>