wice_grid 3.0.4 → 3.2.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (82) hide show
  1. data/CHANGELOG +24 -2
  2. data/README.rdoc +282 -316
  3. data/RELEASE_NOTES_3.2.pre1.rdoc +82 -0
  4. data/Rakefile +4 -2
  5. data/SAVED_QUERIES_HOWTO.rdoc +18 -31
  6. data/VERSION +1 -1
  7. data/lib/generators/wice_grid/add_migration_for_serialized_queries_generator.rb +22 -0
  8. data/lib/generators/wice_grid/install_generator.rb +20 -0
  9. data/lib/generators/wice_grid/templates/create_wice_grid_serialized_queries.rb +13 -0
  10. data/lib/generators/wice_grid/templates/wice_grid.css.scss +139 -0
  11. data/lib/generators/wice_grid/templates/wice_grid.yml +113 -19
  12. data/lib/generators/wice_grid/templates/wice_grid_config.rb +17 -41
  13. data/lib/grid_output_buffer.rb +3 -2
  14. data/lib/grid_renderer.rb +63 -102
  15. data/lib/helpers/js_calendar_helpers.rb +27 -157
  16. data/lib/helpers/wice_grid_misc_view_helpers.rb +1 -66
  17. data/lib/helpers/wice_grid_serialized_queries_view_helpers.rb +41 -32
  18. data/lib/helpers/wice_grid_view_helpers.rb +138 -274
  19. data/lib/table_column_matrix.rb +11 -11
  20. data/lib/view_columns.rb +41 -350
  21. data/lib/view_columns/action_view_column.rb +45 -0
  22. data/lib/view_columns/column_processor_index.rb +16 -0
  23. data/lib/view_columns/view_column_boolean.rb +23 -0
  24. data/lib/view_columns/view_column_custom_dropdown.rb +81 -0
  25. data/lib/view_columns/view_column_date.rb +17 -0
  26. data/lib/view_columns/view_column_datetime.rb +85 -0
  27. data/lib/view_columns/view_column_float.rb +7 -0
  28. data/lib/view_columns/view_column_integer.rb +38 -0
  29. data/lib/view_columns/view_column_string.rb +63 -0
  30. data/lib/wice_grid.rb +23 -26
  31. data/lib/wice_grid_controller.rb +14 -15
  32. data/lib/wice_grid_misc.rb +3 -3
  33. data/lib/wice_grid_serialized_queries_controller.rb +15 -18
  34. data/lib/wice_grid_spreadsheet.rb +2 -2
  35. data/lib/will_paginate_paginator.rb +31 -0
  36. data/test/readme.txt +1 -0
  37. data/{lib/generators/wice_grid/templates/icons → vendor/assets/images/icons/grid}/arrow_down.gif +0 -0
  38. data/{lib/generators/wice_grid/templates/icons → vendor/assets/images/icons/grid}/arrow_up.gif +0 -0
  39. data/{lib/generators/wice_grid/templates/icons → vendor/assets/images/icons/grid}/calendar_view_month.png +0 -0
  40. data/vendor/assets/images/icons/grid/collapse.gif +0 -0
  41. data/{lib/generators/wice_grid/templates/icons → vendor/assets/images/icons/grid}/delete.png +0 -0
  42. data/vendor/assets/images/icons/grid/expand.gif +0 -0
  43. data/{lib/generators/wice_grid/templates/icons → vendor/assets/images/icons/grid}/page_white_excel.png +0 -0
  44. data/{lib/generators/wice_grid/templates/icons → vendor/assets/images/icons/grid}/page_white_find.png +0 -0
  45. data/{lib/generators/wice_grid/templates/icons → vendor/assets/images/icons/grid}/table.png +0 -0
  46. data/{lib/generators/wice_grid/templates/icons → vendor/assets/images/icons/grid}/table_refresh.png +0 -0
  47. data/{lib/generators/wice_grid/templates/icons → vendor/assets/images/icons/grid}/tick_all.png +0 -0
  48. data/{lib/generators/wice_grid/templates/icons → vendor/assets/images/icons/grid}/untick_all.png +0 -0
  49. data/vendor/assets/javascripts/wice_grid.js +3 -0
  50. data/vendor/assets/javascripts/wice_grid_init.js.coffee +247 -0
  51. data/vendor/assets/javascripts/wice_grid_processor.js.coffee +128 -0
  52. data/vendor/assets/javascripts/wice_grid_saved_queries_init.js.coffee +103 -0
  53. data/wice_grid.gemspec +44 -50
  54. metadata +68 -94
  55. data/lib/generators/wice_grid/templates/calendarview.css +0 -107
  56. data/lib/generators/wice_grid/templates/calendarview.js +0 -1168
  57. data/lib/generators/wice_grid/templates/icons/expand.png +0 -0
  58. data/lib/generators/wice_grid/templates/wice_grid.css +0 -173
  59. data/lib/generators/wice_grid/templates/wice_grid_jquery.js +0 -162
  60. data/lib/generators/wice_grid/templates/wice_grid_prototype.js +0 -154
  61. data/lib/generators/wice_grid/wice_grid_assets_jquery_generator.rb +0 -32
  62. data/lib/generators/wice_grid/wice_grid_assets_prototype_generator.rb +0 -34
  63. data/lib/js_adaptors/jquery_adaptor.rb +0 -157
  64. data/lib/js_adaptors/js_adaptor.rb +0 -12
  65. data/lib/js_adaptors/prototype_adaptor.rb +0 -179
  66. data/lib/tasks/wice_grid_tasks.rake +0 -28
  67. data/lib/views/create.rjs +0 -13
  68. data/lib/views/create_jq.rjs +0 -31
  69. data/lib/views/delete.rjs +0 -12
  70. data/lib/views/delete_jq.rjs +0 -26
  71. data/test/.gitignore +0 -2
  72. data/test/database.yml +0 -21
  73. data/test/schema.rb +0 -33
  74. data/test/test_helper.rb +0 -89
  75. data/test/views/projects_and_people_grid.html.erb +0 -12
  76. data/test/views/projects_and_people_grid_invalid.html.erb +0 -12
  77. data/test/views/simple_projects_grid.html.erb +0 -9
  78. data/test/wice_grid_core_ext_test.rb +0 -183
  79. data/test/wice_grid_functional_test.rb +0 -68
  80. data/test/wice_grid_misc_test.rb +0 -41
  81. data/test/wice_grid_test.rb +0 -42
  82. data/test/wice_grid_view_helper_test.rb +0 -12
@@ -1,183 +1,53 @@
1
1
  module Wice #:nodoc:
2
2
  module JsCalendarHelpers #:nodoc:
3
3
 
4
- # Jquery
5
-
6
- def date_calendar_jquery(initial_date, view, opts = {}, html_opts = {}) #:nodoc:
4
+ def date_calendar_jquery(initial_date, title, opts = {}) #:nodoc:
7
5
  date_format = Wice::ConfigurationProvider.value_for(:DATE_FORMAT)
8
6
 
9
- options, name, date_string, dom_id, datepicker_placeholder_id, date_span_id, close_calendar_event_name =
7
+ name, date_string, dom_id, datepicker_placeholder_id, date_span_id, close_calendar_event_name =
10
8
  prepare_data_for_calendar(opts, date_format, initial_date)
11
9
 
12
- remove_date_function = %! $('##{date_span_id}').html(''); $('##{dom_id}')[0].value = ''; !
13
-
14
- date_picker =
15
-
16
- hidden_field_tag(name, date_string, :id => dom_id) + ' ' +
17
-
18
- link_to_function(
19
- content_tag(:span, date_string, :id => date_span_id),
20
- remove_date_function,
21
- :class => 'date_label',
22
- :title => ::Wice::WiceGridNlMessageProvider.get_message(:DATE_STRING_TOOLTIP))
10
+ hidden_field_tag_options = {
11
+ :id => dom_id,
12
+ 'data-locale' => I18n.locale,
13
+ 'data-date-format' => Wice::ConfigurationProvider.value_for(:DATE_FORMAT_JQUERY),
14
+ 'data-button-image' => Wice::ConfigurationProvider.value_for(:CALENDAR_ICON),
15
+ 'data-button-text' => title,
16
+ }
23
17
 
