Class: ActiveAdmin::Comments::Views::Comments

Inherits:
Views::Panel show all
Defined in:
lib/active_admin/comments/views/active_admin_comments.rb

Instance Method Summary collapse

Methods inherited from Views::Panel

#add_child

Methods inherited from ActiveAdmin::Component

#default_class_name, #initialize, #tag_name

Constructor Details

This class inherits a constructor from ActiveAdmin::Component

Instance Method Details

#build(record) ⇒ Object



11
12
13
14
15
# File 'lib/active_admin/comments/views/active_admin_comments.rb', line 11

def build(record)
  @record = record
  super(title_content, :for => record)
  build_comments
end

#build_comment(comment) ⇒ Object (protected)



38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/active_admin/comments/views/active_admin_comments.rb', line 38

def build_comment(comment)
  div :for => comment do
    div :class => "active_admin_comment_meta" do
      user_name = comment.author ? auto_link(comment.author) : "Anonymous"
      h4(user_name, :class => "active_admin_comment_author")
      span(pretty_format(comment.created_at))
    end
    div :class => "active_admin_comment_body" do
      simple_format(comment.body)
    end
    div :style => "clear:both;"
  end
end

#build_comment_formObject (protected)



66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/active_admin/comments/views/active_admin_comments.rb', line 66

def build_comment_form
  self << active_admin_form_for(ActiveAdmin::Comment.new, :url => comment_form_url, :html => {:class => "inline_form"}) do |form|
    form.inputs do
      form.input :resource_type, :value => ActiveAdmin::Comment.resource_type(@record), :as => :hidden
      form.input :resource_id, :value => @record.id, :as => :hidden
      form.input :body, :input_html => {:size => "80x8"}, :label => false
    end
    form.buttons do
      form.commit_button 'Add Comment'
    end
  end
end

#build_commentsObject (protected)



27
28
29
30
31
32
33
34
35
36
# File 'lib/active_admin/comments/views/active_admin_comments.rb', line 27

def build_comments
  if record_comments.count > 0
    record_comments.each do |comment|
      build_comment(comment)
    end
  else
    build_empty_message
  end
  build_comment_form
end

#build_empty_messageObject (protected)



52
53
54
55
56
# File 'lib/active_admin/comments/views/active_admin_comments.rb', line 52

def build_empty_message
  span :class => "empty" do
    "No comments yet."
  end
end

#comment_form_urlObject (protected)



58
59
60
61
62
63
64
# File 'lib/active_admin/comments/views/active_admin_comments.rb', line 58

def comment_form_url
  if active_admin_namespace.root?
    comments_path
  else
    send(:"#{active_admin_namespace.name}_comments_path")
  end
end

#default_id_for_prefixObject (protected)



79
80
81
# File 'lib/active_admin/comments/views/active_admin_comments.rb', line 79

def default_id_for_prefix
  'active_admin_comments_for'
end

#record_commentsObject (protected)



23
24
25
# File 'lib/active_admin/comments/views/active_admin_comments.rb', line 23

def record_comments
  @record_comments ||= ActiveAdmin::Comment.find_for_resource_in_namespace(@record, active_admin_namespace.name)
end

#title_contentObject (protected)



19
20
21
# File 'lib/active_admin/comments/views/active_admin_comments.rb', line 19

def title_content
  "Comments (#{record_comments.count})"
end