diff --git a/r2/r2/controllers/api.py b/r2/r2/controllers/api.py index e26122d57..044c6aef7 100755 --- a/r2/r2/controllers/api.py +++ b/r2/r2/controllers/api.py @@ -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', diff --git a/r2/r2/controllers/wiki.py b/r2/r2/controllers/wiki.py index a8761667a..f945f9fe4 100644 --- a/r2/r2/controllers/wiki.py +++ b/r2/r2/controllers/wiki.py @@ -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"} diff --git a/r2/r2/lib/jsontemplates.py b/r2/r2/lib/jsontemplates.py index 404b516ab..159fc9562 100755 --- a/r2/r2/lib/jsontemplates.py +++ b/r2/r2/lib/jsontemplates.py @@ -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', diff --git a/r2/r2/models/subreddit.py b/r2/r2/models/subreddit.py index d3ae55962..7973027c8 100644 --- a/r2/r2/models/subreddit.py +++ b/r2/r2/models/subreddit.py @@ -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, diff --git a/r2/r2/models/wiki.py b/r2/r2/models/wiki.py index 9bddab538..0b5e6403d 100644 --- a/r2/r2/models/wiki.py +++ b/r2/r2/models/wiki.py @@ -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: diff --git a/r2/r2/public/static/css/reddit.less b/r2/r2/public/static/css/reddit.less index eb30e1c74..fe77afa1a 100755 --- a/r2/r2/public/static/css/reddit.less +++ b/r2/r2/public/static/css/reddit.less @@ -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; + } +} diff --git a/r2/r2/public/static/js/ui.js b/r2/r2/public/static/js/ui.js index 8ce703cd6..3f28b65b1 100644 --- a/r2/r2/public/static/js/ui.js +++ b/r2/r2/public/static/js/ui.js @@ -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() + } + } +}) diff --git a/r2/r2/templates/createsubreddit.html b/r2/r2/templates/createsubreddit.html index a9b650651..8e56316ff 100644 --- a/r2/r2/templates/createsubreddit.html +++ b/r2/r2/templates/createsubreddit.html @@ -92,15 +92,31 @@ ${error_field("CONFLICT", "description")} - - + + <%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 + + ${error_field("CONFLICT", "submit_text")} + + %if thing.site: + ${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')}"> diff --git a/r2/r2/templates/newlink.html b/r2/r2/templates/newlink.html index 82618c985..f121a653c 100755 --- a/r2/r2/templates/newlink.html +++ b/r2/r2/templates/newlink.html @@ -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") %> +

${unsafe(_("submit to %(sr)s") % dict(sr=sr))}

<%utils:submit_form onsubmit="return post_form(this, 'submit', linkstatus, null, true)" @@ -103,6 +105,17 @@ ${thing.formtabs_menu} +
+
+

${unsafe(_('submitting to %(sr)s') % dict(sr='/r/'))}

+ + %if thing.default_sr and thing.default_sr.submit_text: + ${unsafe(safemarkdown(thing.default_sr.submit_text))} + %endif + +
+
+ %if c.user.gold:
<%utils:round_field title="${_('options')}" css_class="gold-accent">