wice_grid_mongoid 0.5.7 → 6.0.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. data/.gitignore +4 -1
  2. data/Gemfile +17 -0
  3. data/Gemfile.lock +140 -0
  4. data/README.rdoc +19 -3
  5. data/Rakefile +1 -3
  6. data/VERSION +1 -1
  7. data/lib/filter_conditions_generators.rb +126 -0
  8. data/{generators/wice_grid_assets_prototype/templates/stylesheets → lib/generators/wice_grid/templates}/calendarview.css +0 -0
  9. data/{generators/wice_grid_assets_prototype/templates/javascripts → lib/generators/wice_grid/templates}/calendarview.js +0 -0
  10. data/{generators/common_templates → lib/generators/wice_grid/templates}/icons/arrow_down.gif +0 -0
  11. data/{generators/common_templates → lib/generators/wice_grid/templates}/icons/arrow_up.gif +0 -0
  12. data/{generators/common_templates → lib/generators/wice_grid/templates}/icons/calendar_view_month.png +0 -0
  13. data/{generators/common_templates → lib/generators/wice_grid/templates}/icons/delete.png +0 -0
  14. data/{generators/common_templates → lib/generators/wice_grid/templates}/icons/expand.png +0 -0
  15. data/{generators/common_templates → lib/generators/wice_grid/templates}/icons/page_white_excel.png +0 -0
  16. data/{generators/common_templates → lib/generators/wice_grid/templates}/icons/page_white_find.png +0 -0
  17. data/{generators/common_templates → lib/generators/wice_grid/templates}/icons/table.png +0 -0
  18. data/{generators/common_templates → lib/generators/wice_grid/templates}/icons/table_refresh.png +0 -0
  19. data/{generators/common_templates → lib/generators/wice_grid/templates}/icons/tick_all.png +0 -0
  20. data/{generators/common_templates → lib/generators/wice_grid/templates}/icons/untick_all.png +0 -0
  21. data/{generators/common_templates/stylesheets → lib/generators/wice_grid/templates}/wice_grid.css +0 -0
  22. data/{generators/common_templates/locales → lib/generators/wice_grid/templates}/wice_grid.yml +0 -0
  23. data/{generators/common_templates/initializers → lib/generators/wice_grid/templates}/wice_grid_config.rb +0 -0
  24. data/{generators/wice_grid_assets_jquery/templates/javascripts → lib/generators/wice_grid/templates}/wice_grid_jquery.js +0 -0
  25. data/{generators/wice_grid_assets_prototype/templates/javascripts → lib/generators/wice_grid/templates}/wice_grid_prototype.js +0 -0
  26. data/lib/generators/wice_grid/wice_grid_assets_jquery_generator.rb +32 -0
  27. data/lib/generators/wice_grid/wice_grid_assets_prototype_generator.rb +34 -0
  28. data/lib/grid_renderer.rb +36 -20
  29. data/lib/helpers/js_calendar_helpers.rb +0 -5
  30. data/lib/helpers/wice_grid_view_helpers.rb +113 -133
  31. data/lib/mongoid_field.rb +50 -0
  32. data/{tasks → lib/tasks}/wice_grid_tasks.rake +0 -0
  33. data/lib/view_columns.rb +23 -29
  34. data/lib/wice_grid.rb +91 -379
  35. data/lib/wice_grid_misc.rb +3 -3
  36. data/mongoid_wice_grid.gemspec +122 -0
  37. data/test/blueprint.rb +17 -0
  38. data/test/public/javascripts/jquery-1.4.2.min.js +154 -0
  39. data/test/public/javascripts/wice_grid.js +163 -0
  40. data/test/rails_mongoid_test.rb +104 -0
  41. data/test/rails_test_app.rb +71 -0
  42. data/test/require_gems.rb +19 -0
  43. data/test/spec_helper.rb +22 -0
  44. data/test/wice_grid_initializer.rb +215 -0
  45. data/wice_grid_mongoid.gemspec +43 -30
  46. metadata +45 -34
  47. data/generators/wice_grid_assets_jquery/templates/USAGE +0 -6
  48. data/generators/wice_grid_assets_jquery/wice_grid_assets_jquery_generator.rb +0 -35
  49. data/generators/wice_grid_assets_prototype/USAGE +0 -8
  50. data/generators/wice_grid_assets_prototype/wice_grid_assets_prototype_generator.rb +0 -37
  51. data/init.rb +0 -1
  52. data/install.rb +0 -1
  53. data/lib/table_column_matrix.rb +0 -51
  54. data/uninstall.rb +0 -1
