Class: Edgar::FormDrawer::Search

Inherits:
Base
  • Object
show all
Defined in:
app/helpers/edgar/form_drawer.rb

Overview

SearchFormDrawer differs from FormDrawerBase 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]

  • edgar_file column is not drawn.

Instance Method Summary (collapse)

Methods inherited from Base

#_draw_2_lane, #_draw_field, #draw, #draw_bitset, #draw_type, #get_bitset

Constructor Details

- (Search) initialize(template, model, f, operator_builder)

INPUTS

template

view template to call helper

model

SearchForm object

f

FormBuilder object

operator_builder

FormBuilder object for operator



196
197
198
199
200
201
202
203
# File 'app/helpers/edgar/form_drawer.rb', line 196

def initialize(template, model, f, operator_builder)
  super(template, model, f)
  @operator_builder = operator_builder
  
  # merge options
  @options[:kind].merge!(:include_blank=>true)
  @options[:default][:date].merge!(:include_blank=>true)
end

Instance Method Details

- (Object) _draw_belongs_to_field(parent_model, col)

overwrite to draw 'belongs_to' field for SearchForm

It is almost the same as data entry 'belongs_to field', plus parent 'name' hidden field to re-used the value at drawing.



267
268
269
270
271
272
273
274
275
276
# File 'app/helpers/edgar/form_drawer.rb', line 267

def _draw_belongs_to_field(parent_model, col)
  model_class = @f.object._klass_str.constantize
  parent_obj  = @f.object._parent && @f.object._parent[col.name]
  _draw_head(col, @template.draw_belongs_to_label(@f, col.name, model_class)){
    @template.draw_belongs_to_field(@f, col.name, model_class) +
    @template.hidden_field_tag(
      'edgar_search_form[search_form_parent][%s]' % col.name,
      parent_obj.blank? ? '' : parent_obj)
  }
end

- (Object) _draw_head(col, label = nil, &block)

overwrite to insert operator



223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# File 'app/helpers/edgar/form_drawer.rb', line 223

def _draw_head(col, label=nil, &block)
  _draw_2_lane{
    sprintf("<th>%s</th><td>", label || @model.class.human_attribute_name(col.name)) +
    
    # add operator for appropreate data type.
    if col.name == 'id'
      @template.draw_search_operator(@operator_builder, '_id')
    else
      case col.type
      when :date, :datetime, :integer
        @template.draw_search_operator(@operator_builder, col.name)
      else
        ''
      end
    end + '</td><td>' + yield + '</td>'
  }
end

- (Object) columns

overwrite



206
207
208
209
# File 'app/helpers/edgar/form_drawer.rb', line 206

def columns
  m = @template.model_class
  m.columns_for(m.view_search_form_columns)
end

- (Object) draw_address(col)

overwrite to draw address fields: TBD



257
258
259
260
261
# File 'app/helpers/edgar/form_drawer.rb', line 257

def draw_address(col)
  _draw_head(col){
    'TBD'
  }
end

- (Object) draw_boolean(col)

overwrite because it is totally different from checkbox on search.



279
280
281
282
283
284
285
286
# File 'app/helpers/edgar/form_drawer.rb', line 279

def draw_boolean(col)
  _draw_head(col){
    @f.select(col.name, [
        ['(both)',  ''],
        ['',        'false'],
        ['',       'true']])
  }
end

- (Object) draw_created_at(col)

overwrite to draw created_at



247
248
249
# File 'app/helpers/edgar/form_drawer.rb', line 247

def draw_created_at(col)
  _draw_head(col){ @template.draw_date(@f, col, @options[:default]) }
end

- (Object) draw_enum(col, enum)

overwrite to add '(all)' at top of enum selection for search.

see overwritten get_enum() also.



298
299
300
301
302
303
304
305
# File 'app/helpers/edgar/form_drawer.rb', line 298

def draw_enum(col, enum)
  _draw_head(col){
    @template.draw_enum(@f, col, enum,
        :choice_1st => ['(all)',''],
        :class      => @model._klass_str.constantize
        )
  }
end

- (Object) draw_file(col)

overwrite to disable file upload column



308
309
310
# File 'app/helpers/edgar/form_drawer.rb', line 308

def draw_file(col)
  ''
end

- (Object) draw_id(col)

overwrite to draw 'id' search field



242
243
244
# File 'app/helpers/edgar/form_drawer.rb', line 242

def draw_id(col)
  _draw_head(col){ @f.text_field('_id', @options[:default][:integer]) }
end

- (Object) draw_updated_at(col)

overwrite to draw updated_at



252
253
254
# File 'app/helpers/edgar/form_drawer.rb', line 252

def draw_updated_at(col)
  _draw_head(col){ @template.draw_date(@f, col, @options[:default]) }
end

- (Boolean) edgar_address?(col)

overwrite

Returns:

  • (Boolean)


212
213
214
# File 'app/helpers/edgar/form_drawer.rb', line 212

def edgar_address?(col)
  @model._klass_str.constantize.edgar_address?(col)
end

- (Boolean) edgar_file?(col)

overwrite

Returns:

  • (Boolean)


217
218
219
# File 'app/helpers/edgar/form_drawer.rb', line 217

def edgar_file?(col)
  @model._klass_str.constantize.edgar_file?(col)
end

- (Object) get_enum(col)

overwrite to return enum of the column in SearchForm

see overwritten draw_enum() also.



291
292
293
# File 'app/helpers/edgar/form_drawer.rb', line 291

def get_enum(col)
  @template.get_enum(@model._klass_str.constantize, col)
end