tabulatr2 0.9.4 → 0.9.6
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +29 -0
- data/Gemfile +1 -2
- data/README.md +155 -95
- data/app/assets/javascripts/tabulatr/_storage.js +41 -0
- data/app/assets/javascripts/tabulatr/_tabulatr.js +598 -0
- data/app/assets/javascripts/tabulatr/application.js +3 -553
- data/app/assets/stylesheets/tabulatr/application.css.scss +21 -12
- data/app/assets/stylesheets/tabulatr.css +1 -0
- data/app/views/tabulatr/_tabulatr_actual_table.html.slim +18 -18
- data/app/views/tabulatr/_tabulatr_filter_dialog.html.slim +1 -1
- data/app/views/tabulatr/_tabulatr_fuzzy_search_field.html.slim +1 -1
- data/app/views/tabulatr/_tabulatr_static_table.html.slim +3 -3
- data/app/views/tabulatr/_tabulatr_table.html.slim +17 -12
- data/lib/tabulatr/data/data.rb +7 -9
- data/lib/tabulatr/data/dsl.rb +36 -21
- data/lib/tabulatr/data/filtering.rb +41 -13
- data/lib/tabulatr/data/formatting.rb +7 -20
- data/lib/tabulatr/data/pagination.rb +1 -2
- data/lib/tabulatr/data/proxy.rb +2 -0
- data/lib/tabulatr/data/sorting.rb +24 -13
- data/lib/tabulatr/engine.rb +1 -0
- data/lib/tabulatr/generators/tabulatr/templates/tabulatr.yml +2 -2
- data/lib/tabulatr/json_builder.rb +23 -25
- data/lib/tabulatr/rails/action_controller.rb +4 -0
- data/lib/tabulatr/rails/action_view.rb +3 -2
- data/lib/tabulatr/renderer/checkbox.rb +3 -1
- data/lib/tabulatr/renderer/column.rb +47 -5
- data/lib/tabulatr/renderer/columns_from_block.rb +24 -6
- data/lib/tabulatr/renderer/renderer.rb +26 -17
- data/lib/tabulatr/utility/unexpected_search_result_error.rb +9 -0
- data/lib/tabulatr/utility/utility.rb +4 -0
- data/lib/tabulatr/version.rb +1 -1
- data/spec/dummy/app/controllers/products_controller.rb +9 -0
- data/spec/dummy/app/views/products/local_storage.html.slim +4 -0
- data/spec/dummy/app/views/products/simple_index.html.erb +1 -1
- data/spec/dummy/app/views/products/stupid_array.html.erb +1 -1
- data/spec/dummy/config/application.rb +1 -1
- data/spec/dummy/config/locales/tabulatr.yml +2 -2
- data/spec/dummy/config/routes.rb +1 -0
- data/spec/features/tabulatrs_spec.rb +27 -27
- data/spec/lib/tabulatr/data/data_spec.rb +12 -16
- data/spec/lib/tabulatr/data/filtering_spec.rb +48 -7
- data/spec/lib/tabulatr/data/formatting_spec.rb +32 -0
- data/spec/lib/tabulatr/data/sorting_spec.rb +81 -0
- data/spec/lib/tabulatr/json_builder_spec.rb +23 -9
- data/spec/lib/tabulatr/renderer/checkbox_spec.rb +14 -0
- data/spec/lib/tabulatr/renderer/renderer_spec.rb +20 -8
- data/tabulatr.gemspec +4 -3
- metadata +45 -9
- data/lib/tabulatr/data/column_name_builder.rb +0 -86
@@ -1,553 +1,3 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
// a copy of this software and associated documentation files (the
|
5
|
-
// "Software"), to deal in the Software without restriction, including
|
6
|
-
// without limitation the rights to use, copy, modify, merge, publish,
|
7
|
-
// distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
-
// permit persons to whom the Software is furnished to do so, subject to
|
9
|
-
// the following conditions:
|
10
|
-
//
|
11
|
-
// The above copyright notice and this permission notice shall be
|
12
|
-
// included in all copies or substantial portions of the Software.
|
13
|
-
//
|
14
|
-
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
-
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
-
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
-
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
-
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
-
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
-
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
|
-
|
22
|
-
function Tabulatr(id){
|
23
|
-
this.id = id;
|
24
|
-
this.name = '';
|
25
|
-
this.moreResults = true;
|
26
|
-
this.currentData = null;
|
27
|
-
this.locked = false;
|
28
|
-
}
|
29
|
-
|
30
|
-
var tabulatr_tables;
|
31
|
-
Tabulatr.prototype = {
|
32
|
-
constructor: Tabulatr,
|
33
|
-
|
34
|
-
createPaginationListItem: function(page, active){
|
35
|
-
var $page = $('<li><a href="" data-page="'+ page +'">'+ page +'</a></li>');
|
36
|
-
if(active){
|
37
|
-
$page.addClass('active');
|
38
|
-
}
|
39
|
-
return $page;
|
40
|
-
},
|
41
|
-
|
42
|
-
updatePagination: function(currentPage, numPages){
|
43
|
-
var $paginatorUl = $('.pagination[data-table='+ this.id +'] > ul');
|
44
|
-
|
45
|
-
$paginatorUl.html('');
|
46
|
-
if(numPages < 13){
|
47
|
-
for(var i = 1; i <= numPages; i++){
|
48
|
-
$paginatorUl.append(this.createPaginationListItem(i, (i == currentPage)));
|
49
|
-
}
|
50
|
-
}else{
|
51
|
-
if(currentPage > 1){
|
52
|
-
$paginatorUl.append(this.createPaginationListItem(1, false));
|
53
|
-
}
|
54
|
-
|
55
|
-
var between = Math.floor((1 + currentPage) / 2);
|
56
|
-
if(between > 1 && between < currentPage - 2){
|
57
|
-
$paginatorUl.append('<li><span>...</span></li>');
|
58
|
-
$paginatorUl.append(this.createPaginationListItem(between, false));
|
59
|
-
}
|
60
|
-
|
61
|
-
if(currentPage > 4){
|
62
|
-
$paginatorUl.append('<li><span>...</span></li>');
|
63
|
-
}
|
64
|
-
|
65
|
-
if(currentPage > 3){
|
66
|
-
$paginatorUl.append(this.createPaginationListItem(currentPage-2, false));
|
67
|
-
$paginatorUl.append(this.createPaginationListItem(currentPage-1, false));
|
68
|
-
}
|
69
|
-
|
70
|
-
$paginatorUl.append(this.createPaginationListItem(currentPage, true));
|
71
|
-
|
72
|
-
if(currentPage < numPages - 1){
|
73
|
-
$paginatorUl.append(this.createPaginationListItem(currentPage+1, false));
|
74
|
-
}
|
75
|
-
|
76
|
-
if(currentPage < numPages - 2){
|
77
|
-
$paginatorUl.append(this.createPaginationListItem(currentPage+2, false));
|
78
|
-
}
|
79
|
-
|
80
|
-
if(currentPage < numPages - 3){
|
81
|
-
$paginatorUl.append('<li><span>...</span></li>');
|
82
|
-
}
|
83
|
-
|
84
|
-
between = Math.floor((currentPage + numPages) / 2);
|
85
|
-
|
86
|
-
if(between > currentPage + 3 && between < numPages - 1){
|
87
|
-
$paginatorUl.append(this.createPaginationListItem(between, false));
|
88
|
-
$paginatorUl.append('<li><span>...</span></li>');
|
89
|
-
}
|
90
|
-
if(currentPage < numPages){
|
91
|
-
$paginatorUl.append(this.createPaginationListItem(numPages, false));
|
92
|
-
}
|
93
|
-
}
|
94
|
-
|
95
|
-
},
|
96
|
-
|
97
|
-
updateTable: function(hash, forceReload) {
|
98
|
-
var $table = $('#'+ this.id);
|
99
|
-
if(hash.page !== undefined && !forceReload){
|
100
|
-
//old page should be stored
|
101
|
-
this.storePage = true;
|
102
|
-
// check if this page was already loaded
|
103
|
-
$table.find('tbody tr').hide();
|
104
|
-
if($table.find('tbody tr[data-page='+ hash.page +']').length > 0){
|
105
|
-
$table.find('tbody tr[data-page='+ hash.page +']').show();
|
106
|
-
|
107
|
-
this.updatePagination(hash.page,
|
108
|
-
$('.pagination[data-table='+ this.id +'] a:last').data('page'),
|
109
|
-
this.id);
|
110
|
-
return;
|
111
|
-
}
|
112
|
-
}else{
|
113
|
-
this.storePage = false;
|
114
|
-
}
|
115
|
-
if(this.locked){ return; }
|
116
|
-
this.locked = true;
|
117
|
-
var curTable = this;
|
118
|
-
this.showLoadingSpinner();
|
119
|
-
$.ajax({
|
120
|
-
context: this,
|
121
|
-
type: 'GET',
|
122
|
-
url: $('table#'+ this.id).data('path') + '.json',
|
123
|
-
data: this.createParameterString(hash, this.id),
|
124
|
-
success: this.handleResponse,
|
125
|
-
complete: this.hideLoadingSpinner
|
126
|
-
});
|
127
|
-
},
|
128
|
-
|
129
|
-
checkIfCheckboxesAreMarked: function(){
|
130
|
-
return $('tr[data-page] input[type=checkbox]:checked').length > 0;
|
131
|
-
},
|
132
|
-
|
133
|
-
currentCount: function(){
|
134
|
-
return $('#'+ this.id +' tbody tr.tabulatr-row').length;
|
135
|
-
},
|
136
|
-
|
137
|
-
handleResponse: function(response) {
|
138
|
-
this.insertTabulatrData(response);
|
139
|
-
this.updatePagination(response.meta.page, response.meta.pages, response.meta.table_id);
|
140
|
-
this.locked = false;
|
141
|
-
},
|
142
|
-
|
143
|
-
insertTabulatrData: function(response){
|
144
|
-
var tableId = response.meta.table_id;
|
145
|
-
var tbody = $('#'+ tableId +' tbody');
|
146
|
-
if(!response.meta.append){
|
147
|
-
if(this.storePage){
|
148
|
-
$('#'+ tableId +' tbody tr').hide();
|
149
|
-
}else{
|
150
|
-
$('#'+ tableId +' tbody').html('');
|
151
|
-
}
|
152
|
-
}
|
153
|
-
if(response.data.length === 0){
|
154
|
-
this.moreResults = false;
|
155
|
-
$('.pagination_trigger[data-table='+ tableId +']').unbind('inview');
|
156
|
-
}else{
|
157
|
-
if(this.currentCount() + response.data.length >= response.meta.count){
|
158
|
-
this.moreResults = false;
|
159
|
-
$('.pagination_trigger[data-table='+ tableId + ']').unbind('inview');
|
160
|
-
}
|
161
|
-
|
162
|
-
// insert the actual data
|
163
|
-
for(var i = 0; i < response.data.length; i++){
|
164
|
-
var data = response.data[i];
|
165
|
-
var id = data.id;
|
166
|
-
var tr = $('tr.empty_row').clone();
|
167
|
-
tr.removeClass('empty_row');
|
168
|
-
if(data._row_config.data){
|
169
|
-
tr.data(data._row_config.data);
|
170
|
-
delete data._row_config.data;
|
171
|
-
}
|
172
|
-
tr.attr(data._row_config);
|
173
|
-
tr.attr('data-page', response.meta.page);
|
174
|
-
tr.attr('data-id', id);
|
175
|
-
tr.find('td').each(function(i,td_raw) {
|
176
|
-
var td = $(td_raw);
|
177
|
-
var coltype = td.data('tabulatr-type');
|
178
|
-
var name = td.data('tabulatr-column-name');
|
179
|
-
var cont = data[name];
|
180
|
-
if(coltype === 'checkbox') {
|
181
|
-
cont = $("<input>").attr('type', 'checkbox').val(id).addClass('tabulatr-checkbox');
|
182
|
-
}
|
183
|
-
td.html(cont);
|
184
|
-
|
185
|
-
});
|
186
|
-
tbody.append(tr);
|
187
|
-
}
|
188
|
-
}
|
189
|
-
var count_string = $('.tabulatr_count[data-table='+ tableId +']').data('format-string');
|
190
|
-
count_string = count_string.replace(/%\{current\}/, response.meta.count);
|
191
|
-
count_string = count_string.replace(/%\{total\}/, response.meta.total);
|
192
|
-
count_string = count_string.replace(/%\{per_page\}/,
|
193
|
-
response.meta.pagesize);
|
194
|
-
$('.tabulatr_count[data-table='+ tableId +']').html(count_string);
|
195
|
-
},
|
196
|
-
|
197
|
-
replacer: function(match, attribute, offset, string){
|
198
|
-
return this.currentData[attribute];
|
199
|
-
},
|
200
|
-
|
201
|
-
|
202
|
-
makeAction: function(action, data){
|
203
|
-
this.currentData = data;
|
204
|
-
return unescape(action).replace(/{{([\w:]+)}}/g, this.replacer);
|
205
|
-
},
|
206
|
-
|
207
|
-
submitFilterForm: function(){
|
208
|
-
if($('.pagination[data-table='+ this.id +']').length === 0){
|
209
|
-
$('.pagination_trigger[data-table='+ this.id +']').unbind('inview', cbfn);
|
210
|
-
$('.pagination_trigger[data-table='+ this.id +']').bind('inview', cbfn);
|
211
|
-
}
|
212
|
-
this.updateTable({page: 1, append: false}, true);
|
213
|
-
return false;
|
214
|
-
},
|
215
|
-
|
216
|
-
createParameterString: function(hash){
|
217
|
-
var tableName = this.id.split('_')[0];
|
218
|
-
if(hash === undefined){
|
219
|
-
hash = {};
|
220
|
-
hash.append = false;
|
221
|
-
}
|
222
|
-
var pagesize = hash.pagesize;
|
223
|
-
if(pagesize === undefined){
|
224
|
-
pagesize = $('table#'+ this.id).data('pagesize');
|
225
|
-
}
|
226
|
-
if(hash.page === undefined){
|
227
|
-
hash.page = Math.floor($('#'+ this.id +' tbody tr[class!=empty_row]').length/pagesize) + 1;
|
228
|
-
if(!isFinite(hash.page)){
|
229
|
-
hash.page = 1;
|
230
|
-
}
|
231
|
-
}
|
232
|
-
hash.pagesize = pagesize;
|
233
|
-
hash.arguments = $.map($('#'+ this.id +' th'), function(n){
|
234
|
-
return $(n).data('tabulatr-column-name');
|
235
|
-
}).filter(function(n){return n; }).join();
|
236
|
-
hash.table_id = this.id;
|
237
|
-
hash[tableName + '_search'] = $('input#'+ tableName +'_fuzzy_search_query').val();
|
238
|
-
var form_array = $('.tabulatr_filter_form[data-table="'+ this.id +'"]')
|
239
|
-
.find('input:visible,select:visible,input[type=hidden]').serializeArray();
|
240
|
-
for(var i = 0; i < form_array.length; i++){
|
241
|
-
hash[form_array[i].name] = form_array[i].value;
|
242
|
-
}
|
243
|
-
return hash;
|
244
|
-
},
|
245
|
-
|
246
|
-
localDate: function(value, $td, $tr, obj){
|
247
|
-
return new Date(value).toLocaleString();
|
248
|
-
},
|
249
|
-
|
250
|
-
showLoadingSpinner: function(){
|
251
|
-
$('.tabulatr-spinner-box[data-table='+ this.id +']').show();
|
252
|
-
},
|
253
|
-
|
254
|
-
hideLoadingSpinner: function(){
|
255
|
-
$('.tabulatr-spinner-box[data-table='+ this.id +']').hide();
|
256
|
-
}
|
257
|
-
|
258
|
-
}
|
259
|
-
|
260
|
-
|
261
|
-
$(document).on('ready page:load', function(){
|
262
|
-
tabulatr_tables = [];
|
263
|
-
|
264
|
-
$('th.tabulatr-sortable').click(function(){
|
265
|
-
var th = $(this);
|
266
|
-
var sort_by = th.data('tabulatr-column-name');
|
267
|
-
var dir = th.attr('data-sorted');
|
268
|
-
var table = th.parents('table');
|
269
|
-
var tableId = table.attr('id');
|
270
|
-
var table_obj = undefined;
|
271
|
-
for(var i = 0; i < tabulatr_tables.length; i++){
|
272
|
-
if(tabulatr_tables[i].id == tableId){
|
273
|
-
table_obj = tabulatr_tables[i];
|
274
|
-
}
|
275
|
-
}
|
276
|
-
var tableName = table_obj.id.split('_')[0];
|
277
|
-
table.find('th.tabulatr-sortable.sorted').removeClass('sorted').removeAttr('data-sorted');
|
278
|
-
dir = (dir === 'asc') ? 'desc' : 'asc';
|
279
|
-
th.addClass('sorted').attr('data-sorted', dir);
|
280
|
-
$('.tabulatr_filter_form[data-table='+ tableId +'] input[name='+ tableName +'_sort]').val(sort_by + ' '+ dir);
|
281
|
-
if(!table_obj.moreResults){
|
282
|
-
table_obj.moreResults = true;
|
283
|
-
if($('.pagination[data-table='+ tableId +']').length === 0){
|
284
|
-
$('.pagination_trigger[data-table='+ tableId +']').bind('inview', cbfn);
|
285
|
-
}
|
286
|
-
}
|
287
|
-
$($(this).parents('table').find('tbody tr')).remove();
|
288
|
-
|
289
|
-
$('.tabulatr_mark_all[data-table='+ tableName +']').prop('checked', false).prop('indeterminate', false);
|
290
|
-
table_obj.updateTable({});
|
291
|
-
});
|
292
|
-
|
293
|
-
|
294
|
-
$('.tabulatr_table').each(function(ix, el){
|
295
|
-
if($('.pagination[data-table="'+ $(el).attr('id') +'"]').length === 0){
|
296
|
-
$('.pagination_trigger[data-table="'+ $(el).attr('id') +'"]').bind('inview', cbfn);
|
297
|
-
}
|
298
|
-
});
|
299
|
-
|
300
|
-
$('.batch-action-inputs').click(function(){
|
301
|
-
var a = $(this);
|
302
|
-
var name = a.data('do-batch-action-name');
|
303
|
-
var key = a.data('do-batch-action');
|
304
|
-
var tableId = a.data('table-id');
|
305
|
-
var params = {page: 1};
|
306
|
-
params[name] = key;
|
307
|
-
params.tabulatr_checked = {checked_ids: jQuery.map($('#'+ tableId +' .tabulatr-checkbox:checked'), function(el){return $(el).val();}).join(',')};
|
308
|
-
$('.tabulatr_mark_all[data-table='+ tableId +']').prop('indeterminate', false).prop('checked', false);
|
309
|
-
$('#'+ tableId +' .tabulatr-wrench').addClass('disabled');
|
310
|
-
var table_obj = undefined;
|
311
|
-
for(var i = 0; i < tabulatr_tables.length; i++){
|
312
|
-
if(tabulatr_tables[i].id == tableId){
|
313
|
-
table_obj = tabulatr_tables[i];
|
314
|
-
}
|
315
|
-
}
|
316
|
-
table_obj.updateTable(params, true);
|
317
|
-
});
|
318
|
-
|
319
|
-
$('form.tabulatr-fuzzy-search').submit(function(){
|
320
|
-
var tableId = $(this).data('table');
|
321
|
-
if($('.pagination[data-table='+ tableId +']').length === 0){
|
322
|
-
$('.pagination_trigger[data-table='+ tableId +']').unbind('inview', cbfn);
|
323
|
-
$('.pagination_trigger[data-table='+ tableId +']').bind('inview', cbfn);
|
324
|
-
}
|
325
|
-
var table_obj = undefined;
|
326
|
-
for(var i = 0; i < tabulatr_tables.length; i++){
|
327
|
-
if(tabulatr_tables[i].id == tableId){
|
328
|
-
table_obj = tabulatr_tables[i];
|
329
|
-
}
|
330
|
-
}
|
331
|
-
table_obj.updateTable({page: 1, append: false}, true);
|
332
|
-
return false;
|
333
|
-
});
|
334
|
-
|
335
|
-
$('form.tabulatr_filter_form').submit(function(){
|
336
|
-
var tableId = $(this).data('table');
|
337
|
-
var table_obj = undefined;
|
338
|
-
for(var i = 0; i < tabulatr_tables.length; i++){
|
339
|
-
if(tabulatr_tables[i].id == tableId){
|
340
|
-
table_obj = tabulatr_tables[i];
|
341
|
-
}
|
342
|
-
}
|
343
|
-
table_obj.submitFilterForm();
|
344
|
-
return false;
|
345
|
-
});
|
346
|
-
|
347
|
-
$('.tabulatr_table').on('click', 'i.tabulatr_remove_filter', function(){
|
348
|
-
var $th = $(this).closest('th');
|
349
|
-
var name = $th.data('tabulatr-form-name').
|
350
|
-
replace(/\[(like|checkbox|from|to)\]/, '');
|
351
|
-
name = name.replace(/(:|\.|\[|\])/g,'\\$1');
|
352
|
-
$th.removeClass('tabulatr_filtered_column');
|
353
|
-
if($('[name^='+ name +']').is(':checkbox')){
|
354
|
-
$('[name^='+ name +']').prop('checked', false);
|
355
|
-
}else{
|
356
|
-
$('[name^='+ name +']').val('');
|
357
|
-
}
|
358
|
-
var tableId = $(this).closest('.tabulatr_table').attr('id');
|
359
|
-
$(this).remove();
|
360
|
-
if($('.pagination[data-table='+ tableId +']').length === 0){
|
361
|
-
$('.pagination_trigger[data-table='+ tableId +']').bind('inview', cbfn);
|
362
|
-
}
|
363
|
-
var table_obj = undefined;
|
364
|
-
for(var i = 0; i < tabulatr_tables.length; i++){
|
365
|
-
if(tabulatr_tables[i].id == tableId){
|
366
|
-
table_obj = tabulatr_tables[i];
|
367
|
-
}
|
368
|
-
}
|
369
|
-
table_obj.updateTable({});
|
370
|
-
return false;
|
371
|
-
});
|
372
|
-
|
373
|
-
$('.tabulatr_mark_all').click(function(){
|
374
|
-
var tableId = $(this).data('table');
|
375
|
-
var table_obj = undefined;
|
376
|
-
for(var i = 0; i < tabulatr_tables.length; i++){
|
377
|
-
if(tabulatr_tables[i].id == tableId){
|
378
|
-
table_obj = tabulatr_tables[i];
|
379
|
-
}
|
380
|
-
}
|
381
|
-
if($(this).is(':checked')){
|
382
|
-
$('#'+ tableId +' tr[data-page]:visible input[type=checkbox]').prop('checked', true);
|
383
|
-
$('#'+ tableId +' .tabulatr-wrench').removeClass('disabled');
|
384
|
-
}else{
|
385
|
-
$('#'+ tableId +' tr[data-page]:visible input[type=checkbox]').prop('checked', false);
|
386
|
-
if(table_obj.checkIfCheckboxesAreMarked()){
|
387
|
-
$('#'+ tableId +' .tabulatr-wrench').removeClass('disabled');
|
388
|
-
}else{
|
389
|
-
$('#'+ tableId +' .tabulatr-wrench').addClass('disabled');
|
390
|
-
}
|
391
|
-
}
|
392
|
-
});
|
393
|
-
|
394
|
-
$('.tabulatr_table').on('click', 'input.tabulatr-checkbox', function(){
|
395
|
-
var tableId = $(this).closest('.tabulatr_table').attr('id');
|
396
|
-
var table_obj = undefined;
|
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
|
-
if($(this).is(':checked')){
|
403
|
-
if($('#'+ tableId +' tr[data-page]:visible input[type=checkbox]').not(':checked').length > 0){
|
404
|
-
$('.tabulatr_mark_all[data-table='+ tableId +']').prop("indeterminate", true);
|
405
|
-
}else{
|
406
|
-
$('.tabulatr_mark_all[data-table='+ tableId +']').prop('indeterminate', false);
|
407
|
-
$('.tabulatr_mark_all[data-table='+ tableId +']').prop('checked', true);
|
408
|
-
}
|
409
|
-
$('#'+ tableId +' .tabulatr-wrench').removeClass('disabled');
|
410
|
-
}else{
|
411
|
-
if($('#'+ tableId +' tr[data-page]:visible input[type=checkbox]:checked').length > 0){
|
412
|
-
$('.tabulatr_mark_all[data-table='+ tableId +']').prop('indeterminate', true);
|
413
|
-
$('#'+ tableId +' .tabulatr-wrench').removeClass('disabled');
|
414
|
-
}else{
|
415
|
-
$('.tabulatr_mark_all[data-table='+ tableId +']').prop('indeterminate', false);
|
416
|
-
$('.tabulatr_mark_all[data-table='+ tableId +']').prop('checked', false);
|
417
|
-
if(table_obj.checkIfCheckboxesAreMarked()){
|
418
|
-
$('#'+ tableId +' .tabulatr-wrench').removeClass('disabled');
|
419
|
-
}else{
|
420
|
-
$('#'+ tableId +' .tabulatr-wrench').addClass('disabled');
|
421
|
-
}
|
422
|
-
}
|
423
|
-
}
|
424
|
-
});
|
425
|
-
|
426
|
-
$('.tabulatr-per-page a').click(function(){
|
427
|
-
if($(this).hasClass('active')){ return false; }
|
428
|
-
$(this).closest('div').find('a').removeClass('active');
|
429
|
-
$(this).addClass('active');
|
430
|
-
var tableId = $(this).closest('div').data('table');
|
431
|
-
var table_obj = undefined;
|
432
|
-
for(var i = 0; i < tabulatr_tables.length; i++){
|
433
|
-
if(tabulatr_tables[i].id == tableId){
|
434
|
-
table_obj = tabulatr_tables[i];
|
435
|
-
}
|
436
|
-
}
|
437
|
-
table_obj.moreResults = true;
|
438
|
-
if($('.pagination[data-table='+ tableId +']').length === 0){
|
439
|
-
$('.pagination_trigger[data-table='+ tableId +']').bind('inview', cbfn);
|
440
|
-
}
|
441
|
-
if(typeof(Storage) !== undefined){
|
442
|
-
localStorage.tabulatr_page_display_count = $(this).data('items-per-page');
|
443
|
-
}
|
444
|
-
table_obj.updateTable({page: 1}, true);
|
445
|
-
});
|
446
|
-
|
447
|
-
if($('.tabulatr_table:not(".tabulatr_static_table")').length > 0){
|
448
|
-
if(typeof(Storage) !== undefined){
|
449
|
-
var count = localStorage.tabulatr_page_display_count;
|
450
|
-
if(count !== undefined){
|
451
|
-
$('.tabulatr-per-page a').removeClass('active');
|
452
|
-
$('.tabulatr-per-page a[data-items-per-page='+ count +']').
|
453
|
-
addClass('active');
|
454
|
-
}
|
455
|
-
}
|
456
|
-
var table_obj = undefined;
|
457
|
-
$('.tabulatr_table:not(".tabulatr_static_table")').each(function(ix, el){
|
458
|
-
var tableId = $(el).attr('id');
|
459
|
-
tabulatr_tables.push(new Tabulatr(tableId));
|
460
|
-
for(var i = 0; i < tabulatr_tables.length; i++){
|
461
|
-
if(tabulatr_tables[i].id == tableId){
|
462
|
-
table_obj = tabulatr_tables[i];
|
463
|
-
}
|
464
|
-
}
|
465
|
-
table_obj.updateTable({});
|
466
|
-
});
|
467
|
-
}
|
468
|
-
});
|
469
|
-
|
470
|
-
$(document).on('click', '.pagination a', function(){
|
471
|
-
var a = $(this);
|
472
|
-
if(a.parent().hasClass('active') ||
|
473
|
-
a.parent().hasClass('disabled')){
|
474
|
-
return false;
|
475
|
-
}
|
476
|
-
var tableId = $(a).closest('.pagination').data('table');
|
477
|
-
$('.tabulatr_mark_all[data-table='+ tableId +']').prop('checked', false);
|
478
|
-
$('.tabulatr_mark_all[data-table='+ tableId +']').prop('indeterminate', false);
|
479
|
-
var table_obj = undefined;
|
480
|
-
for(var i = 0; i < tabulatr_tables.length; i++){
|
481
|
-
if(tabulatr_tables[i].id == tableId){
|
482
|
-
table_obj = tabulatr_tables[i];
|
483
|
-
}
|
484
|
-
}
|
485
|
-
table_obj.updateTable({append: false, page: a.data('page')});
|
486
|
-
return false;
|
487
|
-
});
|
488
|
-
|
489
|
-
|
490
|
-
// TODO: We absolutely need to clean that up!
|
491
|
-
|
492
|
-
$(document).on('click', 'a[data-show-table-filter]', function(){
|
493
|
-
var a = $(this);
|
494
|
-
var name = a.data('show-table-filter');
|
495
|
-
$('div[data-filter-column-name="'+ name +'"]').show('blind');
|
496
|
-
$('div[data-filter-column-name="_submit"]').show('blind');
|
497
|
-
|
498
|
-
a.hide();
|
499
|
-
return false;
|
500
|
-
});
|
501
|
-
|
502
|
-
$(document).on('click', 'a[data-hide-table-filter]', function(){
|
503
|
-
var a = $(this);
|
504
|
-
var nam = a.data('hide-table-filter');
|
505
|
-
var t = $('div[data-filter-column-name="'+nam+'"]');
|
506
|
-
t.hide('blind');
|
507
|
-
t.find('input[type=text]').val("");
|
508
|
-
$('a[data-show-table-filter="'+nam+'"]').show();
|
509
|
-
if ($('div[data-filter-column-name]:visible').length <= 2)
|
510
|
-
$('div[data-filter-column-name="_submit"]').hide('blind');
|
511
|
-
|
512
|
-
var tableId = $(this).parents('form').data('table');
|
513
|
-
var table_obj = undefined;
|
514
|
-
for(var i = 0; i < tabulatr_tables.length; i++){
|
515
|
-
if(tabulatr_tables[i].id == tableId){
|
516
|
-
table_obj = tabulatr_tables[i];
|
517
|
-
}
|
518
|
-
}
|
519
|
-
table_obj.submitFilterForm();
|
520
|
-
return false;
|
521
|
-
});
|
522
|
-
|
523
|
-
$(document).on('change', 'select[data-tabulatr-date-filter]', function() {
|
524
|
-
var select = $(this);
|
525
|
-
var option = select.find('option:selected');
|
526
|
-
var val = option.val();
|
527
|
-
if (val === 'from_to') {
|
528
|
-
select.parents('.controls').find(".from_to").show().removeClass('hidden');
|
529
|
-
} else {
|
530
|
-
select.parents('.controls').find(".from_to").hide().val('');
|
531
|
-
}
|
532
|
-
});
|
533
|
-
|
534
|
-
|
535
|
-
var cbfn = function(event, isInView, visiblePartX, visiblePartY) {
|
536
|
-
if (isInView) {
|
537
|
-
// element is now visible in the viewport
|
538
|
-
if (visiblePartY == 'top') {
|
539
|
-
// top part of element is visible
|
540
|
-
} else if (visiblePartY == 'bottom') {
|
541
|
-
// bottom part of element is visible
|
542
|
-
} else {
|
543
|
-
var tableId = $(event.currentTarget).data('table');
|
544
|
-
var table_obj = undefined;
|
545
|
-
for(var i = 0; i < tabulatr_tables.length; i++){
|
546
|
-
if(tabulatr_tables[i].id == tableId){
|
547
|
-
table_obj = tabulatr_tables[i];
|
548
|
-
}
|
549
|
-
}
|
550
|
-
table_obj.updateTable({append: true});
|
551
|
-
}
|
552
|
-
}
|
553
|
-
};
|
1
|
+
//= require ./_tabulatr
|
2
|
+
//= require ./_storage
|
3
|
+
//= require ./jquery.inview.min
|
@@ -66,18 +66,7 @@ i.tabulatr_remove_filter:hover{
|
|
66
66
|
margin-left: 10px;
|
67
67
|
}
|
68
68
|
|
69
|
-
.pagination{
|
70
|
-
margin: 20px;
|
71
|
-
vertical-align: middle;
|
72
|
-
}
|
73
69
|
|
74
|
-
.pagination_trigger{
|
75
|
-
width: 1px;
|
76
|
-
height: 1px;
|
77
|
-
position: relative;
|
78
|
-
float: left;
|
79
|
-
opacity: 1;
|
80
|
-
}
|
81
70
|
|
82
71
|
div[data-filter-column-name] {
|
83
72
|
display:none;
|
@@ -114,6 +103,9 @@ table.tabulatr_table {
|
|
114
103
|
text-align: center;
|
115
104
|
}
|
116
105
|
}
|
106
|
+
tr.empty_row{
|
107
|
+
display: none;
|
108
|
+
}
|
117
109
|
}
|
118
110
|
|
119
111
|
.tabulatr-table-controls-wrapper {
|
@@ -133,6 +125,20 @@ table.tabulatr_table {
|
|
133
125
|
.tabulatr-paginator-wrapper {
|
134
126
|
display: inline-block;
|
135
127
|
padding: 0;
|
128
|
+
text-align: center;
|
129
|
+
|
130
|
+
.pagination{
|
131
|
+
margin: 10px 0;
|
132
|
+
vertical-align: middle;
|
133
|
+
}
|
134
|
+
|
135
|
+
.pagination_trigger{
|
136
|
+
width: 1px;
|
137
|
+
height: 1px;
|
138
|
+
position: relative;
|
139
|
+
float: left;
|
140
|
+
opacity: 1;
|
141
|
+
}
|
136
142
|
}
|
137
143
|
|
138
144
|
.tabulatr-info-string-wrapper {
|
@@ -155,6 +161,10 @@ table.tabulatr_table {
|
|
155
161
|
}
|
156
162
|
}
|
157
163
|
|
164
|
+
.tabulatr-table-controls-wrapper.row{
|
165
|
+
margin: 0;
|
166
|
+
}
|
167
|
+
|
158
168
|
.tabulatr-spinner-box{
|
159
169
|
width: 100%;
|
160
170
|
height: 50px;
|
@@ -162,4 +172,3 @@ table.tabulatr_table {
|
|
162
172
|
position: relative;
|
163
173
|
text-align: center;
|
164
174
|
}
|
165
|
-
|
@@ -20,22 +20,22 @@
|
|
20
20
|
/ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
21
21
|
|
22
22
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
-
|
28
|
-
|
29
|
-
|
30
|
-
= column.
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
23
|
+
.table-responsive
|
24
|
+
table class=table_options[:html_class] id=table_id data-path=table_options[:path] data-pagesize=table_options[:pagesize] data-persistent=table_options[:persistent].to_s
|
25
|
+
thead
|
26
|
+
tr
|
27
|
+
- columns.each do |column|
|
28
|
+
- classes = column.sortable ? ['tabulatr-sortable'] : []
|
29
|
+
- classes = [classes, column.classes].flatten.compact.join(' ')
|
30
|
+
th data-tabulatr-column-name=column.full_name style=column.html_header_style class=classes
|
31
|
+
= column.human_name
|
32
|
+
tbody
|
33
|
+
tfoot
|
34
|
+
tr.empty_row
|
35
|
+
- columns.each do |column|
|
36
|
+
- classes = column.sortable ? ['tabulatr-sortable'] : []
|
37
|
+
- classes = [classes, column.classes].flatten.compact.join(' ')
|
38
|
+
td data-tabulatr-column-name=column.full_name data-tabulatr-type=column.coltype style=column.html_cell_style class=classes
|
39
|
+
.tabulatr-spinner-box data-table=table_id
|
40
|
+
= image_tag "#{Tabulatr.spinner}-loader.gif"
|
40
41
|
span.pagination_trigger data-table="#{table_id}"
|
41
|
-
|
@@ -78,7 +78,7 @@ form.form.form-horizontal.tabulatr_filter_form data-table=table_id data-remote=
|
|
78
78
|
input.tabulatr_filter.form-control.date-picker.from_to.hidden type="text" id="#{formatted_name}_#{name}_filter_to" name="#{iname}[date][to]"
|
79
79
|
- else
|
80
80
|
.col-sm-11
|
81
|
-
input.tabulatr_filter.form-control type="text"
|
81
|
+
input.tabulatr_filter.form-control type="text" data-tabulatr-attribute="#{name}" name="#{iname}[like]"
|
82
82
|
.col-sm-1
|
83
83
|
= link_to "✕", '#', 'data-hide-table-filter' => name, class: 'form-control btn btn-danger btn-mini'
|
84
84
|
|
@@ -21,4 +21,4 @@
|
|
21
21
|
|
22
22
|
form.form-inline.tabulatr-fuzzy-search.pull-right data-table=table_id role="form"
|
23
23
|
.form-group
|
24
|
-
input.form-control.search id="#{
|
24
|
+
input.form-control.search id="#{table_id}_fuzzy_search_query" placeholder=t('tabulatr.search') type="search"
|