@@ -116,7 +116,7 @@ module Wice
116
116
  if grid.output_buffer
117
117
  if grid.output_buffer == true
118
118
  raise WiceGridException.new("Second occurence of grid helper with the same grid object. " +
119
- "Did you intend to use detached filters and forget to define them?")
119
+ "Did you intend to use detached filters and forget to define them?")
120
120
  else
121
121
  return grid.output_buffer
122
122
  end
@@ -199,12 +199,12 @@ module Wice
199
199
  buff = GridOutputBuffer.new
200
200
 
201
201
  buff << if rendering.blank_slate_handler.is_a?(Proc)
202
- call_block_as_erb_or_ruby(rendering, rendering.blank_slate_handler, nil)
203
- elsif rendering.blank_slate_handler.is_a?(Hash)
204
- render(rendering.blank_slate_handler)
205
- else
206
- rendering.blank_slate_handler
207
- end
202
+ call_block_as_erb_or_ruby(rendering, rendering.blank_slate_handler, nil)
203
+ elsif rendering.blank_slate_handler.is_a?(Hash)
204
+ render(rendering.blank_slate_handler)
205
+ else
206
+ rendering.blank_slate_handler
207
+ end
208
208
 
209
209
  if rendering.find_one_for(:in_html){|column| column.detach_with_id}
210
210
  buff.stubborn_output_mode = true
@@ -268,10 +268,10 @@ module Wice
268
268
  # first row of column labels with sorting links
269
269
 
270
270
  filter_shown = if options[:show_filters] == :when_filtered
271
- grid.filtering_on?
272
- elsif options[:show_filters] == :always
273
- true
274
- end
271
+ grid.filtering_on?
272
+ elsif options[:show_filters] == :always
273
+ true
274
+ end
275
275
 
276
276
  cached_javascript = []
277
277
 
@@ -295,28 +295,27 @@ module Wice
295
295
  direction = 'desc' if grid.order_direction == 'asc'
296
296
  end
297
297
 
298
- col_link = link_to(
299
- column_name,
300
- rendering.column_link(column, direction, params, options[:extra_request_parameters]),
301
- :class => link_style)
298
+ col_link = link_to(column_name,
299
+ rendering.column_link(column, direction, params, options[:extra_request_parameters]),
300
+ :class => link_style)
302
301
  content << content_tag(:th, col_link, Hash.make_hash(:class, css_class))
303
302
  column.css_class = css_class
304
303
  else
305
304
  if reuse_last_column_for_filter_buttons && last
306
305
  content << content_tag(:th,
307
- hide_show_icon(filter_row_id, grid, filter_shown, no_filter_row, options[:show_filters], rendering),
308
- :class => 'hide_show_icon'
309
- )
306
+ hide_show_icon(filter_row_id, grid, filter_shown, no_filter_row, options[:show_filters], rendering),
307
+ :class => 'hide_show_icon'
308
+ )
310
309
  else
311
- content << content_tag(:th, column_name)
310
+ content << content_tag(:th, (column.icon ? image_tag("/images/icons/grid/#{column.icon}", :alt => column_name, :border => 0) : column_name))
312
311
  end
313
312
  end
314
313
  end
315
314
 
316
315
  content << content_tag(:th,
317
- hide_show_icon(filter_row_id, grid, filter_shown, no_filter_row, options[:show_filters], rendering),
318
- :class => 'hide_show_icon'
319
- ) unless no_rightmost_column
316
+ hide_show_icon(filter_row_id, grid, filter_shown, no_filter_row, options[:show_filters], rendering),
317
+ :class => 'hide_show_icon'
318
+ ) unless no_rightmost_column
320
319
 
