Files
nairobi/app/helpers/comments_helper.rb
2017-01-17 15:42:42 +01:00

72 lines
1.8 KiB
Ruby

module CommentsHelper
def comment_tree_title_text(commentable)
if commentable.class == Legislation::Question
t("legislation.questions.comments.comments_title")
else
t("comments_helper.comments_title")
end
end
def leave_comment_text(commentable)
if commentable.class == Legislation::Question
t("legislation.questions.comments.form.leave_comment")
else
t("comments.form.leave_comment")
end
end
def comment_link_text(parent_id)
parent_id.present? ? t("comments_helper.reply_link") : t("comments_helper.comment_link")
end
def comment_button_text(parent_id, commentable)
if commentable.class == Legislation::Question
parent_id.present? ? t("comments_helper.reply_button") : t("legislation.questions.comments.comment_button")
else
parent_id.present? ? t("comments_helper.reply_button") : t("comments_helper.comment_button")
end
end
def parent_or_commentable_dom_id(parent_id, commentable)
parent_id.blank? ? dom_id(commentable) : "comment_#{parent_id}"
end
def child_comments_of(parent)
if @comment_tree.present?
@comment_tree.ordered_children_of(parent)
else
parent.children
end
end
def commentable_path(comment)
if comment.commentable_type == "Budget::Investment"
budget_investment_path(comment.commentable.budget_id, comment.commentable)
else
comment.commentable
end
end
def user_level_class(comment)
if comment.as_administrator?
"is-admin"
elsif comment.as_moderator?
"is-moderator"
elsif comment.user.official?
"level-#{comment.user.official_level}"
else
"" # Default no special user class
end
end
def comment_author_class(comment, author_id)
if comment.user_id == author_id
"is-author"
else
"" # Default not author class
end
end
end