tabulatr2 0.9.4 → 0.9.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (51) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +29 -0
  3. data/Gemfile +1 -2
  4. data/README.md +155 -95
  5. data/app/assets/javascripts/tabulatr/_storage.js +41 -0
  6. data/app/assets/javascripts/tabulatr/_tabulatr.js +598 -0
  7. data/app/assets/javascripts/tabulatr/application.js +3 -553
  8. data/app/assets/stylesheets/tabulatr/application.css.scss +21 -12
  9. data/app/assets/stylesheets/tabulatr.css +1 -0
  10. data/app/views/tabulatr/_tabulatr_actual_table.html.slim +18 -18
  11. data/app/views/tabulatr/_tabulatr_filter_dialog.html.slim +1 -1
  12. data/app/views/tabulatr/_tabulatr_fuzzy_search_field.html.slim +1 -1
  13. data/app/views/tabulatr/_tabulatr_static_table.html.slim +3 -3
  14. data/app/views/tabulatr/_tabulatr_table.html.slim +17 -12
  15. data/lib/tabulatr/data/data.rb +7 -9
  16. data/lib/tabulatr/data/dsl.rb +36 -21
  17. data/lib/tabulatr/data/filtering.rb +41 -13
  18. data/lib/tabulatr/data/formatting.rb +7 -20
  19. data/lib/tabulatr/data/pagination.rb +1 -2
  20. data/lib/tabulatr/data/proxy.rb +2 -0
  21. data/lib/tabulatr/data/sorting.rb +24 -13
  22. data/lib/tabulatr/engine.rb +1 -0
  23. data/lib/tabulatr/generators/tabulatr/templates/tabulatr.yml +2 -2
  24. data/lib/tabulatr/json_builder.rb +23 -25
  25. data/lib/tabulatr/rails/action_controller.rb +4 -0
  26. data/lib/tabulatr/rails/action_view.rb +3 -2
  27. data/lib/tabulatr/renderer/checkbox.rb +3 -1
  28. data/lib/tabulatr/renderer/column.rb +47 -5
  29. data/lib/tabulatr/renderer/columns_from_block.rb +24 -6
  30. data/lib/tabulatr/renderer/renderer.rb +26 -17
  31. data/lib/tabulatr/utility/unexpected_search_result_error.rb +9 -0
  32. data/lib/tabulatr/utility/utility.rb +4 -0
  33. data/lib/tabulatr/version.rb +1 -1
  34. data/spec/dummy/app/controllers/products_controller.rb +9 -0
  35. data/spec/dummy/app/views/products/local_storage.html.slim +4 -0
  36. data/spec/dummy/app/views/products/simple_index.html.erb +1 -1
  37. data/spec/dummy/app/views/products/stupid_array.html.erb +1 -1
  38. data/spec/dummy/config/application.rb +1 -1
  39. data/spec/dummy/config/locales/tabulatr.yml +2 -2
  40. data/spec/dummy/config/routes.rb +1 -0
  41. data/spec/features/tabulatrs_spec.rb +27 -27
  42. data/spec/lib/tabulatr/data/data_spec.rb +12 -16
  43. data/spec/lib/tabulatr/data/filtering_spec.rb +48 -7
  44. data/spec/lib/tabulatr/data/formatting_spec.rb +32 -0
  45. data/spec/lib/tabulatr/data/sorting_spec.rb +81 -0
  46. data/spec/lib/tabulatr/json_builder_spec.rb +23 -9
  47. data/spec/lib/tabulatr/renderer/checkbox_spec.rb +14 -0
  48. data/spec/lib/tabulatr/renderer/renderer_spec.rb +20 -8
  49. data/tabulatr.gemspec +4 -3
  50. metadata +45 -9
  51. data/lib/tabulatr/data/column_name_builder.rb +0 -86