321
320
  content << '</tr>'
322
321
  # rendering first row end
@@ -346,7 +345,6 @@ module Wice
346
345
 
347
346
  rendering.each_column_aware_of_one_last_one(:in_html) do |column, last|
348
347
  if column.filter_shown?
349
-
350
348
  filter_html_code, filter_js_code = column.render_filter
351
349
  filter_html_code = filter_html_code.html_safe_if_necessary
352
350
  cached_javascript << filter_js_code
@@ -360,9 +358,9 @@ module Wice
360
358
  else
361
359
  if reuse_last_column_for_filter_buttons && last
362
360
  content << content_tag(:th,
363
- reset_submit_buttons(options, grid, rendering),
364
- Hash.make_hash(:class, column.css_class).add_or_append_class_value!('filter_icons')
365
- )
361
+ reset_submit_buttons(options, grid, rendering),
362
+ Hash.make_hash(:class, column.css_class).add_or_append_class_value!('filter_icons')
363
+ )
366
364
  else
367
365
  content << content_tag(:th, '', Hash.make_hash(:class, column.css_class))
368
366
  end
@@ -382,6 +380,7 @@ module Wice
382
380
  end
383
381
 
384
382
  content << '</thead><tfoot>'
383
+
385
384
  content << rendering.pagination_panel(no_rightmost_column, options[:hide_csv_button]) do
386
385
  if pagination_panel_content_html
387
386
  pagination_panel_content_html
@@ -402,16 +401,16 @@ module Wice
402
401
  grid.each do |ar| # rows
403
402
 
404
403
  before_row_output = if rendering.before_row_handler
405
- call_block_as_erb_or_ruby(rendering, rendering.before_row_handler, ar)
406
- else
407
- nil
408
- end
404
+ call_block_as_erb_or_ruby(rendering, rendering.before_row_handler, ar)
405
+ else
406
+ nil
407
+ end
409
408
 
410
409
  after_row_output = if rendering.after_row_handler
411
- call_block_as_erb_or_ruby(rendering, rendering.after_row_handler, ar)
412
- else
413
- nil
414
- end
410
+ call_block_as_erb_or_ruby(rendering, rendering.after_row_handler, ar)
411
+ else
412
+ nil
413
+ end
415
414
 
416
415
  row_content = ''
417
416
  rendering.each_column(:in_html) do |column|
@@ -420,23 +419,23 @@ module Wice
420
419
  opts = column.td_html_attrs.clone
421
420
 
422
421
  column_block_output = if column.class == Wice::ActionViewColumn
423
- cell_block.call(ar, params)
424
- else
425
- call_block_as_erb_or_ruby(rendering, cell_block, ar)
426
- end
422
+ cell_block.call(ar, params)
423
+ else
424
+ call_block_as_erb_or_ruby(rendering, cell_block, ar)
425
+ end
427
426
 
428
427
  if column_block_output.kind_of?(Array)
429
428
 
430
429
  unless column_block_output.size == 2
431
430
  raise WiceGridArgumentError.new('When WiceGrid column block returns an array it is expected to contain 2 elements only - '+
432
- 'the first is the contents of the table cell and the second is a hash containing HTML attributes for the <td> tag.')
431
+ 'the first is the contents of the table cell and the second is a hash containing HTML attributes for the <td> tag.')
433
432
  end
434
433
 
435
434
  column_block_output, additional_opts = column_block_output
436
435
 
437
436
  unless additional_opts.is_a?(Hash)
438
437
  raise WiceGridArgumentError.new('When WiceGrid column block returns an array its second element is expected to be a ' +
439
- "hash containing HTML attributes for the <td> tag. The returned value is #{additional_opts.inspect}. Read documentation.")
438
+ "hash containing HTML attributes for the <td> tag. The returned value is #{additional_opts.inspect}. Read documentation.")
440
439
  end
441
440
 
442
441
  additional_css_class = nil
@@ -476,6 +475,8 @@ module Wice
476
475
  end
477
476
 
478
477
  content << '</tbody></table></div>'
