tabulatr2 0.8.9 → 0.9.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e5ce50ecf99d801c82194b66ada63d0f89cb3d23
4
- data.tar.gz: df7ffad4b2cd63c92c6d18279b8b1f1ecd9dfd28
3
+ metadata.gz: 33bcdd2d48f79be42e48d96f15856c24731b6543
4
+ data.tar.gz: db9ecdc0fb072cd452233d3a181bf1524cc0e6d1
5
5
  SHA512:
6
- metadata.gz: 8ae9fba512fd7395ebc96e3bf0e03b0c909e0985f96165d7aa81b88d1aac71a50dc871c2f6702b3953774a56ff23d61165d49c1418061ace5dc1a421a5aaba63
7
- data.tar.gz: 158c404a8e6bd33faf8728f641f278972cb2d72d7c3fc2bb11bfd03ea74929cf39325b085fb27f5d3415ca65b07b5acb4047bb5c9b9f74ad3bafbb438a35ea3b
6
+ metadata.gz: b88025d3af65dd7cceaa36ab28512767de961cd4bbd35878ec5be326456112aaf2ef7ed695ad9f8d8a7b87118c0330f0df1f09ee96aa79986048fd3946754725
7
+ data.tar.gz: 695b0ee5be5f34b8c6464b014ce11e5c4a814ec817469f6100f8f76bc7ec77a9c41190c4da675a7a9c2753c1500993209bd02ab74cefebd73790499001e8fee2
@@ -1,3 +1,28 @@
1
+ ## 0.9
2
+
3
+ * Added `row` to the TabulatrData DSL to provide HTML attributes for the
4
+ table_row of each record.
5
+
6
+ Example:
7
+ ```
8
+ row do |record, row_config|
9
+ if record.super_important?
10
+ row_config[:class] = 'important';
11
+ end
12
+ row_config[:data] = {
13
+ href: edit_user_path(record.id),
14
+ vip: record.super_important?
15
+ }
16
+ end
17
+ ```
18
+
19
+ * Added `id` of record as `data-id` of table row in static table if
20
+ id is available.
21
+
22
+ * Added `columns` keyword argument to `table_for`
23
+
24
+ * Added `checkbox` to the TabulatrData DSL
25
+
1
26
  ## 0.8.9
2
27
 
3
28
  * fix sorting, filtering, searching and batch_actions for tables whose class
data/Gemfile CHANGED
@@ -22,5 +22,5 @@ group :development, :test do
22
22
  gem 'database_cleaner', '< 1.1.0'
23
23
  gem 'poltergeist'
24
24
  gem 'sass-rails', '~> 4.0.0'
25
- gem 'bootstrap-sass', github: 'thomas-mcdonald/bootstrap-sass', branch: '3'
25
+ gem 'bootstrap-sass', '~> 3.0.3.0'
26
26
  end
data/README.md CHANGED
@@ -14,14 +14,8 @@ After that run `bundle install`.
14
14
  Also add `//= require tabulatr` to your application js file and `*= require tabulatr` to your CSS asset
15
15
  pipeline.
16
16
 
17
- If you want to create a `tabulatr` table for an existing model run
18
- `rails g tabulatr:install product`.
19
-
20
- This will generate a `ProductTabulatrData` class in `app/tabulatr_data/product_tabulatr_data.rb` for you.
21
-
22
- You can also run the generator for a new model, if you just run the standard Rails `resource` generator.
23
-
24
- `rails g resource Product title:string vendor:references description:text`
17
+ Now run the Install generator via
18
+ `rails g tabulatr install`
25
19
 
26
20
  ## Usage
27
21
 
@@ -79,6 +73,13 @@ end
79
73
  ```
80
74
  The search method is used for a fuzzy search field.
81
75
 
76
+ You can automatically generate a new TabulatrData-Class by running
77
+ `rails g tabulatr:table MODELNAME`.
78
+
79
+ This will generate a `MODELNAMETabulatrData` class in `app/tabulatr_data/MODELNAME_data.rb` for you.
80
+
81
+ This generator also gets executed if you just run the standard Rails `resource` generator.
82
+
82
83
  ## Controller
83
84
 
84
85
  In `ProductsController#index` we have:
