Class: ScheduleAttributes::FormBuilder

Inherits:
Formtastic::FormBuilder
  • Object
show all
Defined in:
lib/schedule_attributes/form_builder.rb

Instance Method Summary collapse

Instance Method Details

#hiding_field_options(class_name, hidden = false, options = {}) ⇒ Object



35
36
37
38
39
40
41
# File 'lib/schedule_attributes/form_builder.rb', line 35

def hiding_field_options(class_name, hidden=false, options={})
  hidden_style = "display: none" if hidden
  options.tap do |o|
    o.merge!(style: [o[:style], hidden_style].compact.join('; '))
    o.merge!(class: [o[:class], class_name].compact.join(' '))
  end
end

#one_time_fields(options = {}, &block) ⇒ Object



15
16
17
18
# File 'lib/schedule_attributes/form_builder.rb', line 15

def one_time_fields(options={}, &block)
  hidden = object.repeat.to_i == 1
  @template. :div, hiding_field_options("schedule_one_time_fields", hidden, options), &block
end

#ordinal_fields(options = {}, &block) ⇒ Object



25
26
27
28
# File 'lib/schedule_attributes/form_builder.rb', line 25

def ordinal_fields(options={}, &block)
  hidden = object.interval_unit == 'month' && object.by_day_of == 'week'
  @template. :div, hiding_field_options("schedule_ordinal_fields", hidden, options), &block
end

#ordinal_month_daysObject



7
8
9
# File 'lib/schedule_attributes/form_builder.rb', line 7

def ordinal_month_days
  (1..31).map { |d| [d.ordinalize, d] }
end

#ordinal_month_weeksObject



11
12
13
# File 'lib/schedule_attributes/form_builder.rb', line 11

def ordinal_month_weeks
  Hash["first", 1, "second", 2, "third", 3, "fourth", 4, "last", -1]
end

#repeat_fields(options = {}, &block) ⇒ Object



20
21
22
23
# File 'lib/schedule_attributes/form_builder.rb', line 20

def repeat_fields(options={}, &block)
  hidden = object.repeat.to_i != 1
  @template. :div, hiding_field_options("schedule_repeat_fields", hidden, options), &block
end

#weekday_fields(options = {}, &block) ⇒ Object



30
31
32
33
# File 'lib/schedule_attributes/form_builder.rb', line 30

def weekday_fields(options={}, &block)
  hidden = false
  @template. :div, hiding_field_options("schedule_weekday_fields", hidden, options), &block
end

#weekdaysObject



3
4
5
# File 'lib/schedule_attributes/form_builder.rb', line 3

def weekdays
  Hash[ I18n.t('date.day_names').zip(ScheduleAttributes::DAY_NAMES) ]
end