mirror of
https://github.com/reddit-archive/reddit.git
synced 2026-01-27 07:48:16 -05:00
Add selectors for other users in grant flair page.
This commit is contained in:
@@ -1929,12 +1929,15 @@ class ApiController(RedditController):
|
||||
if new:
|
||||
jquery.redirect('?name=%s' % user.name)
|
||||
else:
|
||||
flair = (
|
||||
WrappedUser(user, force_show_flair=True).render(style='html'))
|
||||
jquery('#tabbedpane-grant .id-%s'
|
||||
% user._fullname).parent().html(flair)
|
||||
jquery('.flairtoggle .id-%s'
|
||||
% user._fullname).parent().html(flair)
|
||||
jquery('input[name="text"]').data('saved', text)
|
||||
jquery('input[name="css_class"]').data('saved', css_class)
|
||||
form.set_html('.status', _('saved'))
|
||||
form.set_html(
|
||||
'.tagline',
|
||||
WrappedUser(user, force_show_flair=True).render(style='html'))
|
||||
|
||||
@validate(VFlairManager(),
|
||||
VModhash(),
|
||||
@@ -2086,14 +2089,21 @@ class ApiController(RedditController):
|
||||
FlairTemplateBySubredditIndex.clear(c.site._id)
|
||||
jquery.refresh()
|
||||
|
||||
def POST_flairselector(self):
|
||||
return FlairSelector().render()
|
||||
@validate(VUser(),
|
||||
user = VOptionalExistingUname('name'))
|
||||
def POST_flairselector(self, user):
|
||||
if user and not (c.user_is_admin or c.site.is_moderator(c.user)):
|
||||
# ignore user parameter if c.user is not mod/admin
|
||||
user = None
|
||||
return FlairSelector(user).render()
|
||||
|
||||
@validatedForm(VUser(),
|
||||
VModhash(),
|
||||
user = VOptionalExistingUname('name'),
|
||||
flair_template_id = nop("flair_template_id"),
|
||||
text = VFlairText("text"))
|
||||
def POST_selectflair(self, form, jquery, flair_template_id, text):
|
||||
def POST_selectflair(self, form, jquery, user, flair_template_id, text):
|
||||
# TODO: ignore user parameter if c.user is not mod/admin
|
||||
flair_template = FlairTemplateBySubredditIndex.get_template(
|
||||
c.site._id, flair_template_id)
|
||||
|
||||
@@ -2118,23 +2128,21 @@ class ApiController(RedditController):
|
||||
|
||||
css_class = flair_template.css_class
|
||||
|
||||
c.site.add_flair(c.user)
|
||||
setattr(c.user, 'flair_%s_text' % c.site._id, text)
|
||||
setattr(c.user, 'flair_%s_css_class' % c.site._id, css_class)
|
||||
c.user._commit()
|
||||
c.site.add_flair(user)
|
||||
setattr(user, 'flair_%s_text' % c.site._id, text)
|
||||
setattr(user, 'flair_%s_css_class' % c.site._id, css_class)
|
||||
user._commit()
|
||||
|
||||
g.log.debug('committed flair: %r, %r', text, css_class)
|
||||
|
||||
#jquery('input[name="text"]').data('saved', text).value(text)
|
||||
#jquery('input[name="css_class"]').data('saved', css_class).value(
|
||||
#css_class)
|
||||
|
||||
u = WrappedUser(c.user, force_show_flair=True,
|
||||
# Push some client-side updates back to the browser.
|
||||
u = WrappedUser(user, force_show_flair=True,
|
||||
flair_text_editable=flair_template.text_editable)
|
||||
flair = u.render(style='html')
|
||||
jquery('#tabbedpane-grant .id-%s'
|
||||
% c.user._fullname).parent().html(flair)
|
||||
jquery('.flairtoggle .id-%s' % c.user._fullname).parent().html(flair)
|
||||
jquery('#tabbedpane-grant .id-%s' % user._fullname).parent().html(flair)
|
||||
jquery('.flairtoggle .id-%s' % user._fullname).parent().html(flair)
|
||||
jquery('#flairrow_%s input[name="text"]' % user._id36).data(
|
||||
'saved', text).val(text)
|
||||
jquery('#flairrow_%s input[name="css_class"]' % user._id36).data(
|
||||
'saved', css_class).val(css_class)
|
||||
|
||||
@validatedForm(VAdminOrAdminSecret("secret"),
|
||||
award = VByName("fullname"),
|
||||
|
||||
@@ -2555,12 +2555,15 @@ class FlairPrefs(CachedTemplate):
|
||||
|
||||
class FlairSelector(CachedTemplate):
|
||||
"""Provide user with flair options according to subreddit settings."""
|
||||
def __init__(self):
|
||||
def __init__(self, user=None):
|
||||
if user is None:
|
||||
user = c.user
|
||||
|
||||
position = getattr(c.site, 'flair_position', 'right')
|
||||
|
||||
attr_pattern = 'flair_%s_%%s' % c.site._id
|
||||
text = getattr(c.user, attr_pattern % 'text', '')
|
||||
css_class = getattr(c.user, attr_pattern % 'css_class', '')
|
||||
text = getattr(user, attr_pattern % 'text', '')
|
||||
css_class = getattr(user, attr_pattern % 'css_class', '')
|
||||
|
||||
ids = FlairTemplateBySubredditIndex.get_template_ids(c.site._id)
|
||||
template_dict = FlairTemplate._byID(ids)
|
||||
@@ -2576,7 +2579,7 @@ class FlairSelector(CachedTemplate):
|
||||
|
||||
choices = [
|
||||
WrappedUser(
|
||||
c.user, subreddit=c.site, force_show_flair=True,
|
||||
user, subreddit=c.site, force_show_flair=True,
|
||||
flair_template=template,
|
||||
flair_text_editable=all_text_editable or template.text_editable)
|
||||
for template in templates]
|
||||
@@ -2590,7 +2593,7 @@ class FlairSelector(CachedTemplate):
|
||||
choice.flair_text = text
|
||||
break
|
||||
|
||||
wrapped_user = WrappedUser(c.user, subreddit=c.site,
|
||||
wrapped_user = WrappedUser(user, subreddit=c.site,
|
||||
force_show_flair=True)
|
||||
|
||||
Templated.__init__(self, text=text, css_class=css_class,
|
||||
|
||||
@@ -701,12 +701,6 @@ ul.flat-vert {text-align: left;}
|
||||
}
|
||||
|
||||
.flairselector .error { text-align: center; }
|
||||
|
||||
.flairselector > div {
|
||||
height: 200px;
|
||||
overflow: auto;
|
||||
}
|
||||
|
||||
.flairselector ul { float: left; width: 200px; }
|
||||
|
||||
.flairselector .selected, .flairselector.active li {
|
||||
@@ -725,9 +719,11 @@ ul.flat-vert {text-align: left;}
|
||||
text-align: center;
|
||||
}
|
||||
|
||||
.flairselector .customizer { display: none; }
|
||||
.flairselector .customizer.texteditable { display: inline-block; }
|
||||
.flairoptionpane { height: 200px; overflow: auto; }
|
||||
|
||||
.flairselector .customizer { display: inline-block; }
|
||||
.flairselector .customizer input { display: block; }
|
||||
.flairselector .customizer button { display: inline !important; }
|
||||
|
||||
.media-button .option { color: red; }
|
||||
.media-button .option.active {
|
||||
|
||||
@@ -35,17 +35,20 @@ $(function() {
|
||||
var form = $(this).parent().parent().siblings("form").get(0);
|
||||
$(form).children('input[name="flair_template_id"]').val(this.id);
|
||||
var customizer = $(form).children(".customizer");
|
||||
var input = customizer.children("input");
|
||||
input.val($.trim($(this).children(".flair").text())).select();
|
||||
input.keyup(function() {
|
||||
$(".flairselection .flair").text($(input).val());
|
||||
});
|
||||
if ($(this).hasClass("texteditable")) {
|
||||
customizer.addClass("texteditable");
|
||||
var input = customizer.children("input");
|
||||
input.val($.trim($(this).children(".flair").text())).select();
|
||||
input.keyup(function() {
|
||||
$(".flairselection .flair").text($(input).val());
|
||||
});
|
||||
input.removeAttr("disabled");
|
||||
} else {
|
||||
customizer.removeClass("texteditable");
|
||||
input.attr("disabled", "disabled");
|
||||
}
|
||||
$(".flairselection").html($(this).first().children().clone());
|
||||
$(".flairselector button").removeAttr("disabled");
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -57,6 +60,7 @@ $(function() {
|
||||
|
||||
function openFlairSelector() {
|
||||
var button = this;
|
||||
var selector = $(button).siblings(".flairselector").get(0);
|
||||
|
||||
function columnize(col) {
|
||||
var min_cols = 1;
|
||||
@@ -77,36 +81,39 @@ $(function() {
|
||||
}
|
||||
var start = length - h;
|
||||
length -= h;
|
||||
var tail = $(col).children().slice(start).detach();
|
||||
var tail = $(col).children().slice(start).remove();
|
||||
$(col).after($("<ul>").append(tail));
|
||||
}
|
||||
return num_cols * 200 + 50;
|
||||
}
|
||||
|
||||
function handleResponse(r) {
|
||||
$(".flairselector").html(r);
|
||||
$(selector).html(r);
|
||||
|
||||
var width = columnize($(".flairselector ul"));
|
||||
var left = Math.max(
|
||||
100, $(button).position().left + $(button).width() - width);
|
||||
|
||||
$(".flairselector").width(width)
|
||||
.css("left",
|
||||
($(button).position().left + $(button).width() - width)
|
||||
+ "px");
|
||||
$(".flairselector li:not(.error)").click(selectFlairInSelector);
|
||||
$(".flairselector").click(function(e) { return false; });
|
||||
$(".flairselector form")
|
||||
$(selector).width(width).css("left", left + "px");
|
||||
$(selector).find("li:not(.error)").click(selectFlairInSelector);
|
||||
$(selector).click(function(e) { return false; });
|
||||
$(selector).find("form")
|
||||
.click(function(e) { e.stopPropagation(); });
|
||||
$(".flairselector form").submit(postFlairSelection);
|
||||
|
||||
$(".flairselector li.selected").each(selectFlairInSelector);
|
||||
$(selector).find("form").submit(postFlairSelection);
|
||||
$(selector).find(".customizer input").attr("disabled", "disabled");
|
||||
$(selector).find("button").attr("disabled", "disabled");
|
||||
$(selector).find("li.selected").each(selectFlairInSelector);
|
||||
}
|
||||
|
||||
$(".flairselector").html('<img src="/static/throbber.gif" />');
|
||||
$(".flairselector").addClass("active").width(18)
|
||||
$(selector).html('<img src="/static/throbber.gif" />');
|
||||
$(selector).addClass("active").width(18)
|
||||
.css("left",
|
||||
($(button).position().left + $(button).width() - 18) + "px")
|
||||
.css("top", $(button).position().top + "px");
|
||||
$.request("flairselector", {}, handleResponse, true, "html");
|
||||
|
||||
var name = $(selector).siblings("form").find("input").val();
|
||||
$.request("flairselector", {"name": name}, handleResponse, true,
|
||||
"html");
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
@@ -14,6 +14,9 @@ function close_menus(event) {
|
||||
.removeClass("inuse");
|
||||
$(".drop-choices.active").removeClass("active");
|
||||
|
||||
// Clear any flairselectors that may have been opened.
|
||||
$(".flairselector").empty();
|
||||
|
||||
/* hide the search expando if the user clicks elsewhere on the page */
|
||||
if ($(event.target).closest("#search").length == 0) {
|
||||
$("#moresearchinfo").slideUp();
|
||||
|
||||
@@ -30,9 +30,6 @@ from r2.lib.pages import WrappedUser
|
||||
<form action="/post/flair" id="flair-${thing.user._id36}" method="post"
|
||||
class="medium-text flair-entry">
|
||||
<input type="hidden" name="name" value="${thing.user.name}" />
|
||||
<span class="tagline flaircell">
|
||||
${unsafe(WrappedUser(thing.user, force_show_flair=True).render())}
|
||||
</span>
|
||||
<span class="flaircell">
|
||||
<input type="text" size="32" maxlength="64" name="text"
|
||||
value="${thing.flair_text}" />
|
||||
@@ -46,4 +43,12 @@ from r2.lib.pages import WrappedUser
|
||||
${utils.error_field(('BAD_CSS_NAME', 'flair_css_class'), 'name')}
|
||||
${utils.error_field(('TOO_MUCH_FLAIR_CSS', 'flair_css_class'), 'name')}
|
||||
</form>
|
||||
<span class="tagline flaircell">
|
||||
${unsafe(WrappedUser(thing.user, force_show_flair=True).render())}
|
||||
<form>
|
||||
<input type="hidden" name="name" value="${thing.user.name}">
|
||||
</form>
|
||||
<a class="flairselectbtn" href="javascript://">select</a>
|
||||
<div class="flairselector drop-choices"></div>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
@@ -22,7 +22,7 @@
|
||||
|
||||
<h2>${_("select flair")}</h2>
|
||||
%if thing.choices and c.site.flair_self_assign_enabled:
|
||||
<div>
|
||||
<div class="flairoptionpane">
|
||||
<ul>
|
||||
%for choice in thing.choices:
|
||||
<%
|
||||
@@ -40,6 +40,7 @@
|
||||
</div>
|
||||
<form action="/post/selectflair" method="post">
|
||||
<div class="flairselection"></div>
|
||||
<input type="hidden" name="name" value="${thing.wrapped_user.name}">
|
||||
<input type="hidden" name="flair_template_id">
|
||||
<div class="customizer">
|
||||
${_("customize text")}
|
||||
|
||||
@@ -35,7 +35,6 @@
|
||||
question = question, format = fmt, format_arg = "leave",
|
||||
hidden_data = dict(id = thing.sr._fullname))}
|
||||
</%def>
|
||||
|
||||
<div class="titlebox">
|
||||
<h1 class="hover redditname">
|
||||
${plain_link(thing.sr.name, thing.sr.path, _sr_path=False, _class="hover")}
|
||||
|
||||
Reference in New Issue
Block a user