Merge pull request #604 from shayonj/format-comments-partial

Refactored nested comments. Now using partial to load them
This commit is contained in:
Henne Vogelsang 2015-03-02 11:10:25 +01:00
commit 0894d9ec29
4 changed files with 28 additions and 26 deletions

View file

@ -56,3 +56,15 @@ fieldset {
}
.bootstrap-switch { height: 1.7em }
.comment-reply{
padding-top: 40px;
}
p.comment-body {
padding-top: 20px;
}
.well.comment-section {
padding-bottom: 40px;
}

View file

@ -146,31 +146,6 @@ module ApplicationHelper
end
end
# TODO Output better html
def format_comments(comment, padding = 0)
result = ''
result += "<div style='padding-left:#{padding}px'>"
result += "<div class='well'>"
result += "<b>#{comment.user.name}</b> <i>#{comment.created_at}</i><br><br>"
result += comment.body
result += "<br><div><a href='#' class='pull-right comment-reply-link'>Reply</a><br><br>"
result += "<div class='comment-reply'>"
result += "<form method='post' action='#{comment_admin_conference_event_path(@conference.short_title, comment.commentable_id)}'>"
result += "<input type=hidden name=parent value='#{comment.id}'/>"
result += "<input name='authenticity_token' type='hidden' value='#{form_authenticity_token}' />"
result += "<textarea name='comment'></textarea>"
result += "<button class='btn btn-primary pull-right' name='button' type='submit'>Add Reply</button>"
result += '</form></div></div>'
result += '</div>'
#result += edit_admin_conference_event_path(@conference.short_title, @event)
comment.children.each do |child|
result += format_comments(child, 50)
result += '</div>'
end
result
end
def event_types(conference)
all = conference.event_types.map { |et | et.title.pluralize }
first = all[0...-1]

View file

@ -0,0 +1,15 @@
%div{style: "padding-left:#{padding}px"}
.well.comment-section
%strong= comment.user.name
%i= comment.created_at
%p.comment-body= comment.body
%div
%a.pull-right.comment-reply-link{href: "#"} Reply
.comment-reply
= form_tag "#{comment_admin_conference_event_path(@conference.short_title, comment.commentable_id)}", method: :post do
%input{name: "parent", type: "hidden", value: "#{comment.id}"}
%input{name: "authenticity_token", type: "hidden", value: "#{form_authenticity_token}"}
%textarea{name: "comment"}
%button.btn.btn-primary.pull-right{name: "button", type: "submit"} Add Reply
- comment.children.each do |child|
= render "nested_comments", comment: child, padding: 50

View file

@ -141,4 +141,4 @@
%br
- @comments.each do |comment|
%div
= raw format_comments(comment)
= render "nested_comments", comment: comment, padding: 0