Class: RailsAdmin::FormBuilder
- Inherits:
-
ActionView::Helpers::FormBuilder
- Object
- ActionView::Helpers::FormBuilder
- RailsAdmin::FormBuilder
show all
- Includes:
- NestedForm::BuilderMixin, ApplicationHelper
- Defined in:
- app/helpers/rails_admin/form_builder.rb
Instance Method Summary
collapse
#action, #actions, #authorized?, #breadcrumb, #bulk_menu, #capitalize_first_letter, #current_action?, #edit_user_link, #logout_method, #logout_path, #main_navigation, #menu_for, #navigation, #static_navigation, #wording_for
#abbr_day_names, #abbr_month_names, #date_format, #day_names, #month_names
Instance Method Details
#dom_id(field) ⇒ Object
87
88
89
90
91
92
93
94
|
# File 'app/helpers/rails_admin/form_builder.rb', line 87
def dom_id(field)
(@dom_id ||= {})[field.name] ||=
[
@object_name.to_s.gsub(/\]\[|[^-a-zA-Z0-9:.]/, '_').sub(/_$/, ''),
options[:index],
field.method_name,
].reject(&:blank?).join('_')
end
|
#dom_name(field) ⇒ Object
96
97
98
|
# File 'app/helpers/rails_admin/form_builder.rb', line 96
def dom_name(field)
(@dom_name ||= {})[field.name] ||= %(#{@object_name}#{options[:index] && "[#{options[:index]}]"}[#{field.method_name}]#{field.is_a?(Config::Fields::Association) && field.multiple? ? '[]' : ''})
end
|
#errors_for(field) ⇒ Object
54
55
56
|
# File 'app/helpers/rails_admin/form_builder.rb', line 54
def errors_for(field)
field.errors.present? ? @template.content_tag(:span, field.errors.to_sentence, class: 'help-inline') : ''.html_safe
end
|
#field_for(field) ⇒ Object
62
63
64
65
66
67
68
|
# File 'app/helpers/rails_admin/form_builder.rb', line 62
def field_for(field)
if field.read_only?
field.pretty_value.to_s.html_safe
else
field.render
end
end
|
#field_wrapper_for(field, nested_in) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
|
# File 'app/helpers/rails_admin/form_builder.rb', line 33
def field_wrapper_for(field, nested_in)
if field.label
unless nested_field_association?(field, nested_in)
@template.content_tag(:div, class: "control-group #{field.type_css_class} #{field.css_class} #{'error' if field.errors.present?}", id: "#{dom_id(field)}_field") do
label(field.method_name, capitalize_first_letter(field.label), class: 'control-label') + (field.nested_form ? field_for(field) : input_for(field))
end
end
else
field.nested_form ? field_for(field) : input_for(field)
end
end
|
#fieldset_for(fieldset, nested_in) ⇒ Object
22
23
24
25
26
27
28
29
30
31
|
# File 'app/helpers/rails_admin/form_builder.rb', line 22
def fieldset_for(fieldset, nested_in)
return unless (fields = fieldset.with(form: self, object: @object, view: @template, controller: @template.controller).visible_fields).length > 0
@template.content_tag :fieldset do
contents = []
contents << @template.content_tag(:legend, %(<i class="icon-chevron-#{(fieldset.active? ? 'down' : 'right')}"></i> #{fieldset.label}).html_safe, style: "#{fieldset.name == :default ? 'display:none' : ''}")
contents << @template.content_tag(:p, fieldset.help) if fieldset.help.present?
contents << fields.collect { |field| field_wrapper_for(field, nested_in) }.join
contents.join.html_safe
end
end
|
#generate(options = {}) ⇒ Object
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
# File 'app/helpers/rails_admin/form_builder.rb', line 6
def generate(options = {})
without_field_error_proc_added_div do
options.reverse_merge!(
action: @template.controller.params[:action],
model_config: @template.instance_variable_get(:@model_config),
nested_in: false,
)
object_infos +
visible_groups(options[:model_config], generator_action(options[:action], options[:nested_in])).collect do |fieldset|
fieldset_for fieldset, options[:nested_in]
end.join.html_safe +
(options[:nested_in] ? '' : @template.render(partial: 'rails_admin/main/submit_buttons'))
end
end
|
#help_for(field) ⇒ Object
58
59
60
|
# File 'app/helpers/rails_admin/form_builder.rb', line 58
def help_for(field)
field.help.present? ? @template.content_tag(:p, field.help, class: 'help-block') : ''.html_safe
end
|
46
47
48
49
50
51
52
|
# File 'app/helpers/rails_admin/form_builder.rb', line 46
def input_for(field)
@template.content_tag(:div, class: 'controls') do
field_for(field) +
errors_for(field) +
help_for(field)
end
end
|
#jquery_namespace(field) ⇒ Object
83
84
85
|
# File 'app/helpers/rails_admin/form_builder.rb', line 83
def jquery_namespace(field)
%(#{'#modal ' if @template.controller.params[:modal]}##{dom_id(field)}_field)
end
|
#object_infos ⇒ Object
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'app/helpers/rails_admin/form_builder.rb', line 70
def object_infos
model_config = RailsAdmin.config(object)
model_label = model_config.label
object_label = begin
if object.new_record?
I18n.t('admin.form.new_model', name: model_label)
else
object.send(model_config.object_label_method).presence || "#{model_config.label} ##{object.id}"
end
end
%(<span style="display:none" class="object-infos" data-model-label="#{model_label}" data-object-label="#{CGI.escapeHTML(object_label.to_s)}"></span>).html_safe
end
|