Class: Edgarj::FormDrawer::Search
- Defined in:
- app/helpers/edgarj/form_drawer.rb
Overview
Search-class differs from Base-class as follows:
-
draws the fields of ID, created_at, and updated_at for search
-
‘kind’ selection has blank-option.
-
boolean is not checkbox. Rather, it is selection of [nil,false,true]
-
edgarj_file column is not drawn.
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#_draw_belongs_to_field(parent_model, col) ⇒ Object
overwrite to draw ‘belongs_to’ field for SearchForm.
-
#_draw_head(col, label = nil, &block) ⇒ Object
overwrite to insert operator.
-
#columns ⇒ Object
overwrite.
-
#draw_address(col) ⇒ Object
overwrite to draw address fields: TBD.
-
#draw_boolean(col) ⇒ Object
overwrite because it is totally different from checkbox on search.
-
#draw_created_at(col) ⇒ Object
overwrite to draw created_at.
-
#draw_enum(col, enum) ⇒ Object
overwrite to add ‘(all)’ at top of enum selection for search.
-
#draw_file(col) ⇒ Object
overwrite to disable file upload column.
-
#draw_id(col) ⇒ Object
overwrite to draw ‘id’ search field.
-
#draw_updated_at(col) ⇒ Object
overwrite to draw updated_at.
-
#edgarj_address?(col) ⇒ Boolean
overwrite.
-
#edgarj_file?(col) ⇒ Boolean
overwrite.
-
#get_enum(col) ⇒ Object
overwrite to return enum of the column in SearchForm.
-
#initialize(drawer, model, f, operator_builder) ⇒ Search
constructor
INPUTS drawer:: Edgarj::Drawer instance model:: SearchForm object f:: FormBuilder object operator_builder:: FormBuilder object for operator.
Methods inherited from Base
#_draw_2_lane, #_draw_field, #draw, #draw_bitset, #draw_field, #draw_type, #get_bitset
Constructor Details
#initialize(drawer, model, f, operator_builder) ⇒ Search
INPUTS
- drawer
-
Edgarj::Drawer instance
- model
-
SearchForm object
- f
-
FormBuilder object
- operator_builder
-
FormBuilder object for operator
202 203 204 205 206 207 208 209 |
# File 'app/helpers/edgarj/form_drawer.rb', line 202 def initialize(drawer, model, f, operator_builder) super(drawer, model, f) @operator_builder = operator_builder # merge options [:kind].merge!(:include_blank=>true) [:default][:date].merge!(:include_blank=>true) end |
Instance Method Details
#_draw_belongs_to_field(parent_model, col) ⇒ Object
overwrite to draw ‘belongs_to’ field for SearchForm
This is similar to Base class ‘belongs_to field’, but
-
add parent ‘name’ hidden field at drawing.
-
no link on parent name
274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 |
# File 'app/helpers/edgarj/form_drawer.rb', line 274 def _draw_belongs_to_field(parent_model, col) model = @f.object._klass_str.constantize parent_name = @f.object._parent && @f.object._parent[col.name] _draw_head(col, @vc.draw_belongs_to_label(@f, @drawer.popup_path_on_search(col), col.name, model)){ popup_field = Edgarj::PopupHelper::PopupField.new_builder( @f.object_name, col.name) @vc.content_tag(:span, parent_name, id: popup_field.label_target) + @vc.hidden_field_tag( 'edgarj_search_form[search_form_parent][%s]' % col.name, parent_name.blank? ? '' : parent_name, id: popup_field.label_hidden_field) + @vc.draw_belongs_to_clear_link(@f, col.name, popup_field, parent_name, '[' + @vc.draw_belongs_to_label_sub(model, col.name, parent_model) + ']') } end |
#_draw_head(col, label = nil, &block) ⇒ Object
overwrite to insert operator
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 |
# File 'app/helpers/edgarj/form_drawer.rb', line 229 def _draw_head(col, label=nil, &block) _draw_2_lane{ sprintf("<th>%s</th><td>", label || @vc.column_label(col)).html_safe + # add operator for appropreate data type. if col.name == 'id' @vc.draw_search_operator(@operator_builder, '_id') else case col.type when :date, :datetime, :integer @vc.draw_search_operator(@operator_builder, col.name) else '' end end + '</td><td>'.html_safe + yield + '</td>'.html_safe } end |
#columns ⇒ Object
overwrite
212 213 214 215 |
# File 'app/helpers/edgarj/form_drawer.rb', line 212 def columns drawer = @vc.drawer drawer.columns_for(drawer.search_form_columns, :search_form) end |
#draw_address(col) ⇒ Object
overwrite to draw address fields: TBD
263 264 265 266 267 |
# File 'app/helpers/edgarj/form_drawer.rb', line 263 def draw_address(col) _draw_head(col){ 'TBD' } end |
#draw_boolean(col) ⇒ Object
overwrite because it is totally different from checkbox on search.
293 294 295 296 297 298 299 300 |
# File 'app/helpers/edgarj/form_drawer.rb', line 293 def draw_boolean(col) _draw_head(col){ @f.select(col.name, [ ['(both)', ''], ['', 'false'], ['√', 'true']]) } end |
#draw_created_at(col) ⇒ Object
overwrite to draw created_at
253 254 255 |
# File 'app/helpers/edgarj/form_drawer.rb', line 253 def draw_created_at(col) _draw_head(col){ @vc.draw_date(@f, col, [:default]) } end |
#draw_enum(col, enum) ⇒ Object
overwrite to add ‘(all)’ at top of enum selection for search.
see overwritten get_enum() also.
312 313 314 315 316 317 318 319 |
# File 'app/helpers/edgarj/form_drawer.rb', line 312 def draw_enum(col, enum) _draw_head(col){ @vc.draw_enum(@f, col, enum, :choice_1st => ['(all)',''], :class => @record._klass_str.constantize ) } end |
#draw_file(col) ⇒ Object
overwrite to disable file upload column
322 323 324 |
# File 'app/helpers/edgarj/form_drawer.rb', line 322 def draw_file(col) '' end |
#draw_id(col) ⇒ Object
overwrite to draw ‘id’ search field
248 249 250 |
# File 'app/helpers/edgarj/form_drawer.rb', line 248 def draw_id(col) _draw_head(col){ @f.text_field('_id', [:default][:integer]) } end |
#draw_updated_at(col) ⇒ Object
overwrite to draw updated_at
258 259 260 |
# File 'app/helpers/edgarj/form_drawer.rb', line 258 def draw_updated_at(col) _draw_head(col){ @vc.draw_date(@f, col, [:default]) } end |
#edgarj_address?(col) ⇒ Boolean
overwrite
218 219 220 |
# File 'app/helpers/edgarj/form_drawer.rb', line 218 def edgarj_address?(col) @record._klass_str.constantize.edgarj_address?(col) end |
#edgarj_file?(col) ⇒ Boolean
overwrite
223 224 225 |
# File 'app/helpers/edgarj/form_drawer.rb', line 223 def edgarj_file?(col) @record._klass_str.constantize.edgarj_file?(col) end |
#get_enum(col) ⇒ Object
overwrite to return enum of the column in SearchForm
see overwritten draw_enum() also.
305 306 307 |
# File 'app/helpers/edgarj/form_drawer.rb', line 305 def get_enum(col) @vc.get_enum(@record._klass_str.constantize, col) end |