tabulatr2 0.9.20 → 0.9.21
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +17 -0
- data/.gitignore +1 -0
- data/CHANGELOG.md +4 -0
- data/Gemfile +4 -0
- data/app/assets/javascripts/tabulatr/_events.js +252 -0
- data/app/assets/javascripts/tabulatr/_pagination.js +85 -0
- data/app/assets/javascripts/tabulatr/_tabulatr.js +70 -372
- data/app/assets/javascripts/tabulatr/application.js +2 -0
- data/app/views/tabulatr/_tabulatr_actual_table.html.slim +7 -7
- data/app/views/tabulatr/_tabulatr_filter_dialog.html.slim +1 -1
- data/app/views/tabulatr/_tabulatr_static_table.html.slim +5 -3
- data/lib/tabulatr/data/data.rb +1 -1
- data/lib/tabulatr/data/dsl.rb +62 -86
- data/lib/tabulatr/data/filtering.rb +32 -52
- data/lib/tabulatr/data/sorting.rb +1 -1
- data/lib/tabulatr/params_builder.rb +50 -0
- data/lib/tabulatr/rails/action_view.rb +2 -2
- data/lib/tabulatr/rails/active_record.rb +3 -8
- data/lib/tabulatr/renderer/action.rb +1 -1
- data/lib/tabulatr/renderer/association.rb +3 -3
- data/lib/tabulatr/renderer/buttons.rb +1 -1
- data/lib/tabulatr/renderer/column.rb +40 -125
- data/lib/tabulatr/renderer/columns_from_block.rb +10 -7
- data/lib/tabulatr/renderer/renderer.rb +26 -15
- data/lib/tabulatr/version.rb +1 -1
- data/lib/tabulatr.rb +1 -0
- data/spec/dummy/app/controllers/products_controller.rb +5 -6
- data/spec/dummy/app/tabulatr_data/product_tabulatr_data.rb +6 -6
- data/spec/dummy/app/views/products/stupid_array.html.erb +20 -6
- data/spec/dummy/app/views/products/with_styling.html.erb +1 -1
- data/spec/dummy/app/views/products/without_filters.html.erb +1 -0
- data/spec/dummy/config/routes.rb +1 -0
- data/spec/features/tabulatrs_spec.rb +7 -2
- data/spec/lib/tabulatr/data/data_spec.rb +2 -2
- data/spec/lib/tabulatr/data/dsl_spec.rb +54 -4
- data/spec/lib/tabulatr/data/filtering_spec.rb +164 -7
- data/spec/lib/tabulatr/data/formatting_spec.rb +2 -2
- data/spec/lib/tabulatr/data/sorting_spec.rb +6 -6
- data/spec/lib/tabulatr/params_builder_spec.rb +19 -0
- data/spec/lib/tabulatr/renderer/association_spec.rb +29 -0
- data/spec/lib/tabulatr/renderer/renderer_spec.rb +8 -0
- data/spec/rails_helper.rb +4 -0
- metadata +13 -3
@@ -9,6 +9,8 @@ function Tabulatr(id){
|
|
9
9
|
this.hasInfiniteScrolling = false;
|
10
10
|
}
|
11
11
|
|
12
|
+
var tabulatr_tables;
|
13
|
+
|
12
14
|
var cbfn = function(event, isInView, visiblePartX, visiblePartY) {
|
13
15
|
if (isInView && visiblePartY !== 'top' && visiblePartY !== 'bottom') {
|
14
16
|
var tableId = $(event.currentTarget).data('table');
|
@@ -22,106 +24,41 @@ var cbfn = function(event, isInView, visiblePartX, visiblePartY) {
|
|
22
24
|
}
|
23
25
|
};
|
24
26
|
|
25
|
-
var tabulatr_tables;
|
26
27
|
Tabulatr.prototype = {
|
27
28
|
constructor: Tabulatr,
|
28
29
|
|
29
|
-
|
30
|
-
var $
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
30
|
+
updateTable: function(hash, forceReload) {
|
31
|
+
var $table = $('#'+ this.id);
|
32
|
+
this.storePage = this.pageShouldBeStored(hash.page, forceReload);
|
33
|
+
if((this.storePage && this.retrievePage($table, hash)) || this.locked){ return; }
|
34
|
+
this.locked = true;
|
35
|
+
this.showLoadingSpinner();
|
36
|
+
this.loadDataFromServer(hash);
|
35
37
|
},
|
36
38
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
if($('table#'+ this.id).data('persistent')){
|
41
|
-
$paginatorUl.html('<li><a href="#" data-tabulatr-reset="'+ this.id +'"><i class="fa fa-refresh"></i></a></li>');
|
42
|
-
}else{
|
43
|
-
$paginatorUl.html('');
|
44
|
-
}
|
45
|
-
if(numPages < 13){
|
46
|
-
for(var i = 1; i <= numPages; i++){
|
47
|
-
$paginatorUl.append(this.createPaginationListItem(i, (i == currentPage)));
|
48
|
-
}
|
49
|
-
}else{
|
50
|
-
if(currentPage > 1){
|
51
|
-
$paginatorUl.append(this.createPaginationListItem(1, false));
|
52
|
-
}
|
53
|
-
|
54
|
-
var between = Math.floor((1 + currentPage) / 2);
|
55
|
-
if(between > 1 && between < currentPage - 2){
|
56
|
-
$paginatorUl.append('<li><span>...</span></li>');
|
57
|
-
$paginatorUl.append(this.createPaginationListItem(between, false));
|
58
|
-
}
|
59
|
-
|
60
|
-
if(currentPage > 4){
|
61
|
-
$paginatorUl.append('<li><span>...</span></li>');
|
62
|
-
}
|
63
|
-
|
64
|
-
if(currentPage > 3){
|
65
|
-
$paginatorUl.append(this.createPaginationListItem(currentPage-2, false));
|
66
|
-
}
|
67
|
-
|
68
|
-
if(currentPage > 2){
|
69
|
-
$paginatorUl.append(this.createPaginationListItem(currentPage-1, false));
|
70
|
-
}
|
71
|
-
|
72
|
-
$paginatorUl.append(this.createPaginationListItem(currentPage, true));
|
73
|
-
|
74
|
-
if(currentPage < numPages - 1){
|
75
|
-
$paginatorUl.append(this.createPaginationListItem(currentPage+1, false));
|
76
|
-
}
|
77
|
-
|
78
|
-
if(currentPage < numPages - 2){
|
79
|
-
$paginatorUl.append(this.createPaginationListItem(currentPage+2, false));
|
80
|
-
}
|
81
|
-
|
82
|
-
if(currentPage < numPages - 3){
|
83
|
-
$paginatorUl.append('<li><span>...</span></li>');
|
84
|
-
}
|
39
|
+
pageShouldBeStored: function(page, forceReload){
|
40
|
+
return page !== undefined && !forceReload;
|
41
|
+
},
|
85
42
|
|
86
|
-
|
43
|
+
retrievePage: function(table, hash){
|
44
|
+
table.find('tbody tr').hide();
|
45
|
+
if(table.find('tbody tr[data-page='+ hash.page +']').length > 0){
|
46
|
+
table.find('tbody tr[data-page='+ hash.page +']').show();
|
87
47
|
|
88
|
-
|
89
|
-
$
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
48
|
+
var tabulatrPagination = new TabulatrPagination(
|
49
|
+
$('.pagination[data-table='+ this.id +'] a:last').data('page'), this.id);
|
50
|
+
tabulatrPagination.updatePagination(hash.page);
|
51
|
+
if(this.isAPersistedTable){
|
52
|
+
var data = this.createParameterString(hash, this.id);
|
53
|
+
localStorage[this.id] = JSON.stringify(data);
|
94
54
|
}
|
55
|
+
return true;
|
95
56
|
}
|
96
|
-
|
57
|
+
return false;
|
97
58
|
},
|
98
59
|
|
99
|
-
|
100
|
-
var $table = $('#'+ this.id);
|
60
|
+
getDataForAjax: function(hash){
|
101
61
|
var data;
|
102
|
-
if(hash.page !== undefined && !forceReload){
|
103
|
-
//old page should be stored
|
104
|
-
this.storePage = true;
|
105
|
-
// check if this page was already loaded
|
106
|
-
$table.find('tbody tr').hide();
|
107
|
-
if($table.find('tbody tr[data-page='+ hash.page +']').length > 0){
|
108
|
-
$table.find('tbody tr[data-page='+ hash.page +']').show();
|
109
|
-
|
110
|
-
this.updatePagination(hash.page,
|
111
|
-
$('.pagination[data-table='+ this.id +'] a:last').data('page'),
|
112
|
-
this.id);
|
113
|
-
if(this.isAPersistedTable){
|
114
|
-
data = this.createParameterString(hash, this.id);
|
115
|
-
localStorage[this.id] = JSON.stringify(data);
|
116
|
-
}
|
117
|
-
return;
|
118
|
-
}
|
119
|
-
}else{
|
120
|
-
this.storePage = false;
|
121
|
-
}
|
122
|
-
if(this.locked){ return; }
|
123
|
-
this.locked = true;
|
124
|
-
this.showLoadingSpinner();
|
125
62
|
if(this.initialRequest && this.isAPersistedTable && localStorage[this.id]){
|
126
63
|
data = JSON.parse(localStorage[this.id]);
|
127
64
|
}else{
|
@@ -130,6 +67,10 @@ Tabulatr.prototype = {
|
|
130
67
|
localStorage[this.id] = JSON.stringify(data);
|
131
68
|
}
|
132
69
|
}
|
70
|
+
return data;
|
71
|
+
},
|
72
|
+
|
73
|
+
loadDataFromServer: function(hash){
|
133
74
|
$.ajax({
|
134
75
|
context: this,
|
135
76
|
type: 'GET',
|
@@ -137,7 +78,7 @@ Tabulatr.prototype = {
|
|
137
78
|
accepts: {
|
138
79
|
json: 'application/json'
|
139
80
|
},
|
140
|
-
data:
|
81
|
+
data: this.getDataForAjax(hash),
|
141
82
|
success: this.handleResponse,
|
142
83
|
complete: this.hideLoadingSpinner,
|
143
84
|
error: this.handleError
|
@@ -154,7 +95,9 @@ Tabulatr.prototype = {
|
|
154
95
|
|
155
96
|
handleResponse: function(response) {
|
156
97
|
this.insertTabulatrData(response);
|
157
|
-
|
98
|
+
var tabulatrPagination = new TabulatrPagination(
|
99
|
+
response.meta.pages, response.meta.table_id);
|
100
|
+
tabulatrPagination.updatePagination(response.meta.page);
|
158
101
|
if($('.pagination[data-table='+ response.meta.table_id +']').length > 0){
|
159
102
|
if(response.meta.page > response.meta.pages){
|
160
103
|
this.updateTable({page: response.meta.pages});
|
@@ -217,7 +160,7 @@ Tabulatr.prototype = {
|
|
217
160
|
|
218
161
|
makeAction: function(action, data){
|
219
162
|
this.currentData = data;
|
220
|
-
return
|
163
|
+
return decodeURI(action).replace(/{{([\w:]+)}}/g, this.replacer);
|
221
164
|
},
|
222
165
|
|
223
166
|
submitFilterForm: function(){
|
@@ -232,40 +175,15 @@ Tabulatr.prototype = {
|
|
232
175
|
createParameterString: function(hash){
|
233
176
|
var tableName = this.id.split('_')[0];
|
234
177
|
if(hash === undefined){
|
235
|
-
hash = {};
|
236
|
-
hash.append = false;
|
237
|
-
}
|
238
|
-
var pagesize = hash.pagesize;
|
239
|
-
if(pagesize === undefined){
|
240
|
-
pagesize = $('table#'+ this.id).data('pagesize');
|
178
|
+
hash = {append: false};
|
241
179
|
}
|
242
|
-
|
243
|
-
if(this.hasInfiniteScrolling){
|
244
|
-
hash.page = Math.floor($('#'+ this.id +' tbody tr[class!=empty_row]').length/pagesize) + 1;
|
245
|
-
}
|
246
|
-
if(!isFinite(hash.page)){
|
247
|
-
hash.page = 1;
|
248
|
-
}
|
249
|
-
}
|
250
|
-
hash.pagesize = pagesize;
|
180
|
+
hash = this.getPageParams(hash);
|
251
181
|
hash.arguments = $.map($('#'+ this.id +' th'), function(n){
|
252
182
|
return $(n).data('tabulatr-column-name');
|
253
183
|
}).filter(function(n){return n; }).join();
|
254
184
|
hash.table_id = this.id;
|
255
185
|
hash[tableName + '_search'] = $('input#'+ this.id +'_fuzzy_search_query').val();
|
256
|
-
|
257
|
-
.find('input:visible,select:visible,input[type=hidden]').serializeArray();
|
258
|
-
for(var i = 0; i < form_array.length; i++){
|
259
|
-
if(hash[form_array[i].name] !== undefined){
|
260
|
-
if(!Array.isArray(hash[form_array[i].name])){
|
261
|
-
hash[form_array[i].name] = [hash[form_array[i].name]];
|
262
|
-
}
|
263
|
-
hash[form_array[i].name].push(form_array[i].value);
|
264
|
-
}else{
|
265
|
-
hash[form_array[i].name] = form_array[i].value;
|
266
|
-
}
|
267
|
-
}
|
268
|
-
return hash;
|
186
|
+
return this.readParamsFromForm(hash);
|
269
187
|
},
|
270
188
|
|
271
189
|
localDate: function(value){
|
@@ -291,271 +209,51 @@ Tabulatr.prototype = {
|
|
291
209
|
$('.tabulatr_count[data-table='+ tableId +']').html(count_string);
|
292
210
|
},
|
293
211
|
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
}
|
302
|
-
if(dataCount === 0 || this.currentCount() + dataCount >= actualCount){
|
303
|
-
this.moreResults = false;
|
304
|
-
$('.pagination_trigger[data-table='+ tableId +']').unbind('inview');
|
305
|
-
}
|
306
|
-
}
|
307
|
-
|
308
|
-
};
|
309
|
-
|
310
|
-
$(document).on('ready page:load', function(){
|
311
|
-
tabulatr_tables = [];
|
312
|
-
|
313
|
-
$('th.tabulatr-sortable').click(function(){
|
314
|
-
var th = $(this);
|
315
|
-
var sort_by = th.data('tabulatr-column-name');
|
316
|
-
var dir = th.attr('data-sorted');
|
317
|
-
var table = th.parents('table');
|
318
|
-
var tableId = table.attr('id');
|
319
|
-
var table_obj;
|
320
|
-
for(var i = 0; i < tabulatr_tables.length; i++){
|
321
|
-
if(tabulatr_tables[i].id === tableId){
|
322
|
-
table_obj = tabulatr_tables[i];
|
323
|
-
}
|
324
|
-
}
|
325
|
-
var tableName = table_obj.id.split('_')[0];
|
326
|
-
table.find('th.tabulatr-sortable.sorted').removeClass('sorted').removeAttr('data-sorted');
|
327
|
-
dir = (dir === 'asc') ? 'desc' : 'asc';
|
328
|
-
th.addClass('sorted').attr('data-sorted', dir);
|
329
|
-
$('.tabulatr_filter_form[data-table='+ tableId +'] input[name='+ tableName +'_sort]').val(sort_by + ' '+ dir);
|
330
|
-
if(!table_obj.moreResults){
|
331
|
-
table_obj.moreResults = true;
|
332
|
-
if(table_obj.hasInfiniteScrolling){
|
333
|
-
$('.pagination_trigger[data-table='+ tableId +']').bind('inview', cbfn);
|
334
|
-
}
|
335
|
-
}
|
336
|
-
$($(this).parents('table').find('tbody tr')).remove();
|
337
|
-
|
338
|
-
$('.tabulatr_mark_all[data-table='+ tableName +']').prop('checked', false).prop('indeterminate', false);
|
339
|
-
table_obj.updateTable({});
|
340
|
-
});
|
341
|
-
|
342
|
-
|
343
|
-
$('.tabulatr_table').each(function(ix, el){
|
344
|
-
if($('.pagination[data-table="'+ $(el).attr('id') +'"]').length === 0){
|
345
|
-
$('.pagination_trigger[data-table="'+ $(el).attr('id') +'"]').bind('inview', cbfn);
|
346
|
-
}
|
347
|
-
});
|
348
|
-
|
349
|
-
$('.batch-action-inputs').click(function(){
|
350
|
-
var a = $(this);
|
351
|
-
var name = a.data('do-batch-action-name');
|
352
|
-
var key = a.data('do-batch-action');
|
353
|
-
var tableId = a.data('table-id');
|
354
|
-
var params = {page: 1};
|
355
|
-
params[name] = key;
|
356
|
-
params.tabulatr_checked = {checked_ids: jQuery.map($('#'+ tableId +' .tabulatr-checkbox:checked'), function(el){return $(el).val();}).join(',')};
|
357
|
-
var confirmation = true;
|
358
|
-
if(params.tabulatr_checked.checked_ids == ''){
|
359
|
-
confirmation = confirm(a.parents('ul').data('confirm-text'));
|
360
|
-
}
|
361
|
-
if(confirmation){
|
362
|
-
$('.tabulatr_mark_all[data-table='+ tableId +']').prop('indeterminate', false).prop('checked', false);
|
363
|
-
$('#'+ tableId +' .tabulatr-wrench').addClass('disabled');
|
364
|
-
var table_obj;
|
365
|
-
for(var i = 0; i < tabulatr_tables.length; i++){
|
366
|
-
if(tabulatr_tables[i].id === tableId){
|
367
|
-
table_obj = tabulatr_tables[i];
|
212
|
+
readParamsFromForm: function(hash){
|
213
|
+
var form_array = $('.tabulatr_filter_form[data-table="'+ this.id +'"]')
|
214
|
+
.find('input:visible,select:visible,input[type=hidden]').serializeArray();
|
215
|
+
for(var i = 0; i < form_array.length; i++){
|
216
|
+
if(hash[form_array[i].name] !== undefined){
|
217
|
+
if(!Array.isArray(hash[form_array[i].name])){
|
218
|
+
hash[form_array[i].name] = [hash[form_array[i].name]];
|
368
219
|
}
|
369
|
-
|
370
|
-
table_obj.updateTable(params, true);
|
371
|
-
}
|
372
|
-
});
|
373
|
-
|
374
|
-
$('form.tabulatr-fuzzy-search').submit(function(){
|
375
|
-
var tableId = $(this).data('table');
|
376
|
-
var table_obj;
|
377
|
-
for(var i = 0; i < tabulatr_tables.length; i++){
|
378
|
-
if(tabulatr_tables[i].id === tableId){
|
379
|
-
table_obj = tabulatr_tables[i];
|
380
|
-
}
|
381
|
-
}
|
382
|
-
if(table_obj.hasInfiniteScrolling){
|
383
|
-
$('.pagination_trigger[data-table='+ tableId +']').unbind('inview', cbfn);
|
384
|
-
$('.pagination_trigger[data-table='+ tableId +']').bind('inview', cbfn);
|
385
|
-
}
|
386
|
-
table_obj.updateTable({page: 1, append: false}, true);
|
387
|
-
return false;
|
388
|
-
});
|
389
|
-
|
390
|
-
$('form.tabulatr_filter_form input, form.tabulatr_filter_form select').change(function(){
|
391
|
-
$(this).parents('form.tabulatr_filter_form').submit();
|
392
|
-
});
|
393
|
-
|
394
|
-
$('form.tabulatr_filter_form').submit(function(){
|
395
|
-
var tableId = $(this).data('table');
|
396
|
-
var table_obj;
|
397
|
-
for(var i = 0; i < tabulatr_tables.length; i++){
|
398
|
-
if(tabulatr_tables[i].id === tableId){
|
399
|
-
table_obj = tabulatr_tables[i];
|
400
|
-
}
|
401
|
-
}
|
402
|
-
table_obj.submitFilterForm();
|
403
|
-
return false;
|
404
|
-
});
|
405
|
-
|
406
|
-
$('.tabulatr_mark_all').click(function(){
|
407
|
-
var tableId = $(this).parents('table').prop('id');
|
408
|
-
var table_obj;
|
409
|
-
for(var i = 0; i < tabulatr_tables.length; i++){
|
410
|
-
if(tabulatr_tables[i].id === tableId){
|
411
|
-
table_obj = tabulatr_tables[i];
|
412
|
-
}
|
413
|
-
}
|
414
|
-
if($(this).is(':checked')){
|
415
|
-
$('#'+ tableId +' tr[data-page]:visible input[type=checkbox]').prop('checked', true);
|
416
|
-
$('#'+ tableId +' .tabulatr-wrench').removeClass('disabled');
|
417
|
-
}else{
|
418
|
-
$('#'+ tableId +' tr[data-page]:visible input[type=checkbox]').prop('checked', false);
|
419
|
-
if(table_obj.checkIfCheckboxesAreMarked()){
|
420
|
-
$('#'+ tableId +' .tabulatr-wrench').removeClass('disabled');
|
220
|
+
hash[form_array[i].name].push(form_array[i].value);
|
421
221
|
}else{
|
422
|
-
|
222
|
+
hash[form_array[i].name] = form_array[i].value;
|
423
223
|
}
|
424
224
|
}
|
425
|
-
|
225
|
+
return hash;
|
226
|
+
},
|
426
227
|
|
427
|
-
|
428
|
-
var
|
429
|
-
|
430
|
-
|
431
|
-
var table_obj;
|
432
|
-
for(var i = 0; i < tabulatr_tables.length; i++){
|
433
|
-
if(tabulatr_tables[i].id === tableId){
|
434
|
-
table_obj = tabulatr_tables[i];
|
435
|
-
}
|
228
|
+
getPageParams: function(hash){
|
229
|
+
var pagesize = hash.pagesize;
|
230
|
+
if(pagesize === undefined){
|
231
|
+
pagesize = $('table#'+ this.id).data('pagesize');
|
436
232
|
}
|
437
|
-
if(
|
438
|
-
if(
|
439
|
-
|
440
|
-
}else{
|
441
|
-
$markAllCheckbox.prop('indeterminate', false);
|
442
|
-
$markAllCheckbox.prop('checked', true);
|
233
|
+
if(hash.page === undefined){
|
234
|
+
if(this.hasInfiniteScrolling){
|
235
|
+
hash.page = Math.floor($('#'+ this.id +' tbody tr[class!=empty_row]').length/pagesize) + 1;
|
443
236
|
}
|
444
|
-
|
445
|
-
|
446
|
-
if($('#'+ tableId +' tr[data-page]:visible input[type=checkbox]:checked').length > 0){
|
447
|
-
$markAllCheckbox.prop('indeterminate', true);
|
448
|
-
$('#'+ tableId +' .tabulatr-wrench').removeClass('disabled');
|
449
|
-
}else{
|
450
|
-
$markAllCheckbox.prop('indeterminate', false);
|
451
|
-
$markAllCheckbox.prop('checked', false);
|
452
|
-
if(table_obj.checkIfCheckboxesAreMarked()){
|
453
|
-
$('#'+ tableId +' .tabulatr-wrench').removeClass('disabled');
|
454
|
-
}else{
|
455
|
-
$('#'+ tableId +' .tabulatr-wrench').addClass('disabled');
|
456
|
-
}
|
237
|
+
if(!isFinite(hash.page)){
|
238
|
+
hash.page = 1;
|
457
239
|
}
|
458
240
|
}
|
459
|
-
|
241
|
+
hash.pagesize = pagesize;
|
242
|
+
return hash;
|
243
|
+
},
|
460
244
|
|
461
|
-
|
462
|
-
if(
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
|
467
|
-
for(var i = 0; i < tabulatr_tables.length; i++){
|
468
|
-
if(tabulatr_tables[i].id === tableId){
|
469
|
-
table_obj = tabulatr_tables[i];
|
470
|
-
}
|
471
|
-
}
|
472
|
-
table_obj.moreResults = true;
|
473
|
-
if(table_obj.hasInfiniteScrolling){
|
474
|
-
$('.pagination_trigger[data-table='+ tableId +']').bind('inview', cbfn);
|
475
|
-
}
|
476
|
-
if(typeof(Storage) !== undefined){
|
477
|
-
localStorage.tabulatr_page_display_count = $(this).data('items-per-page');
|
478
|
-
}
|
479
|
-
table_obj.updateTable({page: 1}, true);
|
480
|
-
});
|
481
|
-
|
482
|
-
$(document).on('click', 'a[data-tabulatr-reset]',function(){
|
483
|
-
var a = $(this);
|
484
|
-
var tableObj;
|
485
|
-
var tableId = a.data('tabulatrReset');
|
486
|
-
a.parents('.tabulatr-outer-wrapper').removeClass('filtered');
|
487
|
-
for(var i = 0; i < tabulatr_tables.length; i++){
|
488
|
-
if(tabulatr_tables[i].id === tableId){
|
489
|
-
tableObj = tabulatr_tables[i];
|
490
|
-
tableObj.resetTable();
|
491
|
-
return false;
|
245
|
+
prepareTableForInsert: function(tableId, append, dataCount, actualCount){
|
246
|
+
if(!append){
|
247
|
+
if(this.storePage){
|
248
|
+
$('#'+ tableId +' tbody tr').hide();
|
249
|
+
}else{
|
250
|
+
$('#'+ tableId +' tbody').html('');
|
492
251
|
}
|
493
252
|
}
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
if(typeof(Storage) !== undefined){
|
498
|
-
var count = localStorage.tabulatr_page_display_count;
|
499
|
-
if(count !== undefined){
|
500
|
-
$('.tabulatr-per-page a').removeClass('active');
|
501
|
-
$('.tabulatr-per-page a[data-items-per-page='+ count +']').
|
502
|
-
addClass('active');
|
503
|
-
}
|
253
|
+
if(dataCount === 0 || this.currentCount() + dataCount >= actualCount){
|
254
|
+
this.moreResults = false;
|
255
|
+
$('.pagination_trigger[data-table='+ tableId +']').unbind('inview');
|
504
256
|
}
|
505
|
-
var tableObj, tableId, tabulatrTable;
|
506
|
-
$('.tabulatr_table:not(".tabulatr_static_table")').each(function(ix, el){
|
507
|
-
tableId = $(el).attr('id');
|
508
|
-
tabulatrTable = new Tabulatr(tableId);
|
509
|
-
if($(el).data('persistent')){
|
510
|
-
tabulatrTable.isAPersistedTable = true;
|
511
|
-
}
|
512
|
-
if($('.pagination[data-table='+ tableId +']').length === 0){
|
513
|
-
tabulatrTable.hasInfiniteScrolling = true;
|
514
|
-
}
|
515
|
-
tabulatr_tables.push(tabulatrTable);
|
516
|
-
for(var i = 0; i < tabulatr_tables.length; i++){
|
517
|
-
if(tabulatr_tables[i].id === tableId){
|
518
|
-
tableObj = tabulatr_tables[i];
|
519
|
-
}
|
520
|
-
}
|
521
|
-
tableObj.updateTable({}, false);
|
522
|
-
});
|
523
257
|
}
|
524
258
|
|
525
|
-
|
526
|
-
var a = $(this);
|
527
|
-
a.parents('.tabulatr-outer-wrapper').addClass('filtered');
|
528
|
-
});
|
529
|
-
|
530
|
-
});
|
531
|
-
|
532
|
-
$(document).on('click', '.pagination a[data-page]', function(){
|
533
|
-
var a = $(this);
|
534
|
-
if(a.parent().hasClass('active') ||
|
535
|
-
a.parent().hasClass('disabled')){
|
536
|
-
return false;
|
537
|
-
}
|
538
|
-
var tableId = $(a).closest('.pagination').data('table');
|
539
|
-
$('.tabulatr_mark_all[data-table='+ tableId +']').prop('checked', false);
|
540
|
-
$('.tabulatr_mark_all[data-table='+ tableId +']').prop('indeterminate', false);
|
541
|
-
var table_obj;
|
542
|
-
for(var i = 0; i < tabulatr_tables.length; i++){
|
543
|
-
if(tabulatr_tables[i].id === tableId){
|
544
|
-
table_obj = tabulatr_tables[i];
|
545
|
-
}
|
546
|
-
}
|
547
|
-
table_obj.updateTable({append: false, page: a.data('page')});
|
548
|
-
return false;
|
549
|
-
});
|
550
|
-
|
551
|
-
|
552
|
-
$(document).on('change', 'select[data-tabulatr-date-filter]', function() {
|
553
|
-
var select = $(this);
|
554
|
-
var option = select.find('option:selected');
|
555
|
-
var val = option.val();
|
556
|
-
if (val === 'from_to') {
|
557
|
-
select.parents('.tabulatr-filter-row').find(".from_to").show().removeClass('hidden');
|
558
|
-
} else {
|
559
|
-
select.parents('.tabulatr-filter-row').find(".from_to").hide().val('');
|
560
|
-
}
|
561
|
-
});
|
259
|
+
};
|
@@ -25,17 +25,17 @@
|
|
25
25
|
thead
|
26
26
|
tr
|
27
27
|
- columns.each do |column|
|
28
|
-
- classes = column.sortable ? ['tabulatr-sortable'] : []
|
29
|
-
- classes = [classes, "tabulatr-column-#{column.coltype}", column.classes].flatten.compact.join(' ')
|
30
|
-
th data-tabulatr-column-name
|
31
|
-
|
28
|
+
- classes = column.col_options.sortable ? ['tabulatr-sortable'] : []
|
29
|
+
- classes = [classes, "tabulatr-column-#{column.coltype}", column.col_options.classes].flatten.compact.join(' ')
|
30
|
+
= content_tag('th', column.col_options.header_html.merge(:'data-tabulatr-column-name' => column.full_name, class: classes)) do
|
31
|
+
- column.human_name
|
32
32
|
tbody
|
33
33
|
tfoot
|
34
34
|
tr.empty_row
|
35
35
|
- columns.each do |column|
|
36
|
-
- classes = column.sortable ? ['tabulatr-sortable'] : []
|
37
|
-
- classes = [classes, "tabulatr-column-#{column.coltype}", column.classes].flatten.compact.join(' ')
|
38
|
-
td data-tabulatr-column-name
|
36
|
+
- classes = column.col_options.sortable ? ['tabulatr-sortable'] : []
|
37
|
+
- classes = [classes, "tabulatr-column-#{column.coltype}", column.col_options.classes].flatten.compact.join(' ')
|
38
|
+
= content_tag('td', column.col_options.data_html.merge(:'data-tabulatr-column-name' => column.full_name, :'data-tabulatr-type' => column.coltype, class: classes)){}
|
39
39
|
.tabulatr-spinner-box data-table=table_id
|
40
40
|
= image_tag "#{Tabulatr.spinner}-loader.gif"
|
41
41
|
span.pagination_trigger data-table="#{table_id}"
|
@@ -44,7 +44,7 @@
|
|
44
44
|
- filter_name = "tabulatr_form_#{name}"
|
45
45
|
|
46
46
|
label.control-label for=filter_name
|
47
|
-
= column.filter_label || column.human_name
|
47
|
+
= column.col_options.filter_label || column.human_name
|
48
48
|
|
49
49
|
- if column.filter.is_a?(Hash) || column.filter.is_a?(Array) || column.filter.is_a?(String)
|
50
50
|
select.form-control.no-chosen id=name name=iname
|
@@ -23,11 +23,13 @@ table class="#{table_options[:html_class]} tabulatr_static_table"
|
|
23
23
|
thead
|
24
24
|
tr
|
25
25
|
- columns.each do |column|
|
26
|
-
|
27
|
-
|
26
|
+
- classes = ["tabulatr-column#{column.coltype}", column.col_options.classes].flatten.compact.join(' ')
|
27
|
+
= content_tag('th', column.col_options.header_html.merge(:'data-tabulatr-column-name' => column.full_name, class: classes)) do
|
28
|
+
- column.human_name
|
28
29
|
tbody
|
29
30
|
- records.each do |record|
|
30
31
|
tr data-id=record.try(:id)
|
31
32
|
- columns.each do |column|
|
32
|
-
|
33
|
+
- classes = ["tabulatr-column-#{column.coltype}", column.col_options.classes].flatten.compact.join(' ')
|
34
|
+
= content_tag('td', column.col_options.data_html.merge(:'data-tabulatr-column-name' => column.full_name, :'data-tabulatr-type' => column.coltype, class: classes)) do
|
33
35
|
= column.value_for(record, self)
|
data/lib/tabulatr/data/data.rb
CHANGED
@@ -35,7 +35,7 @@ class Tabulatr::Data
|
|
35
35
|
table_columns.map do |col|
|
36
36
|
next if col.is_a? Tabulatr::Renderer::Checkbox
|
37
37
|
col.klass = @base.reflect_on_association(col.table_name).try(:klass) || @base
|
38
|
-
col.determine_appropriate_filter! if col.filter === true
|
38
|
+
col.determine_appropriate_filter! if col.col_options.filter === true
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|