Module: AdminAssistant::Column::SimpleColumnSearchViewMethods

Includes:
SearchViewMethods
Included in:
ActiveRecordColumn::SearchView, VirtualColumn::SearchView
Defined in:
lib/admin_assistant/column.rb

Instance Method Summary collapse

Methods included from SearchViewMethods

#set_instance_variables_from_options

Instance Method Details

#blank_checkbox_html(form) ⇒ Object



195
196
197
198
199
# File 'lib/admin_assistant/column.rb', line 195

def blank_checkbox_html(form)
  check_box_and_hidden_tags(
    "search[#{name}(blank)]", form.object.blank?(@column.name)
  ) + "is blank"
end

#boolean_input(form) ⇒ Object



201
202
203
204
205
206
207
208
209
210
211
# File 'lib/admin_assistant/column.rb', line 201

def boolean_input(form)
  opts = [['', nil]]
  if @boolean_labels
    opts << [@boolean_labels.first, true]
    opts << [@boolean_labels.last, false]
  else
    opts << ['true', true]
    opts << ['false', false]
  end
  form.select(name, opts)
end

#comparator_html(search) ⇒ Object



213
214
215
216
217
218
219
220
221
222
223
224
225
# File 'lib/admin_assistant/column.rb', line 213

def comparator_html(search)
  selected_comparator = search.comparator(@column.name) || '='
  option_tags = comparator_opts.map { |text, value|
    opt = "<option value=\"#{value}\""
    if selected_comparator == value
      opt << " selected=\"selected\""
    end
    opt << ">#{text}</option>"
  }.join("\n")
  @action_view.select_tag(
    "search[#{name}(comparator)]", @action_view.raw(option_tags)
  )
end

#comparator_optsObject



227
228
229
230
231
232
233
# File 'lib/admin_assistant/column.rb', line 227

def comparator_opts
  [
    ['greater than', '>'], ['greater than or equal to', '>='],
    ['equal to', '='], ['less than or equal to', '<='],
    ['less than', '<']
  ]
end

#datetime_input(form) ⇒ Object



235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
# File 'lib/admin_assistant/column.rb', line 235

def datetime_input(form)
  input = ''
  if @compare_to_range
    input = datetime_range_input(form)
  else
    input << comparator_html(form.object) << ' ' if @comparators == :all
    input << form.datetime_select(name, :include_blank => true)
    input << @action_view.send(
      :link_to, 'Clear', '#',
      'data-prefix' => "search_#{name.underscore}",
      :class => 'clear_datetime_select'
    )
  end
  input
end

#datetime_range_end_point_input(form, comparator, label) ⇒ Object



251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
# File 'lib/admin_assistant/column.rb', line 251

def datetime_range_end_point_input(form, comparator, label)
  input = "#{label} "
  input << ActionView::Helpers::DateTimeSelector.new(
    form.object.send(name)[comparator], 
    :prefix => "search", :field_name => comparator.to_s,
    :include_position => true, :index => name, :include_blank => true,
    :datetime_separator => ' &mdash; ', :time_separator => ' : '
  ).select_datetime
  input << @action_view.send(
    :link_to, 'Clear', '#',
    'data-prefix' => "search_#{name.underscore}_#{comparator}",
    :class => 'clear_datetime_select'
  )
  input
end

#datetime_range_input(form) ⇒ Object



267
268
269
270
271
272
273
# File 'lib/admin_assistant/column.rb', line 267

def datetime_range_input(form)
  input = ''
  input << datetime_range_end_point_input(form, :gt, 'After')
  input << "&nbsp;&nbsp;&nbsp;"
  input << datetime_range_end_point_input(form, :lt, 'Before')
  input
end

#html(form) ⇒ Object



275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
# File 'lib/admin_assistant/column.rb', line 275

def html(form)
  input = ''
  if @column.field_type == :boolean
    input = boolean_input form
  elsif @column.field_type == :datetime
    input = datetime_input form
  else
    if @compare_to_range
      input << "Greater than "
      input << @action_view.send(
        :text_field_tag, "search[#{name}][gt]",
        form.object.send(name)[:gt]
      )
      input << "&nbsp;&nbsp;&nbsp;Less than "
      input << @action_view.send(
        :text_field_tag, "search[#{name}][lt]",
        form.object.send(name)[:lt]
      )
    else
      if @column.field_type == :integer && @comparators == :all
        input << comparator_html(form.object) << ' '
      end
      input << form.text_field(name)
      input << blank_checkbox_html(form) if @blank_checkbox
    end
  end
  "<p><label>#{label}</label> <br/>#{input}</p>"
end