submit: Add text to submit field for rules.

This commit is contained in:
Andre D
2013-07-31 14:44:07 -07:00
committed by Chad Birch
parent 8260159252
commit 6d1a5340b3
9 changed files with 171 additions and 5 deletions

View File

@@ -249,6 +249,18 @@ class ApiController(RedditController, OAuth2ResourceController):
queries.new_message(m, inbox_rel)
@json_validate()
@api_doc(api_section.subreddits)
def GET_submit_text(self, responder):
if c.site.over_18 and not c.over18:
submit_text = None
submit_text_html = None
else:
submit_text = c.site.submit_text
submit_text_html = safemarkdown(c.site.submit_text)
return {'submit_text': submit_text,
'submit_text_html': submit_text_html}
@require_oauth2_scope("submit")
@validatedForm(VUser(),
VModhash(),
@@ -1797,6 +1809,8 @@ class ApiController(RedditController, OAuth2ResourceController):
title = VLength("title", max_length = 100),
header_title = VLength("header-title", max_length = 500),
domain = VCnameDomain("domain"),
submit_text = VMarkdown("submit_text", max_length=1024),
prev_submit_text_id = VLength('prev_submit_text_id', max_length=36),
public_description = VMarkdown("public_description", max_length = 500),
prev_public_description_id = VLength('prev_public_description_id', max_length = 36),
description = VMarkdown("description", max_length = 5120),
@@ -1868,10 +1882,12 @@ class ApiController(RedditController, OAuth2ResourceController):
'submit_text_label', 'lang', 'css_on_cname',
'header_title', 'over_18', 'wikimode', 'wiki_edit_karma',
'wiki_edit_age', 'allow_top', 'public_description',
'spam_links', 'spam_selfposts', 'spam_comments'))
'spam_links', 'spam_selfposts', 'spam_comments',
'submit_text'))
public_description = kw.pop('public_description')
description = kw.pop('description')
submit_text = kw.pop('submit_text')
# Use the raw POST value as we need to tell the difference between
# None/Undefined and an empty string. The validators use a default
@@ -1879,6 +1895,7 @@ class ApiController(RedditController, OAuth2ResourceController):
# In order to avoid breaking functionality, this was done instead.
prev_desc = request.post.get('prev_description_id')
prev_pubdesc = request.post.get('prev_public_description_id')
prev_submit_text = request.post.get('prev_submit_text_id')
def update_wiki_text(sr):
error = False
@@ -1891,6 +1908,15 @@ class ApiController(RedditController, OAuth2ResourceController):
_("Sidebar was not saved")):
error = True
if not apply_wikid_field(sr,
form,
'config/submit_text',
submit_text,
prev_submit_text,
'submit_text',
_("Submission text was not saved")):
error = True
if not apply_wikid_field(sr,
form,
'config/description',

View File

@@ -80,12 +80,15 @@ from r2.lib.errors import reddit_http_error
import json
page_descriptions = {'config/stylesheet':_("This page is the subreddit stylesheet, changes here apply to the subreddit css"),
'config/submit_text':_("The contents of this page appear on the submit page"),
'config/sidebar':_("The contents of this page appear on the subreddit sidebar"),
'config/description':_("The contents of this page appear in the public subreddit description")}
ATTRIBUTE_BY_PAGE = {"config/sidebar": "description",
"config/submit_text": "submit_text",
"config/description": "public_description"}
RENDERERS_BY_PAGE = {"config/sidebar": "reddit",
"config/submit_text": "reddit",
"config/description": "reddit",
"config/stylesheet": "stylesheet"}

View File

@@ -237,6 +237,8 @@ class SubredditJsonTemplate(ThingJsonTemplate):
submission_type="link_type",
submit_link_label="submit_link_label",
submit_text_label="submit_text_label",
submit_text="submit_text",
submit_text_html="submit_text_html",
subreddit_type="type",
subscribers="_ups",
title="title",
@@ -286,6 +288,8 @@ class SubredditJsonTemplate(ThingJsonTemplate):
check_func = getattr(thing, attr)
return bool(check_func(c.user))
return None
elif attr == 'submit_text_html':
return safemarkdown(thing.submit_text)
else:
return ThingJsonTemplate.thing_attr(self, thing, attr)
@@ -853,11 +857,13 @@ class SubredditSettingsTemplate(ThingJsonTemplate):
over_18='site.over_18',
prev_description_id='site.prev_description_id',
prev_public_description_id='site.prev_public_description_id',
prev_submit_text_id='site.prev_submit_text_id',
public_description='site.public_description',
public_traffic='site.public_traffic',
show_media='site.show_media',
submit_link_label='site.submit_link_label',
submit_text_label='site.submit_text_label',
submit_text='site.submit_text',
subreddit_id='site._fullname',
subreddit_type='site.type',
title='site.title',

View File

@@ -221,7 +221,9 @@ class Subreddit(Thing, Printable, BaseSite):
use_quotas=True,
description="",
public_description="",
submit_text="",
prev_description_id="",
prev_submit_text_id="",
prev_public_description_id="",
allow_comment_gilding=True,
hide_subscribers=False,

View File

@@ -50,12 +50,19 @@ impossible_namespaces = ('edit/', 'revisions/', 'settings/', 'discussions/',
restricted_namespaces = ('reddit/', 'config/', 'special/')
# Pages which may only be edited by mods, must be within restricted namespaces
special_pages = ('config/stylesheet', 'config/sidebar', 'config/description')
special_pages = ('config/stylesheet', 'config/sidebar',
'config/submit_text', 'config/description')
# Pages which have a special length restrictions (In bytes)
special_length_restrictions_bytes = {'config/stylesheet': 128*1024, 'config/sidebar': 5120, 'config/description': 500}
special_length_restrictions_bytes = {
'config/stylesheet': 128*1024,
'config/submit_text': 1024,
'config/sidebar': 5120,
'config/description': 500
}
modactions = {'config/sidebar': "Updated subreddit sidebar",
'config/submit_text': "Updated submission text",
'config/description': "Updated subreddit description"}
# Page "index" in the subreddit "reddit.com" and a seperator of "\t" becomes:

View File

@@ -7688,3 +7688,42 @@ body.with-listing-chooser {
}
}
}
.submit_text {
display: none;
max-height: 250px;
overflow: auto;
ol, ul {
margin: 0;
margin-left: 2em;
}
&.working .content:before {
content: "";
width: 16px;
height: 16px;
display: block;
background-image: url(../throbber.gif);
}
h1 {
color: rgb(51, 102, 153);
display: block;
font-size: 16px;
font-weight: bold;
}
.content {
margin: 0;
p {
word-wrap: break-word;
clear: both;
}
}
&.enabled {
display: inline-block;
}
}

