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
59
60
61
62
63
64
|
# File 'app/helpers/custom_table/fieldset_helper.rb', line 17
def field column, **params, &block
defs = @template.custom_table_fields_definition_for_field(@object.class, column) rescue nil
params = {} if params.nil?
params = params.deep_merge(@params)
params[:editable] = true if params[:editable].nil?
params[:adaptive] = false if params[:adaptive].nil?
if params[:label].nil?
if !defs.nil? && !defs[:label].blank?
params[:label] = defs[:label]
else
params[:label] = @object.class.human_attribute_name(column)
end
end
params[:template] = "field" if params[:template].nil?
params[:column] = column
params[:object] = @object
hint_key = "simple_form.hints.#{@object.model_name.singular}.#{column}"
if I18n.exists?(hint_key)
params[:hint] = I18n.t(hint_key)
end
@template.render "custom_table/#{params[:template]}", **params do
if params[:editable] && has_editable?
params[:editable_params] = {} if params[:editable_params].nil?
editable_field = params[:editable_params][:field] || column
@template.editable @object, editable_field, **params[:editable_params] do
if block_given?
yield
else
@template.field_value_for(@object, column, definitions: defs)
end
end
else
if block_given?
yield
else
@template.field_value_for(@object, column, definitions: defs)
end
end
end
end
|