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



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

def active_scaffold_date_bridge_trend_tag(column, options, trend_options)
  trend_controls = text_field_tag("#{trend_options[:name_prefix]}[#{column.name}][number]", trend_options[:number_value], :class => 'text-input', :size => 10, :autocomplete => 'off') << " " <<
  select_tag("#{trend_options[:name_prefix]}[#{column.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", :style => "display:#{trend_options[:show] ? '' : '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 => "display:#{current_search['opt'] == 'BETWEEN' ? '' : 'none'}")  
  ("span", numeric_controls.html_safe, :id => "#{options[:id]}_numeric", :style => "display:#{ActiveScaffold::Finder::NumericComparators.include?(current_search['opt']) ? '' : 'none'}")
end

#active_scaffold_search_date_bridge_range_tag(column, options, current_search) ⇒ Object



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

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

#active_scaffold_search_date_bridge_trend_tag(column, options, current_search) ⇒ Object



35
36
37
38
39
40
41
# 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, 
                                       {:name_prefix => 'search',
                                        :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



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

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

Returns:

  • (Boolean)


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

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