Class: Avo::Fields::DatetimeField

Inherits:
DateField show all
Defined in:
lib/avo/app/fields/datetime_field.rb

Instance Attribute Summary

Attributes inherited from Field

#block, #component, #computable, #default, #format_using, #help, #id, #is_array_param, #is_object_param, #name, #null_values, #nullable, #placeholder, #readonly, #required, #sortable, #updatable

Attributes included from FieldExtensions::VisibleOnDifferentViews

#show_on_create, #show_on_edit, #show_on_index, #show_on_show

Instance Method Summary collapse

Methods inherited from Field

#database_id, #fetch_for_action, #fetch_for_resource, #fill_field, #has_own_panel?, #resolve_attribute

Methods included from FieldExtensions::HasFieldName

#field_name, #field_name_attribute, #get_field_name

Methods included from FieldExtensions::VisibleOnDifferentViews

#except_on, #hide_on, #only_on, #show_on

Constructor Details

#initialize(name, **args, &block) ⇒ DatetimeField

Returns a new instance of DatetimeField.



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/avo/app/fields/datetime_field.rb', line 6

def initialize(name, **args, &block)
  @defaults = {
    sortable: true,
    component: 'datetime-field',
  }

  super(name, **args, &block)

  @picker_format = args[:picker_format].present? ? args[:picker_format] : 'Y-m-d H:i:S'
  @format = args[:format].present? ? args[:format] : 'YYYY-MM-DD hh:mm:ss A'
  @time_24hr = args[:time_24hr].present? ? args[:time_24hr] : false
  @timezone = args[:timezone].present? ? args[:timezone] : Rails.application.config.time_zone
end

Instance Method Details

#hydrate_field(fields, model, resource, view) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/avo/app/fields/datetime_field.rb', line 20

def hydrate_field(fields, model, resource, view)
  {
    first_day_of_week: @first_day_of_week,
    picker_format: @picker_format,
    format: @format,
    placeholder: @placeholder,
    enable_time: true,
    time_24hr: @time_24hr,
    timezone: @timezone,
    relative: @relative,
  }
end