diff --git a/r2/r2/lib/pages/pages.py b/r2/r2/lib/pages/pages.py index cb9463297..afd3037c1 100755 --- a/r2/r2/lib/pages/pages.py +++ b/r2/r2/lib/pages/pages.py @@ -4084,3 +4084,9 @@ class PolicyPage(BoringPage): base_path='/help') toolbars.append(policies_menu) return toolbars + + +class SubscribeButton(Templated): + def __init__(self, sr): + Templated.__init__(self) + self.sr = sr diff --git a/r2/r2/templates/printablebuttons.html b/r2/r2/templates/printablebuttons.html index 84426ecf8..5fe4d73db 100644 --- a/r2/r2/templates/printablebuttons.html +++ b/r2/r2/templates/printablebuttons.html @@ -20,7 +20,7 @@ ## reddit Inc. All Rights Reserved. ############################################################################### -<%namespace file="utils.html" import="plain_link, pretty_button" /> +<%namespace file="utils.html" import="plain_link, pretty_button, data" /> <%! from r2.lib.strings import strings @@ -463,7 +463,7 @@ css_class = '', alt_css_class = '', reverse = False, login_required = False, - style = '', )"> + style = '', data_attrs=None)"> <% if reverse: callback, cancelback = cancelback, callback @@ -471,7 +471,7 @@ css_class, alt_css_class = alt_css_class, css_class extra_class = "login-required" if login_required else "" %> - + <%inherit file="printable.html"/> -<%namespace file="printablebuttons.html" import="toggle_button"/> <%namespace file="utils.html" import="plain_link"/> <%def name="numcol()"> @@ -59,16 +59,6 @@ ${_("a community for %(time)s") % dict(time=timesince(thing._date))} -##this function is used by subscriptionbox.html -<%def name="addremove_button(sr)"> - ${toggle_button("fancy-toggle-button", _("subscribe"), _("unsubscribe"), - "subscribe('%s')" % sr._fullname, - "unsubscribe('%s')" % sr._fullname, - css_class = "add", alt_css_class = "remove", - reverse = sr.subscriber, - login_required = True)} - - ##this function is used by subscriptionbox.html <%def name="permission_icons(sr)"> %if sr.moderator: @@ -101,7 +91,7 @@ <%def name="midcol(display=True, cls='')">
- ${addremove_button(thing)} + ${SubscribeButton(thing)} ${permission_icons(thing)}
diff --git a/r2/r2/templates/subredditinfobar.html b/r2/r2/templates/subredditinfobar.html index 30a78cb6d..6cff99275 100644 --- a/r2/r2/templates/subredditinfobar.html +++ b/r2/r2/templates/subredditinfobar.html @@ -22,11 +22,10 @@ <%! from r2.lib.strings import strings, Score - from r2.lib.pages import WrappedUser, ModList + from r2.lib.pages import WrappedUser, ModList, SubscribeButton %> <%namespace file="utils.html" import="plain_link, thing_timestamp, text_with_links"/> -<%namespace file="subreddit.html" import="addremove_button" /> <%namespace file="printablebuttons.html" import="ynbutton, state_button" />
@@ -34,7 +33,7 @@ ${plain_link(thing.sr.name, thing.sr.path, _sr_path=False, _class="hover")} - ${addremove_button(thing.sr)} + ${SubscribeButton(thing.sr)} ${unsafe(Score.readers(thing.subscribers))}

${unsafe(Score.users_here_now(thing.accounts_active, prepend='~' if thing.accounts_active_fuzzed else ''))} diff --git a/r2/r2/templates/subscribebutton.html b/r2/r2/templates/subscribebutton.html new file mode 100644 index 000000000..a98b400c2 --- /dev/null +++ b/r2/r2/templates/subscribebutton.html @@ -0,0 +1,36 @@ +## The contents of this file are subject to the Common Public Attribution +## License Version 1.0. (the "License"); you may not use this file except in +## compliance with the License. You may obtain a copy of the License at +## http://code.reddit.com/LICENSE. The License is based on the Mozilla Public +## License Version 1.1, but Sections 14 and 15 have been added to cover use of +## software over a computer network and provide for limited attribution for the +## Original Developer. In addition, Exhibit A has been modified to be +## consistent with Exhibit B. +## +## Software distributed under the License is distributed on an "AS IS" basis, +## WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for +## the specific language governing rights and limitations under the License. +## +## The Original Code is reddit. +## +## The Original Developer is the Initial Developer. The Initial Developer of +## the Original Code is reddit Inc. +## +## All portions of the code written by reddit are Copyright (c) 2006-2012 +## reddit Inc. All Rights Reserved. +############################################################################### + +<%namespace file="printablebuttons.html" import="toggle_button"/> + +${toggle_button( + class_name="subscribe-button fancy-toggle-button", + title=_("subscribe"), + alt_title=_("unsubscribe"), + callback="subscribe('%s')" % thing.sr._fullname, + cancelback="unsubscribe('%s')" % thing.sr._fullname, + css_class="add", + alt_css_class="remove", + reverse=thing.sr.subscriber, + login_required=True, + data_attrs=dict(sr_name=thing.sr.name), +)} diff --git a/r2/r2/templates/subscriptionbox.html b/r2/r2/templates/subscriptionbox.html index a463a4e3d..ddb66d84d 100644 --- a/r2/r2/templates/subscriptionbox.html +++ b/r2/r2/templates/subscriptionbox.html @@ -21,10 +21,11 @@ ############################################################################### <%namespace file="utils.html" import="plain_link"/> -<%namespace file="subreddit.html" import="addremove_button, permission_icons"/> +<%namespace file="subreddit.html" import="permission_icons"/> <% from r2.models import MultiReddit + from r2.lib.pages import SubscribeButton is_multi = isinstance(c.site, MultiReddit) %> @@ -63,10 +64,10 @@ ${sr.name} %elif is_spam: - ${addremove_button(sr)} + ${SubscribeButton(sr)} ${sr.name} %else: - ${addremove_button(sr)} + ${SubscribeButton(sr)} ${plain_link(sr.name, sr.path, _class="title")} ${permission_icons(sr)} %endif diff --git a/r2/r2/templates/utils.html b/r2/r2/templates/utils.html index 76a8ba05e..b20c1ab17 100755 --- a/r2/r2/templates/utils.html +++ b/r2/r2/templates/utils.html @@ -57,6 +57,12 @@ id="${arg}_${thing and thing._fullname or ''}" class="${" ".join(filter(None, class_names))}" +<%def name="data(**data_attrs)"> +%for name, value in data_attrs.iteritems(): +data-${name}="${value}" +%endfor + + <%def name="submit_form(onsubmit='', action='', _class='', method='post', _id='', **params)">