Module: ActiveScaffold::Helpers::SearchColumnHelpers
- Included in:
- ViewHelpers
- Defined in:
- lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/search_column_helpers.rb
Overview
Helpers that assist with the rendering of a Form Column
Instance Method Summary collapse
-
#active_scaffold_search_boolean(column, options) ⇒ Object
(also: #active_scaffold_search_checkbox)
we can’t use active_scaffold_input_boolean because we need to have a nil value even when column can’t be null to decide whether search for this field or not.
- #active_scaffold_search_date(column, options) ⇒ Object
-
#active_scaffold_search_datetime(column, options) ⇒ Object
(also: #active_scaffold_search_timestamp)
AST End.
-
#active_scaffold_search_for(column) ⇒ Object
This method decides which input to use for the given column.
-
#active_scaffold_search_multi_select(column, options) ⇒ Object
Search input methods.
-
#active_scaffold_search_options(column) ⇒ Object
the standard active scaffold options used for class, name and scope.
- #active_scaffold_search_range(column, options) ⇒ Object (also: #active_scaffold_search_decimal, #active_scaffold_search_float, #active_scaffold_search_integer, #active_scaffold_search_usa_money, #active_scaffold_search_string, #active_scaffold_search_text)
- #active_scaffold_search_record_select(column, options) ⇒ Object
- #active_scaffold_search_select(column, options) ⇒ Object
- #active_scaffold_search_time(column, options) ⇒ Object
- #active_scaffold_search_usa_state(column, options) ⇒ Object
-
#override_search(form_ui) ⇒ Object
the naming convention for overriding search input types with helpers.
- #override_search?(search_ui) ⇒ Boolean
-
#override_search_field(column) ⇒ Object
the naming convention for overriding form fields with helpers.
-
#override_search_field?(column) ⇒ Boolean
Search column override signatures.
- #search_session_column_multi_select_values(column) ⇒ Object
-
#search_session_column_range_values(column) ⇒ Object
AST Begin.
Instance Method Details
#active_scaffold_search_boolean(column, options) ⇒ Object Also known as: active_scaffold_search_checkbox
we can’t use active_scaffold_input_boolean because we need to have a nil value even when column can’t be null to decide whether search for this field or not
113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/search_column_helpers.rb', line 113 def active_scaffold_search_boolean(column, ) = [] << [as_(:_select_), nil] << [as_(:true), true] << [as_(:false), false] # AST Begin value = @record.send(column.name) value = value.blank? ? nil : (value ? 1 : 0) select_tag([:name], (, value)) # AST End end |
#active_scaffold_search_date(column, options) ⇒ Object
248 249 250 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/search_column_helpers.rb', line 248 def active_scaffold_search_date(column, ) active_scaffold_search_datetime(column, .merge!(:discard_time => true)) end |
#active_scaffold_search_datetime(column, options) ⇒ Object Also known as: active_scaffold_search_timestamp
AST End
239 240 241 242 243 244 245 246 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/search_column_helpers.rb', line 239 def active_scaffold_search_datetime(column, ) = column..merge() helper = "select_#{'date' unless [:discard_date]}#{'time' unless [:discard_time]}" html = [] html << send(helper, nil, {:include_blank => true, :prefix => "#{[:name]}[from]"}.merge()) html << send(helper, nil, {:include_blank => true, :prefix => "#{[:name]}[to]"}.merge()) html * ' - ' end |
#active_scaffold_search_for(column) ⇒ 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 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/search_column_helpers.rb', line 7 def active_scaffold_search_for(column) = (column) # check if the dev has created an override for this specific field for search if override_search_field?(column) # AST - I like column and options as params send(override_search_field(column), @record, column, ) # check if the dev has specified a valid search_ui for this column, using specific ui for searches elsif column.search_ui and override_search?(column.search_ui) send(override_search(column.search_ui), column, ) # check if the dev has specified a valid search_ui for this column, using generic ui for forms elsif column.search_ui and override_input?(column.search_ui) send(override_input(column.search_ui), column, ) # AST - my prefered order # check if the dev has created an override for this specific field elsif override_form_field?(column) # AST - I like column and options as params send(override_form_field(column), @record, column, ) # AST End # fallback: we get to make the decision else if column.association or column.virtual? active_scaffold_search_text(column, ) else # regular model attribute column # if we (or someone else) have created a custom render option for the column type, use that if override_search?(column.column.type) send(override_search(column.column.type), column, ) # if we (or someone else) have created a custom render option for the column type, use that elsif override_input?(column.column.type) send(override_input(column.column.type), column, ) # final ultimate fallback: use rails' generic input method else # for textual fields we pass different options text_types = [:text, :string, :integer, :float, :decimal] = () if text_types.include?(column.column.type) input(:record, column.name, .merge(column.)) end end end end |
#active_scaffold_search_multi_select(column, options) ⇒ Object
Search input methods
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/search_column_helpers.rb', line 62 def active_scaffold_search_multi_select(column, ) # AST not a big fan of checkboxes return active_scaffold_search_select(column, .merge(:multiple => true), ) # AST End = @record.send(column.association.name).collect {|r| [r.to_label, r.id]} = | (column.association, true) return as_(:no_options) if .empty? html = "<ul class=\"checkbox-list\" id=\"#{[:id]}\">" associated_ids = .collect {|a| a[1]} .each_with_index do |option, i| label, id = option this_name = "#{[:name]}[#{i}][id]" this_id = "#{[:id]}_#{i}_id" html << "<li>" html << check_box_tag(this_name, id, associated_ids.include?(id), :id => this_id) html << "<label for='#{this_id}'>" html << label html << "</label>" html << "</li>" end html << '</ul>' html << javascript_tag("new DraggableLists('#{[:id]}')") if column.[:draggable_lists] html end |
#active_scaffold_search_options(column) ⇒ Object
the standard active scaffold options used for class, name and scope
54 55 56 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/search_column_helpers.rb', line 54 def (column) { :name => "search[#{column.name}]", :class => "#{column.name}-input", :id => "search_#{column.name}"} end |
#active_scaffold_search_range(column, options) ⇒ Object Also known as: active_scaffold_search_decimal, active_scaffold_search_float, active_scaffold_search_integer, active_scaffold_search_usa_money, active_scaffold_search_string, active_scaffold_search_text
153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/search_column_helpers.rb', line 153 def active_scaffold_search_range(column, ) opt_value, from_value, to_value = search_session_column_range_values(column) html = [] # AST - give StringComparators labels = [:string].include?(column.column.type) ? ActiveScaffold::Finder::StringComparators.collect {|title, comp| [as_(title), comp]} : ActiveScaffold::Finder::NumericComparators.collect {|comp| [as_(comp), comp]} html << select_tag("#{[:name]}[opt]", (, opt_value), :id => "#{[:id]}_opt", :onchange => "Element[this.value == 'BETWEEN' ? 'show' : 'hide']('#{[:id]}_between');") html << text_field_tag("#{[:name]}[from]", from_value, (:id => [:id], :size => 10)) html << content_tag(:span, ' - ' + text_field_tag("#{[:name]}[to]", to_value, (:id => "#{[:id]}_to", :size => 10)), :id => "#{[:id]}_between", :style => to_value.blank? ? "display:none" : "") html * ' ' end |
#active_scaffold_search_record_select(column, options) ⇒ Object
183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/search_column_helpers.rb', line 183 def active_scaffold_search_record_select(column, ) begin value = @search_session_info[column.name] unless @search_session_info.nil? if column.plural_association? value.collect! {|id| Float(id) rescue nil ? id.to_i : id}.flatten if value @record.send("#{column.name}=", column.association.klass.find(value)) if value else if value.blank? value = nil else value = Float(value) rescue nil ? value.to_i : value value = column.association.klass.find(value) end @record.send("#{column.name}=", value) end rescue Exception => e logger.error Time.now.to_s + "Sorry, we are not that smart yet. Attempted to restore search values to search fields but instead got -- #{e.inspect} -- on the ActiveScaffold column = :#{column.name} in #{@controller.class}" raise e end unless column.association raise ArgumentError, "record_select can only work against associations (and #{column.name} is not). A common mistake is to specify the foreign key field (like :user_id), instead of the association (:user)." end remote_controller = File.join('/', active_scaffold_controller_for(column.association.klass).controller_path) # if the opposite association is a :belongs_to, then only show records that have not been associated yet params = {:parent_model => @record.class} = {:controller => remote_controller, :id => [:id], :params => params} .merge!() .merge!(column.) if column.singular_association? record_select_field([:name], (@record.send(column.name) || column.association.klass.new), ) elsif column.plural_association? record_multi_select_field([:name], @record.send(column.name), ) end end |
#active_scaffold_search_select(column, options) ⇒ Object
90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/search_column_helpers.rb', line 90 def active_scaffold_search_select(column, ) if column.association associated = @record.send(column.association.name) associated = associated.first if associated.is_a?(Array) # for columns with plural association = (column.association, true) .unshift([ associated.to_label, associated.id ]) unless associated.nil? or .find {|label, id| id == associated.id} selected = associated.nil? ? nil : associated.id method = column.association.macro == :belongs_to ? column.association.primary_key_name : column.name [:name] += '[id]' select(:record, method, .uniq, {:selected => selected, :include_blank => as_(:_select_)}, ) else select(:record, column.name, column., { :selected => @record.send(column.name) }, ) end end |
#active_scaffold_search_time(column, options) ⇒ Object
251 252 253 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/search_column_helpers.rb', line 251 def active_scaffold_search_time(column, ) active_scaffold_search_datetime(column, .merge!(:discard_date => true)) end |
#active_scaffold_search_usa_state(column, options) ⇒ Object
175 176 177 178 179 180 181 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/search_column_helpers.rb', line 175 def active_scaffold_search_usa_state(column, ) @record.send("#{column.name}=", search_session_column_multi_select_values(column)) = .delete(:size) .delete([:prompt, :priority]) usa_state_select(:record, column.name, column.[:priority], , column..merge!()) end |
#override_search(form_ui) ⇒ Object
the naming convention for overriding search input types with helpers
274 275 276 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/search_column_helpers.rb', line 274 def override_search(form_ui) "active_scaffold_search_#{form_ui}" end |
#override_search?(search_ui) ⇒ Boolean
269 270 271 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/search_column_helpers.rb', line 269 def override_search?(search_ui) respond_to?(override_search(search_ui)) end |
#override_search_field(column) ⇒ Object
the naming convention for overriding form fields with helpers
265 266 267 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/search_column_helpers.rb', line 265 def override_search_field(column) "#{column.name}_search_column" end |
#override_search_field?(column) ⇒ Boolean
Search column override signatures
260 261 262 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/search_column_helpers.rb', line 260 def override_search_field?(column) respond_to?(override_search_field(column)) end |
#search_session_column_multi_select_values(column) ⇒ Object
222 223 224 225 226 227 228 229 230 231 232 233 234 235 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/search_column_helpers.rb', line 222 def search_session_column_multi_select_values(column) begin value = @search_session_info[column.name] unless @search_session_info.nil? if value.is_a?(Hash) value = Float(value[:id]) rescue nil ? value[:id].to_i : value[:id] if value.has_key?(:id) else value.collect! {|id| Float(id) rescue nil ? id.to_i : id}.flatten if value end value rescue Exception => e logger.error Time.now.to_s + "Sorry, we are not that smart yet. Attempted to restore search values to search fields but instead got -- #{e.inspect} -- on the ActiveScaffold column = :#{column.name} in #{@controller.class}" # raise e end end |
#search_session_column_range_values(column) ⇒ Object
AST Begin
144 145 146 147 148 149 150 151 |
# File 'lib/six-updater-web/vendor/plugins/active_scaffold/lib/active_scaffold/helpers/search_column_helpers.rb', line 144 def search_session_column_range_values(column) search_ui = column.search_ui || column.column.type return nil if @search_session_info.nil? or search_ui.nil? values = @search_session_info[column.name] return nil, nil, nil if values.blank? return nil, values, nil unless values.is_a?(Array) return values[:opt], values[:from], values[:to] end |