@@ -99,6 +100,22 @@ _Hint:_ If you want to prefilter your table, you can do that too! Just pass an `
99
100
  ### View
100
101
 
101
102
  In the view we can use all the attributes which are defined in our `ProductTabulatrData` class.
103
+ To display all the columns defined in the `ProductTabulatrData` class we
104
+ just need to put the following statement in our view:
105
+
106
+ ```erb
107
+ <%= table_for Product %>
108
+ ```
109
+ If you just want do display a subset of the defined columns or show them in a
110
+ different order you can provide them as arguments to the `columns` key:
111
+
112
+ ```erb
113
+ <%= table_for Product, columns: [:vendor_address, 'vendor:name', {tags: :title}]%>
114
+ ```
115
+ Note that you can write associations as a string with colon between association
116
+ name and method or as a hash as you can see above.
117
+
118
+ An other option is to provide the columns in a block:
102
119
 
103
120
  ```erb
104
121
  <%= table_for Product do |t|
@@ -178,49 +195,63 @@ These options should be specified at the view level as parameters to the `table_
178
195
  They change the appearance and behaviour of the table.
179
196
 
180
197
  ```ruby
181
- # which controls to be rendered above and below the table and in which order
182
- :before_table_controls => [:filter, :paginator],
183
- :after_table_controls => [],
184
-
185
- :table_html => false, # a hash with html attributes for the table
186
- :header_html => false, # a hash with html attributes for the header trs
187
- :filter_html => false, # a hash with html attributes for the filter trs
188
- :filter => true, # false for no filter row at all
189
- :paginate => false, # true to show paginator, false for endless scrolling.
190
- # number for limit of items to show via pagination
191
- :sortable => true, # true to allow sorting (can be specified for every sortable column)
192
- :batch_actions => false, # :name => value hash of batch action stuff
193
- :path => '#' # where to send the AJAX-requests to
198
+ filter: true, # false for no filter row at all
199
+ search: true, # show fuzzy search field
200
+ paginate: false, # true to show paginator
201
+ pagesize: 20, # default pagesize
202
+ sortable: true, # true to allow sorting (can be specified for every sortable column)
203
+ batch_actions: false, # :name => value hash of batch action stuff
204
+ footer_content: false, # if given, add a <%= content_for <footer_content> %> before the </table>
205
+ path: '#', # where to send the AJAX-requests to
206
+ order_by: nil # default order
207
+ ```
208
+
209
+ #### Example:
210
+ ```erb
211
+ <%= table_for Product, {order_by: 'price desc', pagesize: 50} %>
194
212
  ```
195
213
 
196
214
  ### Column Options
197
215
 
216
+ You can specify these options either in your `TabulatrData` class or to
217
+ the columns in the block of `table_for`.
218
+
198
219
  ```ruby
