mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-04-27 03:00:12 -04:00
Modify report form to support subreddit rules
Instead of preloading the report dialog, this will request it when the report button is clicked so that the rules for that subreddit are populated in the form.
This commit is contained in:
@@ -79,6 +79,7 @@ from r2.lib.pages import (
|
||||
InvitedModTableItem,
|
||||
ModTableItem,
|
||||
MutedTableItem,
|
||||
ReportForm,
|
||||
SubredditStylesheet,
|
||||
WikiBannedTableItem,
|
||||
WikiMayContributeTableItem,
|
||||
@@ -1676,10 +1677,11 @@ class ApiController(RedditController):
|
||||
VModhash(),
|
||||
thing=VByName('thing_id'),
|
||||
reason=VLength('reason', max_length=100, empty_error=None),
|
||||
site_reason=VLength('site_reason', max_length=100, empty_error=None),
|
||||
other_reason=VLength('other_reason', max_length=100, empty_error=None),
|
||||
)
|
||||
@api_doc(api_section.links_and_comments)
|
||||
def POST_report(self, form, jquery, thing, reason, other_reason):
|
||||
def POST_report(self, form, jquery, thing, reason, site_reason, other_reason):
|
||||
"""Report a link, comment or message.
|
||||
|
||||
Reporting a thing brings it to the attention of the subreddit's
|
||||
@@ -1701,6 +1703,7 @@ class ApiController(RedditController):
|
||||
return
|
||||
|
||||
if (form.has_errors("reason", errors.TOO_LONG) or
|
||||
form.has_errors("site_reason", errors.TOO_LONG) or
|
||||
form.has_errors("other_reason", errors.TOO_LONG)):
|
||||
return
|
||||
|
||||
@@ -1709,6 +1712,8 @@ class ApiController(RedditController):
|
||||
if (reason in ("spam", "vote manipulation", "personal information",
|
||||
"sexualizing minors", "breaking reddit")):
|
||||
reason_type = "SITE_RULES"
|
||||
elif reason == "site_reason_selected":
|
||||
reason = site_reason
|
||||
else:
|
||||
reason_type = "CUSTOM"
|
||||
if reason == "other":
|
||||
@@ -1763,7 +1768,9 @@ class ApiController(RedditController):
|
||||
return
|
||||
|
||||
button.text(_("reported"))
|
||||
form.fadeOut()
|
||||
parent_div = jquery(".report-%s.reportform" % thing._fullname)
|
||||
parent_div.removeClass("active")
|
||||
parent_div.html("")
|
||||
|
||||
@require_oauth2_scope("privatemessages")
|
||||
@noresponse(
|
||||
@@ -5089,6 +5096,15 @@ class ApiController(RedditController):
|
||||
ModAction.create(c.site, c.user, 'deleterule', details=short_name)
|
||||
form.refresh()
|
||||
|
||||
@validatedForm(
|
||||
VUser(),
|
||||
VModhash(),
|
||||
thing=VByName('thing'),
|
||||
)
|
||||
def GET_report_form(self, form, jquery, thing):
|
||||
"""Return information about report reasons for the thing."""
|
||||
return ReportForm(thing).render(style="html")
|
||||
|
||||
@validatedForm(VModhashIfLoggedIn())
|
||||
def POST_hide_locationbar(self, form, jquery):
|
||||
c.user.pref_hide_locationbar = True
|
||||
|
||||
@@ -526,6 +526,7 @@ module["reddit"] = LocalizedModule("reddit.js",
|
||||
"locked.js",
|
||||
"newsletter.js",
|
||||
"flair.js",
|
||||
"report.js",
|
||||
"interestbar.js",
|
||||
"visited.js",
|
||||
"wiki.js",
|
||||
|
||||
@@ -62,8 +62,10 @@ from r2.models import (
|
||||
Random,
|
||||
RandomNSFW,
|
||||
RandomSubscription,
|
||||
SITEWIDE_RULES,
|
||||
StylesheetsEverywhere,
|
||||
Subreddit,
|
||||
SubredditRules,
|
||||
Target,
|
||||
Trophy,
|
||||
USER_FLAIR,
|
||||
@@ -90,7 +92,6 @@ from r2.models.promo import (
|
||||
PromotionLog,
|
||||
Collection,
|
||||
)
|
||||
from r2.models.rules import SubredditRules
|
||||
from r2.models.token import OAuth2Client, OAuth2AccessToken
|
||||
from r2.models import traffic
|
||||
from r2.models import ModAction
|
||||
@@ -396,9 +397,6 @@ class Reddit(Templated):
|
||||
clone_template=True,
|
||||
thing_type="comment",
|
||||
)
|
||||
report_form = ReportForm()
|
||||
|
||||
panes.append(report_form)
|
||||
|
||||
if self.show_sidebar:
|
||||
panes.extend([gold_comment, gold_link])
|
||||
@@ -3300,8 +3298,24 @@ class Gilding(Templated):
|
||||
pass
|
||||
|
||||
|
||||
class ReportForm(Templated):
|
||||
pass
|
||||
class ReportForm(CachedTemplate):
|
||||
def __init__(self, thing=None, **kw):
|
||||
subreddit = thing.subreddit_slow
|
||||
self.rules = []
|
||||
self.system_rules = []
|
||||
self.thing_fullname = thing._fullname
|
||||
|
||||
for rule in SubredditRules.get_rules(subreddit):
|
||||
self.rules.append(rule["short_name"])
|
||||
|
||||
if self.rules:
|
||||
self.system_rules = SITEWIDE_RULES
|
||||
self.rules_page_link = "/r/%s/about/rules" % subreddit.name
|
||||
else:
|
||||
self.rules = SITEWIDE_RULES
|
||||
self.rules_page_link = "/help/contentpolicy"
|
||||
|
||||
Templated.__init__(self)
|
||||
|
||||
|
||||
class FraudForm(Templated):
|
||||
|
||||
@@ -25,6 +25,7 @@ from link import *
|
||||
from listing import *
|
||||
from vote import *
|
||||
from report import *
|
||||
from rules import *
|
||||
from subreddit import *
|
||||
from flair import *
|
||||
from award import *
|
||||
|
||||
@@ -957,6 +957,20 @@ a.banned-user { color: red; }
|
||||
.flairrow .flairdeletebtn { display: inline; }
|
||||
.flairrow:hover .flairdeletebtn { opacity: 1.0; }
|
||||
|
||||
.rules-page-icon {
|
||||
float: right;
|
||||
}
|
||||
|
||||
.reportform {
|
||||
postion: relative;
|
||||
display: none;
|
||||
float: left;
|
||||
}
|
||||
|
||||
.reportform.active {
|
||||
display: block;
|
||||
}
|
||||
|
||||
.flairselector {
|
||||
box-shadow: 4px 4px 4px #ccc;
|
||||
font-size: x-small;
|
||||
@@ -10904,7 +10918,6 @@ body.with-listing-chooser {
|
||||
display: none;
|
||||
background-color: #f6e69f;
|
||||
border: thin solid #d8bb3c;
|
||||
max-width: 300px;
|
||||
padding: 5px;
|
||||
margin: 5px 0;
|
||||
font-size: larger;
|
||||
|
||||
42
r2/r2/public/static/js/report.js
Normal file
42
r2/r2/public/static/js/report.js
Normal file
@@ -0,0 +1,42 @@
|
||||
$(function() {
|
||||
function toggleReportForm() {
|
||||
var $reportForm = $(this).closest('.reportform');
|
||||
$reportForm.toggleClass('active');
|
||||
return false
|
||||
}
|
||||
|
||||
function getReportAttrs($el) {
|
||||
return {thing: $el.thing_id()}
|
||||
}
|
||||
|
||||
function openReportForm(e) {
|
||||
if (r.access.isLinkRestricted(e.target)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
var $flatList = $(this).closest('.flat-list');
|
||||
var $reportForm = $flatList.siblings('.reportform').eq(0);
|
||||
$reportForm.toggleClass('active');
|
||||
|
||||
if (!$reportForm.hasClass('active')) {
|
||||
return;
|
||||
}
|
||||
|
||||
function handleResponse(r) {
|
||||
$reportForm.html(r);
|
||||
var $form = $reportForm.children(".report-action-form");
|
||||
$form.css( "display", "block");
|
||||
}
|
||||
|
||||
$reportForm.html('<img class="flairthrobber" />')
|
||||
var $imgChild = $reportForm.children("img");
|
||||
$imgChild.attr('src', r.utils.staticURL('throbber.gif'));
|
||||
|
||||
var attrs = getReportAttrs($(this))
|
||||
$.request("report_form", attrs, handleResponse, true, "html", true);
|
||||
return false;
|
||||
}
|
||||
|
||||
$("div.content").on("click", ".tagline .reportbtn, .thing .reportbtn", openReportForm);
|
||||
$("div.content").on("click", ".btn.report-cancel", toggleReportForm);
|
||||
});
|
||||
@@ -61,4 +61,5 @@ ${self.commentBody()}
|
||||
<ul class="flat-list buttons">
|
||||
${self.buttons()}
|
||||
</ul>
|
||||
<div class="reportform report-${thing._fullname}"></div>
|
||||
</%def>
|
||||
|
||||
@@ -78,6 +78,7 @@
|
||||
${self.buttons()}
|
||||
${self.admintagline()}
|
||||
</ul>
|
||||
<div class="reportform report-${thing._fullname}"></div>
|
||||
</%def>
|
||||
|
||||
<%def name="flair()">
|
||||
|
||||
@@ -58,8 +58,7 @@
|
||||
|
||||
%if thing.show_report:
|
||||
<li class="report-button">
|
||||
<a href="javascript:void(0)" class="action-thing access-required"
|
||||
data-action-form="#report-action-form"
|
||||
<a href="javascript:void(0)" class="reportbtn access-required"
|
||||
data-event-action="report">
|
||||
${_("report")}
|
||||
</a>
|
||||
|
||||
@@ -19,54 +19,54 @@
|
||||
## All portions of the code written by reddit are Copyright (c) 2006-2015
|
||||
## reddit Inc. All Rights Reserved.
|
||||
###############################################################################
|
||||
|
||||
<%!
|
||||
from r2.lib.template_helpers import static
|
||||
%>
|
||||
<%namespace file="utils.html" import="error_field" />
|
||||
|
||||
<form id="report-action-form" class="action-form report-action-form rounded" data-form-action="report">
|
||||
<input type="hidden" name="thing_id" value="thing-fullname">
|
||||
<span class="reason-prompt">
|
||||
${_('why are you reporting this?')}
|
||||
</span>
|
||||
<ol>
|
||||
<li>
|
||||
<label>
|
||||
<input type="radio" name="reason" value="spam">${_("spam")}
|
||||
</label>
|
||||
</li>
|
||||
<li>
|
||||
<label>
|
||||
<input type="radio" name="reason" value="vote manipulation">${_("vote manipulation")}
|
||||
</label>
|
||||
</li>
|
||||
<li>
|
||||
<label>
|
||||
<input type="radio" name="reason" value="personal information">${_("personal information")}
|
||||
</label>
|
||||
</li>
|
||||
<li>
|
||||
<label>
|
||||
<input type="radio" name="reason" value="sexualizing minors">${_("sexualizing minors")}
|
||||
</label>
|
||||
</li>
|
||||
<li>
|
||||
<label>
|
||||
<input type="radio" name="reason" value="breaking reddit">${_("breaking reddit")}
|
||||
</label>
|
||||
</li>
|
||||
<li>
|
||||
<label>
|
||||
<input type="radio" name="reason" value="other">
|
||||
${_("other (max %(num)s characters):") % dict(num=100)}
|
||||
</label>
|
||||
<input name="other_reason" value="" maxlength="100" type="text" disabled>
|
||||
</li>
|
||||
</ol>
|
||||
<button type="submit" class="btn submit-action-thing" disabled>
|
||||
${_("submit")}
|
||||
</button>
|
||||
<button type="button" class="btn cancel-action-thing">
|
||||
${_("cancel")}
|
||||
</button>
|
||||
<span class="status"></span>
|
||||
${error_field("TOO_LONG", "reason", "span")}
|
||||
</form>
|
||||
<form id="report-action-form" class="action-form report-action-form rounded" data-form-action="report">
|
||||
<input type="hidden" name="thing_id" value="${thing.thing_fullname}">
|
||||
<span class="reason-prompt">
|
||||
${_("Why are you reporting this to the community moderators?")}
|
||||
</span>
|
||||
<span class="rules-page-icon">
|
||||
<a href="${thing.rules_page_link}" title="${_('View the community rules')}">
|
||||
<img src="${static('icon-info.png')}" alt="${_('View the community rules')}"/>
|
||||
</a>
|
||||
</span>
|
||||
<ol>
|
||||
%for rule in thing.rules:
|
||||
<li>
|
||||
<label>
|
||||
<input type="radio" name="reason" value="${rule}">${rule}
|
||||
</label>
|
||||
</li>
|
||||
%endfor
|
||||
%if thing.system_rules:
|
||||
<li>
|
||||
<label>
|
||||
<input type="radio" name="reason" value="site_reason_selected">
|
||||
<select name="site_reason">
|
||||
%for rule in thing.system_rules:
|
||||
<option value="${rule}">${_("Reddit rule: %(rule_name)s" % dict(rule_name=rule))}</option>
|
||||
%endfor
|
||||
</select>
|
||||
</label>
|
||||
</li>
|
||||
%endif
|
||||
<li>
|
||||
<label>
|
||||
<input type="radio" name="reason" value="other">${_("Other (max %(num)s characters):") % dict(num=100)}
|
||||
</label>
|
||||
<input name="other_reason" value="" maxlength="100" type="text" disabled>
|
||||
</li>
|
||||
</ol>
|
||||
<button type="submit" class="btn submit-action-thing">
|
||||
${_("submit")}
|
||||
</button>
|
||||
<button type="button" class="btn report-cancel">
|
||||
${_("cancel")}
|
||||
</button>
|
||||
<span class="status"></span>
|
||||
${error_field("TOO_LONG", "reason", "span")}
|
||||
</form>
|
||||
|
||||
Reference in New Issue
Block a user