tabulatr2 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (112) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +9 -0
  3. data/.rspec +1 -0
  4. data/.travis.yml +4 -0
  5. data/Changelog.textile +124 -0
  6. data/Gemfile +21 -0
  7. data/LICENSE +23 -0
  8. data/README.md +242 -0
  9. data/Rakefile +11 -0
  10. data/app/assets/images/tabulatr/buttons_lite_background.png +0 -0
  11. data/app/assets/images/tabulatr/pager_arrow_left.gif +0 -0
  12. data/app/assets/images/tabulatr/pager_arrow_left_off.gif +0 -0
  13. data/app/assets/images/tabulatr/pager_arrow_right.gif +0 -0
  14. data/app/assets/images/tabulatr/pager_arrow_right_off.gif +0 -0
  15. data/app/assets/images/tabulatr/sort_arrow_down.gif +0 -0
  16. data/app/assets/images/tabulatr/sort_arrow_down_off.gif +0 -0
  17. data/app/assets/images/tabulatr/sort_arrow_up.gif +0 -0
  18. data/app/assets/images/tabulatr/sort_arrow_up_off.gif +0 -0
  19. data/app/assets/javascripts/tabulatr/application.js +452 -0
  20. data/app/assets/javascripts/tabulatr/jquery.inview.min.js +3 -0
  21. data/app/assets/javascripts/tabulatr.js +1 -0
  22. data/app/assets/stylesheets/tabulatr/application.css +40 -0
  23. data/app/assets/stylesheets/tabulatr.css +4 -0
  24. data/init.rb +1 -0
  25. data/lib/generators/tabulatr/install_generator.rb +44 -0
  26. data/lib/generators/tabulatr/templates/tabulatr.rb +5 -0
  27. data/lib/generators/tabulatr/templates/tabulatr.yml +14 -0
  28. data/lib/initializers/action_controller.rb +13 -0
  29. data/lib/initializers/action_view.rb +31 -0
  30. data/lib/initializers/active_record.rb +48 -0
  31. data/lib/initializers/mark_as_localizable.rb +43 -0
  32. data/lib/tabulatr/engine.rb +3 -0
  33. data/lib/tabulatr/tabulatr/adapter/active_record.rb +84 -0
  34. data/lib/tabulatr/tabulatr/adapter.rb +55 -0
  35. data/lib/tabulatr/tabulatr/batch_actions.rb +51 -0
  36. data/lib/tabulatr/tabulatr/data_cell.rb +132 -0
  37. data/lib/tabulatr/tabulatr/dummy_record.rb +40 -0
  38. data/lib/tabulatr/tabulatr/empty_cell.rb +44 -0
  39. data/lib/tabulatr/tabulatr/filter_cell.rb +145 -0
  40. data/lib/tabulatr/tabulatr/filter_icon.rb +6 -0
  41. data/lib/tabulatr/tabulatr/finder/find_for_table.rb +187 -0
  42. data/lib/tabulatr/tabulatr/finder.rb +64 -0
  43. data/lib/tabulatr/tabulatr/formattr.rb +55 -0
  44. data/lib/tabulatr/tabulatr/header_cell.rb +146 -0
  45. data/lib/tabulatr/tabulatr/json_builder.rb +57 -0
  46. data/lib/tabulatr/tabulatr/paginator.rb +76 -0
  47. data/lib/tabulatr/tabulatr/row_builder.rb +128 -0
  48. data/lib/tabulatr/tabulatr/security.rb +21 -0
  49. data/lib/tabulatr/tabulatr/settings.rb +158 -0
  50. data/lib/tabulatr/tabulatr.rb +343 -0
  51. data/lib/tabulatr/version.rb +3 -0
  52. data/lib/tabulatr.rb +34 -0
  53. data/spec/dummy/.gitignore +18 -0
  54. data/spec/dummy/README.rdoc +28 -0
  55. data/spec/dummy/Rakefile +6 -0
  56. data/spec/dummy/app/assets/images/.keep +0 -0
  57. data/spec/dummy/app/assets/javascripts/application.js +16 -0
  58. data/spec/dummy/app/assets/stylesheets/application.css.scss +15 -0
  59. data/spec/dummy/app/controllers/application_controller.rb +5 -0
  60. data/spec/dummy/app/controllers/concerns/.keep +0 -0
  61. data/spec/dummy/app/controllers/products_controller.rb +24 -0
  62. data/spec/dummy/app/controllers/tags_controller.rb +5 -0
  63. data/spec/dummy/app/controllers/vendors_controller.rb +5 -0
  64. data/spec/dummy/app/helpers/application_helper.rb +9 -0
  65. data/spec/dummy/app/mailers/.keep +0 -0
  66. data/spec/dummy/app/models/.keep +0 -0
  67. data/spec/dummy/app/models/concerns/.keep +0 -0
  68. data/spec/dummy/app/models/product.rb +5 -0
  69. data/spec/dummy/app/models/tag.rb +3 -0
  70. data/spec/dummy/app/models/vendor.rb +2 -0
  71. data/spec/dummy/app/views/layouts/application.html.erb +14 -0
  72. data/spec/dummy/app/views/products/count_tags.html.erb +9 -0
  73. data/spec/dummy/app/views/products/one_item_per_page.html.erb +9 -0
  74. data/spec/dummy/app/views/products/simple_index.html.erb +9 -0
  75. data/spec/dummy/app/views/products/stupid_array.html.erb +20 -0
  76. data/spec/dummy/bin/bundle +3 -0
  77. data/spec/dummy/bin/rails +4 -0
  78. data/spec/dummy/bin/rake +4 -0
  79. data/spec/dummy/config/application.rb +23 -0
  80. data/spec/dummy/config/boot.rb +5 -0
  81. data/spec/dummy/config/database.yml +25 -0
  82. data/spec/dummy/config/environment.rb +5 -0
  83. data/spec/dummy/config/environments/development.rb +29 -0
  84. data/spec/dummy/config/environments/production.rb +80 -0
  85. data/spec/dummy/config/environments/test.rb +36 -0
  86. data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
  87. data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
  88. data/spec/dummy/config/initializers/inflections.rb +16 -0
  89. data/spec/dummy/config/initializers/mime_types.rb +5 -0
  90. data/spec/dummy/config/initializers/secret_token.rb +12 -0
  91. data/spec/dummy/config/initializers/session_store.rb +3 -0
  92. data/spec/dummy/config/initializers/tabulatr.rb +5 -0
  93. data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
  94. data/spec/dummy/config/locales/en.yml +23 -0
  95. data/spec/dummy/config/locales/tabulatr.yml +14 -0
  96. data/spec/dummy/config/routes.rb +13 -0
  97. data/spec/dummy/config.ru +4 -0
  98. data/spec/dummy/db/migrate/20130730132101_create_vendors.rb +12 -0
  99. data/spec/dummy/db/migrate/20130730132321_create_products.rb +12 -0
  100. data/spec/dummy/db/migrate/20130730132348_create_tags.rb +14 -0
  101. data/spec/dummy/db/schema.rb +47 -0
  102. data/spec/dummy/lib/assets/.keep +0 -0
  103. data/spec/dummy/log/.keep +0 -0
  104. data/spec/dummy/public/404.html +58 -0
  105. data/spec/dummy/public/422.html +58 -0
  106. data/spec/dummy/public/500.html +57 -0
  107. data/spec/dummy/public/favicon.ico +0 -0
  108. data/spec/features/tabulatrs_spec.rb +227 -0
  109. data/spec/lib/tabulatr/tabulatr/finder/find_for_table_spec.rb +187 -0
  110. data/spec/spec_helper.rb +45 -0
  111. data/tabulatr.gemspec +29 -0
  112. metadata +258 -0
