2
3
4
5
6
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
|
# File 'app/helpers/settings_helper.rb', line 2
def field(form, key, opts = {})
html = '<div class="form-group">'
case form.object.column_type(key)
when :hidden
return form.hidden_field(key)
when :boolean, :flag
html << form.check_box(key, {}, "true", "false")
html << " " html << h(form.label(key))
when :choice
html << h(form.label(key))
html << " " html << form.select(key, form.object.values_of(key), opts)
when :nested
child_data = form.object.class.children[key]
klass = child_data[:class]
options = child_data[:options]
children = form.object.send(key) || {"0" => {}}
children.each_pair do |index, child|
html << %Q!<div class="js-nested-column #{options[:multiple] ? "js-multiple" : ""} well well-sm">!
if options[:multiple]
html << %Q!<a class="btn btn-xs btn-default js-append">#{icon('fa-plus')}</a> !
html << %Q!<a class="btn btn-xs btn-default js-remove" style="display:none">#{icon('fa-minus')}</a> !
end
html << h(form.label(key))
form.fields_for("#{key}[#{index}]", klass.new(child)) do |ff|
klass::KEYS.each do |k|
html << field(ff, k)
end
end
html << "</div>"
end
else
html << h(form.label(key))
html << form.text_field(key, class: "form-control")
end
html << "</div>"
html.html_safe
end
|