Module: ActiveScaffold::Bridges::Shared::DateBridge::HumanConditionHelpers

Defined in:
lib/active_scaffold/bridges/shared/date_bridge.rb

Instance Method Summary collapse

Instance Method Details

#active_scaffold_human_condition_date_bridge(column, value) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/active_scaffold/bridges/shared/date_bridge.rb', line 81

def active_scaffold_human_condition_date_bridge(column, value)
  case value['opt']
  when 'RANGE'
    range_type, range = value['range'].downcase.split('_')
    format = active_scaffold_human_condition_date_bridge_range_format(range_type, range)
    from, = controller.class.date_bridge_from_to(column, value)
    "#{column.active_record_class.human_attribute_name(column.name)} = #{as_(value['range'].downcase).downcase} (#{I18n.l(from, :format => format)})"
  when 'PAST', 'FUTURE'
    from, to = controller.class.date_bridge_from_to(column, value)
    "#{column.active_record_class.human_attribute_name(column.name)} #{as_('BETWEEN'.downcase).downcase} #{I18n.l(from)} - #{I18n.l(to)}"
  else
    from, to = controller.class.date_bridge_from_to(column, value)
    "#{column.active_record_class.human_attribute_name(column.name)} #{as_(value['opt'].downcase).downcase} #{I18n.l(from)} #{value['opt'] == 'BETWEEN' ? '- ' + I18n.l(to) : ''}"
  end
end

#active_scaffold_human_condition_date_bridge_range_format(range_type, range) ⇒ Object



97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/active_scaffold/bridges/shared/date_bridge.rb', line 97

def active_scaffold_human_condition_date_bridge_range_format(range_type, range)
  case range
  when 'week'
    first_day_of_week = I18n.translate 'active_scaffold.date_picker_options.firstDay'
    if first_day_of_week == 1
      '%W %Y'
    else
      '%U %Y'
    end
  when 'month'
    '%b %Y'
  when 'year'
    '%Y'
  else
    I18n.translate 'date.formats.default'
  end
end