diff --git a/app/assets/javascripts/application.js.erb.coffee b/app/assets/javascripts/application.js.erb.coffee index d2e158df..dac8fcc4 100644 --- a/app/assets/javascripts/application.js.erb.coffee +++ b/app/assets/javascripts/application.js.erb.coffee @@ -154,6 +154,21 @@ $(document).on "click", "button[name=ab-smile]", -> btn[0].dataset.action = 'smile' btn.html "" +$(document).on "click", "button[name=ab-comments]", -> + btn = $(this) + aid = btn[0].dataset.aId + state = btn[0].dataset.state + commentBox = $("#ab-comments-#{aid}") + + switch state + when 'hidden' + commentBox.slideDown() + btn[0].dataset.state = 'shown' + when 'shown' + commentBox.slideUp() + btn[0].dataset.state = 'hidden' + + $(document).on "click", "button[name=user-action]", -> btn = $(this) btn.button "loading" diff --git a/app/views/shared/_answerbox.html.haml b/app/views/shared/_answerbox.html.haml index 602a0878..78babfce 100644 --- a/app/views/shared/_answerbox.html.haml +++ b/app/views/shared/_answerbox.html.haml @@ -29,3 +29,5 @@ .row .col-md-6.col-md-offset-6.col-sm-8.col-sm-offset-4.col-xs-6.col-xs-offset-6.text-right = render 'shared/answerbox_buttons', a: a + .panel-footer{id: "ab-comments-#{a.id}", style: 'display: none'} + = render 'shared/comments', comments: a.comments diff --git a/app/views/shared/_answerbox_buttons.html.haml b/app/views/shared/_answerbox_buttons.html.haml index 6e8cfa0f..c54fd0a6 100644 --- a/app/views/shared/_answerbox_buttons.html.haml +++ b/app/views/shared/_answerbox_buttons.html.haml @@ -8,8 +8,9 @@ - else %button.btn.btn-info.btn-sm{type: :button, name: 'ab-smile', 'data-a-id' => a.id, 'data-action' => 'smile'} %i.fa.fa-smile-o -%a.btn.btn-primary.btn-sm +%button.btn.btn-primary.btn-sm{type: :button, name: 'ab-comments', 'data-a-id' => a.id, 'data-state' => :hidden} %i.fa.fa-comments + %span{id: "ab-comment-count-#{a.id}"}= a.comment_count - if privileged? a.user %button.btn.btn-danger.btn-sm{name: 'ab-destroy', 'data-a-id' => a.id} %i.fa.fa-trash-o \ No newline at end of file diff --git a/app/views/shared/_comments.html.haml b/app/views/shared/_comments.html.haml new file mode 100644 index 00000000..51c43158 --- /dev/null +++ b/app/views/shared/_comments.html.haml @@ -0,0 +1,8 @@ +- if comments.all.count == 0 + There are no comments yet. +- else # TODO: some design guy (i.e. pixeldesu) should make some black magic here + %ul + - comments.all.each do |comment| + %li + #{user_screen_name comment.user}: + = comment.content \ No newline at end of file