wice_grid_mongoid 0.5.6

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (67) hide show
  1. data/.gitignore +8 -0
  2. data/CHANGELOG +409 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.rdoc +1172 -0
  5. data/Rakefile +42 -0
  6. data/SAVED_QUERIES_HOWTO.rdoc +123 -0
  7. data/VERSION +1 -0
  8. data/generators/common_templates/icons/arrow_down.gif +0 -0
  9. data/generators/common_templates/icons/arrow_up.gif +0 -0
  10. data/generators/common_templates/icons/calendar_view_month.png +0 -0
  11. data/generators/common_templates/icons/delete.png +0 -0
  12. data/generators/common_templates/icons/expand.png +0 -0
  13. data/generators/common_templates/icons/page_white_excel.png +0 -0
  14. data/generators/common_templates/icons/page_white_find.png +0 -0
  15. data/generators/common_templates/icons/table.png +0 -0
  16. data/generators/common_templates/icons/table_refresh.png +0 -0
  17. data/generators/common_templates/icons/tick_all.png +0 -0
  18. data/generators/common_templates/icons/untick_all.png +0 -0
  19. data/generators/common_templates/initializers/wice_grid_config.rb +215 -0
  20. data/generators/common_templates/locales/wice_grid.yml +269 -0
  21. data/generators/common_templates/stylesheets/wice_grid.css +173 -0
  22. data/generators/wice_grid_assets_jquery/templates/USAGE +6 -0
  23. data/generators/wice_grid_assets_jquery/templates/javascripts/wice_grid_jquery.js +161 -0
  24. data/generators/wice_grid_assets_jquery/wice_grid_assets_jquery_generator.rb +35 -0
  25. data/generators/wice_grid_assets_prototype/USAGE +8 -0
  26. data/generators/wice_grid_assets_prototype/templates/javascripts/calendarview.js +1168 -0
  27. data/generators/wice_grid_assets_prototype/templates/javascripts/wice_grid_prototype.js +153 -0
  28. data/generators/wice_grid_assets_prototype/templates/stylesheets/calendarview.css +107 -0
  29. data/generators/wice_grid_assets_prototype/wice_grid_assets_prototype_generator.rb +37 -0
  30. data/init.rb +1 -0
  31. data/install.rb +1 -0
  32. data/lib/grid_output_buffer.rb +52 -0
  33. data/lib/grid_renderer.rb +531 -0
  34. data/lib/helpers/js_calendar_helpers.rb +188 -0
  35. data/lib/helpers/wice_grid_misc_view_helpers.rb +113 -0
  36. data/lib/helpers/wice_grid_serialized_queries_view_helpers.rb +82 -0
  37. data/lib/helpers/wice_grid_view_helpers.rb +781 -0
  38. data/lib/js_adaptors/jquery_adaptor.rb +145 -0
  39. data/lib/js_adaptors/js_adaptor.rb +12 -0
  40. data/lib/js_adaptors/prototype_adaptor.rb +168 -0
  41. data/lib/table_column_matrix.rb +51 -0
  42. data/lib/view_columns.rb +469 -0
  43. data/lib/views/create.rjs +13 -0
  44. data/lib/views/delete.rjs +12 -0
  45. data/lib/wice_grid.rb +809 -0
  46. data/lib/wice_grid_controller.rb +165 -0
  47. data/lib/wice_grid_core_ext.rb +179 -0
  48. data/lib/wice_grid_misc.rb +99 -0
  49. data/lib/wice_grid_serialized_queries_controller.rb +77 -0
  50. data/lib/wice_grid_serialized_query.rb +14 -0
  51. data/lib/wice_grid_spreadsheet.rb +33 -0
  52. data/tasks/wice_grid_tasks.rake +28 -0
  53. data/test/.gitignore +2 -0
  54. data/test/database.yml +21 -0
  55. data/test/schema.rb +33 -0
  56. data/test/test_helper.rb +89 -0
  57. data/test/views/projects_and_people_grid.html.erb +12 -0
  58. data/test/views/projects_and_people_grid_invalid.html.erb +12 -0
  59. data/test/views/simple_projects_grid.html.erb +9 -0
  60. data/test/wice_grid_core_ext_test.rb +183 -0
  61. data/test/wice_grid_functional_test.rb +68 -0
  62. data/test/wice_grid_misc_test.rb +41 -0
  63. data/test/wice_grid_test.rb +42 -0
  64. data/test/wice_grid_view_helper_test.rb +12 -0
  65. data/uninstall.rb +1 -0
  66. data/wice_grid_mongoid.gemspec +111 -0
  67. metadata +141 -0