199
- :header => false, # a string to write into the header cell
200
- :width => false, # the width of the cell
201
- :align => false, # horizontal alignment
202
- :valign => false, # vertical alignment
203
- :wrap => true, # wraps
204
- :type => :string, # :integer, :date
205
- :th_html => false, # a hash with html attributes for the header cell
206
- :filter_html => false, # a hash with html attributes for the filter cell
207
- :filter => true, # false for no filter field,
208
- # container for options_for_select
209
- # String from options_from_collection_for_select or the like
210
- # :range for range spec
211
- # :checkbox for a 0/1 valued checkbox
212
- :checkbox_value => '1', # value if checkbox is checked
213
- :checkbox_label => '', # text behind the checkbox
214
- :filter_width => '97%', # width of the filter <input>
215
- :range_filter_symbol => '&ndash;', # put between the <inputs> of the range filter
216
- :sortable => true, # if set, sorting-stuff is added to the header cell
217
- :format_methods => [] # javascript method to execute on this column
220
+ header: nil, # override content of header cell
221
+ classes: nil, # CSS classes for this column
222
+ width: false,
223
+ align: false,
224
+ valign: false,
225
+ wrap: nil,
226
+ th_html: false,
227
+ filter_html: false,
228
+ filter: true, # whether this column should be filterable
229
+ checkbox_value: '1',
230
+ checkbox_label: '',
231
+ sortable: true, # whethter this column should be sortable
232
+ format: nil,
233
+ map: true,
234
+ cell_style: {}, # CSS style for all body cells of this column
235
+ header_style: {} # CSS style for all header cells of this column
218
236
  ```
219
237
 
238
+ #### Example:
239
+ ```erb
240
+ # in the view
241
+ <%= table_for Product do |t|
242
+ t.column(:title, header_style: {color: 'red'})
243
+ # ...
244
+ %>
245
+
246
+ # or in TabulatrData
247
+ class ProductTabulatrData < Tabulatr::Data
248
+ column(:title, table_column_options: {header_style: {color: 'red'}})
249
+ end
250
+ ```
220
251
 
221
252
  ## Dependencies
222
253
 
223
- We use [whiny_hash](http://github.com/provideal/whiny_hash) to handle the options in a fail-early-manner.
254
+ We use [Bootstrap from Twitter](http://getbootstrap.com) in order to make the table look pretty decent.
224
255
 
225
256
  ## Known Bugs
226
257
 
@@ -231,11 +262,6 @@ And this limit is hard-coded IIRC. So – If you run into this limitation –
231
262
  please consider using another server.
232
263
  (Thanks to [stepheneb](https://github.com/stepheneb) for calling my attention back to this.)
233
264
 
234
- ## Other, new bugs
235
-
236
- There are roughly another 997 bugs in Tabulatr2, although we do some testing.
237
- If you hunt them, please file an issue.
238
-
239
265
  ## Contributing
240
266
 
241
267
  * Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
@@ -19,105 +19,109 @@
19
19
  // OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
20
  // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
21
 
22
- Tabulatr = {
23
- moreResults: true,
24
- storePage: false,
25
- currentData: null,
26
- locked: false,
27
-
28
- updatePagination: function(currentPage, numPages, tableId){
29
- var ul = $('.pagination[data-table='+ tableId +'] > ul');
30
- if(ul.length == 0){
31
- // bootstrap 3
32
- ul = $('.pagination[data-table='+ tableId +']');
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');
33
38
  }
34
- ul.html('');
39
+ return $page;
40
+ },
41
+
42
+ updatePagination: function(currentPage, numPages){
43
+ var $paginatorUl = $('.pagination[data-table='+ this.id +'] > ul');
44
+
45
+ $paginatorUl.html('');
35
46
  if(numPages < 13){
36
47
  for(var i = 1; i <= numPages; i++){
37
- var cls = '';
38
- if(i == currentPage){
39
- cls = 'active';
40
- }
41
- ul.append('<li class="'+ cls +'"><a href="#" data-page="'+ i+'">'+
42
- i +'</a></li>');
48
+ $paginatorUl.append(this.createPaginationListItem(i, (i == currentPage)));
43
49
  }
44
50
  }else{
45
51
  if(currentPage > 1){
46
- ul.append('<li><a href="#" data-page="1">1</a></li>');
52
+ $paginatorUl.append(this.createPaginationListItem(1, false));
47
53
  }
48
54
 
49
55
  var between = Math.floor((1 + currentPage) / 2);
50
56
  if(between > 1 && between < currentPage - 2){
51
- ul.append('<li><span>...</span></li>');
52
- ul.append('<li><a href="#" data-page="'+ between +'">'+ between +'</a></li');
57
+ $paginatorUl.append('<li><span>...</span></li>');
58
+ $paginatorUl.append(this.createPaginationListItem(between, false));
53
59
  }
54
60
 
55
61
  if(currentPage > 4){
56
- ul.append('<li><span>...</span></li>');
62
+ $paginatorUl.append('<li><span>...</span></li>');
57
63
  }
58
64
 
59
65
  if(currentPage > 3){
60
- ul.append('<li><a href="#" data-page="'+ (currentPage - 2) +'">'+
61
- (currentPage-2) +'</a></li>');
62
- ul.append('<li><a href="#" data-page="'+ (currentPage - 1) +'">'+
63
- (currentPage-1) +'</a></li>');
66
+ $paginatorUl.append(this.createPaginationListItem(currentPage-2, false));
67
+ $paginatorUl.append(this.createPaginationListItem(currentPage-1, false));
64
68
  }
65
69
 
66
- ul.append('<li class="active"><a href="#" data-page="'+ currentPage +'">'+
67
- currentPage +'</a></li>');
70
+ $paginatorUl.append(this.createPaginationListItem(currentPage, true));
68
71
 
69
72
  if(currentPage < numPages - 1){
70
- ul.append('<li><a href="#" data-page="'+ (currentPage+1) +'">'+
71
- (currentPage+1) +'</a></li>');
73
+ $paginatorUl.append(this.createPaginationListItem(currentPage+1, false));
72
74
  }
73
75
 
74
76
  if(currentPage < numPages - 2){
75
- ul.append('<li><a href="#" data-page="'+ (currentPage+2) +'">'+
76
- (currentPage+2) +'</a></li>');
77
+ $paginatorUl.append(this.createPaginationListItem(currentPage+2, false));
77
78
  }
78
79
 
79
80
  if(currentPage < numPages - 3){
80
- ul.append('<li><span>...</span></li>');
81
+ $paginatorUl.append('<li><span>...</span></li>');
81
82
  }
82
83
 
83
84
  between = Math.floor((currentPage + numPages) / 2);
84
85
 
85
86
  if(between > currentPage + 3 && between < numPages - 1){
86
- ul.append('<li><a href="#" data-page="'+ between +'">'+
87
- between +'</a></li>');
88
- ul.append('<li><span>...</span></li>');
87
+ $paginatorUl.append(this.createPaginationListItem(between, false));
88
+ $paginatorUl.append('<li><span>...</span></li>');
89
89
  }
90
90
  if(currentPage < numPages){
91
- ul.append('<li><a href="#" data-page="'+ numPages +'">'+
92
- numPages +'</a></li>');
91
+ $paginatorUl.append(this.createPaginationListItem(numPages, false));
93
92
  }
94
93
  }
95
94
 
96
95
  },
97
96
 
98
- updateTable: function(hash, tableId, forceReload) {
97
+ updateTable: function(hash, forceReload) {
98
+ var $table = $('#'+ this.id);
99
99
  if(hash.page !== undefined && !forceReload){
100
100
  //old page should be stored
101
101
  Tabulatr.storePage = true;
102
102
  // check if this page was already loaded
103
- if($('#'+ tableId + ' tbody tr[data-page='+ hash.page +']').length > 0){
104
- $('#'+ tableId + ' tbody tr').hide();
105
- $('#'+ tableId + ' tbody tr[data-page='+ hash.page +']').show();
103
+ if($table.find('tbody tr[data-page='+ hash.page +']').length > 0){
104
+ $table.find('tbody tr').hide();
105
+ $table.find('tbody tr[data-page='+ hash.page +']').show();
106
106
 
107
- Tabulatr.updatePagination(hash.page,
108
- $('.pagination[data-table='+ tableId +'] a:last').data('page'),
109
- tableId);
107
+ this.updatePagination(hash.page,
108
+ $('.pagination[data-table='+ this.id +'] a:last').data('page'),
109
+ this.id);
110
110
  return;
111
111
  }
112
112
  }else{
113
- Tabulatr.storePage = false;
113
+ this.storePage = false;
114
114
  }
115
- if(Tabulatr.locked){ return; }
116
- Tabulatr.locked = true;
117
- jQuery.get($('table#'+ tableId).data('path') + '.json',
118
- Tabulatr.createParameterString(hash, tableId),
119
- Tabulatr.handleResponse
120
- );
115
+ if(this.locked){ return; }
116
+ this.locked = true;
117
+ var curTable = this;
118
+ $.ajax({
119
+ context: this,
120
+ type: 'GET',
121
+ url: $('table#'+ this.id).data('path') + '.json',
122
+ data: this.createParameterString(hash, this.id),
123
+ success: this.handleResponse
124
+ });
121
125
  },
122
126
 
123
127
  checkIfCheckboxesAreMarked: function(){
@@ -125,32 +129,30 @@ Tabulatr = {
125
129
  },
126
130
 
127
131
  handleResponse: function(response) {
128
- Tabulatr.insertTabulatrData(response);
129
- Tabulatr.updatePagination(response.meta.page, response.meta.pages, response.meta.table_id);
130
- Tabulatr.locked = false;
132
+ this.insertTabulatrData(response);
133
+ this.updatePagination(response.meta.page, response.meta.pages, response.meta.table_id);
134
+ this.locked = false;
131
135
  },
132
136
 
133
137
  insertTabulatrData: function(response){
134
- var columns = [];
135
138
  var tableId = response.meta.table_id;
136
- var tableName = tableId.split('_')[0];
137
139
  var tbody = $('#'+ tableId +' tbody');
138
140
  if(!response.meta.append){
139
- if(Tabulatr.storePage){
141
+ if(this.storePage){
140
142
  $('#'+ tableId +' tbody tr').hide();
141
143
  }else{
142
144
  $('#'+ tableId +' tbody').html('');
143
145
  }
144
146
  }
145
- if(response.data.length == 0){
146
- Tabulatr.moreResults = false;
147
+ if(response.data.length === 0){
148
+ this.moreResults = false;
147
149
  $('.pagination_trigger[data-table='+ tableId +']').unbind('inview');
148
150
  }else{
149
151
  if(response.data.length < response.meta.pagesize){
150
- Tabulatr.moreResults = false;
152
+ this.moreResults = false;
151
153
  $('.pagination_trigger[data-table='+ tableId + ']').unbind('inview');
152
154
  }else{
153
- Tabulatr.moreResults = true;
155
+ this.moreResults = true;
154
156
  }
155
157
 
156
158
  // insert the actual data
@@ -159,13 +161,18 @@ Tabulatr = {
159
161
  var id = data.id;
160
162
  var tr = $('tr.empty_row').clone();
161
163
  tr.removeClass('empty_row');
164
+ if(data._row_config.data){
165
+ tr.data(data._row_config.data);
166
+ delete data._row_config.data;
167
+ }
168
+ tr.attr(data._row_config);
162
169
  tr.attr('data-page', response.meta.page);
163
170
  tr.attr('data-id', id);
164
171
  tr.find('td').each(function(i,td_raw) {
165
172
  var td = $(td_raw);
166
173
  var coltype = td.data('tabulatr-type');
167
174
  var name = td.data('tabulatr-column-name');
168
- var cont = data[name]
175
+ var cont = data[name];
169
176
  if(coltype === 'checkbox') {
170
177
  cont = $("<input>").attr('type', 'checkbox').val(id).addClass('tabulatr-checkbox');
171
178
  }
@@ -184,49 +191,47 @@ Tabulatr = {
184
191
  },
185
192
 
186
193
  replacer: function(match, attribute, offset, string){
187
- return Tabulatr.currentData[attribute];
194
+ return this.currentData[attribute];
188
195
  },
189
196
 
190
197
 
191
198
  makeAction: function(action, data){
192
- Tabulatr.currentData = data;
193
- return unescape(action).replace(/{{([\w:]+)}}/g, Tabulatr.replacer);
199
+ this.currentData = data;
200
+ return unescape(action).replace(/{{([\w:]+)}}/g, this.replacer);
194
201
  },
195
202
 
196
- submitFilterForm: function(tableId){
197
- if($('.pagination[data-table='+ tableId +']').length == 0){
198
- $('.pagination_trigger[data-table='+ tableId +']').unbind('inview', cbfn);
199
- $('.pagination_trigger[data-table='+ tableId +']').bind('inview', cbfn);
203
+ submitFilterForm: function(){
204
+ if($('.pagination[data-table='+ this.id +']').length === 0){
205
+ $('.pagination_trigger[data-table='+ this.id +']').unbind('inview', cbfn);
206
+ $('.pagination_trigger[data-table='+ this.id +']').bind('inview', cbfn);
200
207
  }
201
- Tabulatr.updateTable({page: 1, append: false}, tableId, true);
208
+ this.updateTable({page: 1, append: false}, true);
202
209
  return false;
203
210
  },
204
211
 
205
- createParameterString: function(hash, tableId){
206
- var tableName = tableId.split('_')[0];
212
+ createParameterString: function(hash){
213
+ var tableName = this.id.split('_')[0];
207
214
  if(hash === undefined){
208
215
  hash = {};
209
216
  hash.append = false;
210
217
  }
211
- if(hash.pagesize === undefined){
212
- var pagesize = $('table#'+ tableId).data('pagesize');
213
- if(pagesize == null) {
214
- console.log('Tabulatr: No pagesize specified')
215
- }
218
+ var pagesize = hash.pagesize;
219
+ if(pagesize === undefined){
220
+ pagesize = $('table#'+ this.id).data('pagesize');
216
221
  }
217
222
  if(hash.page === undefined){
218
- hash.page = Math.floor($('#'+ tableId +' tbody tr[class!=empty_row]').length/pagesize) + 1;
223
+ hash.page = Math.floor($('#'+ this.id +' tbody tr[class!=empty_row]').length/pagesize) + 1;
219
224
  if(!isFinite(hash.page)){
220
225
  hash.page = 1;
221
226
  }
222
227
  }
223
228
  hash.pagesize = pagesize;
224
- hash.arguments = $.map($('#'+ tableId +' th'), function(n){
225
- return $(n).data('tabulatr-column-name')
226
- }).filter(function(n){return n}).join();
227
- hash.table_id = tableId;
229
+ hash.arguments = $.map($('#'+ this.id +' th'), function(n){
230
+ return $(n).data('tabulatr-column-name');
231
+ }).filter(function(n){return n; }).join();
232
+ hash.table_id = this.id;
228
233
  hash[tableName + '_search'] = $('input#'+ tableName +'_fuzzy_search_query').val();
229
- var form_array = $('.tabulatr_filter_form[data-table="'+ tableId +'"]')
234
+ var form_array = $('.tabulatr_filter_form[data-table="'+ this.id +'"]')
230
235
  .find('input:visible,select:visible,input[type=hidden]').serializeArray();
231
236
  for(var i = 0; i < form_array.length; i++){
232
237
  hash[form_array[i].name] = form_array[i].value;
@@ -237,9 +242,12 @@ Tabulatr = {
237
242
  localDate: function(value, $td, $tr, obj){
238
243
  return new Date(value).toLocaleString();
239
244
  }
245
+
240
246
  }
241
247
 
248
+
242
249
  $(document).on('ready page:load', function(){
250
+ tabulatr_tables = [];
243
251
 
244
252
  $('th.tabulatr-sortable').click(function(){
245
253
  var th = $(this);
@@ -247,26 +255,32 @@ $(document).on('ready page:load', function(){
247
255
  var dir = th.attr('data-sorted');
248
256
  var table = th.parents('table');
249
257
  var tableId = table.attr('id');
250
- var tableName = tableId.split('_')[0];
258
+ var table_obj = undefined;
259
+ for(var i = 0; i < tabulatr_tables.length; i++){
260
+ if(tabulatr_tables[i].id == tableId){
261
+ table_obj = tabulatr_tables[i];
262
+ }
263
+ }
264
+ var tableName = table_obj.id.split('_')[0];
251
265
  table.find('th.tabulatr-sortable.sorted').removeClass('sorted').removeAttr('data-sorted');
252
266
  dir = (dir === 'asc') ? 'desc' : 'asc';
253
267
  th.addClass('sorted').attr('data-sorted', dir);
254
268
  $('.tabulatr_filter_form[data-table='+ tableId +'] input[name='+ tableName +'_sort]').val(sort_by + ' '+ dir);
255
- if(!Tabulatr.moreResults){
256
- Tabulatr.moreResults = true;
257
- if($('.pagination[data-table='+ tableId +']').length == 0){
269
+ if(!table_obj.moreResults){
270
+ table_obj.moreResults = true;
271
+ if($('.pagination[data-table='+ tableId +']').length === 0){
258
272
  $('.pagination_trigger[data-table='+ tableId +']').bind('inview', cbfn);
259
273
  }
260
274
  }
261
275
  $($(this).parents('table').find('tbody tr')).remove();
262
276
 
263
277
  $('.tabulatr_mark_all[data-table='+ tableName +']').prop('checked', false).prop('indeterminate', false);
264
- Tabulatr.updateTable({}, tableId);
278
+ table_obj.updateTable({});
265
279
  });
266
280
 
267
281
 
268
282
  $('.tabulatr_table').each(function(ix, el){
269
- if($('.pagination[data-table="'+ $(el).attr('id') +'"]').length == 0){
283
+ if($('.pagination[data-table="'+ $(el).attr('id') +'"]').length === 0){
270
284
  $('.pagination_trigger[data-table="'+ $(el).attr('id') +'"]').bind('inview', cbfn);
271
285
  }
272
286
  });
@@ -278,25 +292,43 @@ $(document).on('ready page:load', function(){
278
292
  var tableId = a.data('table-id');
279
293
  var params = {page: 1};
280
294
  params[name] = key;
281
- params['tabulatr_checked'] = {checked_ids: jQuery.map($('#'+ tableId +' .tabulatr-checkbox:checked'), function(el){return $(el).val();}).join(',')};
295
+ params.tabulatr_checked = {checked_ids: jQuery.map($('#'+ tableId +' .tabulatr-checkbox:checked'), function(el){return $(el).val();}).join(',')};
282
296
  $('.tabulatr_mark_all[data-table='+ tableId +']').prop('indeterminate', false).prop('checked', false);
283
297
  $('#'+ tableId +' .tabulatr-wrench').addClass('disabled');
284
- Tabulatr.updateTable(params, tableId, true);
298
+ var table_obj = undefined;
299
+ for(var i = 0; i < tabulatr_tables.length; i++){
300
+ if(tabulatr_tables[i].id == tableId){
301
+ table_obj = tabulatr_tables[i];
302
+ }
303
+ }
304
+ table_obj.updateTable(params, true);
285
305
  });
286
306
 
287
307
  $('form.tabulatr-fuzzy-search').submit(function(){
288
308
  var tableId = $(this).data('table');
289
- if($('.pagination[data-table='+ tableId +']').length == 0){
309
+ if($('.pagination[data-table='+ tableId +']').length === 0){
290
310
  $('.pagination_trigger[data-table='+ tableId +']').unbind('inview', cbfn);
291
311
  $('.pagination_trigger[data-table='+ tableId +']').bind('inview', cbfn);
292
312
  }
293
- Tabulatr.updateTable({page: 1, append: false}, tableId, true);
313
+ var table_obj = undefined;
314
+ for(var i = 0; i < tabulatr_tables.length; i++){
315
+ if(tabulatr_tables[i].id == tableId){
316
+ table_obj = tabulatr_tables[i];
317
+ }
318
+ }
319
+ table_obj.updateTable({page: 1, append: false}, true);
294
320
  return false;
295
321
  });
296
322
 
297
- $('form.tabulatr_filter_form').submit(function(ev){
323
+ $('form.tabulatr_filter_form').submit(function(){
298
324
  var tableId = $(this).data('table');
299
- Tabulatr.submitFilterForm(tableId);
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.submitFilterForm();
300
332
  return false;
301
333
  });
302
334
 
@@ -313,21 +345,33 @@ $(document).on('ready page:load', function(){
313
345
  }
314
346
  var tableId = $(this).closest('.tabulatr_table').attr('id');
315
347
  $(this).remove();
316
- if($('.pagination[data-table='+ tableId +']').length == 0){
348
+ if($('.pagination[data-table='+ tableId +']').length === 0){
317
349
  $('.pagination_trigger[data-table='+ tableId +']').bind('inview', cbfn);
318
350
  }
319
- Tabulatr.updateTable({}, tableId);
351
+ var table_obj = undefined;
352
+ for(var i = 0; i < tabulatr_tables.length; i++){
353
+ if(tabulatr_tables[i].id == tableId){
354
+ table_obj = tabulatr_tables[i];
355
+ }
356
+ }
357
+ table_obj.updateTable({});
320
358
  return false;
321
359
  });
322
360
 
323
361
  $('.tabulatr_mark_all').click(function(){
324
362
  var tableId = $(this).data('table');
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
+ }
325
369
  if($(this).is(':checked')){
326
370
  $('#'+ tableId +' tr[data-page]:visible input[type=checkbox]').prop('checked', true);
327
371
  $('#'+ tableId +' .tabulatr-wrench').removeClass('disabled');
328
372
  }else{
329
373
  $('#'+ tableId +' tr[data-page]:visible input[type=checkbox]').prop('checked', false);
330
- if(Tabulatr.checkIfCheckboxesAreMarked()){
374
+ if(table_obj.checkIfCheckboxesAreMarked()){
331
375
  $('#'+ tableId +' .tabulatr-wrench').removeClass('disabled');
332
376
  }else{
333
377
  $('#'+ tableId +' .tabulatr-wrench').addClass('disabled');
@@ -337,6 +381,12 @@ $(document).on('ready page:load', function(){
337
381
 
338
382
  $('.tabulatr_table').on('click', 'input.tabulatr-checkbox', function(){
339
383
  var tableId = $(this).closest('.tabulatr_table').attr('id');
384
+ var table_obj = undefined;
385
+ for(var i = 0; i < tabulatr_tables.length; i++){
386
+ if(tabulatr_tables[i].id == tableId){
387
+ table_obj = tabulatr_tables[i];
388
+ }
389
+ }
340
390
  if($(this).is(':checked')){
341
391
  if($('#'+ tableId +' tr[data-page]:visible input[type=checkbox]').not(':checked').length > 0){
342
392
  $('.tabulatr_mark_all[data-table='+ tableId +']').prop("indeterminate", true);
@@ -352,7 +402,7 @@ $(document).on('ready page:load', function(){
352
402
  }else{
353
403
  $('.tabulatr_mark_all[data-table='+ tableId +']').prop('indeterminate', false);
354
404
  $('.tabulatr_mark_all[data-table='+ tableId +']').prop('checked', false);
355
- if(Tabulatr.checkIfCheckboxesAreMarked()){
405
+ if(table_obj.checkIfCheckboxesAreMarked()){
356
406
  $('#'+ tableId +' .tabulatr-wrench').removeClass('disabled');
357
407
  }else{
358
408
  $('#'+ tableId +' .tabulatr-wrench').addClass('disabled');
@@ -366,17 +416,23 @@ $(document).on('ready page:load', function(){
366
416
  $(this).closest('div').find('a').removeClass('active');
367
417
  $(this).addClass('active');
368
418
  var tableId = $(this).closest('div').data('table');
369
- Tabulatr.moreResults = true;
370
- if($('.pagination[data-table='+ tableId +']').length == 0){
419
+ var table_obj = undefined;
420
+ for(var i = 0; i < tabulatr_tables.length; i++){
421
+ if(tabulatr_tables[i].id == tableId){
422
+ table_obj = tabulatr_tables[i];
423
+ }
424
+ }
425
+ table_obj.moreResults = true;
426
+ if($('.pagination[data-table='+ tableId +']').length === 0){
371
427
  $('.pagination_trigger[data-table='+ tableId +']').bind('inview', cbfn);
372
428
  }
373
429
  if(typeof(Storage) !== undefined){
374
430
  localStorage.tabulatr_page_display_count = $(this).data('items-per-page');
375
431
  }
376
- Tabulatr.updateTable({page: 1}, tableId, true);
432
+ table_obj.updateTable({page: 1}, true);
377
433
  });
378
434
 
379
- if($('.tabulatr_table').length > 0){
435
+ if($('.tabulatr_table:not(".tabulatr_static_table")').length > 0){
380
436
  if(typeof(Storage) !== undefined){
381
437
  var count = localStorage.tabulatr_page_display_count;
382
438
  if(count !== undefined){
@@ -385,8 +441,16 @@ $(document).on('ready page:load', function(){
385
441
  addClass('active');
386
442
  }
387
443
  }
388
- $('.tabulatr_table').each(function(ix, el){
389
- Tabulatr.updateTable({}, $(el).attr('id'));
444
+ var table_obj = undefined;
445
+ $('.tabulatr_table:not(".tabulatr_static_table")').each(function(ix, el){
446
+ var tableId = $(el).attr('id');
447
+ tabulatr_tables.push(new Tabulatr(tableId));
448
+ for(var i = 0; i < tabulatr_tables.length; i++){
449
+ if(tabulatr_tables[i].id == tableId){
450
+ table_obj = tabulatr_tables[i];
451
+ }
452
+ }
453
+ table_obj.updateTable({});
390
454
  });
391
455
  }
392
456
  });
@@ -400,7 +464,13 @@ $(document).on('click', '.pagination a', function(){
400
464
  var tableId = $(a).closest('.pagination').data('table');
401
465
  $('.tabulatr_mark_all[data-table='+ tableId +']').prop('checked', false);
402
466
  $('.tabulatr_mark_all[data-table='+ tableId +']').prop('indeterminate', false);
403
- Tabulatr.updateTable({append: false, page: a.data('page')}, tableId);
467
+ var table_obj = undefined;
468
+ for(var i = 0; i < tabulatr_tables.length; i++){
469
+ if(tabulatr_tables[i].id == tableId){
470
+ table_obj = tabulatr_tables[i];
471
+ }
472
+ }
473
+ table_obj.updateTable({append: false, page: a.data('page')});
404
474
  return false;
405
475
  });
406
476
 
@@ -409,13 +479,13 @@ $(document).on('click', '.pagination a', function(){
409
479
 
410
480
  $(document).on('click', 'a[data-show-table-filter]', function(){
411
481
  var a = $(this);
412
- var nam = a.data('show-table-filter');
413
- $('div[data-filter-column-name="'+nam+'"]').show('blind');
482
+ var name = a.data('show-table-filter');
483
+ $('div[data-filter-column-name="'+ name +'"]').show('blind');
414
484
  $('div[data-filter-column-name="_submit"]').show('blind');
415
485
 
416
486
  a.hide();
417
487
  return false;
418
- })
488
+ });
419
489
 
420
490
  $(document).on('click', 'a[data-hide-table-filter]', function(){
421
491
  var a = $(this);
@@ -428,9 +498,15 @@ $(document).on('click', 'a[data-hide-table-filter]', function(){
428
498
  $('div[data-filter-column-name="_submit"]').hide('blind');
429
499
 
430
500
  var tableId = $(this).parents('form').data('table');
431
- Tabulatr.submitFilterForm(tableId);
501
+ var table_obj = undefined;
502
+ for(var i = 0; i < tabulatr_tables.length; i++){
503
+ if(tabulatr_tables[i].id == tableId){
504
+ table_obj = tabulatr_tables[i];
505
+ }
506
+ }
507
+ table_obj.submitFilterForm();
432
508
  return false;
433
- })
509
+ });
434
510
 
435
511
  $(document).on('change', 'select[data-tabulatr-date-filter]', function() {
436
512
  var select = $(this);
@@ -452,7 +528,14 @@ var cbfn = function(event, isInView, visiblePartX, visiblePartY) {
452
528
  } else if (visiblePartY == 'bottom') {
453
529
  // bottom part of element is visible
454
530
  } else {
455
- Tabulatr.updateTable({append: true}, $(event.currentTarget).data('table'));
531
+ var tableId = $(event.currentTarget).data('table');
532
+ var table_obj = undefined;
533
+ for(var i = 0; i < tabulatr_tables.length; i++){
534
+ if(tabulatr_tables[i].id == tableId){
535
+ table_obj = tabulatr_tables[i];
536
+ }
537
+ }
538
+ table_obj.updateTable({append: true});
456
539
  }
457
540
  }
458
- };
541
+ };