Module: CamaleonCms::CommentHelper

Included in:
Admin::CommentsController
Defined in:
app/helpers/camaleon_cms/comment_helper.rb

Constant Summary collapse

LABELS =
{ 'approved' => 'success', 'pending' => 'warning', 'spam' => 'danger' }.freeze

Instance Method Summary collapse

Instance Method Details

#cama_comments_get_common_dataObject

return common data to save a new comment user_id, author, aothor_email, author_ip, approved, :agent



7
8
9
10
11
12
13
14
15
16
# File 'app/helpers/camaleon_cms/comment_helper.rb', line 7

def cama_comments_get_common_data
  comment_data = {}
  comment_data[:user_id] = cama_current_user.id
  comment_data[:author] = cama_current_user.the_name
  comment_data[:author_email] = cama_current_user.email
  comment_data[:author_IP] = request.remote_ip.to_s
  comment_data[:approved] = 'approved'
  comment_data[:agent] = request.user_agent.force_encoding('ISO-8859-1').encode('UTF-8')
  comment_data
end

#cama_comments_render_html(comments) ⇒ Object

render as html content all comments recursively comments: collection of comments



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
# File 'app/helpers/camaleon_cms/comment_helper.rb', line 20

def cama_comments_render_html(comments)
  comments.decorate.map do |comment|
    author = comment.the_author
    (:div, class: 'media') do
      [
        (:div, class: 'media-left') do
          link_to(author.the_admin_profile_url) do
            image_tag(author.the_avatar, class: 'media-object', style: 'width: 64px; height: 64px;')
          end
        end,
        (:div, class: 'media-body') do
          [
            (:h4, class: 'media-heading') do
              [
                author.the_name,
                ' ',
                (:small, comment.the_created_at),
                ' ',
                (:span, t("camaleon_cms.admin.comments.message.#{comment.approved}"),
                            class: "label label-#{LABELS[comment.approved]} pull-right")
              ].join.html_safe
            end,
            (:div, sanitize(comment.content), class: 'comment_content'),
            (:div, class: 'comment_actions') do
              [
                (:div, class: 'pull-left') do
                  [
                    link_to(
                      cama_admin_post_comment_answer_path(@post.id, comment.id),
                      data: { comment_id: comment.id },
                      title: t('camaleon_cms.admin.comments.tooltip.reply_comment'),
                      class: 'btn btn-info reply btn-xs ajax_modal'
                    ) { (:span, '', class: 'fa fa-mail-reply') },
                    ' ',
                    link_to(
                      { action: :destroy, id: comment.id },
                      method: :delete,
                      data: { confirm: t('camaleon_cms.admin.message.delete') },
                      class: 'btn btn-danger btn-xs cama_ajax_request',
                      title: t('camaleon_cms.admin.comments.tooltip.delete_comment')
                    ) { (:i, '', class: 'fa fa-trash-o') }
                  ].join.html_safe
                end,
                (:div, class: 'pull-right') do
                  [
                    link_to(
                      url_for({ action: :toggle_status, comment_id: comment.id, s: 'a' }),
                      title: t('camaleon_cms.admin.comments.tooltip.approved_comment'),
                      class: "#{comment.approved == 'approved' ? 'hidden' : ''} btn btn-success approve btn-xs cama_ajax_request"
                    ) { (:span, '', class: 'fa fa-thumbs-o-up') },
                    ' ',
                    link_to(
                      url_for({ action: :toggle_status, comment_id: comment.id, s: 'p' }),
                      title: t('camaleon_cms.admin.comments.tooltip.comment_pending'),
                      class: "#{comment.approved == 'pending' ? 'hidden' : ''} btn btn-primary pending btn-xs cama_ajax_request"
                    ) { (:span, '', class: 'fa fa-warning') },
                    ' ',
                    link_to(
                      url_for({ action: :toggle_status, comment_id: comment.id, s: 's' }),
                      title: t('camaleon_cms.admin.comments.tooltip.comment_spam'),
                      class: "#{comment.approved == 'spam' ? 'hidden' : ''} btn btn-danger spam btn-xs cama_ajax_request"
                    ) { (:span, '', class: 'fa fa-bug') }
                  ].join.html_safe
                end
              ].join.html_safe
            end,
            (:hr),
            (:div, '', class: 'clearfix'),
            cama_comments_render_html(comment.children)
          ].join.html_safe
        end
      ].join.html_safe
    end
  end.join('').html_safe
end