@@ -0,0 +1,145 @@
1
+ # encoding: UTF-8
2
+ module Wice::JsAdaptor #:nodoc:
3
+
4
+ module Jquery #:nodoc:
5
+
6
+ def self.included(base) #:nodoc:
7
+ base.extend(ClassMethods)
8
+ end
9
+
10
+ module ClassMethods #:nodoc:
11
+
12
+ def init #:nodoc:
13
+ end
14
+
15
+ def dom_loaded #:nodoc:
16
+ %/$(document).ready(function(){\n/
17
+ end
18
+
19
+ def reset_button_initialization(grid_name, reset_grid_javascript) #:nodoc:
20
+ %/ $('div##{grid_name}.wice_grid_container .reset').click(function(e){\n/+
21
+ %/ #{reset_grid_javascript};\n/+
22
+ %/ });\n/
23
+ end
24
+
25
+ def submit_button_initialization(grid_name, submit_grid_javascript) #:nodoc:
26
+ %/ $('div##{grid_name}.wice_grid_container .submit').click(function(e){\n/+
27
+ %/ #{submit_grid_javascript};\n/+
28
+ %/ });\n/
29
+ end
30
+
31
+ def show_hide_button_initialization(grid_name, filter_row_id) #:nodoc:
32
+ %/ $('##{grid_name}_show_icon').click(function(){\n/+
33
+ %/ $('##{grid_name}_show_icon').hide();\n/+
34
+ %/ $('##{grid_name}_hide_icon').show();\n/+
35
+ %/ $('##{filter_row_id}').show();\n/+
36
+ %/ })\n/+
37
+ %/ $('##{grid_name}_hide_icon').click(function(){\n/+
38
+ %/ $('##{grid_name}_show_icon').show();\n/+
39
+ %/ $('##{grid_name}_hide_icon').hide();\n/+
40
+ %/ $('##{filter_row_id}').hide();\n/+
41
+ %/ });\n/
42
+ end
43
+
44
+ def enter_key_event_registration(grid_name) #:nodoc:
45
+ %! $('div##{grid_name}.wice_grid_container .wice_grid_filter_row input[type=text]').keydown(function(event){\n! +
46
+ %! if (event.keyCode == 13) {#{grid_name}.process()}\n! +
47
+ %! });\n!
48
+ end
49
+
50
+ def csv_export_icon_initialization(grid_name) #:nodoc:
51
+ %! $('div##{grid_name}.wice_grid_container .export_to_csv_button').click(function(e){\n! +
52
+ %! #{grid_name}.export_to_csv()\n! +
53
+ %! });\n!
54
+ end
55
+
56
+ def auto_reloading_selects_event_initialization(grid_name) #:nodoc:
57
+ %! $('div##{grid_name}.wice_grid_container select.auto_reload, .#{grid_name}_detached_filter select.auto_reload').change(function(e){\n! +
58
+ %! #{grid_name}.process()\n! +
59
+ %! });\n!
60
+ end
61
+
62
+ def auto_reloading_inputs_event_initialization(grid_name) #:nodoc:
63
+ %! $('div##{grid_name}.wice_grid_container input.auto_reload, .#{grid_name}_detached_filter input.auto_reload').keyup(function(event, element){\n! +
64
+ %! #{grid_name}.process(this.id);\n! +
65
+ %! });\n!
66
+ end
67
+
68
+ def auto_reloading_inputs_with_negation_checkboxes_event_initialization(grid_name) #:nodoc:
69
+ %! $('div##{grid_name}.wice_grid_container input.negation_checkbox, .#{grid_name}_detached_filter input.negation_checkbox').click(function(event, element){\n! +
70
+ %! #{grid_name}.process(this.id);\n! +
71
+ %! });\n!
72
+ end
73
+
74
+
75
+ def auto_reloading_calendar_event_initialization(grid_name) #:nodoc:
76
+ %! $(document).bind('wg:calendarChanged', function(event){\n! +
77
+ %! #{grid_name}.process()\n! +
78
+ %! });\n!
79
+ end
80
+
81
+ def show_all_link_initialization(grid_name, confirmation, parameters_json) #:nodoc:
82
+ %/ $('div##{grid_name}.wice_grid_container .show_all_link').click(function(e){ \n/ +
83
+ %/ #{confirmation} #{grid_name}.reload_page_for_given_grid_state(#{parameters_json}) \n/ +
84
+ %/})\n/
85
+ end
86
+
87
+ def back_to_pagination_link_initialization(grid_name, parameters_json) #:nodoc:
88
+ %/ $('div##{grid_name}.wice_grid_container .show_all_link').click(function(e){\n/ +
89
+ %/ #{grid_name}.reload_page_for_given_grid_state(#{parameters_json})\n/ +
90
+ %/ })\n/
91
+ end
92
+
93
+ def call_to_save_query_and_key_event_initialization_for_saving_queries(
94
+ id_and_name, grid_name, base_path_to_query_controller, parameters_json, ids_json) #:nodoc:
95
+ %/ function #{grid_name}_save_query(){\n/ +
96
+ %` if ( typeof(#{grid_name}) != "undefined")\n` +
97
+ %! #{grid_name}.save_query($('##{id_and_name}')[0].value, '#{base_path_to_query_controller}', #{parameters_json}, #{ids_json})\n! +
98
+ %/}\n/ +
99
+ %/ $('##{id_and_name}').keydown(function(event){\n/ +
100
+ %/ if (event.keyCode == 13) #{grid_name}_save_query();\n/ +
101
+ %/ })\n/
102
+ end
103
+
104
+ def js_framework_specific_calendar_assets(view) #:nodoc:
105
+ ''
106
+ end
107
+
108
+ def js_framework_specific_calendar_js_name #:nodoc:
109
+ nil
110
+ end
111
+
112
+ def js_framework_specific_calendar_css_name #:nodoc:
113
+ nil
114
+ end
115
+
116
+ def action_column_initialization(grid_name) #:nodoc:
117
+ %! $('div##{grid_name}.wice_grid_container .select_all').click(function(e){\n! +
118
+ %! $('div##{grid_name}.wice_grid_container .sel input').each(function(i, checkbox){\n! +
119
+ %! checkbox.checked = true;\n! +
120
+ %! })\n! +
121
+ %! })\n! +
122
+ %! $('div##{grid_name}.wice_grid_container .deselect_all').click(function(e){\n! +
123
+ %! $('div##{grid_name}.wice_grid_container .sel input').each(function(i, checkbox){\n! +
124
+ %! checkbox.checked = false;\n! +
125
+ %! })\n! +
126
+ %! })\n!
127
+ end
128
+
129
+ def fade_this #:nodoc:
130
+ 'jQuery([]).pushStack(this).fadeOut()'
131
+ end
132
+
133
+ def focus_element(element_to_focus) #:nodoc:
134
+ %! var elements = $('##{element_to_focus}');\n! +
135
+ %! if (elements[0]){\n! +
136
+ %! var elToFocus = elements[0];\n! +
137
+ %! elToFocus.value = elToFocus.value;\n! + # this will just place the cursor at the end of the text input
138
+ %! elToFocus.focus();\n! +
139
+ %! }\n!
140
+ end
141
+
142
+ end
143
+
144
+ end
145
+ end
@@ -0,0 +1,12 @@
1
+ # encoding: UTF-8
2
+
3
+ module Wice::JsAdaptor #:nodoc:
4
+ mattr_accessor :calendar_module
5
+ def self.init #:nodoc:
6
+ if Wice::Defaults::JS_FRAMEWORK == :prototype
7
+ include Wice::JsAdaptor::Prototype
8
+ else
9
+ include Wice::JsAdaptor::Jquery
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,168 @@
1
+ # encoding: UTF-8
2
+ module Wice::JsAdaptor #:nodoc:
3
+
4
+ module Prototype #:nodoc:
5
+
6
+ def self.included(base) #:nodoc:
7
+ base.extend(ClassMethods)
8
+ end
9
+
10
+ module ClassMethods #:nodoc:
11
+ def init #:nodoc:
12
+ end
13
+
14
+ def dom_loaded #:nodoc:
15
+ %/ document.observe("dom:loaded", function() {\n/
16
+ end
17
+
18
+ def reset_button_initialization(grid_name, reset_grid_javascript) #:nodoc:
19
+ %/ $$('div##{grid_name}.wice_grid_container .reset').each(function(e){\n/+
20
+ %/ e.observe('click', function(){\n/+
21
+ %/ #{reset_grid_javascript};\n/+
22
+ %/ })\n/+
23
+ %/ });\n/
24
+ end
25
+
26
+ def submit_button_initialization(grid_name, submit_grid_javascript) #:nodoc:
27
+ %/ $$('div##{grid_name}.wice_grid_container .submit').each(function(e){\n/+
28
+ %/ e.observe('click', function(){\n/+
29
+ %/ #{submit_grid_javascript};\n/+
30
+ %/ })\n/+
31
+ %/ });\n/
32
+ end
33
+
34
+ def show_hide_button_initialization(grid_name, filter_row_id) #:nodoc:
35
+ %/ $('#{grid_name}_show_icon').observe('click', function(){\n/+
36
+ %/ Element.toggle('#{grid_name}_show_icon');\n/+
37
+ %/ Element.toggle('#{grid_name}_hide_icon');\n/+
38
+ %/ $('#{filter_row_id}').show();\n/+
39
+ %/ })\n/+
40
+ %/ $('#{grid_name}_hide_icon').observe('click', function(){\n/+
41
+ %/ Element.toggle('#{grid_name}_show_icon');\n/+
42
+ %/ Element.toggle('#{grid_name}_hide_icon');\n/+
43
+ %/ $('#{filter_row_id}').hide();\n/+
44
+ %/ });\n/
45
+ end
46
+
47
+ def enter_key_event_registration(grid_name) #:nodoc:
48
+ %! $$('div##{grid_name}.wice_grid_container .wice_grid_filter_row input[type=text]').each(function(e){\n! +
49
+ %! e.observe('keydown', function(event){\n! +
50
+ %! if (event.keyCode == 13) {#{grid_name}.process()}\n! +
51
+ %! })\n! +
52
+ %! });\n!
53
+ end
54
+
55
+ def csv_export_icon_initialization(grid_name) #:nodoc:
56
+ %! $$('div##{grid_name}.wice_grid_container .export_to_csv_button').each(function(e){\n! +
57
+ %! e.observe('click', function(event){\n! +
58
+ %! #{grid_name}.export_to_csv()\n! +
59
+ %! })\n! +
60
+ %! });\n!
61
+ end
62
+
63
+ def auto_reloading_selects_event_initialization(grid_name) #:nodoc:
64
+ %! $$('div##{grid_name}.wice_grid_container select.auto_reload', '.#{grid_name}_detached_filter select.auto_reload').each(function(e){\n! +
65
+ %! e.observe('change', function(event){\n! +
66
+ %! #{grid_name}.process()\n! +
67
+ %! })\n! +
68
+ %! });\n!
69
+ end
70
+
71
+ def auto_reloading_inputs_event_initialization(grid_name) #:nodoc:
72
+ %! $$('div##{grid_name}.wice_grid_container input.auto_reload', '.#{grid_name}_detached_filter input.auto_reload').each(function(e){\n! +
73
+ %! e.observe('keyup', function(event){\n! +
74
+ %! #{grid_name}.process(event.element().id)\n! +
75
+ %! })\n! +
76
+ %! });\n!
77
+ end
78
+
79
+ def auto_reloading_inputs_with_negation_checkboxes_event_initialization(grid_name) #:nodoc:
80
+ %! $$('div##{grid_name}.wice_grid_container input.negation_checkbox', '.#{grid_name}_detached_filter input.negation_checkbox').each(function(e){\n! +
81
+ %! e.observe('click', function(event){\n! +
82
+ %! #{grid_name}.process(event.element().id)\n! +
83
+ %! })\n! +
84
+ %! });\n!
85
+ end
86
+
87
+
88
+ def auto_reloading_calendar_event_initialization(grid_name) #:nodoc:
89
+ %! document.observe('wg:calendarChanged', function(event){\n! +
90
+ %! #{grid_name}.process()\n! +
91
+ %! });\n!
92
+ end
93
+
94
+
95
+ def show_all_link_initialization(grid_name, confirmation, parameters_json) #:nodoc:
96
+ %/ $$('div##{grid_name}.wice_grid_container .show_all_link').each(function(e){\n/ +
97
+ %/ e.observe('click', function(){\n/ +
98
+ %/ #{confirmation} #{grid_name}.reload_page_for_given_grid_state(#{parameters_json})\n/ +
99
+ %/ })\n/ +
100
+ %/ })\n/
101
+ end
102
+
103
+
104
+ def back_to_pagination_link_initialization(grid_name, parameters_json) #:nodoc:
105
+ %/ $$('div##{grid_name}.wice_grid_container .show_all_link').each(function(e){\n/ +
106
+ %/ e.observe('click', function(){\n/ +
107
+ %/ #{grid_name}.reload_page_for_given_grid_state(#{parameters_json})\n/ +
108
+ %/ })\n/ +
109
+ %/ })\n/
110
+ end
111
+
112
+ def call_to_save_query_and_key_event_initialization_for_saving_queries(
113
+ id_and_name, grid_name, base_path_to_query_controller, parameters_json, ids_json) #:nodoc:
114
+ %/ function #{grid_name}_save_query(){\n/ +
115
+ %` if ( typeof(#{grid_name}) != "undefined")\n` +
116
+ %/ #{grid_name}.save_query($F('#{id_and_name}'), '#{base_path_to_query_controller}', #{parameters_json}, #{ids_json})\n/ +
117
+ %/ }\n/ +
118
+ %/ $('#{id_and_name}').observe('keydown', function(event){\n/ +
119
+ %/ if (event.keyCode == 13) #{grid_name}_save_query();\n/ +
120
+ %/ })\n/
121
+ end
122
+
123
+
124
+ def js_framework_specific_calendar_assets(view) #:nodoc:
125
+ view.stylesheet_link_tag("calendarview.css") + view.javascript_include_tag("calendarview.js")
126
+ end
127
+
128
+ def js_framework_specific_calendar_js_name #:nodoc:
129
+ 'calendarview.js'
130
+ end
131
+
132
+ def js_framework_specific_calendar_css_name #:nodoc:
133
+ 'calendarview.css'
134
+ end
135
+
136
+
137
+ def action_column_initialization(grid_name) #:nodoc:
138
+ %! $$('div##{grid_name}.wice_grid_container .select_all').each(function(e){\n! +
139
+ %! e.observe('click', function(){\n! +
140
+ %! $$('div##{grid_name}.wice_grid_container .sel input').each(function(checkbox){\n! +
141
+ %! checkbox.checked = true;\n! +
142
+ %! })\n! +
143
+ %! })\n! +
144
+ %! })\n! +
145
+ %! $$('div##{grid_name}.wice_grid_container .deselect_all').each(function(e){\n! +
146
+ %! e.observe('click', function(){\n! +
147
+ %! $$('div##{grid_name}.wice_grid_container .sel input').each(function(checkbox){\n! +
148
+ %! checkbox.checked = false;\n! +
149
+ %! })\n! +
150
+ %! })\n! +
151
+ %! })\n!
152
+ end
153
+
154
+ def fade_this #:nodoc:
155
+ 'new Effect.Fade(this)'
156
+ end
157
+
158
+ def focus_element(element_to_focus) #:nodoc:
159
+ %! var elToFocus = $('#{element_to_focus}');\n! +
160
+ %! elToFocus.focus();\n! +
161
+ %! elToFocus.value = elToFocus.value;\n! # this will just place the cursor at the end of the text input
162
+ end
163
+
164
+ end
165
+
166
+ end
167
+
168
+ end
@@ -0,0 +1,51 @@
1
+ # encoding: UTF-8
2
+ module Wice
3
+ class TableColumnMatrix < Hash #:nodoc:
4
+
5
+ attr_reader :generated_conditions
6
+
7
+ def initialize() #:nodoc:
8
+ super
9
+ @generated_conditions = []
10
+ @by_table_names = HashWithIndifferentAccess.new
11
+ end
12
+
13
+ def add_condition(column, conditions)
14
+ @generated_conditions << [column, conditions] unless conditions.blank?
15
+ end
16
+
17
+ def conditions
18
+ @generated_conditions.collect{|_, cond| cond}
19
+ end
20
+
21
+ alias_method :get, :[]
22
+
23
+ attr_reader :default_model_class
24
+ def default_model_class=(model_klass) #:nodoc:
25
+ init_columns_of_table(model_klass) unless has_key?(model_klass)
26
+ @default_model_class = model_klass
27
+ end
28
+
29
+ def [](model_klass) #:nodoc:
30
+ init_columns_of_table(model_klass) unless has_key?(model_klass)
31
+ get(model_klass)
32
+ end
33
+
34
+ def get_column_by_model_class_and_column_name(model_class, column_name) #:nodoc:
35
+ self[model_class][column_name]
36
+ end
37
+
38
+ def get_column_in_default_model_class_by_column_name(column_name) #:nodoc:
39
+ raise WiceGridException.new("Cannot search for a column in a default model as the default model is not set") if @default_model_class.nil?
40
+ self[@default_model_class][column_name]
41
+ end
42
+
43
+ def init_columns_of_table(model_klass) #:nodoc:
44
+ self[model_klass] = HashWithIndifferentAccess.new(model_klass.columns.index_by(&:name))
45
+ @by_table_names[model_klass.table_name] = self[model_klass]
46
+ self[model_klass].each_value{|c| c.model_klass = model_klass}
47
+ end
48
+ alias_method :<< , :init_columns_of_table
49
+
50
+ end
51
+ end
@@ -0,0 +1,469 @@
1
+ # encoding: UTF-8
2
+ module Wice
3
+
4
+ class ViewColumn
5
+ include ActionView::Helpers::FormTagHelper
6
+ include ActionView::Helpers::TagHelper
7
+ include ActionView::Helpers::JavaScriptHelper
8
+ include ActionView::Helpers::AssetTagHelper
9
+
10
+ # fields defined from the options parameter
11
+ FIELDS = [:attribute_name, :column_name, :td_html_attrs, :no_filter, :model_class, :allow_multiple_selection,
12
+ :in_html, :in_csv, :helper_style, :table_alias, :custom_order, :detach_with_id, :allow_ordering, :auto_reload]
13
+
14
+ attr_accessor *FIELDS
15
+
16
+ attr_accessor :cell_rendering_block, :grid, :css_class, :table_name, :main_table, :model_class, :custom_filter
17
+
18
+ attr_reader :contains_a_text_input
19
+
20
+ def initialize(block, options, grid_obj, tname, mtable, cfilter, view) #:nodoc:
21
+ self.cell_rendering_block = block
22
+ self.grid = grid_obj
23
+ self.table_name = tname
24
+ self.main_table = mtable
25
+ self.custom_filter = cfilter
26
+ @view = view
27
+
28
+ FIELDS.each do |field|
29
+ self.send(field.to_s + '=', options[field])
30
+ end
31
+ end
32
+
33
+ cattr_accessor :handled_type
34
+ @@handled_type = Hash.new
35
+
36
+ def css_class #:nodoc:
37
+ @css_class || ''
38
+ end
39
+
40
+ def yield_declaration_of_column_filter #:nodoc:
41
+ nil
42
+ end
43
+
44
+ def detachness #:nodoc:
45
+ (! detach_with_id.blank?).to_s
46
+ end
47
+
48
+ def yield_javascript #:nodoc:
49
+ declaration = yield_declaration_of_column_filter
50
+ if declaration
51
+ %!#{@grid.name}.register( {
52
+ filter_name : "#{self.column_name}",
53
+ detached : #{detachness},
54
+ #{declaration}
55
+ } ); !
56
+ else
57
+ ''
58
+ end
59
+ end
60
+
61
+ def render_filter #:nodoc:
62
+ params = @grid.filter_params(self)
63
+ res = render_filter_internal(params)
64
+ return (res.is_a?(Array)) ? res : [res, nil]
65
+ end
66
+
67
+ def render_filter_internal(params) #:nodoc:
68
+ '<!-- implement me! -->'
69
+ end
70
+
71
+ def form_parameter_name_id_and_query(v) #:nodoc:
72
+ query = form_parameter_template(v)
73
+ query_without_equals_sign = query.sub(/=$/,'')
74
+ parameter_name = CGI.unescape(query_without_equals_sign)
75
+ dom_id = id_out_of_name(parameter_name)
76
+ return query, query_without_equals_sign, parameter_name, dom_id.tr('.', '_')
77
+ end
78
+
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
+ def filter_shown? #:nodoc:
90
+ self.attribute_name && ! self.no_filter
91
+ end
92
+
93
+ def filter_shown_in_main_table? #:nodoc:
94
+ filter_shown? && ! self.detach_with_id
95
+ end
96
+
97
+
98
+ def table_alias_or_table_name #:nodoc:
99
+ table_alias || table_name
100
+ end
101
+
102
+ def capable_of_hosting_filter_related_icons? #:nodoc:
103
+ self.attribute_name.blank? && self.column_name.blank? && ! self.filter_shown?
104
+ end
105
+
106
+ def has_auto_reloading_input? #:nodoc:
107
+ false
108
+ end
109
+
110
+ def auto_reloading_input_with_negation_checkbox? #:nodoc:
111
+ false
112
+ end
113
+
114
+ def has_auto_reloading_select? #:nodoc:
115
+ false
116
+ end
117
+
118
+ def has_auto_reloading_calendar? #:nodoc:
119
+ false
120
+ end
121
+
122
+ protected
123
+
124
+ def form_parameter_template(v) #:nodoc:
125
+ {@grid.name => {:f => {self.attribute_name_fully_qualified_for_all_but_main_table_columns => v}}}.to_query
126
+ end
127
+
128
+ def form_parameter_name(v) #:nodoc:
129
+ form_parameter_template_hash(v).to_query
130
+ end
131
+
132
+ def name_out_of_template(s) #:nodoc:
133
+ CGI.unescape(s).sub(/=$/,'')
134
+ end
135
+
136
+ def id_out_of_name(s) #:nodoc:
137
+ s.gsub(/[\[\]]+/,'_').sub(/_+$/, '')
138
+ end
139
+
140
+ end
141
+
142
+ class ActionViewColumn < ViewColumn #:nodoc:
143
+ def initialize(grid_obj, td_html_attrs, param_name, select_all_buttons, object_property, view) #:nodoc:
144
+ @view = view
145
+ @select_all_buttons = select_all_buttons
146
+ self.grid = grid_obj
147
+ self.td_html_attrs = td_html_attrs
148
+ self.td_html_attrs.add_or_append_class_value!('sel')
149
+ grid_name = self.grid.name
150
+ @param_name = param_name
151
+ @cell_rendering_block = lambda do |object, params|
152
+ selected = if params[grid_name] && params[grid_name][param_name] &&
153
+ params[grid_name][param_name].index(object.send(object_property).to_s)
154
+ true
155
+ else
156
+ false
157
+ end
158
+ check_box_tag("#{grid_name}[#{param_name}][]", object.send(object_property), selected, :id => nil)
159
+ end
160
+ end
161
+
162
+ def in_html #:nodoc:
163
+ true
164
+ end
165
+
166
+ def capable_of_hosting_filter_related_icons? #:nodoc:
167
+ false
168
+ end
169
+
170
+ def column_name #:nodoc:
171
+ return '' unless @select_all_buttons
172
+ select_all_tootip = WiceGridNlMessageProvider.get_message(:SELECT_ALL)
173
+ deselect_all_tootip = WiceGridNlMessageProvider.get_message(:DESELECT_ALL)
174
+
175
+ html = content_tag(:span, image_tag(Defaults::TICK_ALL_ICON, :alt => select_all_tootip),
176
+ :class => 'clickable select_all', :title => select_all_tootip) + ' ' +
177
+ content_tag(:span, image_tag(Defaults::UNTICK_ALL_ICON, :alt => deselect_all_tootip),
178
+ :class => 'clickable deselect_all', :title => deselect_all_tootip)
179
+
180
+ js = JsAdaptor.action_column_initialization(grid.name)
181
+
182
+ [html, js]
183
+ end
184
+
185
+ end
186
+
187
+ class ViewColumnInteger < ViewColumn #:nodoc:
188
+ @@handled_type[:integer] = self
189
+
190
+ def render_filter_internal(params) #:nodoc:
191
+ @contains_a_text_input = true
192
+
193
+ @query, _, parameter_name, @dom_id = form_parameter_name_id_and_query(:fr => '')
194
+ @query2, _, parameter_name2, @dom_id2 = form_parameter_name_id_and_query(:to => '')
195
+
196
+ opts1 = {:size => 3, :id => @dom_id}
197
+ opts2 = {:size => 3, :id => @dom_id2}
198
+
199
+ if auto_reload
200
+ opts1[:class] = ' auto_reload'
201
+ opts2[:class] = ' auto_reload'
202
+ end
203
+
204
+ text_field_tag(parameter_name, params[:fr], opts1) + text_field_tag(parameter_name2, params[:to], opts2)
205
+ end
206
+
207
+ def yield_declaration_of_column_filter #:nodoc:
208
+ %$templates : ['#{@query}', '#{@query2}'],
209
+ ids : ['#{@dom_id}', '#{@dom_id2}'] $
210
+ end
211
+
212
+ def has_auto_reloading_input? #:nodoc:
213
+ auto_reload
214
+ end
215
+
216
+ end
217
+
218
+ class ViewColumnFloat < ViewColumnInteger #:nodoc:
219
+ @@handled_type[:decimal] = self
220
+ @@handled_type[:float] = self
221
+ end
222
+
223
+ class ViewColumnCustomDropdown < ViewColumn #:nodoc:
224
+ include ActionView::Helpers::FormOptionsHelper
225
+
226
+ attr_accessor :filter_all_label
227
+ attr_accessor :custom_filter
228
+
229
+ def render_filter_internal(params) #:nodoc:
230
+ @query, @query_without_equals_sign, @parameter_name, @dom_id = form_parameter_name_id_and_query('')
231
+ @query_without_equals_sign += '%5B%5D='
232
+
233
+ @custom_filter = @custom_filter.call if @custom_filter.kind_of? Proc
234
+
235
+ if @custom_filter.kind_of? Array
236
+
237
+ @custom_filter = [[@filter_all_label, nil]] + @custom_filter.map{|label, value|
238
+ [label.to_s, value.to_s]
239
+ }
240
+
241
+ end
242
+
243
+ select_options = {:name => @parameter_name, :id => @dom_id, :class => 'custom_dropdown'}
244
+
245
+ if @turn_off_select_toggling
246
+ select_toggle = ''
247
+ else
248
+ if self.allow_multiple_selection
249
+ select_options[:multiple] = params.is_a?(Array) && params.size > 1
250
+ select_toggle = content_tag(:a,
251
+ tag(:img, :alt => 'Expand/Collapse', :src => Defaults::TOGGLE_MULTI_SELECT_ICON),
252
+ :href => "javascript: toggle_multi_select('#{@dom_id}', this, 'Expand', 'Collapse');", # TO DO: to locales
253
+ :class => 'toggle_multi_select_icon', :title => 'Expand')
254
+ else
255
+ select_options[:multiple] = false
256
+ select_toggle = ''
257
+ end
258
+ end
259
+
260
+ if auto_reload
261
+ select_options[:class] += ' auto_reload'
262
+ end
263
+
264
+ '<span class="custom_dropdown_container">'.html_safe_if_necessary +
265
+ content_tag(:select, options_for_select(@custom_filter, params), select_options) +
266
+ select_toggle.html_safe_if_necessary + '</span>'.html_safe_if_necessary
267
+ end
268
+
269
+ def yield_declaration_of_column_filter #:nodoc:
270
+ %$templates : ['#{@query_without_equals_sign}'],
271
+ ids : ['#{@dom_id}'] $
272
+ end
273
+
274
+ def has_auto_reloading_select? #:nodoc:
275
+ auto_reload
276
+ end
277
+ end
278
+
279
+ class ViewColumnBoolean < ViewColumnCustomDropdown #:nodoc:
280
+ @@handled_type[:boolean] = self
281
+ include ActionView::Helpers::FormOptionsHelper
282
+
283
+ attr_accessor :boolean_filter_true_label, :boolean_filter_false_label
284
+
285
+ def render_filter_internal(params) #:nodoc:
286
+ @custom_filter = {@filter_all_label => nil,
287
+ @boolean_filter_true_label => 't',
288
+ @boolean_filter_false_label => 'f' }
289
+ @turn_off_select_toggling = true
290
+ super(params)
291
+ end
292
+ end
293
+
294
+ class ViewColumnDatetime < ViewColumn #:nodoc:
295
+ @@handled_type[:datetime] = self
296
+ @@handled_type[:timestamp] = self
297
+ include ActionView::Helpers::DateHelper
298
+ include Wice::JsCalendarHelpers
299
+
300
+
301
+ # name_and_id_from_options in Rails Date helper does not substitute '.' with '_'
302
+ # like all other simpler form helpers do. Thus, overriding it here.
303
+ def name_and_id_from_options(options, type) #:nodoc:
304
+ options[:name] = (options[:prefix] || DEFAULT_PREFIX) + (options[:discard_type] ? '' : "[#{type}]")
305
+ options[:id] = options[:name].gsub(/([\[\(])|(\]\[)/, '_').gsub(/[\]\)]/, '').gsub(/\./, '_').gsub(/_+/, '_')
306
+ end
307
+
308
+ @@datetime_chunk_names = %w(year month day hour minute)
309
+
310
+ def prepare_for_standard_filter #:nodoc:
311
+ x = lambda{|sym|
312
+ @@datetime_chunk_names.collect{|datetime_chunk_name|
313
+ triple = form_parameter_name_id_and_query(sym => {datetime_chunk_name => ''})
314
+ [triple[0], triple[3]]
315
+ }
316
+ }
317
+
318
+ @queris_ids = x.call(:fr) + x.call(:to)
319
+
320
+ _, _, @name1, _ = form_parameter_name_id_and_query({:fr => ''})
321
+ _, _, @name2, _ = form_parameter_name_id_and_query({:to => ''})
322
+ end
323
+
324
+
325
+ def prepare_for_calendar_filter #:nodoc:
326
+ query, _, @name1, @dom_id = form_parameter_name_id_and_query(:fr => '')
327
+ query2, _, @name2, @dom_id2 = form_parameter_name_id_and_query(:to => '')
328
+
329
+ @queris_ids = [[query, @dom_id], [query2, @dom_id2] ]
330
+ end
331
+
332
+
333
+ def render_standard_filter_internal(params) #:nodoc:
334
+ '<div class="date-filter">' +
335
+ select_datetime(params[:fr], {:include_blank => true, :prefix => @name1}) + '<br/>' +
336
+ select_datetime(params[:to], {:include_blank => true, :prefix => @name2}) +
337
+ '</div>'
338
+ end
339
+
340
+ def render_calendar_filter_internal(params) #:nodoc:
341
+ html1, js1 = datetime_calendar_prototype(params[:fr], @view,
342
+ {:include_blank => true, :prefix => @name1, :id => @dom_id, :fire_event => auto_reload},
343
+ :title => WiceGridNlMessageProvider.get_message(:DATE_SELECTOR_TOOLTIP_FROM))
344
+ html2, js2 = datetime_calendar_prototype(params[:to], @view,
345
+ {:include_blank => true, :prefix => @name2, :id => @dom_id2, :fire_event => auto_reload},
346
+ :title => WiceGridNlMessageProvider.get_message(:DATE_SELECTOR_TOOLTIP_TO))
347
+ [%!<div class="date-filter">#{html1}<br/>#{html2}</div>!, js1 + js2]
348
+ end
349
+
350
+
351
+ def render_filter_internal(params) #:nodoc:
352
+ # falling back to the Rails helpers for Datetime
353
+ if helper_style == :standard || Defaults::JS_FRAMEWORK == :jquery
354
+ prepare_for_standard_filter
355
+ render_standard_filter_internal(params)
356
+ else
357
+ prepare_for_calendar_filter
358
+ render_calendar_filter_internal(params)
359
+ end
360
+ end
361
+
362
+ def yield_declaration_of_column_filter #:nodoc:
363
+ %$templates : [ #{@queris_ids.collect{|tuple| "'" + tuple[0] + "'"}.join(', ')} ],
364
+ ids : [ #{@queris_ids.collect{|tuple| "'" + tuple[1] + "'"}.join(', ')} ] $
365
+ end
366
+
367
+ def has_auto_reloading_calendar? #:nodoc:
368
+ auto_reload && helper_style == :calendar
369
+ end
370
+
371
+ end
372
+
373
+ class ViewColumnDate < ViewColumnDatetime #:nodoc:
374
+ @@handled_type[:date] = self
375
+
376
+ @@datetime_chunk_names = %w(year month day)
377
+
378
+ def render_standard_filter_internal(params) #:nodoc:
379
+ '<div class="date-filter">' +
380
+ select_date(params[:fr], {:include_blank => true, :prefix => @name1, :id => @dom_id}) + '<br/>' +
381
+ select_date(params[:to], {:include_blank => true, :prefix => @name2, :id => @dom_id2}) +
382
+ '</div>'
383
+ end
384
+
385
+ def render_calendar_filter_internal(params) #:nodoc:
386
+
387
+ calendar_helper_method = if Wice::Defaults::JS_FRAMEWORK == :prototype
388
+ :date_calendar_prototype
389
+ else
390
+ :date_calendar_jquery
391
+ end
392
+
393
+ html1, js1 = send(calendar_helper_method, params[:fr], @view,
394
+ {:include_blank => true, :prefix => @name1, :fire_event => auto_reload},
395
+ :title => WiceGridNlMessageProvider.get_message(:DATE_SELECTOR_TOOLTIP_FROM))
396
+ html2, js2 = send(calendar_helper_method, params[:to], @view,
397
+ {:include_blank => true, :prefix => @name2, :fire_event => auto_reload},
398
+ :title => WiceGridNlMessageProvider.get_message(:DATE_SELECTOR_TOOLTIP_TO))
399
+
400
+ [%!<div class="date-filter">#{html1}<br/>#{html2}</div>!, js1 + js2]
401
+ end
402
+
403
+ def render_filter_internal(params) #:nodoc:
404
+
405
+ if helper_style == :standard
406
+ prepare_for_standard_filter
407
+ render_standard_filter_internal(params)
408
+ else
409
+ prepare_for_calendar_filter
410
+ render_calendar_filter_internal(params)
411
+ end
412
+ end
413
+ end
414
+
415
+ class ViewColumnString < ViewColumn #:nodoc:
416
+ @@handled_type[:string] = self
417
+ @@handled_type[:text] = self
418
+
419
+ attr_accessor :negation, :auto_reloading_input_with_negation_checkbox
420
+
421
+ def render_filter_internal(params) #:nodoc:
422
+ @contains_a_text_input = true
423
+ css_class = auto_reload ? 'auto_reload' : nil
424
+
425
+ if negation
426
+ self.auto_reloading_input_with_negation_checkbox = true if auto_reload
427
+
428
+ @query, _, parameter_name, @dom_id = form_parameter_name_id_and_query(:v => '')
429
+ @query2, _, parameter_name2, @dom_id2 = form_parameter_name_id_and_query(:n => '')
430
+
431
+ '<div class="text_filter_container">' +
432
+ text_field_tag(parameter_name, params[:v], :size => 8, :id => @dom_id, :class => css_class) +
433
+ if defined?(::Wice::Defaults::NEGATION_CHECKBOX_LABEL) && ! ::Wice::Defaults::NEGATION_CHECKBOX_LABEL.blank?
434
+ ::Wice::Defaults::NEGATION_CHECKBOX_LABEL
435
+ else
436
+ ''
437
+ end +
438
+ check_box_tag(parameter_name2, '1', (params[:n] == '1'),
439
+ :id => @dom_id2,
440
+ :title => WiceGridNlMessageProvider.get_message(:NEGATION_CHECKBOX_TITLE),
441
+ :class => 'negation_checkbox') +
442
+ '</div>'
443
+ else
444
+ @query, _, parameter_name, @dom_id = form_parameter_name_id_and_query('')
445
+ text_field_tag(parameter_name, (params.blank? ? '' : params), :size => 8, :id => @dom_id, :class => css_class)
446
+ end
447
+ end
448
+
449
+ def yield_declaration_of_column_filter #:nodoc:
450
+ if negation
451
+ %$templates : ['#{@query}', '#{@query2}'],
452
+ ids : ['#{@dom_id}', '#{@dom_id2}'] $
453
+ else
454
+ %$templates : ['#{@query}'],
455
+ ids : ['#{@dom_id}'] $
456
+ end
457
+ end
458
+
459
+ def has_auto_reloading_input? #:nodoc:
460
+ auto_reload
461
+ end
462
+
463
+ def auto_reloading_input_with_negation_checkbox? #:nodoc:
464
+ self.auto_reloading_input_with_negation_checkbox
465
+ end
466
+
467
+ end
468
+
469
+ end