Module: EngineRoom::ContentHelper

Defined in:
app/helpers/engine_room/content_helper.rb

Instance Method Summary collapse

Instance Method Details

#field_to_form(field, element, form) ⇒ Object



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
# File 'app/helpers/engine_room/content_helper.rb', line 35

def field_to_form(field, element, form)
  html = form.label field.column, field.column.humanize

  case field.field_type
    when "hidden"
      html += form.hidden_field field.column 
    when "read_only"
      html += element[field.column]
    when "text_field"
      html += form.text_field field.column
    when "email_field"
      html += form.text_field field.column
    when "number_field"
      html += form.number_field field.column
    when "date_field"
      html += form.date_select field.column
    when "text_area"
      html += form.text_area field.column, :rows => 4
    when "boolean"
      html += form.check_box field.column
    when "enum"
      html += form.select field.column
    when "belongs_to"
      html += form.select field.column, options_for_belongs_to(field, element)
    when "paperclip_field"
      if element.respond_to?("#{field.column}_file_name")
        img_name = element["#{field.column}_file_name"]
        html += image_tag( element.send( field.column ).url, :title => img_name, :height => "50px" )
        html += (:p, "file name: #{img_name}")
      end
      html += form.file_field field.column
  end

  unless field.help.blank?
    html += (:i, field.help)
  end

  return (:div, html, :class => "field")
end

#field_to_overview(field, element, section, bt_section_name = nil, bt_id = nil) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'app/helpers/engine_room/content_helper.rb', line 11

def field_to_overview(field, element, section, bt_section_name=nil, bt_id=nil)
  html = element[field.column]
  if html.class.name == "Time"
    html = l( html, :format => :short )
  end

  case field.field_type
    when "paperclip_field"
      img_name = element["#{field.column}_file_name"]
      html = image_tag( element.send( field.column ).url, :title => img_name, :height => "50px" )
  end

  if field.overview_link
    link_options = {:controller => 'engine_room/content', :section_name => section.name, :id => element.id, :action => :edit}
    if bt_section_name && bt_id
      link_options[:bt_section] = bt_section_name
      link_options[:bt_id] = bt_id
    end
    html = link_to html, link_options
  end
  return (:td, html, nil, false)
end

#has_many_elements(element, target_model) ⇒ Object

get all elements that element has_many of (paginated)



76
77
78
79
80
81
82
83
84
# File 'app/helpers/engine_room/content_helper.rb', line 76

def has_many_elements(element, target_model)
  element.class.reflect_on_all_associations(:has_many).each do |assoc|
    if assoc.name.to_s == target_model.downcase.pluralize
      model = Object.const_get(target_model.singularize.camelize)
      return element.send(target_model.downcase.pluralize).paginate(:per_page => 10, :page => 1)
    end
  end
  return []
end

#sortable(column) ⇒ Object



4
5
6
7
8
# File 'app/helpers/engine_room/content_helper.rb', line 4

def sortable(column)
  css_class = column == sort_column ? "current #{sort_direction}" : nil
  direction = column == sort_column && sort_direction == "asc" ? "desc" : "asc"
  link_to column.titleize, {:sort => column, :direction => direction}, {:class => css_class}
end