wice_grid 3.0.0.pre1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (64) hide show
  1. data/.gitignore +1 -0
  2. data/CHANGELOG +412 -0
  3. data/MIT-LICENSE +20 -0
  4. data/README.rdoc +1179 -0
  5. data/Rakefile +42 -0
  6. data/SAVED_QUERIES_HOWTO.rdoc +123 -0
  7. data/VERSION +1 -0
  8. data/lib/generators/wice_grid/templates/calendarview.css +107 -0
  9. data/lib/generators/wice_grid/templates/calendarview.js +1168 -0
  10. data/lib/generators/wice_grid/templates/icons/arrow_down.gif +0 -0
  11. data/lib/generators/wice_grid/templates/icons/arrow_up.gif +0 -0
  12. data/lib/generators/wice_grid/templates/icons/calendar_view_month.png +0 -0
  13. data/lib/generators/wice_grid/templates/icons/delete.png +0 -0
  14. data/lib/generators/wice_grid/templates/icons/expand.png +0 -0
  15. data/lib/generators/wice_grid/templates/icons/page_white_excel.png +0 -0
  16. data/lib/generators/wice_grid/templates/icons/page_white_find.png +0 -0
  17. data/lib/generators/wice_grid/templates/icons/table.png +0 -0
  18. data/lib/generators/wice_grid/templates/icons/table_refresh.png +0 -0
  19. data/lib/generators/wice_grid/templates/icons/tick_all.png +0 -0
  20. data/lib/generators/wice_grid/templates/icons/untick_all.png +0 -0
  21. data/lib/generators/wice_grid/templates/wice_grid.css +173 -0
  22. data/lib/generators/wice_grid/templates/wice_grid.yml +279 -0
  23. data/lib/generators/wice_grid/templates/wice_grid_config.rb +154 -0
  24. data/lib/generators/wice_grid/templates/wice_grid_jquery.js +161 -0
  25. data/lib/generators/wice_grid/templates/wice_grid_prototype.js +153 -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_output_buffer.rb +52 -0
  29. data/lib/grid_renderer.rb +535 -0
  30. data/lib/helpers/js_calendar_helpers.rb +183 -0
  31. data/lib/helpers/wice_grid_misc_view_helpers.rb +113 -0
  32. data/lib/helpers/wice_grid_serialized_queries_view_helpers.rb +91 -0
  33. data/lib/helpers/wice_grid_view_helpers.rb +781 -0
  34. data/lib/js_adaptors/jquery_adaptor.rb +145 -0
  35. data/lib/js_adaptors/js_adaptor.rb +12 -0
  36. data/lib/js_adaptors/prototype_adaptor.rb +168 -0
  37. data/lib/table_column_matrix.rb +51 -0
  38. data/lib/tasks/wice_grid_tasks.rake +28 -0
  39. data/lib/view_columns.rb +486 -0
  40. data/lib/views/create.rjs +13 -0
  41. data/lib/views/create_jq.rjs +31 -0
  42. data/lib/views/delete.rjs +12 -0
  43. data/lib/views/delete_jq.rjs +26 -0
  44. data/lib/wice_grid.rb +827 -0
  45. data/lib/wice_grid_controller.rb +165 -0
  46. data/lib/wice_grid_core_ext.rb +179 -0
  47. data/lib/wice_grid_misc.rb +98 -0
  48. data/lib/wice_grid_serialized_queries_controller.rb +86 -0
  49. data/lib/wice_grid_serialized_query.rb +15 -0
  50. data/lib/wice_grid_spreadsheet.rb +33 -0
  51. data/test/.gitignore +2 -0
  52. data/test/database.yml +21 -0
  53. data/test/schema.rb +33 -0
  54. data/test/test_helper.rb +89 -0
  55. data/test/views/projects_and_people_grid.html.erb +12 -0
  56. data/test/views/projects_and_people_grid_invalid.html.erb +12 -0
  57. data/test/views/simple_projects_grid.html.erb +9 -0
  58. data/test/wice_grid_core_ext_test.rb +183 -0
  59. data/test/wice_grid_functional_test.rb +68 -0
  60. data/test/wice_grid_misc_test.rb +41 -0
  61. data/test/wice_grid_test.rb +42 -0
  62. data/test/wice_grid_view_helper_test.rb +12 -0
  63. data/wice_grid.gemspec +111 -0
  64. metadata +153 -0