24
- html = "<span id=\"#{datepicker_placeholder_id}\">#{date_picker}</span>"
18
+ if opts[:fire_event]
19
+ hidden_field_tag_options['data-close-calendar-event-name'] = close_calendar_event_name
20
+ end
25
21
 
26
- javascript = calendar_constructor_jquery(dom_id, view, Wice::ConfigurationProvider.value_for(:DATE_FORMAT_JQUERY),
27
- date_span_id, opts[:fire_event], html_opts[:title], datepicker_placeholder_id, close_calendar_event_name)
22
+ if Rails.env == 'development'
23
+ hidden_field_tag_options['class'] = 'check-for-datepicker'
24
+ end
28
25
 
29
- [html, javascript]
30
- end
26
+ date_picker = hidden_field_tag(name, date_string, hidden_field_tag_options) + ' ' +
31
27
 
32
- # Prototype
33
- def date_calendar_prototype(initial_date, view, opts = {}, html_opts = {}) #:nodoc:
34
- select_date_datetime_common_prototype(initial_date, view, opts, html_opts, false, Wice::ConfigurationProvider.value_for(:DATE_FORMAT))
35
- end
28
+ link_to(date_string,
29
+ '#',
30
+ :id => date_span_id,
31
+ :class => 'date-label',
32
+ :title => ::Wice::NlMessage['date_string_tooltip'],
33
+ 'data-dom-id' => dom_id
34
+ )
36
35
 
37
- def datetime_calendar_prototype(initial_date, view, opts = {}, html_opts = {}) #:nodoc:
38
- select_date_datetime_common_prototype(initial_date, view, opts, html_opts, true, Wice::ConfigurationProvider.value_for(:DATETIME_FORMAT))
36
+ "<span id=\"#{datepicker_placeholder_id}\">#{date_picker}</span>"
39
37
  end
40
38
 
41
39
  protected
42
40
 
43
- # common
44
-
45
41
  def prepare_data_for_calendar(opts, date_format, initial_date) #:nodoc:
46
42
  options = {:prefix => 'date'}
47
43
  options.merge!(opts)
48
44
  name = options[:prefix]
49
45
  date_string = initial_date.nil? ? '' : initial_date.strftime(date_format)
50
- dom_id = options[:id] || name.gsub(/([\[\(])|(\]\[)/, '_').gsub(/[\]\)]/, '').gsub(/\./, '_').gsub(/_+/, '_')
46
+ dom_id = name.gsub(/([\[\(])|(\]\[)/, '_').gsub(/[\]\)]/, '').gsub(/\./, '_').gsub(/_+/, '_')
51
47
  datepicker_placeholder_id = dom_id + '_date_placeholder'
52
48
  date_span_id = dom_id + '_date_view'