@@ -0,0 +1,598 @@
1
+ function Tabulatr(id){
2
+ this.id = id;
3
+ this.name = '';
4
+ this.moreResults = true;
5
+ this.currentData = null;
6
+ this.locked = false;
7
+ this.isAPersistedTable = false;
8
+ this.initialRequest = true;
9
+ }
10
+
11
+ var tabulatr_tables;
12
+ Tabulatr.prototype = {
13
+ constructor: Tabulatr,
14
+
15
+ createPaginationListItem: function(page, active){
16
+ var $page = $('<li><a href="" data-page="'+ page +'">'+ page +'</a></li>');
17
+ if(active){
18
+ $page.addClass('active');
19
+ }
20
+ return $page;
21
+ },
22
+
23
+ updatePagination: function(currentPage, numPages){
24
+ var $paginatorUl = $('.pagination[data-table='+ this.id +'] > ul');
25
+
26
+ if($('table#'+ this.id).data('persistent')){
27
+ $paginatorUl.html('<li><a href="#" data-tabulatr-reset="'+ this.id +'"><i class="fa fa-refresh"></i></a></li>');
28
+ }else{
29
+ $paginatorUl.html('');
30
+ }
31
+ if(numPages < 13){
32
+ for(var i = 1; i <= numPages; i++){
33
+ $paginatorUl.append(this.createPaginationListItem(i, (i == currentPage)));
34
+ }
35
+ }else{
36
+ if(currentPage > 1){
37
+ $paginatorUl.append(this.createPaginationListItem(1, false));
38
+ }
39
+
40
+ var between = Math.floor((1 + currentPage) / 2);
41
+ if(between > 1 && between < currentPage - 2){
42
+ $paginatorUl.append('<li><span>...</span></li>');
43
+ $paginatorUl.append(this.createPaginationListItem(between, false));
44
+ }
45
+
46
+ if(currentPage > 4){
47
+ $paginatorUl.append('<li><span>...</span></li>');
48
+ }
49
+
50
+ if(currentPage > 3){
51
+ $paginatorUl.append(this.createPaginationListItem(currentPage-2, false));
52
+ }
53
+
54
+ if(currentPage > 2){
55
+ $paginatorUl.append(this.createPaginationListItem(currentPage-1, false));
56
+ }
57
+
58
+ $paginatorUl.append(this.createPaginationListItem(currentPage, true));
59
+
60
+ if(currentPage < numPages - 1){
61
+ $paginatorUl.append(this.createPaginationListItem(currentPage+1, false));
62
+ }
63
+
64
+ if(currentPage < numPages - 2){
65
+ $paginatorUl.append(this.createPaginationListItem(currentPage+2, false));
66
+ }
67
+
68
+ if(currentPage < numPages - 3){
69
+ $paginatorUl.append('<li><span>...</span></li>');
70
+ }
71
+
72
+ between = Math.floor((currentPage + numPages) / 2);
73
+
74
+ if(between > currentPage + 3 && between < numPages - 1){
75
+ $paginatorUl.append(this.createPaginationListItem(between, false));
76
+ $paginatorUl.append('<li><span>...</span></li>');
77
+ }
78
+ if(currentPage < numPages){
79
+ $paginatorUl.append(this.createPaginationListItem(numPages, false));
80
+ }
81
+ }
82
+
83
+ },
84
+
85
+ updateTable: function(hash, forceReload) {
86
+ var $table = $('#'+ this.id);
87
+ var data;
88
+ if(hash.page !== undefined && !forceReload){
89
+ //old page should be stored
90
+ this.storePage = true;
91
+ // check if this page was already loaded
92
+ $table.find('tbody tr').hide();
93
+ if($table.find('tbody tr[data-page='+ hash.page +']').length > 0){
94
+ $table.find('tbody tr[data-page='+ hash.page +']').show();
95
+
96
+ this.updatePagination(hash.page,
97
+ $('.pagination[data-table='+ this.id +'] a:last').data('page'),
98
+ this.id);
99
+ if(this.isAPersistedTable){
100
+ data = this.createParameterString(hash, this.id);
101
+ localStorage[this.id] = JSON.stringify(data);
102
+ }
103
+ return;
104
+ }
105
+ }else{
106
+ this.storePage = false;
107
+ }
108
+ if(this.locked){ return; }
109
+ this.locked = true;
110
+ var curTable = this;
111
+ this.showLoadingSpinner();
112
+ if(this.initialRequest && this.isAPersistedTable && localStorage[this.id]){
113
+ data = JSON.parse(localStorage[this.id]);
114
+ }else{
115
+ data = this.createParameterString(hash, this.id);
116
+ if(this.isAPersistedTable) {
117
+ localStorage[this.id] = JSON.stringify(data);
118
+ }
119
+ }
120
+ $.ajax({
121
+ context: this,
122
+ type: 'GET',
123
+ url: $('table#'+ this.id).data('path'),
124
+ accepts: {
125
+ json: 'application/json'
126
+ },
127
+ data: data,
128
+ success: this.handleResponse,
129
+ complete: this.hideLoadingSpinner,
130
+ error: this.handleError
131
+ });
132
+ },
133
+
134
+ checkIfCheckboxesAreMarked: function(){
135
+ return $('tr[data-page] input[type=checkbox]:checked').length > 0;
136
+ },
137
+
138
+ currentCount: function(){
139
+ return $('#'+ this.id +' tbody tr.tabulatr-row').length;
140
+ },
141
+
142
+ handleResponse: function(response) {
143
+ this.insertTabulatrData(response);
144
+ this.updatePagination(response.meta.page, response.meta.pages, response.meta.table_id);
145
+ if($('.pagination[data-table='+ response.meta.table_id +']').length > 0){
146
+ if(response.meta.page > response.meta.pages){
147
+ this.updateTable({page: response.meta.pages});
148
+ }
149
+ }
150
+ },
151
+
152
+ handleError: function(foo, bar){
153
+ if(this.isAPersistedTable && this.initialRequest){
154
+ this.initialRequest = false;
155
+ this.locked = false;
156
+ this.resetTable();
157
+ }
158
+ },
159
+
160
+ insertTabulatrData: function(response){
161
+ var tableId = response.meta.table_id;
162
+ var tbody = $('#'+ tableId +' tbody');
163
+ if(!response.meta.append){
164
+ if(this.storePage){
165
+ $('#'+ tableId +' tbody tr').hide();
166
+ }else{
167
+ $('#'+ tableId +' tbody').html('');
168
+ }
169
+ }
170
+ if(response.data.length === 0){
171
+ this.moreResults = false;
172
+ $('.pagination_trigger[data-table='+ tableId +']').unbind('inview');
173
+ }else{
174
+ if(this.currentCount() + response.data.length >= response.meta.count){
175
+ this.moreResults = false;
176
+ $('.pagination_trigger[data-table='+ tableId + ']').unbind('inview');
177
+ }
178
+
179
+ // insert the actual data
180
+ for(var i = 0; i < response.data.length; i++){
181
+ var data = response.data[i];
182
+ var id = data.id;
183
+ var tr = $('#'+ tableId +' tr.empty_row').clone();
184
+ tr.removeClass('empty_row');
185
+ if(data._row_config.data){
186
+ tr.data(data._row_config.data);
187
+ delete data._row_config.data;
188
+ }
189
+ tr.attr(data._row_config);
190
+ tr.attr('data-page', response.meta.page);
191
+ tr.attr('data-id', id);
192
+ tr.find('td').each(function(index,element) {
193
+ var td = $(element);
194
+ var coltype = td.data('tabulatr-type');
195
+ var name = td.data('tabulatr-column-name');
196
+ var cont = data[name];
197
+ if(coltype === 'checkbox') {
198
+ cont = $("<input>").attr('type', 'checkbox').val(id).addClass('tabulatr-checkbox');
199
+ }
200
+ td.html(cont);
201
+ });
202
+ tbody.append(tr);
203
+ }
204
+ }
205
+ var count_string = $('.tabulatr_count[data-table='+ tableId +']').data('format-string');
206
+ count_string = count_string.replace(/%\{current\}/, response.meta.count);
207
+ count_string = count_string.replace(/%\{total\}/, response.meta.total);
208
+ count_string = count_string.replace(/%\{per_page\}/,
209
+ response.meta.pagesize);
210
+ $('.tabulatr_count[data-table='+ tableId +']').html(count_string);
211
+
212
+ if(this.isAPersistedTable){
213
+ this.retrieveTableFromLocalStorage(response);
214
+ }
215
+ },
216
+
217
+
218
+ replacer: function(match, attribute, offset, string){
219
+ return this.currentData[attribute];
220
+ },
221
+
222
+
223
+ makeAction: function(action, data){
224
+ this.currentData = data;
225
+ return unescape(action).replace(/{{([\w:]+)}}/g, this.replacer);
226
+ },
227
+
228
+ submitFilterForm: function(){
229
+ if($('.pagination[data-table='+ this.id +']').length === 0){
230
+ $('.pagination_trigger[data-table='+ this.id +']').unbind('inview', cbfn);
231
+ $('.pagination_trigger[data-table='+ this.id +']').bind('inview', cbfn);
232
+ }
233
+ this.updateTable({page: 1, append: false}, true);
234
+ return false;
235
+ },
236
+
237
+ createParameterString: function(hash){
238
+ var tableName = this.id.split('_')[0];
239
+ if(hash === undefined){
240
+ hash = {};
241
+ hash.append = false;
242
+ }
243
+ var pagesize = hash.pagesize;
244
+ if(pagesize === undefined){
245
+ pagesize = $('table#'+ this.id).data('pagesize');
246
+ }
247
+ if(hash.page === undefined){
248
+ hash.page = Math.floor($('#'+ this.id +' tbody tr[class!=empty_row]').length/pagesize) + 1;
249
+ if(!isFinite(hash.page)){
250
+ hash.page = 1;
251
+ }
252
+ }
253
+ hash.pagesize = pagesize;
254
+ hash.arguments = $.map($('#'+ this.id +' th'), function(n){
255
+ return $(n).data('tabulatr-column-name');
256
+ }).filter(function(n){return n; }).join();
257
+ hash.table_id = this.id;
258
+ hash[tableName + '_search'] = $('input#'+ this.id +'_fuzzy_search_query').val();
259
+ var form_array = $('.tabulatr_filter_form[data-table="'+ this.id +'"]')
260
+ .find('input:visible,select:visible,input[type=hidden]').serializeArray();
261
+ for(var i = 0; i < form_array.length; i++){
262
+ hash[form_array[i].name] = form_array[i].value;
263
+ }
264
+ return hash;
265
+ },
266
+
267
+ localDate: function(value, $td, $tr, obj){
268
+ return new Date(value).toLocaleString();
269
+ },
270
+
271
+ showLoadingSpinner: function(){
272
+ $('.tabulatr-spinner-box[data-table="'+ this.id +'"]').show();
273
+ },
274
+
275
+ hideLoadingSpinner: function(){
276
+ this.initialRequest = false;
277
+ this.locked = false;
278
+ $('.tabulatr-spinner-box[data-table="'+ this.id +'"]').hide();
279
+ }
280
+
281
+ };
282
+
283
+ $(document).on('ready page:load', function(){
284
+ tabulatr_tables = [];
285
+
286
+ $('th.tabulatr-sortable').click(function(){
287
+ var th = $(this);
288
+ var sort_by = th.data('tabulatr-column-name');
289
+ var dir = th.attr('data-sorted');
290
+ var table = th.parents('table');
291
+ var tableId = table.attr('id');
292
+ var table_obj;
293
+ for(var i = 0; i < tabulatr_tables.length; i++){
294
+ if(tabulatr_tables[i].id == tableId){
295
+ table_obj = tabulatr_tables[i];
296
+ }
297
+ }
298
+ var tableName = table_obj.id.split('_')[0];
299
+ table.find('th.tabulatr-sortable.sorted').removeClass('sorted').removeAttr('data-sorted');
300
+ dir = (dir === 'asc') ? 'desc' : 'asc';
301
+ th.addClass('sorted').attr('data-sorted', dir);
302
+ $('.tabulatr_filter_form[data-table='+ tableId +'] input[name='+ tableName +'_sort]').val(sort_by + ' '+ dir);
303
+ if(!table_obj.moreResults){
304
+ table_obj.moreResults = true;
305
+ if($('.pagination[data-table='+ tableId +']').length === 0){
306
+ $('.pagination_trigger[data-table='+ tableId +']').bind('inview', cbfn);
307
+ }
308
+ }
309
+ $($(this).parents('table').find('tbody tr')).remove();
310
+
311
+ $('.tabulatr_mark_all[data-table='+ tableName +']').prop('checked', false).prop('indeterminate', false);
312
+ table_obj.updateTable({});
313
+ });
314
+
315
+
316
+ $('.tabulatr_table').each(function(ix, el){
317
+ if($('.pagination[data-table="'+ $(el).attr('id') +'"]').length === 0){
318
+ $('.pagination_trigger[data-table="'+ $(el).attr('id') +'"]').bind('inview', cbfn);
319
+ }
320
+ });
321
+
322
+ $('.batch-action-inputs').click(function(){
323
+ var a = $(this);
324
+ var name = a.data('do-batch-action-name');
325
+ var key = a.data('do-batch-action');
326
+ var tableId = a.data('table-id');
327
+ var params = {page: 1};
328
+ params[name] = key;
329
+ params.tabulatr_checked = {checked_ids: jQuery.map($('#'+ tableId +' .tabulatr-checkbox:checked'), function(el){return $(el).val();}).join(',')};
330
+ $('.tabulatr_mark_all[data-table='+ tableId +']').prop('indeterminate', false).prop('checked', false);
331
+ $('#'+ tableId +' .tabulatr-wrench').addClass('disabled');
332
+ var table_obj;
333
+ for(var i = 0; i < tabulatr_tables.length; i++){
334
+ if(tabulatr_tables[i].id == tableId){
335
+ table_obj = tabulatr_tables[i];
336
+ }
337
+ }
338
+ table_obj.updateTable(params, true);
339
+ });
340
+
341
+ $('form.tabulatr-fuzzy-search').submit(function(){
342
+ var tableId = $(this).data('table');
343
+ if($('.pagination[data-table='+ tableId +']').length === 0){
344
+ $('.pagination_trigger[data-table='+ tableId +']').unbind('inview', cbfn);
345
+ $('.pagination_trigger[data-table='+ tableId +']').bind('inview', cbfn);
346
+ }
347
+ var table_obj;
348
+ for(var i = 0; i < tabulatr_tables.length; i++){
349
+ if(tabulatr_tables[i].id == tableId){
350
+ table_obj = tabulatr_tables[i];
351
+ }
352
+ }
353
+ table_obj.updateTable({page: 1, append: false}, true);
354
+ return false;
355
+ });
356
+
357
+ $('form.tabulatr_filter_form').submit(function(){
358
+ var tableId = $(this).data('table');
359
+ var table_obj;
360
+ for(var i = 0; i < tabulatr_tables.length; i++){
361
+ if(tabulatr_tables[i].id == tableId){
362
+ table_obj = tabulatr_tables[i];
363
+ }
364
+ }
365
+ table_obj.submitFilterForm();
366
+ return false;
367
+ });
368
+
369
+ $('.tabulatr_table').on('click', 'i.tabulatr_remove_filter', function(){
370
+ var $th = $(this).closest('th');
371
+ var name = $th.data('tabulatr-form-name').
372
+ replace(/\[(like|checkbox|from|to)\]/, '');
373
+ name = name.replace(/(:|\.|\[|\])/g,'\\$1');
374
+ $th.removeClass('tabulatr_filtered_column');
375
+ if($('[name^='+ name +']').is(':checkbox')){
376
+ $('[name^='+ name +']').prop('checked', false);
377
+ }else{
378
+ $('[name^='+ name +']').val('');
379
+ }
380
+ var tableId = $(this).closest('.tabulatr_table').attr('id');
381
+ $(this).remove();
382
+ if($('.pagination[data-table='+ tableId +']').length === 0){
383
+ $('.pagination_trigger[data-table='+ tableId +']').bind('inview', cbfn);
384
+ }
385
+ var table_obj;
386
+ for(var i = 0; i < tabulatr_tables.length; i++){
387
+ if(tabulatr_tables[i].id == tableId){
388
+ table_obj = tabulatr_tables[i];
389
+ }
390
+ }
391
+ table_obj.updateTable({});
392
+ return false;
393
+ });
394
+
395
+ $('.tabulatr_mark_all').click(function(){
396
+ var tableId = $(this).parents('table').prop('id');
397
+ var table_obj;
398
+ for(var i = 0; i < tabulatr_tables.length; i++){
399
+ if(tabulatr_tables[i].id == tableId){
400
+ table_obj = tabulatr_tables[i];
401
+ }
402
+ }
403
+ if($(this).is(':checked')){
404
+ $('#'+ tableId +' tr[data-page]:visible input[type=checkbox]').prop('checked', true);
405
+ $('#'+ tableId +' .tabulatr-wrench').removeClass('disabled');
406
+ }else{
407
+ $('#'+ tableId +' tr[data-page]:visible input[type=checkbox]').prop('checked', false);
408
+ if(table_obj.checkIfCheckboxesAreMarked()){
409
+ $('#'+ tableId +' .tabulatr-wrench').removeClass('disabled');
410
+ }else{
411
+ $('#'+ tableId +' .tabulatr-wrench').addClass('disabled');
412
+ }
413
+ }
414
+ });
415
+
416
+ $('.tabulatr_table').on('click', 'input.tabulatr-checkbox', function(){
417
+ var $table = $(this).closest('.tabulatr_table');
418
+ var tableId = $table.attr('id');
419
+ var $markAllCheckbox = $table.find('.tabulatr_mark_all');
420
+ var table_obj;
421
+ for(var i = 0; i < tabulatr_tables.length; i++){
422
+ if(tabulatr_tables[i].id == tableId){
423
+ table_obj = tabulatr_tables[i];
424
+ }
425
+ }
426
+ if($(this).is(':checked')){
427
+ if($('#'+ tableId +' tr[data-page]:visible input[type=checkbox]').not(':checked').length > 0){
428
+ $markAllCheckbox.prop("indeterminate", true);
429
+ }else{
430
+ $markAllCheckbox.prop('indeterminate', false);
431
+ $markAllCheckbox.prop('checked', true);
432
+ }
433
+ $('#'+ tableId +' .tabulatr-wrench').removeClass('disabled');
434
+ }else{
435
+ if($('#'+ tableId +' tr[data-page]:visible input[type=checkbox]:checked').length > 0){
436
+ $markAllCheckbox.prop('indeterminate', true);
437
+ $('#'+ tableId +' .tabulatr-wrench').removeClass('disabled');
438
+ }else{
439
+ $markAllCheckbox.prop('indeterminate', false);
440
+ $markAllCheckbox.prop('checked', false);
441
+ if(table_obj.checkIfCheckboxesAreMarked()){
442
+ $('#'+ tableId +' .tabulatr-wrench').removeClass('disabled');
443
+ }else{
444
+ $('#'+ tableId +' .tabulatr-wrench').addClass('disabled');
445
+ }
446
+ }
447
+ }
448
+ });
449
+
450
+ $('.tabulatr-per-page a').click(function(){
451
+ if($(this).hasClass('active')){ return false; }
452
+ $(this).closest('div').find('a').removeClass('active');
453
+ $(this).addClass('active');
454
+ var tableId = $(this).closest('div').data('table');
455
+ var table_obj;
456
+ for(var i = 0; i < tabulatr_tables.length; i++){
457
+ if(tabulatr_tables[i].id == tableId){
458
+ table_obj = tabulatr_tables[i];
459
+ }
460
+ }
461
+ table_obj.moreResults = true;
462
+ if($('.pagination[data-table='+ tableId +']').length === 0){
463
+ $('.pagination_trigger[data-table='+ tableId +']').bind('inview', cbfn);
464
+ }
465
+ if(typeof(Storage) !== undefined){
466
+ localStorage.tabulatr_page_display_count = $(this).data('items-per-page');
467
+ }
468
+ table_obj.updateTable({page: 1}, true);
469
+ });
470
+
471
+ $(document).on('click', 'a[data-tabulatr-reset]',function(){
472
+ var tableObj, tableName;
473
+ var tableId = $(this).data('tabulatrReset');
474
+ for(var i = 0; i < tabulatr_tables.length; i++){
475
+ if(tabulatr_tables[i].id == tableId){
476
+ tableObj = tabulatr_tables[i];
477
+ tableObj.resetTable();
478
+ return false;
479
+ }
480
+ }
481
+ });
482
+
483
+ if($('.tabulatr_table:not(".tabulatr_static_table")').length > 0){
484
+ if(typeof(Storage) !== undefined){
485
+ var count = localStorage.tabulatr_page_display_count;
486
+ if(count !== undefined){
487
+ $('.tabulatr-per-page a').removeClass('active');
488
+ $('.tabulatr-per-page a[data-items-per-page='+ count +']').
489
+ addClass('active');
490
+ }
491
+ }
492
+ var tableObj, tableId, tabulatrTable;
493
+ $('.tabulatr_table:not(".tabulatr_static_table")').each(function(ix, el){
494
+ tableId = $(el).attr('id');
495
+ tabulatrTable = new Tabulatr(tableId);
496
+ if($(el).data('persistent')){
497
+ tabulatrTable.isAPersistedTable = true;
498
+ }
499
+ tabulatr_tables.push(tabulatrTable);
500
+ for(var i = 0; i < tabulatr_tables.length; i++){
501
+ if(tabulatr_tables[i].id == tableId){
502
+ tableObj = tabulatr_tables[i];
503
+ }
504
+ }
505
+ tableObj.updateTable({}, false);
506
+ });
507
+ }
508
+ });
509
+
510
+ $(document).on('click', '.pagination a[data-page]', function(){
511
+ var a = $(this);
512
+ if(a.parent().hasClass('active') ||
513
+ a.parent().hasClass('disabled')){
514
+ return false;
515
+ }
516
+ var tableId = $(a).closest('.pagination').data('table');
517
+ $('.tabulatr_mark_all[data-table='+ tableId +']').prop('checked', false);
518
+ $('.tabulatr_mark_all[data-table='+ tableId +']').prop('indeterminate', false);
519
+ var table_obj;
520
+ for(var i = 0; i < tabulatr_tables.length; i++){
521
+ if(tabulatr_tables[i].id == tableId){
522
+ table_obj = tabulatr_tables[i];
523
+ }
524
+ }
525
+ table_obj.updateTable({append: false, page: a.data('page')});
526
+ return false;
527
+ });
528
+
529
+
530
+ // TODO: We absolutely need to clean that up!
531
+
532
+ $(document).on('click', 'a[data-show-table-filter]', function(){
533
+ var a = $(this);
534
+ var name = a.data('show-table-filter');
535
+ var tableId = a.parents('.tabulatr-filter-menu-wrapper').data('table-id');
536
+ var filterForm = $('.tabulatr_filter_form[data-table="'+ tableId +'"]');
537
+ filterForm.find($('div[data-filter-column-name="'+ name +'"]')).show('blind');
538
+ filterForm.find($('div[data-filter-column-name="_submit"]')).show('blind');
539
+
540
+ a.hide();
541
+ return false;
542
+ });
543
+
544
+ $(document).on('click', 'a[data-hide-table-filter]', function(){
545
+ var a = $(this);
546
+ var nam = a.data('hide-table-filter');
547
+ var filterForm = a.parents('.tabulatr_filter_form');
548
+ var t = filterForm.find($('div[data-filter-column-name="'+nam+'"]'));
549
+ t.hide();
550
+ t.find('input[type=text]').val("");
551
+ t.find('select').val('');
552
+ var filterMenu = $('.tabulatr-filter-menu-wrapper[data-table-id="'+ filterForm.data('table') +'"]');
553
+ filterMenu.find($('a[data-show-table-filter="'+nam+'"]')).show();
554
+ if (filterForm.find($('div[data-filter-column-name]:visible')).length <= 2)
555
+ filterForm.find($('div[data-filter-column-name="_submit"]')).hide('blind');
556
+
557
+ var tableId = filterForm.data('table');
558
+ var table_obj;
559
+ for(var i = 0; i < tabulatr_tables.length; i++){
560
+ if(tabulatr_tables[i].id == tableId){
561
+ table_obj = tabulatr_tables[i];
562
+ }
563
+ }
564
+ table_obj.submitFilterForm();
565
+ return false;
566
+ });
567
+
568
+ $(document).on('change', 'select[data-tabulatr-date-filter]', function() {
569
+ var select = $(this);
570
+ var option = select.find('option:selected');
571
+ var val = option.val();
572
+ if (val === 'from_to') {
573
+ select.parents('.controls').find(".from_to").show().removeClass('hidden');
574
+ } else {
575
+ select.parents('.controls').find(".from_to").hide().val('');
576
+ }
577
+ });
578
+
579
+
580
+ var cbfn = function(event, isInView, visiblePartX, visiblePartY) {
581
+ if (isInView) {
582
+ // element is now visible in the viewport
583
+ if (visiblePartY == 'top') {
584
+ // top part of element is visible
585
+ } else if (visiblePartY == 'bottom') {
586
+ // bottom part of element is visible
587
+ } else {
588
+ var tableId = $(event.currentTarget).data('table');
589
+ var table_obj;
590
+ for(var i = 0; i < tabulatr_tables.length; i++){
591
+ if(tabulatr_tables[i].id == tableId){
592
+ table_obj = tabulatr_tables[i];
593
+ }
594
+ }
595
+ table_obj.updateTable({append: true});
596
+ }
597
+ }
598
+ };