View File

@@ -28,6 +28,10 @@ r.ui.init = function() {
$(el).data('HelpBubble', new r.ui.Bubble({el: el}))
})
$('.submit_text').each(function(idx, el) {
$(el).data('SubredditSubmitText', new r.ui.SubredditSubmitText({el: el}))
})
r.ui.PermissionEditor.init()
}
@@ -604,3 +608,53 @@ r.ui.ConfirmButton = Backbone.View.extend({
}
}
})
r.ui.SubredditSubmitText = Backbone.View.extend({
initialize: function() {
this.lookup = _.throttle(this._lookup, 500)
this.cache = new r.utils.LRUCache()
this.$input = $('#sr-autocomplete')
this.$input.on('sr-changed change input', _.bind(this.lookup, this))
this.$sr = this.$el.find('.sr').first()
this.$content = this.$el.find('.content').first()
if (this.$content.text().trim()) {
this.$sr.text(r.config.post_site)
this.show()
}
},
_lookup: function() {
this.$content.empty()
var sr = this.$input.val()
this.$sr.text(sr)
this.$el.addClass('working')
this.cache.ajax(sr, {
url: '/r/' + sr + '/api/submit_text/.json',
dataType: 'json'
}).done(_.bind(this.settext, this, sr))
.fail(_.bind(this.error, this))
},
show: function() {
this.$el.addClass('enabled')
},
hide: function() {
this.$el.removeClass('enabled')
},
error: function() {
this.hide()
},
settext: function(sr, data) {
if (!data.submit_text || !data.submit_text.trim()) {
this.hide()
} else {
this.$sr.text(sr)
this.$content.html($.unsafe(data.submit_text_html))
this.$el.removeClass('working')
this.show()
}
}
})

View File

@@ -92,15 +92,31 @@
</div>
${error_field("CONFLICT", "description")}
</%utils:line_field>
<%utils:line_field title="${_('submission text')}" css_class="usertext"
description="${_('text to show on submission page. 1024 characters max.')}">
%if thing.site and thing.site.submit_text:
${UserText(None, text=thing.site.submit_text or "", editable=True, creating=True, name="submit_text", have_form=False)}
%else:
${UserText(None, text="", creating=True, name="submit_text", have_form=False)}
%endif
<div id="submit_text_conflict_box" style="display: none">
<div id="submit_text_conflict_diff"></div>
${UserText(None, text="", editable=True, creating=True, name="submit_text_conflict_old", have_form=False)}
</div>
${error_field("CONFLICT", "submit_text")}
</%utils:line_field>
%if thing.site:
<input type="hidden" name="prev_public_description_id" value="${thing.site.prev_public_description_id}"/>
<input type="hidden" name="prev_description_id" value="${thing.site.prev_description_id}"/>
<input type="hidden" name="prev_submit_text_id" value="${thing.site.prev_submit_text_id}"/>
${error_field("TOO_LONG", "prev_public_description_id")}
${error_field("TOO_LONG", "prev_description_id")}
${error_field("TOO_LONG", "prev_submit_text_id")}
${error_field("BAD_REVISION", "prev_public_description_id")}
${error_field("BAD_REVISION", "prev_description_id")}
${error_field("BAD_REVISION", "prev_submit_text_id")}
%endif
<%utils:line_field title="${_('language')}">

View File

@@ -24,6 +24,7 @@
from r2.lib.strings import strings
from r2.lib.pages import SubredditSelector, UserText
from r2.lib.template_helpers import add_sr
from r2.lib.filters import safemarkdown
%>
<%namespace file="utils.html" import="error_field, submit_form, _a_buffered, text_with_links"/>
@@ -35,6 +36,7 @@
else:
sr = _("reddit")
%>
<h1>${unsafe(_("submit to %(sr)s") % dict(sr=sr))}</h1>
<%utils:submit_form onsubmit="return post_form(this, 'submit', linkstatus, null, true)"
@@ -103,6 +105,17 @@ ${thing.formtabs_menu}
</%utils:round_field>
</div>
<div class="spacer">
<div class="submit_text roundfield">
<h1>${unsafe(_('submitting to %(sr)s') % dict(sr='/r/<span class="sr"></span>'))}</h1>
<span class="content">
%if thing.default_sr and thing.default_sr.submit_text:
${unsafe(safemarkdown(thing.default_sr.submit_text))}
%endif
</span>
</div>
</div>
%if c.user.gold:
<div class="spacer">
<%utils:round_field title="${_('options')}" css_class="gold-accent">