Sha256: 265bfb7f4938d94a6a9b59839da88533939f8fe6c7eb642f896f4830014275bd

Contents?: true

Size: 1.37 KB

Versions: 6

Compression:

Stored size: 1.37 KB

Contents

class ScheduleAttributes::FormBuilder < Formtastic::FormBuilder

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

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

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

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

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

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

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

  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
end

Version data entries

6 entries across 6 versions & 2 rubygems

Version Path
dgp-schedule_attributes-0.5.3 lib/schedule_attributes/form_builder.rb
dgp-schedule_attributes-0.5.2 lib/schedule_attributes/form_builder.rb
dgp-schedule_attributes-0.5.1 lib/schedule_attributes/form_builder.rb
dgp-schedule_attributes-0.5.0 lib/schedule_attributes/form_builder.rb
dgp-schedule_attributes-0.4.0 lib/schedule_attributes/form_builder.rb
schedule_attributes-0.3.0 lib/schedule_attributes/form_builder.rb