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
-
#active_scaffold_update_for(column, scope = nil, options = {}) ⇒ Object
This method decides which input to use for the given column.
- #active_scaffold_update_generic_operators(column) ⇒ Object
- #active_scaffold_update_generic_operators_select(column, options) ⇒ Object
- #active_scaffold_update_numeric(column, options) ⇒ Object (also: #active_scaffold_update_integer, #active_scaffold_update_decimal, #active_scaffold_update_float)
- #active_scaffold_update_scope_select(select_options = active_scaffold_update_scope_select_options) ⇒ Object
- #active_scaffold_update_scope_select_options ⇒ Object
-
#override_update(update_ui) ⇒ Object
the naming convention for overriding search input types with helpers.
-
#override_update_field(column) ⇒ Object
the naming convention for overriding form fields with helpers.
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 23 24 |
# File 'lib/active_scaffold/helpers/update_column_helpers.rb', line 7 def active_scaffold_update_for(column, scope = nil, = {}) = (column, scope, ) .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, [:object], ) # 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, ) elsif column.column and column.form_ui.nil? and (method = override_update(column.column.type)) send(method, column, ) else show_field = batch_update_values.dig(column.name, :value, :operator) == 'REPLACE' active_scaffold_update_generic_operators_select(column, ) << ' ' << active_scaffold_render_input(column, .merge(name: "record[#{column.name}][value]", style: ('display: none;' unless show_field))) end end |
#active_scaffold_update_generic_operators(column) ⇒ Object
26 27 28 29 30 31 32 |
# File 'lib/active_scaffold/helpers/update_column_helpers.rb', line 26 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
34 35 36 37 38 39 40 41 |
# File 'lib/active_scaffold/helpers/update_column_helpers.rb', line 34 def active_scaffold_update_generic_operators_select(column, ) current = {:operator => 'NO_UPDATE'} current.merge!(batch_update_values[column.name][:value].symbolize_keys) if batch_update_values.dig(column.name, :value) select_tag("record[#{column.name}][operator]", (active_scaffold_update_generic_operators(column), current[:operator]), :id => "#{[: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
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/active_scaffold/helpers/update_column_helpers.rb', line 43 def active_scaffold_update_numeric(column, ) 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] = active_scaffold_update_generic_operators(column) + ActiveScaffold::Actions::BatchUpdate::NumericOperators.collect {|comp| [as_(comp.downcase.to_sym), comp]} = ActiveScaffold::Actions::BatchUpdate::NumericOptions.collect {|comp| [as_(comp.downcase.to_sym), comp]} html = select_tag("record[#{column.name}][operator]", (, current[:operator]), :id => "#{[:id]}_operator", :class => "as_update_numeric_option") html << ' ' << text_field_tag("record[#{column.name}][value]", current[:value], ) html << ' ' << select_tag("record[#{column.name}][opt]", (, current[:opt]), :id => "#{[:id]}_opt", :class => "as_update_numeric_option") html end |
#active_scaffold_update_scope_select(select_options = active_scaffold_update_scope_select_options) ⇒ Object
63 64 65 66 67 68 69 70 71 |
# File 'lib/active_scaffold/helpers/update_column_helpers.rb', line 63 def active_scaffold_update_scope_select( = ) if .length > 1 select_tag("batch_scope", (, batch_scope || .last[1]), :class => "text_input") else hidden_field_tag("batch_scope", .first[1]) unless .empty? end end |
#active_scaffold_update_scope_select_options ⇒ Object
73 74 75 76 77 78 |
# File 'lib/active_scaffold/helpers/update_column_helpers.rb', line 73 def = [] << [as_(:listed), 'LISTED'] if active_scaffold_config.batch_update.list_mode_enabled << [as_(:marked), 'MARKED'] if active_scaffold_config.actions.include?(:mark) end |
#override_update(update_ui) ⇒ Object
the naming convention for overriding search input types with helpers
90 91 92 93 |
# File 'lib/active_scaffold/helpers/update_column_helpers.rb', line 90 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
85 86 87 |
# File 'lib/active_scaffold/helpers/update_column_helpers.rb', line 85 def override_update_field(column) override_helper column, 'update_column' end |