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



70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/active_scaffold/bridges/shared/date_bridge.rb', line 70

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, to = 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



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/active_scaffold/bridges/shared/date_bridge.rb', line 86

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