Module: ActiveScaffold::Helpers::UpdateColumnHelpers

Defined in:
lib/active_scaffold/helpers/update_column_helpers.rb

Overview

Helpers that assist with the rendering of a Form Column

Instance Method Summary collapse

Instance Method Details

#active_scaffold_update_for(column, scope = nil, options = {}) ⇒ Object

This method decides which input to use for the given column. It does not do any rendering. It only decides which method is responsible for rendering.



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/active_scaffold/helpers/update_column_helpers.rb', line 7

def active_scaffold_update_for(column, scope = nil, options = {})
  options = active_scaffold_input_options(column, scope, options)
  options.delete(:required)

  # first, check if the dev has created an override for this specific field for search
  if (method = override_update_field(column))
    send(method, options[:object], options)
  # second, check if the dev has specified a valid form_ui for this column, using specific ui for searches
  elsif column.form_ui and (method = override_update(column.form_ui))
    send(method, column, options)
 elsif column.column and column.form_ui.nil? and (method = override_update(column.column.type))
    send(method, column, options)
  else
    active_scaffold_update_generic_operators_select(column, options)<< ' ' << active_scaffold_render_input(column, options.merge(:name => "record[#{column.name}][value]"))
  end
end

#active_scaffold_update_generic_operators(column) ⇒ Object



24
25
26
27
28
29
30
# File 'lib/active_scaffold/helpers/update_column_helpers.rb', line 24

def active_scaffold_update_generic_operators(column)
  operators = ActiveScaffold::Actions::BatchUpdate::GenericOperators.collect {|comp| [as_(comp.downcase.to_sym), comp]}
  if column.column.nil? || column.column.null
    operators << [as_(:null), 'NULL']
  end
  operators
end

#active_scaffold_update_generic_operators_select(column, options) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/active_scaffold/helpers/update_column_helpers.rb', line 32

def active_scaffold_update_generic_operators_select(column, options)
  current = {:operator => 'NO_UPDATE'}
  current.merge!(batch_update_values[column.name][:value].symbolize_keys) if batch_update_values[column.name] && batch_update_values[column.name][:value]
  select_tag("[record][#{column.name}][operator]",
        options_for_select(active_scaffold_update_generic_operators(column), current[:operator]),
        :id => "#{options[:id]}_operator",
        :class => "as_batch_update_operator text_input")
end

#active_scaffold_update_numeric(column, options) ⇒ Object Also known as: active_scaffold_update_integer, active_scaffold_update_decimal, active_scaffold_update_float



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/active_scaffold/helpers/update_column_helpers.rb', line 41

def active_scaffold_update_numeric(column, options)
  current = {:value => nil, :opt => 'ABSOLUTE', :operator => 'NO_UPDATE'}
  current.merge!(batch_update_values[column.name][:value].symbolize_keys) if batch_update_values[column.name] && batch_update_values[column.name][:value]
  operator_options = active_scaffold_update_generic_operators(column) + ActiveScaffold::Actions::BatchUpdate::NumericOperators.collect {|comp| [as_(comp.downcase.to_sym), comp]}
  select_options = ActiveScaffold::Actions::BatchUpdate::NumericOptions.collect {|comp| [as_(comp.downcase.to_sym), comp]}
  html = select_tag("[record][#{column.name}][operator]",
        options_for_select(operator_options, current[:operator]),
        :id => "#{options[:id]}_operator",
        :class => "as_update_numeric_option")
  html << ' ' << text_field_tag("[record][#{column.name}][value]", current[:value], active_scaffold_input_text_options)
  html << ' ' << select_tag("[record][#{column.name}][opt]",
        options_for_select(select_options, current[:opt]),
        :id => "#{options[:id]}_opt",
        :class => "as_update_numeric_option")
  html
end

#active_scaffold_update_scope_select(select_options = active_scaffold_update_scope_select_options) ⇒ Object



61
62
63
64
65
66
67
68
69
# File 'lib/active_scaffold/helpers/update_column_helpers.rb', line 61

def active_scaffold_update_scope_select(select_options = active_scaffold_update_scope_select_options)
  if select_options.length > 1
    select_tag("batch_scope",
               options_for_select(select_options, batch_scope || select_options.last[1]),
               :class => "text_input")
  else
    hidden_field_tag("batch_scope", select_options.first[1]) unless select_options.empty?
  end
end

#active_scaffold_update_scope_select_optionsObject



71
72
73
74
75
76
# File 'lib/active_scaffold/helpers/update_column_helpers.rb', line 71

def active_scaffold_update_scope_select_options
  select_options = []
  select_options << [as_(:listed), 'LISTED'] if active_scaffold_config.batch_update.list_mode_enabled
  select_options << [as_(:marked), 'MARKED'] if active_scaffold_config.actions.include?(:mark)
  select_options
end

#override_update(update_ui) ⇒ Object

the naming convention for overriding search input types with helpers



88
89
90
91
# File 'lib/active_scaffold/helpers/update_column_helpers.rb', line 88

def override_update(update_ui)
  method = "active_scaffold_update_#{update_ui}"
  method if respond_to? method
end

#override_update_field(column) ⇒ Object

the naming convention for overriding form fields with helpers



83
84
85
# File 'lib/active_scaffold/helpers/update_column_helpers.rb', line 83

def override_update_field(column)
  override_helper column, 'update_column'
end