@@ -0,0 +1,154 @@
1
+ if defined?(Wice::Defaults)
2
+
3
+ Wice::Defaults::JS_FRAMEWORK = :<%= active_js_framework %>
4
+ # Wice::Defaults::JS_FRAMEWORK = :<%= inactive_js_framework %>
5
+
6
+ # Style of the view helper.
7
+ # +false+ is a usual view helper.
8
+ # +true+ will allow to embed erb content in column (cell) definitions.
9
+ Wice::Defaults::ERB_MODE = false
10
+
11
+ # Default number of rows to show per page.
12
+ Wice::Defaults::PER_PAGE = 20
13
+
14
+ # Default order direction
15
+ Wice::Defaults::ORDER_DIRECTION = 'asc'
16
+
17
+ # Default name for a grid. A grid name is the basis for a lot of
18
+ # names including parameter names, DOM IDs, etc
19
+ # The shorter the name is the shorter the request URI will be.
20
+ Wice::Defaults::GRID_NAME = 'grid'
21
+
22
+ # If REUSE_LAST_COLUMN_FOR_FILTER_ICONS is true and the last column doesn't have any filter and column name, it will be used
23
+ # for filter related icons (filter icon, reset icon, show/hide icon), otherwise an additional table column is added.
24
+ Wice::Defaults::REUSE_LAST_COLUMN_FOR_FILTER_ICONS = true
25
+
26
+ Wice::Defaults::SHOW_HIDE_FILTER_ICON = 'icons/grid/page_white_find.png'
27
+
28
+
29
+ # Icon to trigger filtering.
30
+ Wice::Defaults::FILTER_ICON = 'icons/grid/table_refresh.png'
31
+
32
+ # Icon to reset the filter.
33
+ Wice::Defaults::RESET_ICON = "icons/grid/table.png"
34
+
35
+ # Icon to reset the filter.
36
+ Wice::Defaults::TOGGLE_MULTI_SELECT_ICON = "/images/icons/grid/expand.png"
37
+
38
+ # CSV Export icon.
39
+ Wice::Defaults::CSV_EXPORT_ICON = "/images/icons/grid/page_white_excel.png"
40
+
41
+ # Tick-All icon for the action column.
42
+ Wice::Defaults::TICK_ALL_ICON = "/images/icons/grid/tick_all.png"
43
+
44
+ # Untick-All icon for the action column.
45
+ Wice::Defaults::UNTICK_ALL_ICON = "/images/icons/grid/untick_all.png"
46
+
47
+ # The label of the first option of a custom dropdown list meaning 'All items'
48
+ Wice::Defaults::CUSTOM_FILTER_ALL_LABEL = '--'
49
+
50
+
51
+ # Allow switching between a single and multiple selection modes in custom filters (dropdown boxes)
52
+ Wice::Defaults::ALLOW_MULTIPLE_SELECTION = true
53
+
54
+ # Show the upper pagination panel by default or not
55
+ Wice::Defaults::SHOW_UPPER_PAGINATION_PANEL = false
56
+
57
+ # Enabling CSV export by default
58
+ Wice::Defaults::ENABLE_EXPORT_TO_CSV = false
59
+
60
+
61
+ # The strategy when to show the filter.
62
+ # * <tt>:when_filtered</tt> - when the table is the result of filtering
63
+ # * <tt>:always</tt> - show the filter always
64
+ # * <tt>:no</tt> - never show the filter
65
+ Wice::Defaults::SHOW_FILTER = :always
66
+
67
+ # A boolean value specifying if a change in a filter triggers reloading of the grid.
68
+ Wice::Defaults::AUTO_RELOAD = false
69
+
70
+
71
+ # SQL operator used for matching strings in string filters.
72
+ Wice::Defaults::STRING_MATCHING_OPERATOR = 'LIKE'
73
+ # STRING_MATCHING_OPERATOR = 'ILIKE' # Use this for Postgresql case-insensitive matching.
74
+
75
+
76
+ # Defining one string matching operator globally for the whole application turns is not enough
77
+ # when you connect to two databases one of which is MySQL and the other is Postgresql.
78
+ # If the key for an adapter is missing it will fall back to Wice::Defaults::STRING_MATCHING_OPERATOR
79
+ Wice::Defaults::STRING_MATCHING_OPERATORS = {
80
+ 'ActiveRecord::ConnectionAdapters::MysqlAdapter' => 'LIKE',
81
+ 'ActiveRecord::ConnectionAdapters::PostgreSQLAdapter' => 'ILIKE'
82
+ }
83
+
84
+
85
+
86
+ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
87
+ # Advanced Filters #
88
+
89
+ # Switch of the negation checkbox in all text filters
90
+ Wice::Defaults::NEGATION_IN_STRING_FILTERS = false
91
+
92
+
93
+
94
+ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
95
+ # Showing All Queries #
96
+
97
+ # Enable or disable showing all queries (non-paginated table)
98
+ Wice::Defaults::ALLOW_SHOWING_ALL_QUERIES = true
99
+
100
+ # If number of all queries is more than this value, the user will be given a warning message
101
+ Wice::Defaults::START_SHOWING_WARNING_FROM = 100
102
+
103
+
104
+ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
105
+ # Saving Queries #
106
+
107
+ # Icon to delete a saved query
108
+ Wice::Defaults::DELETE_QUERY_ICON = 'icons/grid/delete.png'
109
+
110
+ # ActiveRecord model to store queries. Read the documentation for details
111
+ # QUERY_STORE_MODEL = 'WiceGridSerializedQuery'
112
+ Wice::Defaults::QUERY_STORE_MODEL = 'WiceGridSerializedQuery'
113
+
114
+
115
+ # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # #
116
+ # Here go settings related to the calendar helpers #
117
+
118
+ # The default style of the date and datetime helper
119
+ # * <tt>:calendar</tt> - JS calendar
120
+ # * <tt>:standard</tt> - standard Rails date and datetime helpers
121
+ Wice::Defaults::HELPER_STYLE = :calendar
122
+
123
+ # Format of the datetime displayed.
124
+ # If you change the format, make sure to check if +DATETIME_PARSER+ can still parse this string.
125
+ Wice::Defaults::DATETIME_FORMAT = "%Y-%m-%d %H:%M"
126
+
127
+ # Format of the date displayed.
128
+ # If you change the format, make sure to check if +DATE_PARSER+ can still parse this string.
129
+ Wice::Defaults::DATE_FORMAT = "%Y-%m-%d"
130
+
131
+ # Format of the date displayed in jQuery's Datepicker
132
+ # If you change the format, make sure to check if +DATE_PARSER+ can still parse this string.
133
+ Wice::Defaults::DATE_FORMAT_JQUERY = "yy-mm-dd"
134
+
135
+
136
+ # With Calendar helpers enabled the parameter sent is the string displayed. This lambda will be given a date string in the
137
+ # format defined by +DATETIME_FORMAT+ and must generate a DateTime object.
138
+ # In many cases <tt>Time.zone.parse</tt> is enough, for instance, <tt>%Y-%m-%d</tt>. If you change the format, make sure to check this code
139
+ # and modify it if needed.
140
+ Wice::Defaults::DATETIME_PARSER = lambda{|datetime_string| Time.zone.parse(datetime_string) }
141
+
142
+ # With Calendar helpers enabled the parameter sent is the string displayed. This lambda will be given a date string in the
143
+ # format defined by +DATETIME+ and must generate a Date object.
144
+ # In many cases <tt>Date.parse</tt> is enough, for instance, <tt>%Y-%m-%d</tt>. If you change the format, make sure to check this code
145
+ # and modify it if needed.
146
+ Wice::Defaults::DATE_PARSER = lambda{|date_string| Date.parse(date_string) }
147
+
148
+ # Icon to popup the calendar.
149
+ Wice::Defaults::CALENDAR_ICON = "/images/icons/grid/calendar_view_month.png"
150
+
151
+ # popup calendar will be shown relative to the popup trigger element or to the mouse pointer
152
+ Wice::Defaults::POPUP_PLACEMENT_STRATEGY = :trigger # :pointer
153
+
154
+ end
@@ -0,0 +1,161 @@
1
+ function WiceGridProcessor(name, base_request_for_filter, base_link_for_show_all_records,
2
+ link_for_export, parameter_name_for_query_loading, parameter_name_for_focus, environment){
3
+
4
+ this.checkIfJsFrameworkIsLoaded = function(){
5
+ if (! jQuery){
6
+ alert("jQuery not loaded, WiceGrid cannot proceed!")
7
+ }
8
+ }
9
+
10
+ this.checkIfJsFrameworkIsLoaded();
11
+ this.name = name;
12
+ this.parameter_name_for_query_loading = parameter_name_for_query_loading;
13
+ this.parameter_name_for_focus = parameter_name_for_focus;
14
+ this.base_request_for_filter = base_request_for_filter;
15
+ this.base_link_for_show_all_records = base_link_for_show_all_records;
16
+ this.link_for_export = link_for_export;
17
+ this.filter_declarations = new Array();
18
+ this.environment = environment;
19
+
20
+ this.toString = function(){
21
+ return "<WiceGridProcessor instance for grid '" + this.name + "'>";
22
+ }
23
+
24
+
25
+ this.process = function(dom_id_to_focus){
26
+ window.location = this.build_url_with_params(dom_id_to_focus);
27
+ }
28
+
29
+ this.reload_page_for_given_grid_state = function(grid_state){
30
+ var request_path = this.grid_state_to_request(grid_state);
31
+ window.location = this.append_to_url(this.base_link_for_show_all_records, request_path);
32
+ }
33
+
34
+ this.load_query = function(query_id){
35
+ var request = this.append_to_url(this.build_url_with_params(),
36
+ (this.parameter_name_for_query_loading + encodeURIComponent(query_id)));
37
+ window.location = request;
38
+ }
39
+
40
+ this.save_query = function(query_name, base_path_to_query_controller, grid_state, input_ids){
41
+ if (input_ids instanceof Array) {
42
+ input_ids.each(function(dom_id){
43
+ grid_state.push(['extra[' + dom_id + ']', $('#'+ dom_id)[0].value])
44
+ });
45
+ }
46
+
47
+ var request_path = this.grid_state_to_request(grid_state);
48
+
49
+ jQuery.ajax({
50
+ url: base_path_to_query_controller,
51
+ async: true,
52
+ data: request_path + '&query_name=' + encodeURIComponent(query_name),
53
+ dataType: 'script',
54
+ type: 'POST'
55
+ });
56
+ }
57
+
58
+ this.grid_state_to_request = function(grid_state){
59
+ return jQuery.map(grid_state, function(pair){
60
+ return encodeURIComponent(pair[0]) + '=' + encodeURIComponent(pair[1]);
61
+ }).join('&');
62
+ }
63
+
64
+
65
+ this.append_to_url = function(url, str){
66
+ var sep;
67
+ if (url.indexOf('?') != -1){
68
+ if (/[&\?]$/.exec(url)){
69
+ sep = '';
70
+ }else{
71
+ sep = '&';
72
+ }
73
+ }else{
74
+ sep = '?';
75
+ }
76
+ return url + sep + str;
77
+ }
78
+
79
+
80
+ this.build_url_with_params = function(dom_id_to_focus){
81
+ var results = new Array();
82
+ var _this = this;
83
+ jQuery.each(this.filter_declarations, function(i, filter_declaration){
84
+ param = _this.read_values_and_form_query_string(
85
+ filter_declaration.filter_name, filter_declaration.detached,
86
+ filter_declaration.templates, filter_declaration.ids);
87
+ if (param && param != ''){
88
+ results.push(param);
89
+ }
90
+ });
91
+
92
+ var res = this.base_request_for_filter;
93
+ if ( results.length != 0){
94
+ all_filter_params = results.join('&');
95
+ res = this.append_to_url(res, all_filter_params);
96
+ }
97
+ if (dom_id_to_focus){
98
+ res = this.append_to_url(res, this.parameter_name_for_focus + dom_id_to_focus);
99
+ }
100
+ return res;
101
+ }
102
+
103
+ this.reset = function(){
104
+ window.location = this.base_request_for_filter;
105
+ }
106
+
107
+ this.export_to_csv = function(){
108
+ window.location = this.link_for_export;
109
+ }
110
+
111
+ this.register = function(func){
112
+ this.filter_declarations.push(func);
113
+ }
114
+
115
+ this.read_values_and_form_query_string = function(filter_name, detached, templates, ids){
116
+ var res = new Array();
117
+ for(i = 0; i < templates.length; i++){
118
+ if($(ids[i]) == null){
119
+ if (this.environment == "development"){
120
+ message = 'WiceGrid: Error reading state of filter "' + filter_name + '". No DOM element with id "' + ids[i] + '" found.'
121
+ if (detached){
122
+ message += 'You have declared "' + filter_name +
123
+ '" as a detached filter but have not output it anywhere in the template. Read documentation about detached filters.'
124
+ }
125
+ alert(message);
126
+ }
127
+ return '';
128
+ }
129
+ var el = $('#' + ids[i]);
130
+ var val;
131
+ if (el[0] && el[0].type == 'checkbox'){
132
+ if (el[0].checked) val = 1;
133
+ } else {
134
+ val = el.val();
135
+ }
136
+ if (val instanceof Array) {
137
+ for(j = 0; j < val.length; j++){
138
+ if (val[j] && val[j] != "")
139
+ res.push(templates[i] + encodeURIComponent(val[j]));
140
+ }
141
+ } else if (val && val != ''){
142
+ res.push(templates[i] + encodeURIComponent(val));
143
+ }
144
+ }
145
+ return res.join('&');
146
+ }
147
+
148
+ };
149
+
150
+ function toggle_multi_select(select_id, link_obj, expand_label, collapse_label) {
151
+ var select = $('#' + select_id)[0];
152
+ if (select.multiple == true) {
153
+ select.multiple = false;
154
+ link_obj.title = expand_label;
155
+ } else {
156
+ select.multiple = true;
157
+ link_obj.title = collapse_label;
158
+ }
159
+ }
160
+
161
+ WiceGridProcessor._version = '0.4.3';
@@ -0,0 +1,153 @@
1
+ function WiceGridProcessor(name, base_request_for_filter, base_link_for_show_all_records,
2
+ link_for_export, parameter_name_for_query_loading, parameter_name_for_focus, environment){
3
+
4
+ this.checkIfJsFrameworkIsLoaded = function(){
5
+ if (typeof(Prototype) == "undefined"){
6
+ alert("Prototype javascript library not loaded, WiceGrid cannot proceed!")
7
+ }
8
+ }
9
+
10
+
11
+ this.checkIfJsFrameworkIsLoaded();
12
+ this.name = name;
13
+ this.parameter_name_for_query_loading = parameter_name_for_query_loading;
14
+ this.parameter_name_for_focus = parameter_name_for_focus;
15
+ this.base_request_for_filter = base_request_for_filter;
16
+ this.base_link_for_show_all_records = base_link_for_show_all_records;
17
+ this.link_for_export = link_for_export;
18
+ this.filter_declarations = new Array();
19
+ this.environment = environment;
20
+
21
+ this.toString = function(){
22
+ return "<WiceGridProcessor instance for grid '" + this.name + "'>";
23
+ }
24
+
25
+
26
+ this.process = function(dom_id_to_focus){
27
+ window.location = this.build_url_with_params(dom_id_to_focus);
28
+ }
29
+
30
+ this.reload_page_for_given_grid_state = function(grid_state){
31
+ var request_path = this.grid_state_to_request(grid_state);
32
+ window.location = this.append_to_url(this.base_link_for_show_all_records, request_path);
33
+ }
34
+
35
+ this.load_query = function(query_id){
36
+ var request = this.append_to_url(this.build_url_with_params(),
37
+ (this.parameter_name_for_query_loading + encodeURIComponent(query_id)));
38
+ window.location = request;
39
+ }
40
+
41
+ this.save_query = function(query_name, base_path_to_query_controller, grid_state, input_ids){
42
+ if (input_ids instanceof Array) {
43
+ input_ids.each(function(dom_id){
44
+ grid_state.push(['extra[' + dom_id + ']', $F(dom_id)])
45
+ });
46
+ }
47
+
48
+ var request_path = this.grid_state_to_request(grid_state);
49
+
50
+ new Ajax.Request(base_path_to_query_controller, {
51
+ asynchronous:true,
52
+ evalScripts:true,
53
+ parameters: request_path + '&query_name=' + encodeURIComponent(query_name)
54
+ })
55
+ }
56
+
57
+ this.grid_state_to_request = function(grid_state){
58
+ return res = grid_state.collect(function(pair){
59
+ return encodeURIComponent(pair[0]) + '=' + encodeURIComponent(pair[1]);
60
+ }).join('&');
61
+ }
62
+
63
+
64
+ this.append_to_url = function(url, str){
65
+ var sep;
66
+ if (url.include('?')){
67
+ if (/[&\?]$/.exec(url)){
68
+ sep = '';
69
+ }else{
70
+ sep = '&';
71
+ }
72
+ }else{
73
+ sep = '?';
74
+ }
75
+ return url + sep + str;
76
+ }
77
+
78
+
79
+ this.build_url_with_params = function(dom_id_to_focus){
80
+ var results = new Array();
81
+ this.filter_declarations.each(function(filter_declaration){
82
+ param = this.read_values_and_form_query_string(
83
+ filter_declaration.filter_name, filter_declaration.detached,
84
+ filter_declaration.templates, filter_declaration.ids);
85
+ if (param && param != ''){
86
+ results.push(param);
87
+ }
88
+ }.bind(this));
89
+ var res = this.base_request_for_filter;
90
+ if ( results.length != 0){
91
+ all_filter_params = results.join('&');
92
+ res = this.append_to_url(res, all_filter_params);
93
+ }
94
+ if (dom_id_to_focus){
95
+ res = this.append_to_url(res, this.parameter_name_for_focus + dom_id_to_focus);
96
+ }
97
+ return res;
98
+ }
99
+
100
+ this.reset = function(){
101
+ window.location = this.base_request_for_filter;
102
+ }
103
+
104
+ this.export_to_csv = function(){
105
+ window.location = this.link_for_export;
106
+ }
107
+
108
+
109
+ this.register = function(func){
110
+ this.filter_declarations.push(func);
111
+ }
112
+
113
+ this.read_values_and_form_query_string = function(filter_name, detached, templates, ids){
114
+ var res = new Array();
115
+ for(i = 0; i < templates.length; i++){
116
+ if($(ids[i]) == null){
117
+ if (this.environment == "development"){
118
+ message = 'WiceGrid: Error reading state of filter "' + filter_name + '". No DOM element with id "' + ids[i] + '" found.'
119
+ if (detached){
120
+ message += 'You have declared "' + filter_name +
121
+ '" as a detached filter but have not output it anywhere in the template. Read documentation about detached filters.'
122
+ }
123
+ alert(message);
124
+ }
125
+ return '';
126
+ }
127
+ var val = $F(ids[i]);
128
+ if (val instanceof Array) {
129
+ for(j = 0; j < val.length; j++){
130
+ if (val[j] && val[j] != "")
131
+ res.push(templates[i] + encodeURIComponent(val[j]));
132
+ }
133
+ } else if (val && ! val.empty()){
134
+ res.push(templates[i] + encodeURIComponent(val));
135
+ }
136
+ }
137
+ return res.join('&');
138
+ }
139
+
140
+ };
141
+
142
+ function toggle_multi_select(select_id, link_obj, expand_label, collapse_label) {
143
+ var select = $(select_id);
144
+ if (select.multiple == true) {
145
+ select.multiple = false;
146
+ link_obj.title = expand_label;
147
+ } else {
148
+ select.multiple = true;
149
+ link_obj.title = collapse_label;
150
+ }
151
+ }
152
+
153
+ WiceGridProcessor._version = '0.4.3';