Module: ActiveScaffold::Bridges::Shared::DateBridge::SearchColumnHelpers

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

Instance Method Summary collapse

Instance Method Details

#active_scaffold_date_bridge_trend_tag(column, options, trend_options) ⇒ Object



42
43
44
45
46
47
48
# File 'lib/active_scaffold/bridges/shared/date_bridge.rb', line 42

def active_scaffold_date_bridge_trend_tag(column, options, trend_options)
  trend_controls = text_field_tag("#{options[:name]}[number]", trend_options[:number_value], :class => 'text-input', :size => 10, :autocomplete => 'off') << " " <<
  select_tag("#{options[:name]}[unit]",
   options_for_select(active_scaffold_search_date_bridge_trend_units(column), trend_options[:unit_value]),
   :class => 'text-input')
  ("span", trend_controls.html_safe, :id => "#{options[:id]}_trend", :class => "search-date-trend", :style => trend_options[:show] ? nil : "display: none")
end

#active_scaffold_search_date_bridge(column, options) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
# File 'lib/active_scaffold/bridges/shared/date_bridge.rb', line 6

def active_scaffold_search_date_bridge(column, options)
  current_search = {'from' => nil, 'to' => nil, 'opt' => 'BETWEEN',
                    'number' => 1, 'unit' => 'DAYS', 'range' => nil}
  current_search.merge!(options[:value]) unless options[:value].nil?
  tags = []
  tags << active_scaffold_search_date_bridge_comparator_tag(column, options, current_search)
  tags << active_scaffold_search_date_bridge_trend_tag(column, options, current_search)
  tags << active_scaffold_search_date_bridge_numeric_tag(column, options, current_search)
  tags << active_scaffold_search_date_bridge_range_tag(column, options, current_search)
  tags.join("&nbsp;").html_safe
end

#active_scaffold_search_date_bridge_comparator_options(column) ⇒ Object



18
19
20
21
# File 'lib/active_scaffold/bridges/shared/date_bridge.rb', line 18

def active_scaffold_search_date_bridge_comparator_options(column)
  select_options = ActiveScaffold::Finder::DateComparators.collect {|comp| [as_(comp.downcase.to_sym), comp]}
  select_options + ActiveScaffold::Finder::NumericComparators.collect {|comp| [as_(comp.downcase.to_sym), comp]}
end

#active_scaffold_search_date_bridge_comparator_tag(column, options, current_search) ⇒ Object



23
24
25
# File 'lib/active_scaffold/bridges/shared/date_bridge.rb', line 23

def active_scaffold_search_date_bridge_comparator_tag(column, options, current_search)
  select_tag("#{options[:name]}[opt]", options_for_select(active_scaffold_search_date_bridge_comparator_options(column),current_search['opt']), :id => "#{options[:id]}_opt", :class => "as_search_range_option as_search_date_time_option")
end

#active_scaffold_search_date_bridge_numeric_tag(column, options, current_search) ⇒ Object



27
28
29
30
31
32
33
# File 'lib/active_scaffold/bridges/shared/date_bridge.rb', line 27

def active_scaffold_search_date_bridge_numeric_tag(column, options, current_search)
  numeric_controls = "" << 
  active_scaffold_search_date_bridge_calendar_control(column, options, current_search, 'from') <<
  (:span, (" - " + active_scaffold_search_date_bridge_calendar_control(column, options, current_search, 'to')).html_safe,
    :id => "#{options[:id]}_between", :class => "as_search_range_between", :style => current_search['opt'] == 'BETWEEN' ? nil : "display: none")
  ("span", numeric_controls.html_safe, :id => "#{options[:id]}_numeric", :class => "search-date-numeric", :style => ActiveScaffold::Finder::NumericComparators.include?(current_search['opt']) ? nil : "display: none")
end

#active_scaffold_search_date_bridge_range_tag(column, options, current_search) ⇒ Object



56
57
58
59
60
61
# File 'lib/active_scaffold/bridges/shared/date_bridge.rb', line 56

def active_scaffold_search_date_bridge_range_tag(column, options, current_search)
  range_controls = select_tag("#{options[:name]}[range]", 
    options_for_select( ActiveScaffold::Finder::DateRanges.collect{|range| [as_(range.downcase.to_sym), range]}, current_search["range"]), 
   :class => 'text-input', :id => nil)
  ("span", range_controls.html_safe, :id => "#{options[:id]}_range", :class => "search-date-range", :style => (current_search['opt'] == 'RANGE') ? nil : "display: none")
end

#active_scaffold_search_date_bridge_trend_tag(column, options, current_search) ⇒ Object



35
36
37
38
39
40
# File 'lib/active_scaffold/bridges/shared/date_bridge.rb', line 35

def active_scaffold_search_date_bridge_trend_tag(column, options, current_search)
  active_scaffold_date_bridge_trend_tag(column, options, 
                                       {:number_value => current_search['number'],
                                        :unit_value => current_search["unit"],
                                        :show => (current_search['opt'] == 'PAST' || current_search['opt'] == 'FUTURE')})
end

#active_scaffold_search_date_bridge_trend_units(column) ⇒ Object



50
51
52
53
54
# File 'lib/active_scaffold/bridges/shared/date_bridge.rb', line 50

def active_scaffold_search_date_bridge_trend_units(column)
   options = ActiveScaffold::Finder::DateUnits.collect{|unit| [as_(unit.downcase.to_sym), unit]}
   options = ActiveScaffold::Finder::TimeUnits.collect{|unit| [as_(unit.downcase.to_sym), unit]} + options if column_datetime?(column)
   options
end

#column_datetime?(column) ⇒ Boolean



63
64
65
# File 'lib/active_scaffold/bridges/shared/date_bridge.rb', line 63

def column_datetime?(column)
  (!column.column.nil? && [:datetime, :time].include?(column.column.type))
end