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
56
57
58
|
# File 'app/helpers/exo/resources_helper.rb', line 15
def resource_input_for form, item, field
type = field.datum_type.to_sym
value = item.value_for field
if type == :markdown
render(
partial: 'exo/admin/application/fields/markdown',
locals: {form: form, field: field, value: value}
)
elsif [:image, :file].include?(type)
render(
partial: 'exo/admin/application/fields/' + (type == :image ? 'image' : 'file'),
locals: {form: form, field: field, value: value}
)
else
options = {}
html = options[:input_html] = {}
options[:required] = field.required
options[:required] = false if !item.new_record?
options[:label] = field.name
case field
when Exo::Resource::MetaValue
html[:class] = TYPE_CLASS[type] if TYPE_CLASS[type]
options[:as] = TYPE_CONVERSION[type]
hash = type == :text ? html : options
if value.blank?
hash[:value] = field.default
else
hash[:value] = value.form_value
end
when Exo::Resource::MetaRelation
_resource = exo_site.resource_name field.resource_slug_id
options[:selected] = item.value_for(field).form_value
options[:include_blank] = false
options[:collection] = _resource.items.asc(:name).collect {|i| [i.name, i.id.to_s]}
html[:multiple] = true
end
form.input field.slug_id, options
end
end
|