@@ -0,0 +1,452 @@
1
+ Tabulatr = {
2
+ moreResults: true,
3
+ storePage: false,
4
+ currentData: null,
5
+ locked: false,
6
+
7
+ updatePagination: function(currentPage, numPages, tableId){
8
+ var ul = $('.pagination[data-table='+ tableId +'] > ul');
9
+ if(ul.length == 0){
10
+ // bootstrap 3
11
+ ul = $('.pagination[data-table='+ tableId +']');
12
+ }
13
+ ul.html('');
14
+ if(numPages < 13){
15
+ for(var i = 1; i <= numPages; i++){
16
+ var cls = '';
17
+ if(i == currentPage){
18
+ cls = 'active';
19
+ }
20
+ ul.append('<li class="'+ cls +'"><a href="#" data-page="'+ i+'">'+
21
+ i +'</a></li>');
22
+ }
23
+ }else{
24
+ if(currentPage > 1){
25
+ ul.append('<li><a href="#" data-page="1">1</a></li>');
26
+ }
27
+
28
+ var between = Math.floor((1 + currentPage) / 2);
29
+ if(between > 1 && between < currentPage - 2){
30
+ ul.append('<li><span>...</span></li>');
31
+ ul.append('<li><a href="#" data-page="'+ between +'">'+ between +'</a></li');
32
+ }
33
+
34
+ if(currentPage > 4){
35
+ ul.append('<li><span>...</span></li>');
36
+ }
37
+
38
+ if(currentPage > 3){
39
+ ul.append('<li><a href="#" data-page="'+ (currentPage - 2) +'">'+
40
+ (currentPage-2) +'</a></li>');
41
+ ul.append('<li><a href="#" data-page="'+ (currentPage - 1) +'">'+
42
+ (currentPage-1) +'</a></li>');
43
+ }
44
+
45
+ ul.append('<li class="active"><a href="#" data-page="'+ currentPage +'">'+
46
+ currentPage +'</a></li>');
47
+
48
+ if(currentPage < numPages - 1){
49
+ ul.append('<li><a href="#" data-page="'+ (currentPage+1) +'">'+
50
+ (currentPage+1) +'</a></li>');
51
+ }
52
+
53
+ if(currentPage < numPages - 2){
54
+ ul.append('<li><a href="#" data-page="'+ (currentPage+2) +'">'+
55
+ (currentPage+2) +'</a></li>');
56
+ }
57
+
58
+ if(currentPage < numPages - 3){
59
+ ul.append('<li><span>...</span></li>');
60
+ }
61
+
62
+ between = Math.floor((currentPage + numPages) / 2);
63
+
64
+ if(between > currentPage + 3 && between < numPages - 1){
65
+ ul.append('<li><a href="#" data-page="'+ between +'">'+
66
+ between +'</a></li>');
67
+ ul.append('<li><span>...</span></li>');
68
+ }
69
+ if(currentPage < numPages){
70
+ ul.append('<li><a href="#" data-page="'+ numPages +'">'+
71
+ numPages +'</a></li>');
72
+ }
73
+ }
74
+
75
+ },
76
+
77
+ updateTable: function(hash, tableId, forceReload) {
78
+ if(hash.page !== undefined && !forceReload){
79
+ //old page should be stored
80
+ Tabulatr.storePage = true;
81
+ // check if this page was already loaded
82
+ if($('#'+ tableId + ' tbody tr[data-page='+ hash.page +']').length > 0){
83
+ $('#'+ tableId + ' tbody tr').hide();
84
+ $('#'+ tableId + ' tbody tr[data-page='+ hash.page +']').show();
85
+
86
+ Tabulatr.updatePagination(hash.page,
87
+ $('.pagination[data-table='+ tableId +'] a:last').data('page'),
88
+ tableId);
89
+ return;
90
+ }
91
+ }else{
92
+ Tabulatr.storePage = false;
93
+ }
94
+ if(Tabulatr.locked){ return; }
95
+ Tabulatr.locked = true;
96
+ jQuery.get($('table#'+ tableId).data('path') + '.json',
97
+ Tabulatr.createParameterString(hash, tableId),
98
+ Tabulatr.handleResponse
99
+ );
100
+ },
101
+
102
+ checkIfCheckboxesAreMarked: function(){
103
+ return $('tr[data-page] input[type=checkbox]:checked').length > 0;
104
+ },
105
+
106
+ handleResponse: function(response) {
107
+ Tabulatr.insertTabulatrData(response);
108
+ Tabulatr.updatePagination(response.meta.page, response.meta.pages, response.meta.table_id);
109
+ Tabulatr.locked = false;
110
+ },
111
+
112
+ insertTabulatrData: function(response){
113
+ columns = [];
114
+ tableId = response.meta.table_id;
115
+ tableName = tableId.split('_')[0];
116
+ if(!response.meta.append){
117
+ if(Tabulatr.storePage){
118
+ $('#'+ tableId +' tbody tr').hide();
119
+ }else{
120
+ $('#'+ tableId +' tbody').html('');
121
+ }
122
+ }
123
+ if(response.data.length == 0){
124
+ Tabulatr.moreResults = false;
125
+ $('.tabulatr_count[data-table='+ tableId +']').unbind('inview');
126
+ }else{
127
+ if(response.data.length < response.meta.pagesize){
128
+ Tabulatr.moreResults = false;
129
+ $('.tabulatr_count[data-table='+ tableId + ']').unbind('inview');
130
+ }else{
131
+ Tabulatr.moreResults = true;
132
+ }
133
+ $('#'+ tableId +' th').each(function(ix,el){
134
+ var column_name = $(el).data('tabulatr-column-name');
135
+ var association = $(el).data('tabulatr-association');
136
+ var column_type = $(el).data('tabulatr-column-type');
137
+ var action = $(el).data('tabulatr-action');
138
+ var callback_methods = $(el).data('tabulatr-methods').split(',');
139
+ columns.push({ name: column_name,
140
+ methods: callback_methods,
141
+ type: column_type,
142
+ association: association,
143
+ action: action });
144
+ });
145
+ $('.empty_row').remove();
146
+
147
+
148
+ for(var i = 0; i < response.data.length; i++){
149
+ $tr = $('<tr data-page="'+ response.meta.page +'"></tr>');
150
+ var td = '';
151
+ var column;
152
+ for(var c = 0; c < columns.length; c++){
153
+ column = columns[c];
154
+ if(column.association === undefined){
155
+ var value = response.data[i][column.name];
156
+ }else{
157
+ try{
158
+ var assoc = response.data[i][column.association];
159
+ if(Array.isArray(assoc)){
160
+ var arry = [];
161
+ for(var j = 0; j < assoc.length; j++){
162
+ arry.push(assoc[j][column.name]);
163
+ }
164
+ var value = arry.join(', ');
165
+ }else{
166
+ var value = response.data[i][column.association][column.name];
167
+ }
168
+ }catch(e){
169
+ var value = '';
170
+ }
171
+ }
172
+ var formatters = column.methods;
173
+ $td = $('<td></td>');
174
+ if(column.type == 'checkbox'){
175
+ $td.html(Tabulatr.makeCheckboxFor(response.data[i]));
176
+ }else if(column.type == 'action'){
177
+ $td.html(Tabulatr.makeAction(column.action, response.data[i]));
178
+ }else{
179
+ if(value === false){
180
+ value = "false"; // because false won't be displayed
181
+ }
182
+ $td.html(value);
183
+ for(var j = 0; j < formatters.length; j++){
184
+ var fn = Tabulatr[formatters[j]];
185
+ if(typeof fn === 'function'){
186
+ try{
187
+ var result = fn(value, $td, $tr, response.data[i]);
188
+ if(result != null && result !== undefined){
189
+ $td.html(result);
190
+ value = result;
191
+ }
192
+ }catch(e){
193
+ $td.html('<span class="error">#ERROR</span>');
194
+ }
195
+ }
196
+ }
197
+ }
198
+ td += $td[0].outerHTML;
199
+ }
200
+ $tr.append(td);
201
+ $('#'+ tableId +' tbody').append($tr);
202
+ }
203
+ }
204
+ var count_string = $('.tabulatr_count[data-table='+ tableId +']').data('format-string');
205
+ count_string = count_string.replace(/%\{current\}/, response.meta.count);
206
+ count_string = count_string.replace(/%\{total\}/, response.meta.total);
207
+ count_string = count_string.replace(/%\{per_page\}/,
208
+ response.meta.pagesize);
209
+ $('.tabulatr_count[data-table='+ tableId +']').html(count_string);
210
+
211
+ },
212
+
213
+ makeCheckboxFor: function(data){
214
+ return "<input type='checkbox' value='"+ data.id +
215
+ "' class='tabulatr-checkbox' />";
216
+ },
217
+
218
+ replacer: function(match, attribute, offset, string){
219
+ return Tabulatr.currentData[attribute];
220
+ },
221
+
222
+
223
+ makeAction: function(action, data){
224
+ Tabulatr.currentData = data;
225
+ return unescape(action).replace(/{{([\w:]+)}}/g, Tabulatr.replacer);
226
+ },
227
+
228
+ createParameterString: function(hash, tableId){
229
+ tableName = tableId.split('_')[0];
230
+ if(hash === undefined){
231
+ hash = {};
232
+ hash.append = false;
233
+ }
234
+ if($('#'+ tableId +' i.sorted').length == 1){
235
+ hash.sort_by = $('#'+ tableId +' i.sorted').closest('th').data('tabulatr-sorting-name');
236
+ if($('#'+ tableId +' i.sorted').data('sort') == 'asc'){
237
+ hash.orientation = 'desc';
238
+ }else{
239
+ hash.orientation = 'asc';
240
+ }
241
+ }
242
+ if(hash.pagesize === undefined){
243
+ var pagesize = $('.tabulatr-per-page[data-table='+ tableId +'] a.active').data('items-per-page');
244
+ if(pagesize == null){ pagesize = 10; }
245
+ }
246
+ if(hash.page === undefined){
247
+ hash.page = Math.floor($('#'+ tableId +' tbody tr[class!=empty_row]').length/pagesize) + 1;
248
+ if(!isFinite(hash.page)){
249
+ hash.page = 1;
250
+ }
251
+ }
252
+ hash.pagesize = pagesize;
253
+ hash.arguments = $.map($('#'+ tableId +' th'), function(n){ return $(n).data('tabulatr-column-name') })
254
+ .filter(function(n){return n}).join();
255
+ hash.hash = $('#tabulatr_security_'+ tableName).data('hash');
256
+ hash.salt = $('#tabulatr_security_'+ tableName).data('salt');
257
+ hash.table_id = tableId;
258
+ var form_array = $('.tabulatr_filter_form[data-table='+ tableId +']').serializeArray();
259
+ for(var i = 0; i < form_array.length; i++){
260
+ hash[form_array[i].name] = form_array[i].value;
261
+ }
262
+ return hash;
263
+ },
264
+
265
+ localDate: function(value, $td, $tr, obj){
266
+ return new Date(value).toLocaleString();
267
+ }
268
+ }
269
+
270
+ $(document).on('ready page:load', function(){
271
+
272
+ $('.tabulatr-sort').click(function(){
273
+ orientation = $(this).data('sort');
274
+ $($(this).parents('tr').find('.tabulatr-sort')).removeClass('sorted');
275
+ $(this).addClass('sorted');
276
+ var tableId = $(this).parents('table').attr('id');
277
+ var tableName = tableId.split('_')[0];
278
+ $($(this).parents('table').find('tbody tr')).remove();
279
+ $('.tabulatr_filter_form[data-table='+ tableId +'] input[name=orientation]').val(orientation);
280
+ var sort_by = $(this).closest('th').data('tabulatr-sorting-name');
281
+ $('.tabulatr_filter_form[data-table='+ tableId +'] input[name=sort_by]').val(sort_by);
282
+ if(orientation == 'asc'){
283
+ $(this).removeClass('icon-arrow-down').addClass('icon-arrow-up');
284
+ $(this).data('sort', 'desc');
285
+ }else{
286
+ $(this).addClass('icon-arrow-up').addClass('icon-arrow-down');
287
+ $(this).data('sort', 'asc');
288
+ }
289
+ if(!Tabulatr.moreResults){
290
+ Tabulatr.moreResults = true;
291
+ if($('.pagination[data-table='+ tableId +']').length == 0){
292
+ $('.tabulatr_count[data-table='+ tableId +']').bind('inview', cbfn);
293
+ }
294
+ }
295
+
296
+ $('.tabulatr_mark_all[data-table='+ tableName +']').prop('checked', false).prop('indeterminate', false);
297
+ Tabulatr.updateTable({}, tableId);
298
+ });
299
+
300
+ var cbfn = function(event, isInView, visiblePartX, visiblePartY) {
301
+ if (isInView) {
302
+ // element is now visible in the viewport
303
+ if (visiblePartY == 'top') {
304
+ // top part of element is visible
305
+ } else if (visiblePartY == 'bottom') {
306
+ // bottom part of element is visible
307
+ } else {
308
+ Tabulatr.updateTable({append: true}, $(event.currentTarget).data('table'));
309
+ }
310
+ }
311
+ };
312
+
313
+ $('.tabulatr_table').each(function(ix, el){
314
+ if($('.pagination[data-table='+ $(el).attr('id') +']').length == 0){
315
+ $('.tabulatr_count[data-table='+ $(el).attr('id') +']').bind('inview', cbfn);
316
+ }
317
+ });
318
+
319
+ $('.batch-action-inputs').click(function(){
320
+ params = {page: 1};
321
+ params[$(this).attr('name')] = $(this).val();
322
+ var tableId = $(this).closest('table').attr('id');
323
+ params['tabulatr_checked'] = {checked_ids: jQuery.map($('#'+ tableId +' .tabulatr-checkbox:checked'), function(el){return $(el).val();}).join(',')};
324
+ $('.tabulatr_mark_all[data-table='+ tableId +']').prop('indeterminate', false).prop('checked', false);
325
+ $('#'+ tableId +' .tabulatr-wrench').addClass('disabled');
326
+ Tabulatr.updateTable(params, tableId, true);
327
+ });
328
+
329
+ $('form.tabulatr_filter_form').submit(function(ev){
330
+ var tableId = $(this).data('table');
331
+ Tabulatr.updateTable({page: 1, append: false}, tableId, true);
332
+ var ary = $(this).serializeArray();
333
+ $('#'+ tableId +' th').removeClass('tabulatr_filtered_column');
334
+ $('#'+ tableId +' i.icon-remove-sign').remove();
335
+ for(var i = 0; i < ary.length; i++){
336
+ if(ary[i].value != ""){
337
+ var name = ary[i].name.replace(/\[(like|checkbox|from|to)\]/, '');
338
+ name = name.replace(/(:|\.|\[|\])/g,'\\$1');
339
+ // var attr = $(this).find("input[name="+ name +"]").data('tabulatr-attribute');
340
+ var $col = $('#'+ tableId +' th[data-tabulatr-form-name^='+ name +']');
341
+ if($col.length > 0){
342
+ $col.addClass('tabulatr_filtered_column');
343
+ // icon-remove-sign
344
+ $col.append('<i class="icon-remove-sign '+
345
+ 'tabulatr_remove_filter" ></i>');
346
+ }
347
+ }
348
+ }
349
+ $('#tabulatr_filter_dialog_'+ tableId.split('_')[0]).modal('hide');
350
+ return false;
351
+ });
352
+
353
+ $('.tabulatr_table').on('click', 'i.tabulatr_remove_filter', function(){
354
+ var $th = $(this).closest('th');
355
+ var name = $th.data('tabulatr-form-name').
356
+ replace(/\[(like|checkbox|from|to)\]/, '');
357
+ name = name.replace(/(:|\.|\[|\])/g,'\\$1');
358
+ $th.removeClass('tabulatr_filtered_column');
359
+ if($('[name^='+ name +']').is(':checkbox')){
360
+ $('[name^='+ name +']').prop('checked', false);
361
+ }else{
362
+ $('[name^='+ name +']').val('');
363
+ }
364
+ var tableId = $(this).closest('.tabulatr_table').attr('id');
365
+ $(this).remove();
366
+ Tabulatr.updateTable({}, tableId);
367
+ return false;
368
+ });
369
+
370
+ $('.tabulatr_mark_all').click(function(){
371
+ var tableId = $(this).data('table');
372
+ if($(this).is(':checked')){
373
+ $('#'+ tableId +' tr[data-page]:visible input[type=checkbox]').prop('checked', true);
374
+ $('#'+ tableId +' .tabulatr-wrench').removeClass('disabled');
375
+ }else{
376
+ $('#'+ tableId +' tr[data-page]:visible input[type=checkbox]').prop('checked', false);
377
+ if(Tabulatr.checkIfCheckboxesAreMarked()){
378
+ $('#'+ tableId +' .tabulatr-wrench').removeClass('disabled');
379
+ }else{
380
+ $('#'+ tableId +' .tabulatr-wrench').addClass('disabled');
381
+ }
382
+ }
383
+ });
384
+
385
+ $('.tabulatr_table').on('click', 'input.tabulatr-checkbox', function(){
386
+ var tableId = $(this).closest('.tabulatr_table').attr('id');
387
+ if($(this).is(':checked')){
388
+ if($('#'+ tableId +' tr[data-page]:visible input[type=checkbox]').not(':checked').length > 0){
389
+ $('.tabulatr_mark_all[data-table='+ tableId +']').prop("indeterminate", true);
390
+ }else{
391
+ $('.tabulatr_mark_all[data-table='+ tableId +']').prop('indeterminate', false);
392
+ $('.tabulatr_mark_all[data-table='+ tableId +']').prop('checked', true);
393
+ }
394
+ $('#'+ tableId +' .tabulatr-wrench').removeClass('disabled');
395
+ }else{
396
+ if($('#'+ tableId +' tr[data-page]:visible input[type=checkbox]:checked').length > 0){
397
+ $('.tabulatr_mark_all[data-table='+ tableId +']').prop('indeterminate', true);
398
+ $('#'+ tableId +' .tabulatr-wrench').removeClass('disabled');
399
+ }else{
400
+ $('.tabulatr_mark_all[data-table='+ tableId +']').prop('indeterminate', false);
401
+ $('.tabulatr_mark_all[data-table='+ tableId +']').prop('checked', false);
402
+ if(Tabulatr.checkIfCheckboxesAreMarked()){
403
+ $('#'+ tableId +' .tabulatr-wrench').removeClass('disabled');
404
+ }else{
405
+ $('#'+ tableId +' .tabulatr-wrench').addClass('disabled');
406
+ }
407
+ }
408
+ }
409
+ });
410
+
411
+ $('.tabulatr-per-page a').click(function(){
412
+ if($(this).hasClass('active')){ return false; }
413
+ $(this).closest('div').find('a').removeClass('active');
414
+ $(this).addClass('active');
415
+ var tableId = $(this).closest('div').data('table');
416
+ Tabulatr.moreResults = true;
417
+ if($('.pagination[data-table='+ tableId +']').length == 0){
418
+ $('.tabulatr_count[data-table='+ tableId +']').bind('inview', cbfn);
419
+ }
420
+ if(typeof(Storage) !== undefined){
421
+ localStorage.tabulatr_page_display_count = $(this).data('items-per-page');
422
+ }
423
+ Tabulatr.updateTable({page: 1}, tableId, true);
424
+ });
425
+
426
+ if($('.tabulatr_table').length > 0){
427
+ if(typeof(Storage) !== undefined){
428
+ var count = localStorage.tabulatr_page_display_count;
429
+ if(count !== undefined){
430
+ $('.tabulatr-per-page a').removeClass('active');
431
+ $('.tabulatr-per-page a[data-items-per-page='+ count +']').
432
+ addClass('active');
433
+ }
434
+ }
435
+ $('.tabulatr_table').each(function(ix, el){
436
+ Tabulatr.updateTable({}, $(el).attr('id'));
437
+ });
438
+ }
439
+ });
440
+
441
+ $(document).on('click', '.pagination a', function(){
442
+ var a = $(this);
443
+ if(a.parent().hasClass('active') ||
444
+ a.parent().hasClass('disabled')){
445
+ return;
446
+ }
447
+ var tableId = $(a).closest('.pagination').data('table');
448
+ $('.tabulatr_mark_all[data-table='+ tableId +']').prop('checked', false);
449
+ $('.tabulatr_mark_all[data-table='+ tableId +']').prop('indeterminate', false);
450
+ Tabulatr.updateTable({append: false, page: a.data('page')}, tableId);
451
+ return false;
452
+ });
@@ -0,0 +1,3 @@
1
+ (function(d){var p={},e,a,h=document,i=window,f=h.documentElement,j=d.expando;d.event.special.inview={add:function(a){p[a.guid+"-"+this[j]]={data:a,$element:d(this)}},remove:function(a){try{delete p[a.guid+"-"+this[j]]}catch(d){}}};d(i).bind("scroll resize",function(){e=a=null});!f.addEventListener&&f.attachEvent&&f.attachEvent("onfocusin",function(){a=null});setInterval(function(){var k=d(),j,n=0;d.each(p,function(a,b){var c=b.data.selector,d=b.$element;k=k.add(c?d.find(c):d)});if(j=k.length){var b;
2
+ if(!(b=e)){var g={height:i.innerHeight,width:i.innerWidth};if(!g.height&&((b=h.compatMode)||!d.support.boxModel))b="CSS1Compat"===b?f:h.body,g={height:b.clientHeight,width:b.clientWidth};b=g}e=b;for(a=a||{top:i.pageYOffset||f.scrollTop||h.body.scrollTop,left:i.pageXOffset||f.scrollLeft||h.body.scrollLeft};n<j;n++)if(d.contains(f,k[n])){b=d(k[n]);var l=b.height(),m=b.width(),c=b.offset(),g=b.data("inview");if(!a||!e)break;c.top+l>a.top&&c.top<a.top+e.height&&c.left+m>a.left&&c.left<a.left+e.width?
3
+ (m=a.left>c.left?"right":a.left+e.width<c.left+m?"left":"both",l=a.top>c.top?"bottom":a.top+e.height<c.top+l?"top":"both",c=m+"-"+l,(!g||g!==c)&&b.data("inview",c).trigger("inview",[!0,m,l])):g&&b.data("inview",!1).trigger("inview",[!1])}}},250)})(jQuery);
@@ -0,0 +1 @@
1
+ //= require_tree .
@@ -0,0 +1,40 @@
1
+ .tabulatr-sort{
2
+ opacity: 0.3;
3
+ }
4
+
5
+ .tabulatr-sort:hover{
6
+ cursor: pointer;
7
+ }
8
+
9
+ i.sorted{
10
+ opacity: 1;
11
+ }
12
+
13
+ i.tabulatr_remove_filter:hover{
14
+ cursor: pointer;
15
+ }
16
+
17
+ .tabulatr_filtered_column{
18
+ text-decoration: underline;
19
+ }
20
+
21
+ .tabulatr-per-page {
22
+ margin: 20px 10px;
23
+ a.active{
24
+ background-color: red;
25
+ }
26
+ }
27
+
28
+ .table-controls div{
29
+ margin: 20px 10px;
30
+ display: inline-block;
31
+ vertical-align: middle;
32
+ }
33
+
34
+ .table-controls i, .tabulatr_table i{
35
+ margin-right: 5px;
36
+ }
37
+
38
+ #tabulatr-wrench{
39
+ margin-left: 10px;
40
+ }
@@ -0,0 +1,4 @@
1
+ /*
2
+ *
3
+ *= require tabulatr/application
4
+ */
data/init.rb ADDED
@@ -0,0 +1 @@
1
+ require 'tabulatr'
@@ -0,0 +1,44 @@
1
+ #--
2
+ # Copyright (c) 2010-2011 Peter Horn, Provideal GmbH
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+ class Tabulatr
24
+ module Generators
25
+ class InstallGenerator < Rails::Generators::Base
26
+ desc "initialize tabulatr"
27
+ source_root File.expand_path('../templates', __FILE__)
28
+
29
+ def copy_initializer_file
30
+ copy_file "tabulatr.rb", "config/initializers/tabulatr.rb"
31
+ end
32
+
33
+ def copy_translation_file
34
+ copy_file "tabulatr.yml", "config/locales/tabulatr.yml"
35
+ end
36
+
37
+ def bootstrap
38
+ unless yes?('Do you use Bootstrap version 3 ?')
39
+ gsub_file 'config/initializers/tabulatr.rb', 'create_ul_paginator', 'create_div_paginator'
40
+ end
41
+ end
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,5 @@
1
+ Tabulatr.config do |c|
2
+ c.secret_tokens = ['wrw234lk32n4l2n', 'nflwh23p4h']
3
+ end
4
+
5
+ Tabulatr.bootstrap_paginator = :create_ul_paginator
@@ -0,0 +1,14 @@
1
+ en:
2
+ tabulatr:
3
+ rows_per_page: 'No. of rows per page:'
4
+ filter: 'Filter'
5
+ batch_actions: 'Batch actions'
6
+ count: 'Showing: %{current} of total %{total}. %{per_page} items per page.'
7
+ apply_filters: 'Apply'
8
+ de:
9
+ tabulatr:
10
+ rows_per_page: 'Ergebnisse pro Seite'
11
+ filter: 'Filter'
12
+ batch_actions: 'Batch-Aktionen'
13
+ count: 'Zeige %{current} von insgesamt %{total}. %{per_page} pro Seite.'
14
+ apply_filters: 'Anwenden'
@@ -0,0 +1,13 @@
1
+ class ActionController::Base
2
+ def tabulatr_for(klaz, serializer: nil, **options, &block)
3
+ respond_to do |format|
4
+ format.json {
5
+ records = klaz.find_for_table(params, options, &block)
6
+ render json: records.to_tabulatr_json(serializer)
7
+ }
8
+ format.html {
9
+ render action: options[:action] || action_name
10
+ }
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,31 @@
1
+ #--
2
+ # Copyright (c) 2010-2011 Peter Horn, Provideal GmbH
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
24
+ class ActionView::Base
25
+ # render the table in a view
26
+ def table_for(klass, opts={}, &block)
27
+ tabulatr = Tabulatr.new(klass, self, opts)
28
+ tabulatr.build_table(&block)
29
+ end
30
+ end
31
+
@@ -0,0 +1,48 @@
1
+ #--
2
+ # Copyright (c) 2010-2011 Peter Horn, Provideal GmbH
3
+ #
4
+ # Permission is hereby granted, free of charge, to any person obtaining
5
+ # a copy of this software and associated documentation files (the
6
+ # "Software"), to deal in the Software without restriction, including
7
+ # without limitation the rights to use, copy, modify, merge, publish,
8
+ # distribute, sublicense, and/or sell copies of the Software, and to
9
+ # permit persons to whom the Software is furnished to do so, subject to
10
+ # the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be
13
+ # included in all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ # NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ # LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ # OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ # WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
22
+ #++
23
+
24
+ # We monkey patch ActiveRecord::Base to add a function for finding using
25
+ # the information of the params hash as created by a Tabulatr table
26
+ if Object.const_defined? "ActiveRecord"
27
+ class ActiveRecord::Base
28
+ def self.find_for_table(params, opts={}, &block)
29
+ Tabulatr::Finder.find_for_table(self, params, opts, &block)
30
+ end
31
+
32
+ def self.tabulatr_name_mapping(name_mapping_hash)
33
+ tabulatr_name_mappings.merge! name_mapping_hash
34
+ end
35
+
36
+ def self.tabulatr_name_mappings
37
+ @tabulatr_name_mappings ||= {}
38
+ end
39
+
40
+ def self.tabulatr_select_attributes(more={})
41
+ maps = tabulatr_name_mappings.merge(more)
42
+ return nil if maps.blank?
43
+ "#{table_name}.*, " + maps.map do |name, mapping|
44
+ %{#{mapping} AS "#{name}"}
45
+ end.join(", ")
46
+ end
47
+ end
48
+ end