478
+
479
+ content << link_to( "More &#x25BC;".html_safe, rendering.more_link(controller, options[:extra_request_parameters]), :id => 'more') if grid.has_more_to_show?
479
480
 
480
481
  base_link_for_filter, base_link_for_show_all_records = rendering.base_link_for_filter(controller, options[:extra_request_parameters])
481
482
 
@@ -485,18 +486,18 @@ module Wice
485
486
  parameter_name_for_focus = {grid.name => {:foc => ''}}.to_query
486
487
 
487
488
  prototype_and_js_version_check = if ENV['RAILS_ENV'] == 'development'
488
- %$ if (typeof(WiceGridProcessor) == "undefined"){\n$ +
489
- %$ alert('wice_grid.js not loaded, WiceGrid cannot proceed! ' +\n$ +
490
- %$ 'Please make sure that you include WiceGrid javascript in your page. ' +\n$ +
491
- %$ 'Use <%= include_wice_grid_assets %> or <%= include_wice_grid_assets(:include_calendar => true) %> ' +\n$ +
492
- %$ 'for WiceGrid javascripts and assets.')\n$ +
493
- %$ } else if ((typeof(WiceGridProcessor._version) == "undefined") || ( WiceGridProcessor._version != "0.4.3")) {\n$ +
494
- %$ alert("wice_grid.js in your /public is outdated, please run\\n ./script/generate wice_grid_assets_jquery\\n$ +
495
- %$ or\\n ./script/generate wice_grid_assets_prototype\\nto update it.");\n$ +
496
- %$ }\n$
497
- else
498
- ''
499
- end
489
+ %$ if (typeof(WiceGridProcessor) == "undefined"){\n$ +
490
+ %$ alert('wice_grid.js not loaded, WiceGrid cannot proceed! ' +\n$ +
491
+ %$ 'Please make sure that you include WiceGrid javascript in your page. ' +\n$ +
492
+ %$ 'Use <%= include_wice_grid_assets %> or <%= include_wice_grid_assets(:include_calendar => true) %> ' +\n$ +
493
+ %$ 'for WiceGrid javascripts and assets.')\n$ +
494
+ %$ } else if ((typeof(WiceGridProcessor._version) == "undefined") || ( WiceGridProcessor._version != "0.4.3")) {\n$ +
495
+ %$ alert("wice_grid.js in your /public is outdated, please run\\n ./script/generate wice_grid_assets_jquery\\n$ +
496
+ %$ or\\n ./script/generate wice_grid_assets_prototype\\nto update it.");\n$ +
497
+ %$ }\n$
498
+ else
499
+ ''
500
+ end
500
501
 
501
502
  if rendering.show_hide_button_present
502
503
  cached_javascript << JsAdaptor.show_hide_button_initialization(grid.name, filter_row_id)
@@ -539,21 +540,21 @@ module Wice
539
540
  end
540
541
 
541
542
  content << javascript_tag(
542
- JsAdaptor.dom_loaded +
543
- %/ #{prototype_and_js_version_check}\n/ +
544
- %/ window['#{grid.name}'] = new WiceGridProcessor('#{grid.name}', '#{base_link_for_filter}',\n/ +
545
- %/ '#{base_link_for_show_all_records}', '#{link_for_export}', '#{parameter_name_for_query_loading}',\n/ +
546
- %/ '#{parameter_name_for_focus}', '#{ENV['RAILS_ENV']}');\n/ +
547
- if no_filters_at_all
548
- ''
549
- else
550
- rendering.select_for(:in_html) do |vc|
551
- vc.attribute_name and not vc.no_filter
552
- end.collect{|column| column.yield_javascript}.join("\n")
553
- end +
554
- "\n" + cached_javascript.compact.join('') +
555
- '})'
556
- )
543
+ JsAdaptor.dom_loaded +
544
+ %/ #{prototype_and_js_version_check}\n/ +
545
+ %/ window['#{grid.name}'] = new WiceGridProcessor('#{grid.name}', '#{base_link_for_filter}',\n/ +
546
+ %/ '#{base_link_for_show_all_records}', '#{link_for_export}', '#{parameter_name_for_query_loading}',\n/ +
547
+ %/ '#{parameter_name_for_focus}', '#{ENV['RAILS_ENV']}');\n/ +
548
+ if no_filters_at_all
549
+ ''
550
+ else
551
+ rendering.select_for(:in_html) do |vc|
552
+ vc.attribute_name and not vc.no_filter
553
+ end.collect{|column| column.yield_javascript}.join("\n")
554
+ end +
555
+ "\n" + cached_javascript.compact.join('') +
556
+ '})'
557
+ )
557
558
 
558
559
  if content.stubborn_output_mode
559
560
  grid.output_buffer = content
@@ -582,25 +583,25 @@ module Wice
582
583
  filter_tooltip = WiceGridNlMessageProvider.get_message(:HIDE_FILTER_TOOLTIP)
583
584
 
584
585
  hide_icon = content_tag(:span,
585
- image_tag(Defaults::SHOW_HIDE_FILTER_ICON,
586
- :title => filter_tooltip,
587
- :alt => filter_tooltip),
588
- :id => grid_name + '_hide_icon',
589
- :style => styles[0],
590
- :class => 'clickable'
591
- )
586
+ image_tag(Defaults::SHOW_HIDE_FILTER_ICON,
587
+ :title => filter_tooltip,
588
+ :alt => filter_tooltip),
589
+ :id => grid_name + '_hide_icon',
590
+ :style => styles[0],
591
+ :class => 'clickable'
592
+ )
592
593
 
