Class: Wice::ViewColumnDatetime

Inherits:
ViewColumn show all
Includes:
ActionView::Helpers::DateHelper, JsCalendarHelpers
Defined in:
lib/view_columns.rb

Overview

:nodoc:

Direct Known Subclasses

ViewColumnDate

Constant Summary collapse

@@datetime_chunk_names =
%w(year month day hour minute)

Constants inherited from ViewColumn

Wice::ViewColumn::FIELDS

Instance Attribute Summary

Attributes inherited from ViewColumn

#cell_rendering_block, #contains_a_text_input, #css_class, #custom_filter, #grid, #main_table, #model_class, #table_name

Instance Method Summary collapse

Methods included from JsCalendarHelpers

#date_calendar_jquery, #date_calendar_prototype, #datetime_calendar_prototype

Methods included from ActionView::Helpers::TagHelper

#tag_options

Methods inherited from ViewColumn

#attribute_name_fully_qualified_for_all_but_main_table_columns, #auto_reloading_input_with_negation_checkbox?, #capable_of_hosting_filter_related_icons?, #detachness, #filter_shown?, #filter_shown_in_main_table?, #form_parameter_name_id_and_query, #fully_qualified_attribute_name, #has_auto_reloading_input?, #has_auto_reloading_select?, #initialize, #render_filter, #table_alias_or_table_name, #yield_javascript

Constructor Details

This class inherits a constructor from Wice::ViewColumn

Instance Method Details

#has_auto_reloading_calendar?Boolean

:nodoc:


377
378
379
# File 'lib/view_columns.rb', line 377

def has_auto_reloading_calendar? #:nodoc:
  auto_reload && helper_style == :calendar
end

#name_and_id_from_options(options, type) ⇒ Object

name_and_id_from_options in Rails Date helper does not substitute '.' with '_' like all other simpler form helpers do. Thus, overriding it here.


313
314
315
316
# File 'lib/view_columns.rb', line 313

def name_and_id_from_options(options, type)  #:nodoc:
  options[:name] = (options[:prefix] || DEFAULT_PREFIX) + (options[:discard_type] ? '' : "[#{type}]")
  options[:id] = options[:name].gsub(/([\[\(])|(\]\[)/, '_').gsub(/[\]\)]/, '').gsub(/\./, '_').gsub(/_+/, '_')
end

#prepare_for_calendar_filterObject

:nodoc:


335
336
337
338
339
340
# File 'lib/view_columns.rb', line 335

def prepare_for_calendar_filter #:nodoc:
  query, _, @name1, @dom_id = form_parameter_name_id_and_query(:fr => '')
  query2, _, @name2, @dom_id2 = form_parameter_name_id_and_query(:to => '')

  @queris_ids = [[query, @dom_id], [query2, @dom_id2] ]
end

#prepare_for_standard_filterObject

:nodoc:


320
321
322
323
324
325
326
327
328
329
330
331
332
# File 'lib/view_columns.rb', line 320

def prepare_for_standard_filter #:nodoc:
  x = lambda{|sym|
    @@datetime_chunk_names.collect{|datetime_chunk_name|
      triple = form_parameter_name_id_and_query(sym => {datetime_chunk_name => ''})
      [triple[0], triple[3]]
    }
  }

  @queris_ids = x.call(:fr) + x.call(:to)

  _, _, @name1, _ = form_parameter_name_id_and_query({:fr => ''})
  _, _, @name2, _ = form_parameter_name_id_and_query({:to => ''})
end

#render_calendar_filter_internal(params) ⇒ Object

:nodoc:


350
351
352
353
354
355
356
357
358
# File 'lib/view_columns.rb', line 350

def render_calendar_filter_internal(params) #:nodoc:
  html1, js1 = datetime_calendar_prototype(params[:fr], @view,
    {:include_blank => true, :prefix => @name1, :id => @dom_id, :fire_event => auto_reload, :grid_name => self.grid.name},
    :title => WiceGridNlMessageProvider.get_message(:DATE_SELECTOR_TOOLTIP_FROM))
  html2, js2 = datetime_calendar_prototype(params[:to], @view,
    {:include_blank => true, :prefix => @name2, :id => @dom_id2, :fire_event => auto_reload, :grid_name => self.grid.name},
    :title => WiceGridNlMessageProvider.get_message(:DATE_SELECTOR_TOOLTIP_TO))
  [%!<div class="date-filter">#{html1}<br/>#{html2}</div>!, js1 + js2]
end

#render_filter_internal(params) ⇒ Object

:nodoc:


361
362
363
364
365
366
367
368
369
370
# File 'lib/view_columns.rb', line 361

def render_filter_internal(params) #:nodoc:
  # falling back to the Rails helpers for Datetime
  if helper_style == :standard || Defaults::JS_FRAMEWORK == :jquery
    prepare_for_standard_filter
    render_standard_filter_internal(params)
  else
    prepare_for_calendar_filter
    render_calendar_filter_internal(params)
  end
end

#render_standard_filter_internal(params) ⇒ Object

:nodoc:


343
344
345
346
347
348
# File 'lib/view_columns.rb', line 343

def render_standard_filter_internal(params) #:nodoc:
  '<div class="date-filter">' +
  select_datetime(params[:fr], {:include_blank => true, :prefix => @name1}) + '<br/>' +
  select_datetime(params[:to], {:include_blank => true, :prefix => @name2}) +
  '</div>'
end

#yield_declaration_of_column_filterObject

:nodoc:


372
373
374
375
# File 'lib/view_columns.rb', line 372

def yield_declaration_of_column_filter #:nodoc:
  %$templates : [ #{@queris_ids.collect{|tuple| "'" + tuple[0] + "'"}.join(', ')} ],
      ids : [ #{@queris_ids.collect{|tuple| "'" + tuple[1] + "'"}.join(', ')} ] $
end