53
- close_calendar_event_name = "wg:calendarChanged_#{opts[:grid_name]}"
54
- return options, name, date_string, dom_id, datepicker_placeholder_id, date_span_id, close_calendar_event_name
55
- end
56
-
57
- # jquery
58
-
59
- def calendar_constructor_jquery(dom_id, view, date_format, date_span_id, fireEvent, title,
60
- datepicker_placeholder_id, close_calendar_event_name)
61
-
62
- javascript = %| $( "##{dom_id}" ).datepicker({\n|
63
- javascript << %| firstDay: 1,\n|
64
- javascript << %| showOn: "button",\n|
65
- javascript << %| dateFormat: "#{date_format}",\n|
66
- javascript << %| buttonImage: "#{Wice::ConfigurationProvider.value_for(:CALENDAR_ICON)}",\n|
67
- javascript << %| buttonImageOnly: true,\n|
68
- javascript << %| buttonText: "#{title}",\n|
69
- javascript << %| changeMonth: true,\n|
70
- javascript << %| changeYear: true,\n|
71
- javascript << %| onSelect: function(dateText, inst) {\n|
72
- javascript << %| $("##{date_span_id}").html(dateText);\n|
73
- if fireEvent
74
- javascript << %| $("##{dom_id}").trigger('#{close_calendar_event_name}');\n|
75
- end
76
- javascript << %| }\n|
77
- javascript << %| });\n|
78
-
79
- lang = Object.const_defined?(:I18n) ? I18n.locale : nil
80
-
81
- if Rails.env == 'development'
82
- unless view.respond_to? :datepicker_check_done
83
-
84
- javascript << %| if (! $.datepicker ){\n|
85
- javascript << %| alert("Seems like you do not have jQuery datepicker (http://jqueryui.com/demos/datepicker/)|
86
- javascript << %| installed. Either install it or set Wice::Defaults::HELPER_STYLE to :standard in |
87
- javascript << %| wice_grid_config.rb in order to use standard Rails date helpers")\n|
88
- javascript << %| }\n|
89
-
90
- def view.datepicker_check_done
91
- end
92
- end
93
- end
94
-
95
- if lang
96
- unless view.respond_to? :wg_calendar_lang_set
97
-
98
- javascript << %| wgCalendarLangRegionalOptions = $.datepicker.regional['#{lang}'];\n|
99
- javascript << %| if (wgCalendarLangRegionalOptions){\n|
100
- javascript << %| delete wgCalendarLangRegionalOptions.dateFormat ;\n|
101
- javascript << %| delete wgCalendarLangRegionalOptions.firstDate ;\n|
102
- javascript << %| }\n|
103
-
104
- def view.wg_calendar_lang_set
105
- end
106
- end
107
- javascript << %| if (wgCalendarLangRegionalOptions){\n|
108
- javascript << %| $( "##{dom_id}" ).datepicker("option", wgCalendarLangRegionalOptions);\n|
109
- javascript << %| }\n|
110
- end
111
-
112
- javascript += %| $('##{datepicker_placeholder_id} .ui-datepicker-trigger').addClass('clickable');\n|
113
-
114
- javascript
115
- end
116
-
117
- # prortotype
118
-
119
- def calendar_constructor_prototype(popup_trigger_icon_id, view, dom_id, date_format,
120
- date_span_id, with_time, fireEvent, close_calendar_event_name)
121
- javascript = ''
122
-
123
- unless view.respond_to? :wg_calendar_lang_set
124
- lang = Object.const_defined?(:I18n) ? I18n.locale : nil
125
- javascript << %| Calendar.language = '#{lang}';\n| unless lang.blank?
126
-
127
- def view.wg_calendar_lang_set
128
- end
129
- end
130
-
131
-
132
- javascript << %| new Calendar({\n |
133
- javascript << %| popupTriggerElement : "#{popup_trigger_icon_id}",\n |
134
- javascript << %| initialDate : $('#{dom_id}').value,\n |
135
- if fireEvent
136
- javascript << %| onHideCallback : function(){Event.fire($(#{dom_id}), '#{close_calendar_event_name}')},\n |
137
- end
138
- javascript << %| dateFormat : "#{date_format}",\n|
139
- unless Wice::ConfigurationProvider.value_for(:POPUP_PLACEMENT_STRATEGY) == :trigger
140
- javascript << %| popupPositioningStrategy : "#{Wice::ConfigurationProvider.value_for(:POPUP_PLACEMENT_STRATEGY)}",\n|
141
- end
142
- if with_time
143
- javascript << %| withTime : true,\n|
144
- end
145
- javascript << %| outputFields : $A(['#{date_span_id}', '#{dom_id}'])\n |
146
- javascript << %| });\n|
147
-
148
- javascript
149
- end
150
-
151
- def select_date_datetime_common_prototype(initial_date, view, opts, html_opts, with_time, date_format) #:nodoc:
152
-
153
- options, name, date_string, dom_id, datepicker_placeholder_id, date_span_id, close_calendar_event_name =
154
- prepare_data_for_calendar(opts, date_format, initial_date)
155
-
156
- popup_trigger_icon_id = dom_id + '_trigger'
157
-
158
- function = %! $('#{date_span_id}').innerHTML = ''; $('#{dom_id}').value = ''; !
159
- if opts[:fire_event]
160
- function += "Event.fire($(#{dom_id}), '#{close_calendar_event_name}')"
161
- end
162
-
163
- date_picker = image_tag(Defaults::CALENDAR_ICON,
164
- :id => popup_trigger_icon_id,
165
- :class => 'clickable',
166
- :title => html_opts[:title]) +
167
-
168
- link_to_function(
169
- content_tag(:span, date_string, :id => date_span_id),
170
- function,
171
- :class => 'date_label',
172
- :title => WiceGridNlMessageProvider.get_message(:DATE_STRING_TOOLTIP)) + ' ' +
173
-
174
- hidden_field_tag(name, date_string, :class => 'text-input', :id => dom_id)
175
-
176
- html = "<span id=\"#{datepicker_placeholder_id}\">#{date_picker}</span>"
177
-
178
- javascript = calendar_constructor_prototype(popup_trigger_icon_id, view, dom_id, date_format, date_span_id, with_time, opts[:fire_event], close_calendar_event_name)
179
-
180
- [html, javascript]
49
+ close_calendar_event_name = "wg:calendarChanged_#{options[:grid_name]}"
50
+ return name, date_string, dom_id, datepicker_placeholder_id, date_span_id, close_calendar_event_name
181
51
  end
182
52
 
183
53
  end
@@ -26,7 +26,6 @@ module Wice
26
26
  # WiceGrid is not a scaffolding solution, I hate scaffolding and how certain idiots associate scaffolding with Rails,
27
27
  # so I do not document this method to avoid contributing to this misunderstanding.
28
28
  def scaffolded_grid(grid_obj, opts = {}) #:nodoc:
29
- Wice::JsAdaptor.init
30
29
  unless grid_obj.kind_of? WiceGrid
31
30
  raise WiceGridArgumentError.new("scaffolded_grid: the parameter must be a WiceGrid instance.")
32
31
  end
@@ -42,76 +41,12 @@ module Wice
42
41
  end
43
42
  grid(grid_obj, opts) do |g|
44
43
  columns.each do |column_name|
45
- g.column :column_name => column_name.humanize, :attribute_name => column_name do |ar|
44
+ g.column :name => column_name.humanize, :attribute => column_name do |ar|
46
45
  ar.send(column_name)
47
46
  end
48
47
  end
49
48
  end
50
49
  end
51
50
 
52
- # View helper to include all stylesheets and javascript files needed for WiceGrid to function. Add it to template/layout in the
53
- # page header section.
54
- #
55
- # By default the helper returns WiceGrid javascripts and stylesheets include statements only on demand, that is, only if at least one initialize_grid has been
56
- # called in the controller. Otherwise the helper returns an empty string. However, you can force the old unconditioned behavior if you need by submitting
57
- # parameter <tt>:load_on_demand</tt> set to +false+:
58
- # <%= include_wice_grid_assets(:load_on_demand => false) %>
59
- #
60
- # By default +include_wice_grid_assets+ adds include statements for the javascript calendar widget used for date/datetime filters,
61
- # but it's possible not to include them setting parameter +include_calendar+ to false:
62
- # <%= include_wice_grid_assets(:include_calendar => false) %>
63
- def include_wice_grid_assets(options = {})
64
- Wice::JsAdaptor.init
65
- opts = {:include_calendar => true, :load_on_demand => true}
66
- options.assert_valid_keys(opts.keys)
67
- opts.merge!(options)
68
-
69
- if @__wice_grid_on_page || ! opts[:load_on_demand]
70
- javascript_include_tag('wice_grid') +
71
- stylesheet_link_tag('wice_grid') +
72
- if opts[:include_calendar]
73
- JsAdaptor.js_framework_specific_calendar_assets(self)
74
- else
75
- ''
76
- end
77
- end
78
- end
79
-
80
- # Returns a list of names of javascript files for WiceGrid thus providing compatibility with Rails asset caching.
81
- # Mind the parameters, and the fact that Prototype has to be loaded before WiceGrid javascripts:
82
- #
83
- # <%= javascript_include_tag *([:defaults] + names_of_wice_grid_javascripts + [ 'ui', 'swfobject', {:cache => true}]) %>
84
- #
85
- # By default +names_of_wice_grid_javascripts+ returns all javascripts, but it's possible not to include calendar widget javascripts by
86
- # setting parameter <tt>:include_calendar</tt> to +false+.
87
- def names_of_wice_grid_javascripts(options = {})
88
- Wice::JsAdaptor.init
89
- opts = {:include_calendar => true}
90
- options.assert_valid_keys(opts.keys)
91
- opts.merge!(options)
92
- res = ['wice_grid']
93
- n = JsAdaptor.js_framework_specific_calendar_js_name
94
- res << n if n && opts[:include_calendar]
95
- res
96
- end
97
-
98
- # Returns a list of names of stylesheet files for WiceGrid thus providing compatibility with Rails asset caching.
99
- # Mind the parameters, for example:
100
- #
101
- # <%= stylesheet_link_tag *(['core', 'modalbox'] + names_of_wice_grid_stylesheets + [ {:cache => true}]) %>
102
- #
103
- # By default +names_of_wice_grid_stylesheets+ returns all javascripts, but it's possible not to include calendar widget javascripts by
104
- # setting parameter <tt>:include_calendar</tt> to +false+.
105
- def names_of_wice_grid_stylesheets(options = {})
106
- Wice::JsAdaptor.init
107
- opts = {:include_calendar => true}
108
- options.assert_valid_keys(opts.keys)
109
- opts.merge!(options)
110
- res = ['wice_grid']
111
- n = JsAdaptor.js_framework_specific_calendar_css_name
112
- res << n if n && opts[:include_calendar]
113
- res
114
- end
115
-
116
51
  end
117
52
  end
@@ -5,19 +5,20 @@ module Wice
5
5
  # View helper to render the list of saved queries and the form to create a new query.
6
6
  # Parameters:
7
7
  # * <tt>:extra_parameters</tt> - a hash of additional parameters to use when creating a new query object.
8
+ # * <tt>:confirm</tt> - A boolean value which turns on or off the JS confirm dialogs when deleting saved queries.
8
9
  # Read section "Adding Application Specific Logic to Saving/Restoring Queries" in README for more details.
9
10
  def saved_queries_panel(grid, opts = {})
10
11
  unless grid.kind_of? WiceGrid
11
12
  raise WiceGridArgumentError.new("saved_queries_panel: the parameter must be a WiceGrid instance.")
12
13
  end
13
14
 
14
- options = {:extra_parameters => {}}
15
+ options = {:extra_parameters => {}, :confirm => 1}
15
16
  opts.assert_valid_keys(options.keys)
16
17
  options.merge!(opts)
17
18
 
18
19
  grid_name = grid.name
19
- id_and_name = "#{grid_name}_saved_query_name"
20
- base_path_to_query_controller = create_serialized_query_url(:grid_name => grid_name)
20
+ input_field_name = "#{grid_name}_saved_query_name"
21
+ base_path_to_query_controller = create_serialized_query_url(:grid_name => grid_name, :confirm => options[:confirm])
21
22
 
22
23
  parameters = grid.get_state_as_parameter_value_pairs
23
24
 
@@ -26,58 +27,66 @@ module Wice
26
27
  end
27
28
  parameters << ['authenticity_token', form_authenticity_token]
28
29
  notification_messages_id = "#{grid_name}_notification_messages"
29
- (%! <div class="wice_grid_query_panel"><h3>#{WiceGridNlMessageProvider.get_message(:SAVED_QUERY_PANEL_TITLE)}</h3>! +
30
- saved_queries_list(grid_name, grid.saved_query, options[:extra_parameters]) +
31
- %!<div id="#{notification_messages_id}" onmouseover="#{Wice::JsAdaptor.fade_this(notification_messages_id)}"></div>! +
30
+ (%! <div class="wice-grid-query-panel well"><h3>#{NlMessage['saved_query_panel_title']}</h3>! +
31
+ saved_queries_list(grid_name, grid.saved_query, options[:extra_parameters], options[:confirm]) +
32
+ %!<div id="#{notification_messages_id}" ></div>! +
32
33
  if block_given?
33
34
  view, ids = yield
34
35
  view
35
36
  else
36
37
  ''
37
38
  end +
38
- '<div class="wg-saved-query-input-controls">'+
39
- text_field_tag(id_and_name, '', :size => 20, :onkeydown=>'', :id => id_and_name) +
40
- button_to_function(WiceGridNlMessageProvider.get_message(:SAVE_QUERY_BUTTON_LABEL), "#{grid_name}_save_query()" ) +
41
- '</div></div>' +
42
- javascript_tag do
43
- JsAdaptor.call_to_save_query_and_key_event_initialization_for_saving_queries(
44
- id_and_name, grid_name, base_path_to_query_controller, parameters.to_json, ids.to_json
45
- ).html_safe
46
- end
39
+
40
+ '<div class="form-horizontal"><div class="wg-saved-query-input-controls input-append">'+
41
+
42
+ text_field_tag(input_field_name, '', :onkeydown=>'', :class => 'wice-grid-save-query-field span4') +
43
+ button_tag(
44
+ NlMessage['save_query_button_label'],
45
+ :class => 'wice-grid-save-query-button btn',
46
+ 'data-grid-name' => grid_name,
47
+ 'data-base-path-to-query-controller' => base_path_to_query_controller,
48
+ 'data-parameters' => parameters.to_json,
49
+ 'data-ids' => ids.to_json
50
+ ) +
51
+ '</div></div></div>'
47
52
  ).html_safe
48
53
  end
49
54
 
50
- def saved_queries_list(grid_name, saved_query = nil, extra_parameters = {}) #:nodoc:
55
+ def saved_queries_list(grid_name, saved_query = nil, extra_parameters = {}, confirm = 1) #:nodoc:
51
56
 
52
- link_title = WiceGridNlMessageProvider.get_message(:SAVED_QUERY_LINK_TITLE)
53
- deletion_confirmation = WiceGridNlMessageProvider.get_message(:SAVED_QUERY_DELETION_CONFIRMATION)
54
- deletion_link_title = WiceGridNlMessageProvider.get_message(:SAVED_QUERY_DELETION_LINK_TITLE)
57
+ link_title = NlMessage['saved_query_link_title']
58
+ deletion_confirmation = confirm ? NlMessage['saved_query_deletion_confirmation'] : nil
59
+ deletion_link_title = NlMessage['saved_query_deletion_link_title']
55
60
 
56
61
  query_store_model = ::Wice::get_query_store_model
57
62
  currently_loaded_query_id = saved_query ? saved_query.id : nil
58
63
  with = extra_parameters.nil? ? nil : "'" + {:extra => extra_parameters}.to_query + "'"
59
64
 
60
- %!<ul id="#{grid_name}_query_list" class="query_list"> ! +
65
+ %!<ul id="#{grid_name}_query_list" class="query-list"> ! +
61
66
  query_store_model.list(grid_name, controller).collect do |sq|
62
- link_opts = {:class => 'query_load_link', :title => "#{link_title} #{sq.name}"}
67
+ link_opts = {
68
+ :class => 'wice-grid-query-load-link',
69
+ :title => "#{link_title} #{sq.name}",
70
+ 'data-query-id' => sq.id,
71
+ 'data-grid-name' => grid_name
72
+ }
63
73
  link_opts[:class] += ' current' if saved_query == sq
64
74
  "<li>"+
65
75
  link_to(
66
- image_tag(Defaults::DELETE_QUERY_ICON),
76
+ content_tag(:div, '', :class => 'delete-icon'),
67
77
  delete_serialized_query_path(
68
78
  :grid_name => grid_name,
69
- :id => sq.id,
70
- :current => currently_loaded_query_id,
71
- :extra => extra_parameters
79
+ :id => sq.id,
80
+ :current => currently_loaded_query_id,
81
+ :extra => extra_parameters,
82
+ :confirm => confirm
72
83
  ),
73
- :remote => true,
74
- :confirm => deletion_confirmation,
75
- :title => "#{deletion_link_title} #{sq.name}",
76
- :with => 'with'
84
+ :class => 'wice-grid-delete-query',
85
+ 'data-wg-confirm' => deletion_confirmation,
86
+ 'data-grid-name' => grid_name,
87
+ :title => "#{deletion_link_title} #{sq.name}"
77
88
  ) + ' &nbsp; ' +
78
- link_to_function(h(sq.name),
79
- %/ if (typeof(#{grid_name}) != "undefined") #{grid_name}.load_query(#{sq.id}) /,
80
- link_opts) +
89
+ link_to(h(sq.name), '#', link_opts) +
81
90
  if sq.respond_to? :description
82
91
  desc = sq.description
83
92
  desc.blank? ? '' : " <i>#{desc}</i>"
@@ -7,9 +7,9 @@ module Wice
7
7
  # The first parameter is a grid object returned by +initialize_grid+ in the controller.
8
8
  #
9
9
  # The second parameter is a hash of options:
10
- # * <tt>:table_html_attrs</tt> - a hash of HTML attributes to be included into the <tt>table</tt> tag.
11
- # * <tt>:class</tt> - a shortcut for <tt>:table_html_attrs => {:class => 'css_class'}</tt>
12
- # * <tt>:header_tr_html_attrs</tt> - a hash of HTML attributes to be included into the first <tt>tr</tt> tag
10
+ # * <tt>:html</tt> - a hash of HTML attributes to be included into the <tt>table</tt> tag.
11
+ # * <tt>:class</tt> - a shortcut for <tt>:html => {:class => 'css_class'}</tt>
12
+ # * <tt>:header_tr_html</tt> - a hash of HTML attributes to be included into the first <tt>tr</tt> tag
13
13
  # (or two first <tt>tr</tt>'s if the filter row is present).
14
14
  # * <tt>:show_filters</tt> - defines when the filter is shown. Possible values are:
15
15
  # * <tt>:when_filtered</tt> - the filter is shown when the current table is the result of filtering
@@ -28,17 +28,15 @@ module Wice
28
28
  # * <tt>:sorting_dependant_row_cycling</tt> - When set to true (by default it is false) the row styles +odd+
29
29
  # and +even+ will be changed only when the content of the cell belonging to the sorted column changes.
30
30
  # In other words, rows with identical values in the ordered column will have the same style (color).
31
- # * <tt>:erb_mode</tt> - can be <tt>true</tt> or <tt>false</tt>. Defines the style of the helper method
32
- # in the view. The default is <tt>false</tt>.
33
31
  # * <tt>:allow_showing_all_records</tt> - allow or prohibit the "All Records" mode.
34
32
  # * <tt>:hide_reset_button</tt> - Do not show the default Filter Reset button.
35
- # Useful when using a custom reset button (helper +reset_grid_javascript+).
33
+ # Useful when using a custom reset button.
36
34
  # By default it is false.
37
35
  # * <tt>:hide_submit_button</tt> - Do not show the default Filter Submit button.
38
- # Useful when using a custom submit button (helper +submit_grid_javascript+).
36
+ # Useful when using a custom submit button
39
37
  # By default it is false.
40
38
  # * <tt>:hide_csv_button</tt> - a boolean value which defines whether the default Export To CSV button
41
- # should be rendered. Useful when using a custom Export To CSV button (helper +export_to_csv_javascript+).
39
+ # should be rendered. Useful when using a custom Export To CSV button.
42
40
  # By default it is false.
43
41
  # Please read README for more insights.
44
42
  #
@@ -47,13 +45,13 @@ module Wice
47
45
  # first block is called for cells of the first column for each row (each ActiveRecord instance), the
48
46
  # second block is called for cells of the second column, and so on. See the example:
49
47
  #
50
- # <%= grid(@accounts_grid, :table_html_attrs => {:class => 'grid_style', :id => 'accounts_grid'}, :header_tr_html_attrs => {:class => 'grid_headers'}) do |g|
48
+ # <%= grid(@accounts_grid, :html => {:class => 'grid_style', :id => 'accounts_grid'}, :header_tr_html => {:class => 'grid_headers'}) do |g|
51
49
  #
52
- # g.column :column_name => 'Username', :attribute_name => 'username' do |account|
50
+ # g.column :name => 'Username', :attribute => 'username' do |account|
53
51
  # account.username
54
52
  # end
55
53
  #
56
- # g.column :column_name => 'application_account.field.identity_id'._, :attribute_name => 'firstname', :model_class => Person do |account|
54
+ # g.column :name => 'application_account.field.identity_id'._, :attribute => 'firstname', :model => Person do |account|
57
55
  # link_to(account.identity.name, identity_path(account.identity))
58
56
  # end
59
57
  #
@@ -63,43 +61,6 @@ module Wice
63
61
  #
64
62
  # end -%>
65
63
  #
66
- # The helper may have two styles defined by the +erb_mode+ parameter to the +initialize_grid+ in the contoller.
67
- # By default (<tt>erb_mode = false</tt>) this is a simple helper surrounded by <tt><%=</tt> and <tt>%></tt>:
68
- #
69
- # <%= grid(@countries_grid) do |g|
70
- #
71
- # g.column :column_name => 'Name', :attribute_name => 'name' do |country|
72
- # link_to(country.name, country_path(country))
73
- # end
74
- #
75
- # g.column :column_name => 'Numeric Code', :attribute_name => 'numeric_code' do |country|
76
- # country.numeric_code
77
- # end
78
- #
79
- # end -%>
80
- #
81
- #
82
- #
83
- # The second style (<tt>erb_mode = true</tt>) is called <em>ERB mode</em> and it allows to embed any ERB content inside blocks,
84
- # which is basically the style of the
85
- # <tt>form_for</tt> helper, only <tt>form_for</tt> takes one block, while inside the <tt>grid</tt> block there are other method calls taking
86
- # blocks as parameters:
87
- #
88
- # <% grid(@countries_grid) do |g|
89
- #
90
- # <% g.column :column_name => 'Name', :attribute_name => 'name' do |country| %>
91
- # <b>Name: <%= link_to(country.name, country_path(country)) %></b>
92
- # <% end %>
93
- #
94
- # <% g.column :column_name => 'Numeric Code', :attribute_name => 'numeric_code' do |country| %>
95
- # <i>Numeric Code: <%= country.numeric_code %></i>
96
- # <% end %>
97
- #
98
- # <% end -%>
99
- #
100
- # This mode can be usable if you like to have much HTML code inside cells.
101
- #
102
- # Please remember that in this mode the helper opens with <tt><%</tt> instead of <tt><%=</tt>, similar to <tt>form_for</tt>.
103
64
  #
104
65
  # Defaults for parameters <tt>:show_filters</tt> and <tt>:upper_pagination_panel</tt>
105
66
  # can be changed in <tt>lib/wice_grid_config.rb</tt> using constants <tt>Wice::Defaults::SHOW_FILTER</tt> and
@@ -109,6 +70,7 @@ module Wice
109
70
  # Pease read documentation about the +column+ method to achieve the enlightenment.
110
71
 
111
72
  def grid(grid, opts = {}, &block)
73
+ # strip the method from HTML stuff
112
74
  unless grid.class == WiceGrid
113
75
  raise WiceGridArgumentError.new("The first argument for the grid helper must be an instance of the WiceGrid class")
114
76
  end
@@ -125,15 +87,14 @@ module Wice
125
87
  options = {
126
88
  :allow_showing_all_records => Defaults::ALLOW_SHOWING_ALL_QUERIES,
127
89
  :class => nil,
128
- :erb_mode => Defaults::ERB_MODE,
129
90
  :extra_request_parameters => {},
130
- :header_tr_html_attrs => {},
91
+ :header_tr_html => {},
131
92
  :hide_reset_button => false,
132
93
  :hide_submit_button => false,
133
94
  :hide_csv_button => false,
134
95
  :show_filters => Defaults::SHOW_FILTER,
135
96
  :sorting_dependant_row_cycling => false,
136
- :table_html_attrs => {},
97
+ :html => {},
137
98
  :upper_pagination_panel => Defaults::SHOW_UPPER_PAGINATION_PANEL
138
99
  }
139
100
 
@@ -144,15 +105,8 @@ module Wice
144
105
  options[:show_filters] = :no if options[:show_filters] == false
145
106
  options[:show_filters] = :always if options[:show_filters] == true
146
107
 
147
- options[:table_html_attrs].add_or_append_class_value!('wice_grid', true)
148
-
149
- if options[:class]
150
- options[:table_html_attrs].add_or_append_class_value!(options[:class])
151
- options.delete(:class)
152
- end
153
108
 
154
109
  rendering = GridRenderer.new(grid, self)
155
- rendering.erb_mode = options[:erb_mode]
156
110
 
157
111
  block.call(rendering) # calling block containing column() calls
158
112
 
@@ -165,36 +119,21 @@ module Wice
165
119
  # If blank_slate is defined we don't show any grid at all
166
120
  if rendering.blank_slate_handler && grid.resultset.size == 0 && ! grid.filtering_on?
167
121
  content = generate_blank_slate(grid, rendering)
168
- return prepare_result(rendering, grid, content, block)
122
+ return content
169
123
  end
170
124
 
171
125
  content = grid_html(grid, options, rendering, reuse_last_column_for_filter_buttons)
172
126
  end
173
127
 
174
128
  grid.view_helper_finished = true
175
- prepare_result(rendering, grid, content, block)
176
- end
177
-
178
- def prepare_result(rendering, grid, content, block) #:nodoc:
179
- if rendering.erb_mode
180
- # true in this case is a sign that grid_html has run in a normal mode, i.e. without detached filters
181
- if grid.output_buffer.nil? || grid.output_buffer == true
182
- return content.to_s
183
- else
184
- # this way we're sending an empty string and setting flag stubborn_output_mode of GridOutputBuffer to false
185
- return grid.output_buffer.to_s
186
- end
187
- else
188
- return content
189
- end
129
+ content
190
130
  end
191
131
 
192
-
193
132
  def generate_blank_slate(grid, rendering) #:nodoc:
194
133
  buff = GridOutputBuffer.new
195
134
 
196
135
  buff << if rendering.blank_slate_handler.is_a?(Proc)
197
- call_block_as_erb_or_ruby(rendering, rendering.blank_slate_handler, nil)
136
+ call_block(rendering.blank_slate_handler, nil)
198
137
  elsif rendering.blank_slate_handler.is_a?(Hash)
199
138
  render(rendering.blank_slate_handler)
200
139
  else
@@ -209,27 +148,38 @@ module Wice
209
148
  buff
210
149
  end
211
150
 
212
- def call_block_as_erb_or_ruby(rendering, block, ar) #:nodoc:
213
- if rendering.erb_mode
214
- capture(ar, &block)
215
- else
216
- block.call(ar)
217
- end
151
+ def call_block(block, ar, extra_argument = nil) #:nodoc:
152
+ extra_argument ? block.call(ar, extra_argument) : block.call(ar)
218
153
  end
219
154
 
220
155
  # the longest method? :(
221
156
  def grid_html(grid, options, rendering, reuse_last_column_for_filter_buttons) #:nodoc:
222
157
 
223
- table_html_attrs, header_tr_html_attrs = options[:table_html_attrs], options[:header_tr_html_attrs]
158
+ table_html_attrs, header_tr_html = options[:html], options[:header_tr_html]
159
+
160
+ table_html_attrs.add_or_append_class_value!('wice-grid', true)
161
+
162
+ if Array === Defaults::DEFAULT_TABLE_CLASSES
163
+ Defaults::DEFAULT_TABLE_CLASSES.each do |default_class|
164
+ table_html_attrs.add_or_append_class_value!(default_class, true)
165
+ end
166
+ end
167
+
168
+ if options[:class]
169
+ table_html_attrs.add_or_append_class_value!(options[:class])
170
+ options.delete(:class)
171
+ end
172
+
173
+
224
174
 
225
175
  cycle_class = nil
226
176
  sorting_dependant_row_cycling = options[:sorting_dependant_row_cycling]
227
177
 
228
178
  content = GridOutputBuffer.new
229
- # Ruby 1.9.1
179
+ # Ruby 1.9.x
230
180
  content.force_encoding('UTF-8') if content.respond_to?(:force_encoding)
231
181
 
232
- content << %!<div class="wice_grid_container" id="#{grid.name}"><div id="#{grid.name}_title">!
182
+ content << %!<div class="wice-grid-container" id="#{grid.name}"><div id="#{grid.name}_title">!
233
183
  content << content_tag(:h3, grid.saved_query.name) if grid.saved_query
234
184
  content << "</div><table #{tag_options(table_html_attrs, true)}>"
235
185
  content << "<thead>"
@@ -244,17 +194,22 @@ module Wice
244
194
 
245
195
  no_rightmost_column = true if reuse_last_column_for_filter_buttons
246
196
 
197
+ number_of_columns = rendering.number_of_columns(:in_html)
198
+ number_of_columns -= 1 if no_rightmost_column
199
+
200
+ number_of_columns_for_extra_rows = number_of_columns + 1
201
+
247
202
  pagination_panel_content_html, pagination_panel_content_js = nil, nil
248
203
  if options[:upper_pagination_panel]
249
- content << rendering.pagination_panel(no_rightmost_column, options[:hide_csv_button]) do
250
- pagination_panel_content_html, pagination_panel_content_js =
204
+ content << rendering.pagination_panel(number_of_columns, options[:hide_csv_button]) do
205
+ pagination_panel_content_html =
251
206
  pagination_panel_content(grid, options[:extra_request_parameters], options[:allow_showing_all_records])
252
207
  pagination_panel_content_html
253
208
  end
254
209
  end
255
210
 
256
- title_row_attrs = header_tr_html_attrs.clone
257
- title_row_attrs.add_or_append_class_value!('wice_grid_title_row', true)
211
+ title_row_attrs = header_tr_html.clone
212
+ title_row_attrs.add_or_append_class_value!('wice-grid-title-row', true)
258
213
 
259
214
  content << %!<tr #{tag_options(title_row_attrs, true)}>!
260
215
 
@@ -268,19 +223,13 @@ module Wice
268
223
  true
269
224
  end
270
225
 
271
- cached_javascript = []
272
-
273
226
  rendering.each_column_aware_of_one_last_one(:in_html) do |column, last|
274
227
 
275
- column_name = column.column_name
276
- if column_name.is_a? Array
277
- column_name, js = column_name
278
- cached_javascript << js
279
- end
228
+ column_name = column.name
280
229
 
281
- if column.attribute_name && column.allow_ordering
230
+ if column.attribute && column.ordering
282
231
 
283
- css_class = grid.filtered_by?(column) ? 'active_filter' : nil
232
+ css_class = grid.filtered_by?(column) ? 'active-filter' : nil
284
233
 
285
234
  direction = 'asc'
286
235
  link_style = nil
@@ -299,8 +248,7 @@ module Wice
299
248
  else
300
249
  if reuse_last_column_for_filter_buttons && last
301
250
  content << content_tag(:th,
302
- hide_show_icon(filter_row_id, grid, filter_shown, no_filter_row, options[:show_filters], rendering),
303
- :class => 'hide_show_icon'
251
+ hide_show_icon(filter_row_id, grid, filter_shown, no_filter_row, options[:show_filters], rendering)
304
252
  )
305
253
  else
306
254
  content << content_tag(:th, column_name)
@@ -309,8 +257,7 @@ module Wice
309
257
  end
310
258
 
311
259
  content << content_tag(:th,
312
- hide_show_icon(filter_row_id, grid, filter_shown, no_filter_row, options[:show_filters], rendering),
313
- :class => 'hide_show_icon'
260
+ hide_show_icon(filter_row_id, grid, filter_shown, no_filter_row, options[:show_filters], rendering)
314
261
  ) unless no_rightmost_column
315
262
 
316
263
  content << '</tr>'
@@ -322,17 +269,16 @@ module Wice
322
269
  content.stubborn_output_mode = true
323
270
  rendering.each_column(:in_html) do |column|
324
271
  if column.filter_shown?
325
- filter_html_code, filter_js_code = column.render_filter
272
+ filter_html_code = column.render_filter
326
273
  filter_html_code = filter_html_code.html_safe_if_necessary
327
- cached_javascript << filter_js_code
328
274
  content.add_filter(column.detach_with_id, filter_html_code)
329
275
  end
330
276
  end
331
277
 
332
278
  else # some filters are present in the table
333
279
 
334
- filter_row_attrs = header_tr_html_attrs.clone
335
- filter_row_attrs.add_or_append_class_value!('wice_grid_filter_row', true)
280
+ filter_row_attrs = header_tr_html.clone
281
+ filter_row_attrs.add_or_append_class_value!('wg-filter-row', true)
336
282
  filter_row_attrs['id'] = filter_row_id
337
283
 
338
284
  content << %!<tr #{tag_options(filter_row_attrs, true)} !
@@ -342,9 +288,8 @@ module Wice
342
288
  rendering.each_column_aware_of_one_last_one(:in_html) do |column, last|
343
289
  if column.filter_shown?
344
290
 
345
- filter_html_code, filter_js_code = column.render_filter
291
+ filter_html_code = column.render_filter
346
292
  filter_html_code = filter_html_code.html_safe_if_necessary
347
- cached_javascript << filter_js_code
348
293
  if column.detach_with_id
349
294
  content.stubborn_output_mode = true
350
295
  content << content_tag(:th, '', Hash.make_hash(:class, column.css_class))
@@ -372,23 +317,23 @@ module Wice
372
317
 
373
318
  rendering.each_column(:in_html) do |column|
374
319
  unless column.css_class.blank?
375
- column.td_html_attrs.add_or_append_class_value!(column.css_class)
320
+ column.html.add_or_append_class_value!(column.css_class)
376
321
  end
377
322
  end
378
323
 
379
324
  content << '</thead><tfoot>'
380
- content << rendering.pagination_panel(no_rightmost_column, options[:hide_csv_button]) do
325
+ content << rendering.pagination_panel(number_of_columns, options[:hide_csv_button]) do
381
326
  if pagination_panel_content_html
382
327
  pagination_panel_content_html
383
328
  else
384
- pagination_panel_content_html, pagination_panel_content_js =
329
+ pagination_panel_content_html =
385
330
  pagination_panel_content(grid, options[:extra_request_parameters], options[:allow_showing_all_records])
386
331
  pagination_panel_content_html
387
332
  end
388
333
  end
389
334
 
390
335
  content << '</tfoot><tbody>'
391
- cached_javascript << pagination_panel_content_js
336
+
392
337
 
393
338
  # rendering rows
394
339
  cell_value_of_the_ordered_column = nil
@@ -397,13 +342,13 @@ module Wice
397
342
  grid.each do |ar| # rows
398
343
 
399
344
  before_row_output = if rendering.before_row_handler
400
- call_block_as_erb_or_ruby(rendering, rendering.before_row_handler, ar)
345
+ call_block(rendering.before_row_handler, ar, number_of_columns_for_extra_rows)
401
346
  else
402
347
  nil
403
348
  end
404
349
 
405
350
  after_row_output = if rendering.after_row_handler
406
- call_block_as_erb_or_ruby(rendering, rendering.after_row_handler, ar)
351
+ call_block(rendering.after_row_handler, ar, number_of_columns_for_extra_rows)
407
352
  else
408
353
  nil
409
354
  end
@@ -412,12 +357,12 @@ module Wice
412
357
  rendering.each_column(:in_html) do |column|
413
358
  cell_block = column.cell_rendering_block
414
359
 
415
- opts = column.td_html_attrs.clone
360
+ opts = column.html.clone
416
361
 
417
- column_block_output = if column.class == Wice::ActionViewColumn
362
+ column_block_output = if column.class == ViewColumn.get_column_processor(:action)
418
363
  cell_block.call(ar, params)
419
364
  else
420
- call_block_as_erb_or_ruby(rendering, cell_block, ar)
365
+ call_block(cell_block, ar)
421
366
  end
422
367
 
423
368
  if column_block_output.kind_of?(Array)
@@ -446,7 +391,7 @@ module Wice
446
391
  opts.add_or_append_class_value!(additional_css_class) unless additional_css_class.blank?
447
392
  end
448
393
 
449
- if sorting_dependant_row_cycling && column.attribute_name && grid.ordered_by?(column)
394
+ if sorting_dependant_row_cycling && column.attribute && grid.ordered_by?(column)
450
395
  cell_value_of_the_ordered_column = column_block_output
451
396
  end
452
397
  row_content += content_tag(:td, column_block_output, opts)
@@ -471,14 +416,14 @@ module Wice
471
416
  end
472
417
 
473
418
  last_row_output = if rendering.last_row_handler
474
- call_block_as_erb_or_ruby(rendering, rendering.last_row_handler, nil)
419
+ call_block(rendering.last_row_handler, number_of_columns_for_extra_rows)
475
420
  else
476
421
  nil
477
422
  end
478
423
 
479
424
  content << last_row_output if last_row_output
480
425
 
481
- content << '</tbody></table></div>'
426
+ content << '</tbody></table>'
482
427
 
483
428
  base_link_for_filter, base_link_for_show_all_records = rendering.base_link_for_filter(controller, options[:extra_request_parameters])
484
429
 
@@ -487,82 +432,40 @@ module Wice
487
432
  parameter_name_for_query_loading = {grid.name => {:q => ''}}.to_query
488
433
  parameter_name_for_focus = {grid.name => {:foc => ''}}.to_query
489
434
 
490
- prototype_and_js_version_check = if Rails.env == 'development'
491
- %$ if (typeof(WiceGridProcessor) == "undefined"){\n$ +
492
- %$ alert('wice_grid.js not loaded, WiceGrid cannot proceed! ' +\n$ +
493
- %$ 'Please make sure that you include WiceGrid javascript in your page. ' +\n$ +
494
- %$ 'Use <%= include_wice_grid_assets %> or <%= include_wice_grid_assets(:include_calendar => true) %> ' +\n$ +
495
- %$ 'for WiceGrid javascripts and assets.')\n$ +
496
- %$ } else if ((typeof(WiceGridProcessor._version) == "undefined") || ( WiceGridProcessor._version != "0.4.3")) {\n$ +
497
- %$ alert("wice_grid.js in your /public is outdated, please run\\n ./script/generate wice_grid_assets_jquery\\n$ +
498
- %$ or\\n ./script/generate wice_grid_assets_prototype\\nto update it.");\n$ +
499
- %$ }\n$
500
- else
501
- ''
502
- end
503
-
504
- if rendering.show_hide_button_present
505
- cached_javascript << JsAdaptor.show_hide_button_initialization(grid.name, filter_row_id)
506
- end
507
-
508
- if rendering.reset_button_present
509
- cached_javascript << JsAdaptor.reset_button_initialization(grid.name, reset_grid_javascript(grid))
510
- end
435
+ processor_initializer_arguments = [base_link_for_filter, base_link_for_show_all_records,
436
+ link_for_export, parameter_name_for_query_loading, parameter_name_for_focus, Rails.env]
511
437
 
512
- if rendering.submit_button_present
513
- cached_javascript << JsAdaptor.submit_button_initialization(grid.name, submit_grid_javascript(grid))
514
- end
515
-
516
- if rendering.contains_a_text_input?
517
- cached_javascript << JsAdaptor.enter_key_event_registration(grid.name)
438
+ filter_declarations = if no_filters_at_all
439
+ []
440
+ else
441
+ rendering.select_for(:in_html) do |vc|
442
+ vc.attribute && vc.filter
443
+ end.collect{|column| column.yield_declaration}
518
444
  end
519
445
 
520
- if rendering.csv_export_icon_present
521
- cached_javascript << JsAdaptor.csv_export_icon_initialization(grid.name)
522
- end
446
+ wg_data = {
447
+ 'data-processor-initializer-arguments' => processor_initializer_arguments.to_json,
448
+ 'data-filter-declarations' => filter_declarations.to_json,
449
+ :class => 'wg-data'
450
+ }
523
451
 
524
- if rendering.contains_auto_reloading_selects
525
- cached_javascript << JsAdaptor.auto_reloading_selects_event_initialization(grid.name)
526
- end
452
+ wg_data['data-foc'] = grid.status['foc'] if grid.status['foc']
527
453
 
528
- if rendering.contains_auto_reloading_inputs
529
- cached_javascript << JsAdaptor.auto_reloading_inputs_event_initialization(grid.name)
530
- end
454
+ content << content_tag(:div, '', wg_data)
531
455
 
532
- if rendering.contains_auto_reloading_inputs_with_negation_checkboxes
533
- cached_javascript << JsAdaptor.auto_reloading_inputs_with_negation_checkboxes_event_initialization(grid.name)
534
- end
456
+ content << '</div>'
535
457
 
536
- if rendering.contains_auto_reloading_calendars
537
- cached_javascript << JsAdaptor.auto_reloading_calendar_event_initialization(grid.name)
458
+ if Rails.env == 'development'
459
+ content << javascript_tag(%/ $(document).ready(function(){ \n/ +
460
+ %$ if (typeof(WiceGridProcessor) == "undefined"){\n$ +
461
+ %$ alert("wice_grid.js not loaded, WiceGrid cannot proceed!\\n" +\n$ +
462
+ %$ "Make sure that you have loaded wice_grid.js.\\n" +\n$ +
463
+ %$ "Add line\\n//= require wice_grid.js\\n" +\n$ +
464
+ %$ "to app/assets/javascripts/application.js")\n$ +
465
+ %$ }\n$ +
466
+ %$ }) $)
538
467
  end
539
468
 
540
- if rendering.element_to_focus
541
- cached_javascript << JsAdaptor.focus_element(rendering.element_to_focus)
542
- end
543
-
544
- if Wice::ConfigurationProvider.value_for(:SECOND_RANGE_VALUE_FOLLOWING_THE_FIRST) && rendering.contains_range_filters
545
- cached_javascript << JsAdaptor.update_ranges(grid.name)
546
- end
547
-
548
-
549
- content << javascript_tag(
550
- JsAdaptor.dom_loaded +
551
- %/ #{prototype_and_js_version_check}\n/ +
552
- %/ window['#{grid.name}'] = new WiceGridProcessor('#{grid.name}', '#{base_link_for_filter}',\n/ +
553
- %/ '#{base_link_for_show_all_records}', '#{link_for_export}', '#{parameter_name_for_query_loading}',\n/ +
554
- %/ '#{parameter_name_for_focus}', '#{Rails.env}');\n/ +
555
- if no_filters_at_all
556
- ''
557
- else
558
- rendering.select_for(:in_html) do |vc|
559
- vc.attribute_name and not vc.no_filter
560
- end.collect{|column| column.yield_javascript}.join("\n")
561
- end +
562
- "\n" + cached_javascript.compact.join('') +
563
- '})'
564
- )
565
-
566
469
  if content.stubborn_output_mode
567
470
  grid.output_buffer = content
568
471
  else
@@ -585,32 +488,18 @@ module Wice
585
488
  hide_icon = show_icon = ''
586
489
  else
587
490
 
588
-
589
- rendering.show_hide_button_present = true
590
- filter_tooltip = WiceGridNlMessageProvider.get_message(:HIDE_FILTER_TOOLTIP)
591
-
592
- hide_icon = content_tag(:span,
593
- image_tag(Defaults::SHOW_HIDE_FILTER_ICON,
594
- :title => filter_tooltip,
595
- :alt => filter_tooltip),
596
- :id => grid_name + '_hide_icon',
491
+ content_tag(:div, '',
492
+ :title => NlMessage['hide_filter_tooltip'],
597
493
  :style => styles[0],
598
- :class => 'clickable'
599
- )
600
-
494
+ :class => 'clickable wg-hide-filter'
495
+ ) +
601
496
 
602
- filter_tooltip = WiceGridNlMessageProvider.get_message(:SHOW_FILTER_TOOLTIP)
603
-
604
- show_icon = content_tag(:span,
605
- image_tag(Defaults::SHOW_HIDE_FILTER_ICON,
606
- :title => filter_tooltip,
607
- :alt => filter_tooltip),
608
- :id => grid_name + '_show_icon',
497
+ content_tag(:div, '',
498
+ :title => NlMessage['show_filter_tooltip'],
609
499
  :style => styles[1],
610
- :class => 'clickable'
500
+ :class => 'clickable wg-show-filter'
611
501
  )
612
502
 
613
- hide_icon + show_icon
614
503
  end
615
504
  end
616
505
 
@@ -618,16 +507,21 @@ module Wice
618
507
  (if options[:hide_submit_button]
619
508
  ''
620
509
  else
621
- rendering.submit_button_present = true
622
- filter_tooltip = WiceGridNlMessageProvider.get_message(:FILTER_TOOLTIP)
623
- image_tag(Defaults::FILTER_ICON, :title => filter_tooltip, :alt => filter_tooltip, :class => 'submit clickable')
510
+ content_tag(:div, '',
511
+ :title => NlMessage['filter_tooltip'],
512
+ :id => grid.name + '_submit_grid_icon',
513
+ :class => 'submit clickable'
514
+ )
624
515
  end + ' ' +
625
516
  if options[:hide_reset_button]
626
517
  ''
627
518
  else
628
- rendering.reset_button_present = true
629
- filter_tooltip = WiceGridNlMessageProvider.get_message(:RESET_FILTER_TOOLTIP)
630
- image_tag(Defaults::RESET_ICON, :title => filter_tooltip, :alt => filter_tooltip, :class => 'reset clickable')
519
+
520
+ content_tag(:div, '',
521
+ :title => NlMessage['reset_filter_tooltip'],
522
+ :id => grid.name + '_reset_grid_icon',
523
+ :class => 'reset clickable'
524
+ )
631
525
  end).html_safe_if_necessary
632
526
  end
633
527
 
@@ -636,7 +530,7 @@ module Wice
636
530
  # * +filter_key+ an identifier of the filter specified in the column declaration by parameter +:detach_with_id+
637
531
  def grid_filter(grid, filter_key)
638
532
  unless grid.kind_of? WiceGrid
639
- raise WiceGridArgumentError.new("submit_grid_javascript: the parameter must be a WiceGrid instance.")
533
+ raise WiceGridArgumentError.new("grid_filter: the parameter must be a WiceGrid instance.")
640
534
  end
641
535
  if grid.output_buffer.nil?
642
536
  raise WiceGridArgumentError.new("grid_filter: You have attempted to run 'grid_filter' before 'grid'. Read about detached filters in the documentation.")
@@ -646,44 +540,16 @@ module Wice
646
540
  ":show_filters => :no (set :show_filters to :always in this case). Read about detached filters in the documentation.")
647
541
  end
648
542
 
649
- content_tag :span, grid.output_buffer.filter_for(filter_key), :class => "#{grid.name}_detached_filter"
650
- end
651
-
652
- # Returns javascript which applies current filters. The parameter is a WiceGrid instance. Use it with +button_to_function+ to create
653
- # your Submit button.
654
- def submit_grid_javascript(grid)
655
- unless grid.kind_of? WiceGrid
656
- raise WiceGridArgumentError.new("submit_grid_javascript: the parameter must be a WiceGrid instance.")
657
- end
658
- "#{grid.name}.process()"
659
- end
660
-
661
- # Returns javascript which resets the grid, clearing the state of filters.
662
- # The parameter is a WiceGrid instance. Use it with +button_to_function+ to create
663
- # your Reset button.
664
- def reset_grid_javascript(grid)
665
- unless grid.kind_of? WiceGrid
666
- raise WiceGridArgumentError.new("reset_grid_javascript: the parameter must be a WiceGrid instance.")
667
- end
668
- "#{grid.name}.reset()"
669
- end
670
-
671
- # Returns javascript which triggers export to CSV.
672
- # The parameter is a WiceGrid instance. Use it with +button_to_function+ to create
673
- # your own Export To CSV button.
674
- def export_to_csv_javascript(grid)
675
- unless grid.kind_of? WiceGrid
676
- raise WiceGridArgumentError.new("export_csv_javascript: the parameter must be a WiceGrid instance.")
677
- end
678
- "#{grid.name}.export_to_csv()"
543
+ content_tag :span,
544
+ grid.output_buffer.filter_for(filter_key),
545
+ :class => "wg-detached-filter #{grid.name}_detached_filter",
546
+ 'data-grid-name' => grid.name
679
547
  end
680
548
 
681
549
 
682
550
  def grid_csv(grid, rendering) #:nodoc:
683
551
 
684
-
685
- field_separator = (grid.export_to_csv_enabled && grid.export_to_csv_enabled.is_a?(String)) ? grid.export_to_csv_enabled : ','
686
- spreadsheet = ::Wice::Spreadsheet.new(grid.name, field_separator)
552
+ spreadsheet = ::Wice::Spreadsheet.new(grid.name, grid.csv_field_separator)
687
553
 
688
554
  # columns
689
555
  spreadsheet << rendering.column_labels(:in_csv)
@@ -695,7 +561,7 @@ module Wice
695
561
  rendering.each_column(:in_csv) do |column|
696
562
  cell_block = column.cell_rendering_block
697
563
 
698
- column_block_output = call_block_as_erb_or_ruby(rendering, cell_block, ar)
564
+ column_block_output = call_block(cell_block, ar)
699
565
 
700
566
  if column_block_output.kind_of?(Array)
701
567
  column_block_output, additional_opts = column_block_output
@@ -715,43 +581,44 @@ module Wice
715
581
  extra_request_parameters["#{grid.name}[q]"] = grid.saved_query.id
716
582
  end
717
583
 
718
- html, js = pagination_info(grid, allow_showing_all_records)
584
+ html = pagination_info(grid, allow_showing_all_records)
719
585
 
720
- [will_paginate(grid.resultset,
721
- :previous_label => WiceGridNlMessageProvider.get_message(:PREVIOUS_LABEL),
722
- :next_label => WiceGridNlMessageProvider.get_message(:NEXT_LABEL),
586
+ will_paginate(grid.resultset,
587
+ :previous_label => NlMessage['previous_label'],
588
+ :next_label => NlMessage['next_label'],
723
589
  :param_name => "#{grid.name}[page]",
590
+ :renderer => ::Wice::WillPaginatePaginator,
724
591
  :params => extra_request_parameters).to_s +
725
- (' <div class="pagination_status">' + html + '</div>').html_safe_if_necessary, js]
592
+ (' <div class="pagination_status">' + html + '</div>').html_safe_if_necessary
726
593
  end
727
594
 
728
595
 
729
596
  def show_all_link(collection_total_entries, parameters, grid_name) #:nodoc:
730
597
 
731
- message = WiceGridNlMessageProvider.get_message(:ALL_QUERIES_WARNING)
732
- confirmation = collection_total_entries > Defaults::START_SHOWING_WARNING_FROM ? "if (confirm('#{message}'))" : ''
598
+ message = NlMessage['all_queries_warning']
599
+ confirmation = collection_total_entries > Defaults::START_SHOWING_WARNING_FROM ? message : nil
733
600
 
734
- js = JsAdaptor.show_all_link_initialization(grid_name, confirmation, parameters.to_json)
735
-
736
- tooltip = WiceGridNlMessageProvider.get_message(:SHOW_ALL_RECORDS_TOOLTIP)
737
- html = %/<span class="show_all_link"><a href="#" title="#{tooltip}">/ +
738
- WiceGridNlMessageProvider.get_message(:SHOW_ALL_RECORDS_LABEL) +
739
- '</a></span>'
601
+ html = content_tag(:a, NlMessage['show_all_records_label'],
602
+ :href=>"#",
603
+ :title => NlMessage['show_all_records_tooltip'],
604
+ :class => 'wg-show-all-link',
605
+ 'data-grid-state' => parameters.to_json,
606
+ 'data-confim-message' => confirmation
607
+ )
740
608
 
741
- [html, js]
609
+ [html, '']
742
610
  end
743
611
 
744
612
  def back_to_pagination_link(parameters, grid_name) #:nodoc:
745
613
  pagination_override_parameter_name = "#{grid_name}[pp]"
746
614
  parameters = parameters.reject{|k, v| k == pagination_override_parameter_name}
747
615
 
748
- js = JsAdaptor.back_to_pagination_link_initialization(grid_name, parameters.to_json)
749
-
750
- tooltip = WiceGridNlMessageProvider.get_message(:SWITCH_BACK_TO_PAGINATED_MODE_TOOLTIP)
751
- html = %/ <span class="show_all_link"><a href="#" title="#{tooltip}">/ +
752
- WiceGridNlMessageProvider.get_message(:SWITCH_BACK_TO_PAGINATED_MODE_LABEL) +
753
- '</a></span>'
754
- [html, js]
616
+ content_tag(:a, NlMessage['switch_back_to_paginated_mode_label'],
617
+ :href=>"#",
618
+ :title => NlMessage['switch_back_to_paginated_mode_tooltip'],
619
+ :class => 'wg-back-to-pagination-link',
620
+ 'data-grid-state' => parameters.to_json
621
+ )
755
622
  end
756
623
 
757
624
  def pagination_info(grid, allow_showing_all_records) #:nodoc:
@@ -776,13 +643,10 @@ module Wice
776
643
  end
777
644
  end +
778
645
  if grid.all_record_mode?
779
- res, js = back_to_pagination_link(parameters, grid.name)
780
- res
646
+ back_to_pagination_link(parameters, grid.name)
781
647
  else
782
648
  ''
783
649
  end
784
-
785
- [html, js]
786
650
  end
787
651
 
788
652
  end