593
594
 
594
595
  filter_tooltip = WiceGridNlMessageProvider.get_message(:SHOW_FILTER_TOOLTIP)
595
596
 
596
597
  show_icon = content_tag(:span,
597
- image_tag(Defaults::SHOW_HIDE_FILTER_ICON,
598
- :title => filter_tooltip,
599
- :alt => filter_tooltip),
600
- :id => grid_name + '_show_icon',
601
- :style => styles[1],
602
- :class => 'clickable'
603
- )
598
+ image_tag(Defaults::SHOW_HIDE_FILTER_ICON,
599
+ :title => filter_tooltip,
600
+ :alt => filter_tooltip),
601
+ :id => grid_name + '_show_icon',
602
+ :style => styles[1],
603
+ :class => 'clickable'
604
+ )
604
605
 
605
606
  hide_icon + show_icon
606
607
  end
@@ -608,19 +609,19 @@ module Wice
608
609
 
609
610
  def reset_submit_buttons(options, grid, rendering) #:nodoc:
610
611
  (if options[:hide_submit_button]
611
- ''
612
- else
613
- rendering.submit_button_present = true
614
- filter_tooltip = WiceGridNlMessageProvider.get_message(:FILTER_TOOLTIP)
615
- image_tag(Defaults::FILTER_ICON, :title => filter_tooltip, :alt => filter_tooltip, :class => 'submit clickable')
616
- end + ' ' +
617
- if options[:hide_reset_button]
618
- ''
619
- else
620
- rendering.reset_button_present = true
621
- filter_tooltip = WiceGridNlMessageProvider.get_message(:RESET_FILTER_TOOLTIP)
622
- image_tag(Defaults::RESET_ICON, :title => filter_tooltip, :alt => filter_tooltip, :class => 'reset clickable')
623
- end).html_safe_if_necessary
612
+ ''
613
+ else
614
+ rendering.submit_button_present = true
615
+ filter_tooltip = WiceGridNlMessageProvider.get_message(:FILTER_TOOLTIP)
616
+ image_tag(Defaults::FILTER_ICON, :title => filter_tooltip, :alt => filter_tooltip, :class => 'submit clickable')
617
+ end + ' ' +
618
+ if options[:hide_reset_button]
619
+ ''
620
+ else
621
+ rendering.reset_button_present = true
622
+ filter_tooltip = WiceGridNlMessageProvider.get_message(:RESET_FILTER_TOOLTIP)
623
+ image_tag(Defaults::RESET_ICON, :title => filter_tooltip, :alt => filter_tooltip, :class => 'reset clickable')
624
+ end).html_safe_if_necessary
624
625
  end
