## 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="utils.html" import="plain_link, pretty_button" />
<%!
from r2.lib.strings import strings
from r2.lib.promote import STATUS
%>
<%def name="banbuttons()">
%if thing.show_delete:
${ynbutton(_("delete"), _("deleted"), "del", "hide_thing")}
%endif
%if thing.show_indict:
${ynbutton(_("indict"), _("indicted"), "indict")}
%endif
%if thing.can_ban:
%if not getattr(thing.thing, "use_big_modbuttons", False):
%if not thing.show_spam:
${ynbutton(_("spam"), _("spammed"), "remove")}
${ynbutton(_("remove"), _("removed"), "remove", hidden_data=dict(spam=False))}
%endif
%if thing.show_approve:
${self.state_button("approve", _("approve"),
"return change_state(this, 'approve');", _("approved"))}
%endif
%endif
%elif thing.show_report:
${ynbutton(_("report"), _("reported"), "report", "hide_thing")}
%endif
%if thing.show_marknsfw:
${ynbutton(_("nsfw"), _("marked"), "marknsfw")}
%endif
%if thing.show_unmarknsfw:
${ynbutton(_("un-nsfw"), _("unmarked"), "unmarknsfw")}
%endif
%if not getattr(thing, 'promoted', None) and c.site.link_flair_position and thing.show_flair:
${_('flair')}
%endif
%def>
<%def name="distinguish_setter(name, value=None)">
${_(name)}
%def>
<%def name="distinguish()">
%if thing.show_distinguish:
%endif
%def>
<%def name="big_modbuttons(thing, kind)">
%if getattr(thing, "moderator_banned", None):
%elif thing._spam:
${pretty_button(_("confirm spam"), "big_mod_action", -2, "negative")}
${pretty_button(_("remove ham"), "big_mod_action", -1, "neutral")}
%else:
${pretty_button(_("spam"), "big_mod_action", -2, "negative")}
${pretty_button(_("remove"), "big_mod_action", -1, "neutral")}
%endif
%if getattr(thing, "approval_checkmark", None):
${pretty_button(_("reapprove %(obj)s") % dict(obj=kind),
"big_mod_action", 1, "positive")}
%else:
${pretty_button(_("approve %(obj)s") % dict(obj=kind),
"big_mod_action", 1, "positive")}
%endif
${_("spammed")}
${_("removed")}
${_("approved")}
%def>
<%def name="linkbuttons()">
%if thing.show_comments:
${self.comment_button("comment", thing.comment_label, thing.permalink,
_sr_path = (thing.promoted is None),
a_class = thing.commentcls,
newwindow = thing.new_window)}
%endif
%if thing.editable:
${self.simple_button(_("edit"), "edit_usertext", css_class="edit-usertext")}
%endif
% if c.user_is_loggedin or not g.read_only_mode:
${self.toggle_button("share-button", _("share"), _("cancel"),
"share", "cancelShare", login_required = True)}
% endif
%if thing.is_loggedin:
%if thing.saved:
${self.state_button("unsave", _("unsave"), \
"return change_state(this, 'unsave', unsave_thing);", _("unsaved"))}
%else:
${self.state_button("save", _("save"), \
"return change_state(this, 'save', save_thing);", _("saved"))}
%endif
%if thing.hidden:
${self.state_button("unhide", _("unhide"), \
"change_state(this, 'unhide', hide_thing);", _("unhidden"))}
%else:
${self.state_button("hide", _("hide"), \
"change_state(this, 'hide', hide_thing);", _("hidden"))}
%endif
%endif
${self.distinguish()}
${self.banbuttons()}
%if thing.promoted is not None:
%if thing.user_is_sponsor or thing.is_author:
${plain_link(_("edit"), thing.promo_url, _sr_path = False)}
%endif
%if c.user_is_sponsor:
${toggle_button("reject_promo", \
_("reject"), _("cancel"), \
"reject_promo", "cancel_reject_promo")}
%if thing.promote_status in (STATUS.unseen, STATUS.rejected):
${ynbutton(_("accept"), _("accepted"), "promote")}
%endif
%endif
%if thing.user_is_sponsor or thing.is_author:
${plain_link(_("traffic"), thing.traffic_url, _sr_path = False)}
%endif
%endif
%if getattr(thing.thing, "reveal_trial_info", False):
${_("deputy opinion:")}
${_("%d spam") % thing.thing.trial_info.get("spams", "?")}
/
${_("%d kosher") % thing.thing.trial_info.get("koshers", "?")}
%endif
%if thing.show_reports and not thing.show_spam:
${strings.reports % thing.thing.reported}
%endif
%if getattr(thing.thing, "use_big_modbuttons", False):
${big_modbuttons(thing.thing, "link")}
%endif
%def>
<%def name="commentbuttons()">
${self.bylink_button(_("permalink"), thing.permalink)}
%if c.profilepage:
${self.bylink_button(_("context"), thing.permalink + "?context=3")}
${self.comment_button("comment", _("full comments"),
thing.full_comment_path,
_sr_path = True,
a_class = None,
newwindow = thing.new_window)}
%endif
%if thing.deleted:
%if thing.parent_permalink and not thing.profilepage:
${self.bylink_button(_("parent"), thing.parent_permalink)}
%endif
%else:
%if not thing.profilepage:
%if thing.parent_permalink:
${self.bylink_button(_("parent"), thing.parent_permalink)}
%endif
%if thing.is_author:
${self.simple_button(_("edit"), "edit_usertext", css_class="edit-usertext")}
%endif
%endif
${self.banbuttons()}
${self.distinguish()}
%if not thing.profilepage and thing.can_reply:
${self.simple_button(_("reply {verb}"), "reply")}
%endif
%if thing.show_reports and not thing.show_spam:
${strings.reports % thing.thing.reported}
%endif
%if getattr(thing.thing, "use_big_modbuttons", False):
${big_modbuttons(thing.thing, "comment")}
%endif
%endif
%def>
<%def name="messagebuttons()">
%if thing.was_comment:
${self.bylink_button(_("context"), thing.permalink + "?context=3")}
%else:
${self.bylink_button(_("permalink"), thing.permalink)}
%endif
%if thing.recipient:
${self.banbuttons()}
%if not thing.was_comment and thing.thing.author_id != c.user._id and thing.thing.author_id not in c.user.enemies:
${ynbutton(_("block user"), _("blocked"), "block", "hide_thing")}
%endif
${self.state_button("unread", _("mark unread"), \
"return change_state(this, 'unread_message', unread_thing, true);", \
_("unread"))}
%endif
%if thing.can_reply:
${self.simple_button(_("reply {verb}"), "reply")}
%endif
%def>
##------------
<%def name="state_button(name, title, onclick, executed, clicked=False, a_class = '', fmt=None, fmt_param = '', hidden_data = {})">
<%def name="_link()" buffered="True">
${title}
%def>
<%
link = _link()
if fmt:
link = fmt % {fmt_param: link}
## preserve spaces before and after < & > for space compression
link = link.replace(" <", " <").replace("> ", "> ")
%>
%if clicked:
${executed}
%else:
%for key, value in hidden_data.iteritems():
%endfor
${unsafe(link)}
%endif
%def>
<%def name="ynbutton(title, executed, op, callback = 'null',
question = None,
format = '%(link)s',
format_arg = 'link',
hidden_data = {},
_class = '')">
<%
if question is None:
question = _("are you sure?")
link = (''
+ title + ' ')
link = format % {format_arg : link}
link = unsafe(link.replace(" <", " <").replace("> ", "> "))
%>
%for k, v in hidden_data.iteritems():
%endfor
${link}
${question}
${_("yes")}
/
${_("no")}
%def>
<%def name="simple_button(title, nameFunc, css_class='')">
${title}
%def>
<%def name="toggle_button(class_name, title, alt_title,
callback, cancelback,
css_class = '', alt_css_class = '',
reverse = False,
login_required = False,
style = '', )">
<%
if reverse:
callback, cancelback = cancelback, callback
title, alt_title = alt_title, title
css_class, alt_css_class = alt_css_class, css_class
extra_class = "login-required" if login_required else ""
%>
%if alt_title:
${alt_title}
%else:
%endif
%def>
### originally in commentbutton
<%def name="comment_button(name, link_text, link,\
_sr_path = True, a_class='', title='', newwindow = False)">
${plain_link(link_text, link,
_sr_path = _sr_path,
_class=a_class, title=title,
target='_blank' if newwindow else '_parent')}
%def>
<%def name="bylink_button(title, link)">
${plain_link(title, link, _class="bylink", rel="nofollow")}
%def>
<%def name="toggleable_label(class_name,
title, alt_title,
callback, cancelback,
reverse = False)">
<%
if reverse:
callback, cancelback = cancelback, callback
title, alt_title = alt_title, title
%>
${title}
${alt_title}
(
${_("toggle")}
)
%def>