Move subscribe button into own template / add sr name data attr.

This commit is contained in:
Max Goodman
2013-03-08 22:45:51 -08:00
parent a531bc76df
commit 9613d65d6e
7 changed files with 59 additions and 21 deletions

View File

@@ -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

View File

@@ -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 ""
%>
<span class="${class_name} toggle" style="${style}">
<span class="${class_name} toggle" style="${style}" ${data(**data_attrs or dict())}>
<a class="option active ${css_class} ${extra_class}" href="#" tabindex="100"
%if not login_required or c.user_is_loggedin:
onclick="return toggle(this, ${callback}, ${cancelback})"

View File

@@ -24,10 +24,10 @@
from r2.lib.template_helpers import static
from r2.lib.strings import strings
from r2.lib.utils import timesince
from r2.lib.pages import SubscribeButton
%>
<%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))}
</%def>
##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)}
</%def>
##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='')">
<div class="midcol">
${addremove_button(thing)}
${SubscribeButton(thing)}
${permission_icons(thing)}
</div>
</%def>

View File

@@ -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" />
<div class="titlebox">
@@ -34,7 +33,7 @@
${plain_link(thing.sr.name, thing.sr.path, _sr_path=False, _class="hover")}
</h1>
${addremove_button(thing.sr)}
${SubscribeButton(thing.sr)}
<span class="subscribers">${unsafe(Score.readers(thing.subscribers))}</span>
<p class="users-online ${'fuzzed' if thing.accounts_active_fuzzed else ''}" title="${_('logged-in users viewing this subreddit in the past 15 minutes')}">
${unsafe(Score.users_here_now(thing.accounts_active, prepend='~' if thing.accounts_active_fuzzed else ''))}

View File

@@ -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),
)}

View File

@@ -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 @@
</span>
<span class="title banned">${sr.name}</span>
%elif is_spam:
${addremove_button(sr)}
${SubscribeButton(sr)}
<span class="title banned">${sr.name}</span>
%else:
${addremove_button(sr)}
${SubscribeButton(sr)}
${plain_link(sr.name, sr.path, _class="title")}
${permission_icons(sr)}
%endif

View File

@@ -57,6 +57,12 @@ id="${arg}_${thing and thing._fullname or ''}"
class="${" ".join(filter(None, class_names))}"
</%def>
<%def name="data(**data_attrs)">
%for name, value in data_attrs.iteritems():
data-${name}="${value}"
%endfor
</%def>
<%def name="submit_form(onsubmit='', action='', _class='', method='post', _id='', **params)">
<form class="${_class or ''}" onsubmit="${onsubmit or ''}"
action="${action or ''}" ${_id and "id='" + _id + "'" or ""} method="${method}"