625
626
 
626
627
  # Renders a detached filter. The parameters are:
@@ -635,7 +636,7 @@ module Wice
635
636
  end
636
637
  if grid.output_buffer == true
637
638
  raise WiceGridArgumentError.new("grid_filter: You have defined no detached filters, or you try use detached filters with" +
638
- ":show_filters => :no (set :show_filters to :always in this case). Read about detached filters in the documentation.")
639
+ ":show_filters => :no (set :show_filters to :always in this case). Read about detached filters in the documentation.")
639
640
  end
640
641
 
641
642
  content_tag :span, grid.output_buffer.filter_for(filter_key), :class => "#{grid.name}_detached_filter"
@@ -672,8 +673,6 @@ module Wice
672
673
 
673
674
 
674
675
  def grid_csv(grid, rendering) #:nodoc:
675
-
676
-
677
676
  field_separator = (grid.export_to_csv_enabled && grid.export_to_csv_enabled.is_a?(String)) ? grid.export_to_csv_enabled : ','
678
677
  spreadsheet = ::Wice::Spreadsheet.new(grid.name, field_separator)
679
678
 
@@ -708,13 +707,14 @@ module Wice
708
707
  end
709
708
 
710
709
  html, js = pagination_info(grid, allow_showing_all_records)
711
-
712
- [will_paginate(grid.resultset,
713
- :previous_label => WiceGridNlMessageProvider.get_message(:PREVIOUS_LABEL),
714
- :next_label => WiceGridNlMessageProvider.get_message(:NEXT_LABEL),
715
- :param_name => "#{grid.name}[page]",
716
- :params => extra_request_parameters).to_s +
717
- (' <div class="pagination_status">' + html + '</div>').html_safe_if_necessary, js]
710
+ '<div class="pagination_status">' + html + '</div>'
711
+
712
+ # [will_paginate(grid.resultset,
713
+ # :previous_label => WiceGridNlMessageProvider.get_message(:PREVIOUS_LABEL),
714
+ # :next_label => WiceGridNlMessageProvider.get_message(:NEXT_LABEL),
715
+ # :param_name => "#{grid.name}[page]",
716
+ # :params => extra_request_parameters).to_s +
717
+ # (' <div class="pagination_status">' + html + '</div>').html_safe_if_necessary, js]
718
718
  end
719
719
 
720
720
 
@@ -747,35 +747,15 @@ module Wice
747
747
  end
748
748
 
749
749
  def pagination_info(grid, allow_showing_all_records) #:nodoc:
750
- collection = grid.resultset
751
-
752
- collection_total_entries = collection.total_entries
753
- collection_total_entries_str = collection_total_entries.to_s
754
- parameters = grid.get_state_as_parameter_value_pairs
755
-
756
- js = ''
757
- html = if (collection.total_pages < 2 && collection.length == 0)
758
- '0'
759
- else
760
- parameters << ["#{grid.name}[pp]", collection_total_entries_str]
761
-
762
- "#{collection.offset + 1}-#{collection.offset + collection.length} / #{collection_total_entries_str} " +
763
- if (! allow_showing_all_records) || collection_total_entries <= collection.length
764
- ''
765
- else
766
- res, js = show_all_link(collection_total_entries, parameters, grid.name)
767
- res
768
- end
769
- end +
770
- if grid.all_record_mode?
771
- res, js = back_to_pagination_link(parameters, grid.name)
772
- res
773
- else
774
- ''
775
- end
776
-
777
- [html, js]
750
+ found = grid.resultset.count
751
+ total = grid.klass.count
752
+ shown = [found, grid.status[:per_page].to_i].min
753
+ summary = ""
754
+ summary << "Shown: #{shown}"
755
+ summary << ", Found: #{found}" if grid.has_any_filter_criteria?
756
+ summary << ", Total: #{total}"
757
+ [summary, ""]
778
758
  end
779
759
 
780
760
  end
