Class: Basepack::Forms::Edit

Inherits:
Base
  • Object
show all
Extended by:
RailsAdmin::I18nSupport
Defined in:
lib/basepack/forms/edit.rb

Direct Known Subclasses

BulkEdit, Diff

Instance Attribute Summary collapse

Attributes inherited from Base

#association_chain, #factory, #groups, #nested_in, #partial, #resource, #resource_class, #view

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Base

#build_from_factory, #chain, #chain_with_class, #configure, #content_for_field, #default_group, #field, #field_names, #fields, #fields_hash, #group, #has_field?, #hide_field, #hide_fields, #inspect, #inverse_of_nested_in?, #label, #label_plural, #new_form, #new_record?, #permit_params, #render_field, #sanitize_params, #show_fields, #show_only_fields, #translate, #visible_field, #visible_fields, #visible_groups, #with_resource

Constructor Details

#initialize(factory, chain, options = {}) ⇒ Edit

Returns a new instance of Edit.



29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/basepack/forms/edit.rb', line 29

def initialize(factory, chain, options = {})
  super
  @path = options[:path]
  @builder_default_options = {
    html:     { multipart: true, class: 'form-horizontal denser' },
    defaults: { input_html: { class: 'span6'} }
  }

  if options[:method].present?
    @builder_default_options[:method] = options[:method]
  end
end

Instance Attribute Details

#builder_default_optionsObject

Returns the value of attribute builder_default_options.



26
27
28
# File 'lib/basepack/forms/edit.rb', line 26

def builder_default_options
  @builder_default_options
end

#pathObject

Returns the value of attribute path.



27
28
29
# File 'lib/basepack/forms/edit.rb', line 27

def path
  @path
end

#simple_formObject (readonly)

Returns the value of attribute simple_form.



25
26
27
# File 'lib/basepack/forms/edit.rb', line 25

def simple_form
  @simple_form
end

Class Method Details

.data_picker_optionsObject



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/basepack/forms/edit.rb', line 9

def data_picker_options
  {
    dateFormat:        date_format, # TODO - without %d -> dd, ...
    dayNames:          day_names,
    dayNamesShort:     abbr_day_names,
    dayNamesMin:       abbr_day_names,
    firstDay:          "1",
    monthNames:        month_names,
    monthNamesShort:   abbr_month_names,
  }
end

Instance Method Details

#builderObject



50
51
52
# File 'lib/basepack/forms/edit.rb', line 50

def builder
  simple_form
end

#default_partialObject



46
47
48
# File 'lib/basepack/forms/edit.rb', line 46

def default_partial
  'forms/edit'
end

#render_field!(field) ⇒ Object



155
156
157
158
159
160
161
162
163
# File 'lib/basepack/forms/edit.rb', line 155

def render_field!(field)
  if field.read_only?
    simple_form.input field.name, label: field.label, hint: field.help, required: field.required? do
      field.pretty_value
    end
  else
    view.render field.partial, form: self, field: field
  end
end

#textfield_options(field) ⇒ Object



141
142
143
144
145
# File 'lib/basepack/forms/edit.rb', line 141

def textfield_options(field)
  options = (field.html_attributes || {}).dup
  options.reverse_merge!(@builder_default_options[:defaults][:input_html]) if @builder_default_options[:defaults]
  options
end

#with_simple_form(simple_form, &block) ⇒ Object



54
55
56
57
58
59
60
61
# File 'lib/basepack/forms/edit.rb', line 54

def with_simple_form(simple_form, &block)
  @simple_form = simple_form
  begin
    yield(self)
  ensure
    @simple_form = nil
  end
end