mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-04-27 03:00:12 -04:00
Suggested sorts: set per-thread suggested sort
This commit is contained in:
@@ -1441,7 +1441,7 @@ class ApiController(RedditController):
|
||||
VModhash(),
|
||||
VSrCanAlter('id'),
|
||||
thing=VByName('id', thing_cls=Link),
|
||||
sort=VOneOf('sort', CommentSortMenu._options))
|
||||
sort=VOneOf('sort', CommentSortMenu.suggested_sort_options))
|
||||
def POST_set_default_sort(self, form, jquery, thing, sort):
|
||||
"""Set a default sort for a link.
|
||||
|
||||
|
||||
@@ -577,6 +577,10 @@ class CommentSortMenu(SortMenu):
|
||||
'random', 'qa',)
|
||||
button_cls = PostButton
|
||||
|
||||
# Links may have a suggested sort of 'blank', which is an explicit None -
|
||||
# that is, do not check the subreddit for a suggested sort, either.
|
||||
suggested_sort_options = _options + ('blank',)
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.suggested_sort = kwargs.pop('suggested_sort', None)
|
||||
super(CommentSortMenu, self).__init__(*args, **kwargs)
|
||||
|
||||
@@ -4732,17 +4732,19 @@ class Goldvertisement(Templated):
|
||||
Templated.__init__(self)
|
||||
|
||||
class LinkCommentsSettings(Templated):
|
||||
def __init__(self, link):
|
||||
def __init__(self, link, sort, suggested_sort):
|
||||
Templated.__init__(self)
|
||||
sr = link.subreddit_slow
|
||||
self.sr = link.subreddit_slow
|
||||
self.link = link
|
||||
self.is_author = c.user_is_loggedin and c.user._id == link.author_id
|
||||
self.contest_mode = link.contest_mode
|
||||
self.stickied = link._fullname == sr.sticky_fullname
|
||||
self.stickied = link._fullname == self.sr.sticky_fullname
|
||||
self.sendreplies = link.sendreplies
|
||||
self.can_edit = (c.user_is_loggedin
|
||||
and (c.user_is_admin or
|
||||
sr.is_moderator(c.user)))
|
||||
self.sr.is_moderator(c.user)))
|
||||
self.sort = sort
|
||||
self.suggested_sort = suggested_sort
|
||||
|
||||
class ModeratorPermissions(Templated):
|
||||
def __init__(self, user, permissions_type, permissions,
|
||||
|
||||
@@ -745,6 +745,10 @@ class Link(Thing, Printable):
|
||||
def sort_if_suggested(self):
|
||||
"""Returns a sort, if the link or its subreddit has suggested one."""
|
||||
if self.default_sort:
|
||||
# A default sort of "blank" means explicitly empty: Do not obey
|
||||
# the subreddit's default sort, either.
|
||||
if self.default_sort == 'blank':
|
||||
return None
|
||||
return self.default_sort
|
||||
|
||||
sr = self.subreddit_slow
|
||||
|
||||
@@ -965,6 +965,18 @@ function set_distinguish(elem, value) {
|
||||
$(elem).children().toggle();
|
||||
}
|
||||
|
||||
function toggle_clear_suggested_sort(elem) {
|
||||
var form = $(elem).parents("form")[0];
|
||||
$(form).children().toggle();
|
||||
}
|
||||
|
||||
function set_suggested_sort(elem, value) {
|
||||
$(elem).parents('form').first().find('input[name="sort"]').val(value);
|
||||
change_state(elem, "set_default_sort");
|
||||
$(elem).children().toggle();
|
||||
}
|
||||
|
||||
|
||||
function populate_click_gadget() {
|
||||
/* if we can find the click-gadget, populate it */
|
||||
if($('.click-gadget').length) {
|
||||
|
||||
@@ -20,8 +20,72 @@
|
||||
## reddit Inc. All Rights Reserved.
|
||||
###############################################################################
|
||||
|
||||
<%!
|
||||
from r2.config import feature
|
||||
from r2.lib.filters import jssafe
|
||||
%>
|
||||
|
||||
<%namespace file="printablebuttons.html" import="ynbutton" />
|
||||
|
||||
|
||||
<%def name="suggested_clear_type(name, value=None)">
|
||||
<a href="javascript:void(0)"
|
||||
onclick="return set_suggested_sort(this, '${jssafe(value or name)}')">${_(name)}</a>
|
||||
</%def>
|
||||
|
||||
<%def name="clear_suggested_sort()">
|
||||
<li class="toggle">
|
||||
<form method="post" action="/api/set_default_sort">
|
||||
<input type="hidden" name="id" value="${thing.link._fullname}" />
|
||||
<input type="hidden" name="sort" value="" />
|
||||
<input type="hidden" value="${_('suggested sort cleared')}" name="executed"/>
|
||||
<a href="javascript:void(0)"
|
||||
onclick="return toggle_clear_suggested_sort(this)">${_("clear suggested sort")}</a>
|
||||
<span class="option error">
|
||||
${_("clear suggested sort?")}
|
||||
|
||||
%if thing.sr.default_comment_sort:
|
||||
|
||||
 
|
||||
## Set to explicitly "blank", which will disallow using the subreddit setting and use the user's setting
|
||||
${suggested_clear_type('clear', 'blank')}
|
||||
 /
|
||||
|
||||
## Show "use subreddit setting" only if a link's suggested sort is explicitly set
|
||||
%if thing.link.default_sort is not None:
|
||||
 
|
||||
## Set back to default, which will be the subreddit's suggested sort
|
||||
${suggested_clear_type('use subreddit setting', '')}
|
||||
 /
|
||||
%endif
|
||||
|
||||
%else:
|
||||
|
||||
 
|
||||
## Set back to "default" in case they explicitly set a subreddit suggested sort in the future
|
||||
${suggested_clear_type('clear', '')}
|
||||
 /
|
||||
|
||||
%endif
|
||||
|
||||
 
|
||||
<a href="javascript:void(0)"
|
||||
onclick="return toggle_clear_suggested_sort(this)">${_('cancel')}</a>
|
||||
 
|
||||
</span>
|
||||
</form>
|
||||
</li>
|
||||
</%def>
|
||||
|
||||
%if feature.is_enabled('default_sort') and thing.can_edit:
|
||||
%if thing.suggested_sort == thing.sort:
|
||||
<% clear_suggested_sort() %>
|
||||
%else:
|
||||
${ynbutton(_("set as suggested sort"), _("suggested sort set"), "set_default_sort",
|
||||
hidden_data=dict(id=thing.link._fullname, sort=thing.sort))}
|
||||
%endif
|
||||
%endif
|
||||
|
||||
%if thing.is_author:
|
||||
%if thing.sendreplies:
|
||||
${ynbutton(_("disable inbox replies"), _("inbox replies disabled"), "sendreplies",
|
||||
|
||||
Reference in New Issue
Block a user