781
- end
761
+ end
@@ -0,0 +1,50 @@
1
+ require 'filter_conditions_generators'
2
+
3
+ module Wice
4
+ # to be mixed in into Mongoid::Field
5
+ module MongoidField
6
+ def wice_add_filter_criteria(all_filter_params, criteria, custom_filter_active) #:nodoc:
7
+ request_params = all_filter_params ? all_filter_params[name] : nil
8
+ return nil unless request_params
9
+
10
+ # Preprocess incoming parameters for datetime, if what's coming in is
11
+ # a datetime (with custom_filter it can be anything else, and not
12
+ # the datetime hash {"fr" => ..., "to" => ...})
13
+ if (self.type == Time) && request_params.is_a?(Hash)
14
+ ["fr", "to"].each do |sym|
15
+ if request_params[sym]
16
+ if request_params[sym].is_a?(String)
17
+ request_params[sym] = Time.parse(Wice::Defaults::DATETIME_PARSER.call(request_params[sym]).to_s)
18
+ elsif request_params[sym].is_a?(Hash)
19
+ request_params[sym] = Time.parse(::Wice::GridTools.params_2_datetime(request_params[sym]).to_s)
20
+ end
21
+ end
22
+ end
23
+ end
24
+
25
+ # Preprocess incoming parameters for date, if what's coming in is
26
+ # a date (with custom_filter it can be anything else, and not
27
+ # the date hash {"fr" => ..., "to" => ...})
28
+ if self.type == Date && request_params.is_a?(Hash)
29
+ ["fr", "to"].each do |sym|
30
+ if request_params[sym]
31
+ if request_params[sym].is_a?(String)
32
+ request_params[sym] = Wice::Defaults::DATE_PARSER.call(request_params[sym]).to_time
33
+ elsif request_params[sym].is_a?(Hash)
34
+ request_params[sym] = ::Wice::GridTools.params_2_date(request_params[sym]).to_time
35
+ end
36
+ end
37
+ end
38
+ end
39
+
40
+ processor_klass = ::Wice::FilterConditionsGeneratorCustomFilter if custom_filter_active
41
+ processor_klass = ::Wice::FilterConditionsGenerator.handled_type[self.type] unless processor_klass
42
+ unless processor_klass
43
+ Wice.log("No processor for database type #{self.type}!!!")
44
+ return nil
45
+ end
46
+ processor_klass.new(self, criteria).generate_conditions(request_params)
47
+ end
48
+
49
+ end
50
+ end
File without changes
data/lib/view_columns.rb CHANGED
@@ -8,7 +8,7 @@ module Wice
8
8
  include ActionView::Helpers::AssetTagHelper
9
9
 
10
10
  # fields defined from the options parameter
