7
8
9
10
11
12
13
14
15
16
17
18
19
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
|
# File 'lib/templates/helper.rb', line 7
def template_part_field(template_part, index, drafts_enabled = false)
field_html = []
if drafts_enabled
live_part_content = @page.part(template_part.name).try(:content) || '' rescue ''
live_field_name = "#{page_part_name(index)}[content]"
live_field_id = "page_parts_#{index}_content"
part_content = @page.part(template_part.name).try(:draft_content) || '' rescue ''
field_name = "#{page_part_name(index)}[draft_content]"
field_id = "page_parts_#{index}_draft_content"
field_html << hidden_field_tag(live_field_name, h(live_part_content), :id => live_field_id)
else
part_content = @page.part(template_part.name).try(:content) || '' rescue ''
field_name = "#{page_part_name(index)}[content]"
field_id = "page_parts_#{index}_content"
end
options = {:class => template_part.part_type.field_class,
:style => template_part.part_type.field_styles,
:id => field_id}.reject{ |k,v| v.blank? }
case template_part.part_type.field_type
when "text_area"
field_html << text_area_tag(field_name, part_content, options)
when "text_field"
field_html << text_field_tag(field_name, part_content, options)
when "radio_button"
options[:style] = "display:inline;margin-left:1em;"
options [:style] << template_part.part_type.field_styles if template_part.part_type.field_styles
field_html << "<span>"
options[:id] = "#{field_id}_true"
field_html << "—" + radio_button_tag(field_name, "true", part_content =~ /true/, options)
field_html << label_tag("True",nil,:style=>"display:inline;")
options[:id] = "#{field_id}_false"
field_html << radio_button_tag(field_name, "false", part_content !~ /true/, options)
field_html << label_tag("False",nil,:style=>"display:inline;")
field_html << "</span>"
when "hidden"
field_html << hidden_field_tag(field_name, part_content, options)
when "predefined"
field_html << hidden_field_tag(field_name, template_part.description, options)
end
field_html.join("\n")
end
|