11
- FIELDS = [:attribute_name, :column_name, :td_html_attrs, :no_filter, :model_class, :allow_multiple_selection,
11
+ FIELDS = [:attribute_name, :column_name, :icon, :td_html_attrs, :no_filter, :model_class, :allow_multiple_selection,
12
12
  :in_html, :in_csv, :helper_style, :table_alias, :custom_order, :detach_with_id, :allow_ordering, :auto_reload]
13
13
 
14
14
  attr_accessor *FIELDS
@@ -26,7 +26,7 @@ module Wice
26
26
  @view = view
27
27
 
28
28
  FIELDS.each do |field|
29
- self.send(field.to_s + '=', options[field])
29
+ self.send("#{field}=", options[field])
30
30
  end
31
31
  end
32
32
 
@@ -58,6 +58,15 @@ module Wice
58
58
  end
59
59
  end
60
60
 
61
+
62
+ def config
63
+ @view.config
64
+ end
65
+
66
+ def controller
67
+ @view.controller
68
+ end
69
+
61
70
  def render_filter #:nodoc:
62
71
  params = @grid.filter_params(self)
63
72
  res = render_filter_internal(params)
@@ -76,16 +85,6 @@ module Wice
76
85
  return query, query_without_equals_sign, parameter_name, dom_id.tr('.', '_')
77
86
  end
78
87
 
79
- # bad name, because for the main table the name is not really 'fully_qualified'
80
- def attribute_name_fully_qualified_for_all_but_main_table_columns #:nodoc:
81
- self.main_table ? attribute_name : table_alias_or_table_name + '.' + attribute_name
82
- end
83
-
84
- def fully_qualified_attribute_name #:nodoc:
85
- table_alias_or_table_name + '.' + attribute_name
86
- end
87
-
88
-
89
88
  def filter_shown? #:nodoc:
90
89
  self.attribute_name && ! self.no_filter
91
90
  end
@@ -93,12 +92,7 @@ module Wice
93
92
  def filter_shown_in_main_table? #:nodoc:
94
93
  filter_shown? && ! self.detach_with_id
95
94
  end
96
-
97
-
98
- def table_alias_or_table_name #:nodoc:
99
- table_alias || table_name
100
- end
101
-
95
+
102
96
  def capable_of_hosting_filter_related_icons? #:nodoc:
103
97
  self.attribute_name.blank? && self.column_name.blank? && ! self.filter_shown?
104
98
  end
@@ -122,7 +116,7 @@ module Wice
122
116
  protected
123
117
 
124
118
  def form_parameter_template(v) #:nodoc:
125
- {@grid.name => {:f => {self.attribute_name_fully_qualified_for_all_but_main_table_columns => v}}}.to_query
119
+ {@grid.name => {:f => {self.attribute_name => v}}}.to_query
126
120
  end
127
121
 
128
122
  def form_parameter_name(v) #:nodoc:
@@ -185,7 +179,7 @@ module Wice
185
179
  end
186
180
 
187
181
  class ViewColumnInteger < ViewColumn #:nodoc:
188
- @@handled_type[:integer] = self
182
+ @@handled_type[Integer] = self
189
183
 
190
184
  def render_filter_internal(params) #:nodoc:
191
185
  @contains_a_text_input = true
@@ -216,8 +210,8 @@ module Wice
216
210
  end
217
211
 
218
212
  class ViewColumnFloat < ViewColumnInteger #:nodoc:
219
- @@handled_type[:decimal] = self
220
- @@handled_type[:float] = self
213
+ @@handled_type[BigDecimal] = self
214
+ @@handled_type[Float] = self
221
215
  end
222
216
 
223
217
  class ViewColumnCustomDropdown < ViewColumn #:nodoc:
@@ -277,7 +271,7 @@ module Wice
277
271
  end
278
272
 
279
273
  class ViewColumnBoolean < ViewColumnCustomDropdown #:nodoc:
280
- @@handled_type[:boolean] = self
274
+ @@handled_type[Boolean] = self
281
275
  include ActionView::Helpers::FormOptionsHelper
282
276
 
283
277
  attr_accessor :boolean_filter_true_label, :boolean_filter_false_label
@@ -292,8 +286,8 @@ module Wice
292
286
  end
293
287
 
294
288
  class ViewColumnDatetime < ViewColumn #:nodoc:
295
- @@handled_type[:datetime] = self
296
- @@handled_type[:timestamp] = self
289
+ @@handled_type[DateTime] = self
290
+ @@handled_type[Time] = self
297
291
  include ActionView::Helpers::DateHelper
298
292
  include Wice::JsCalendarHelpers
299
293
 
@@ -371,7 +365,7 @@ module Wice
371
365
  end
372
366
 
373
367
  class ViewColumnDate < ViewColumnDatetime #:nodoc:
374
- @@handled_type[:date] = self
368
+ @@handled_type[Date] = self
375
369
 
376
370
  @@datetime_chunk_names = %w(year month day)
377
371
 
@@ -413,8 +407,8 @@ module Wice
413
407
  end
414
408
 
415
409
  class ViewColumnString < ViewColumn #:nodoc:
416
- @@handled_type[:string] = self
417
- @@handled_type[:text] = self
410
+ @@handled_type[String] = self
411
+ # @@handled_type[:text] = self
418
412
 
419
413
  attr_accessor :negation, :auto_reloading_input_with_negation_checkbox
420
414
 
@@ -466,4 +460,4 @@ module Wice
466
460
 
467
461
  end
468
462
 
469
- end
463
+ end