tabulatr2 0.6.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -1
- data/README.md +71 -27
- data/app/assets/javascripts/tabulatr/application.js +130 -133
- data/app/assets/stylesheets/tabulatr/application.css.scss +153 -0
- data/app/assets/stylesheets/tabulatr/bootstrap2_fixes.css.scss +24 -0
- data/app/views/tabulatr/_tabulatr_actual_table.html.slim +35 -0
- data/app/views/tabulatr/_tabulatr_batch_actions_menu.html.slim +34 -0
- data/app/views/tabulatr/_tabulatr_filter_dialog.html.slim +84 -0
- data/app/views/tabulatr/_tabulatr_filter_menu.html.slim +30 -0
- data/app/views/tabulatr/_tabulatr_fuzzy_search_field.html.slim +24 -0
- data/app/views/tabulatr/_tabulatr_info_string.html.slim +23 -0
- data/app/views/tabulatr/_tabulatr_paginator.html.slim +24 -0
- data/app/views/tabulatr/_tabulatr_static_table.html.slim +33 -0
- data/app/views/tabulatr/_tabulatr_table.html.slim +45 -0
- data/lib/tabulatr/data/column_name_builder.rb +86 -0
- data/lib/tabulatr/data/data.rb +135 -0
- data/lib/tabulatr/data/dsl.rb +61 -0
- data/lib/tabulatr/data/filtering.rb +101 -0
- data/lib/tabulatr/data/formatting.rb +65 -0
- data/lib/tabulatr/data/invoker.rb +37 -0
- data/lib/tabulatr/data/pagination.rb +48 -0
- data/lib/tabulatr/data/proxy.rb +41 -0
- data/lib/tabulatr/{tabulatr/batch_actions.rb → data/sorting.rb} +20 -23
- data/lib/tabulatr/engine.rb +24 -1
- data/lib/tabulatr/generators/railtie.rb +33 -0
- data/lib/tabulatr/generators/resource_override.rb +35 -0
- data/lib/{generators → tabulatr/generators}/tabulatr/install_generator.rb +21 -3
- data/lib/{generators → tabulatr/generators}/tabulatr/templates/tabulatr.yml +3 -1
- data/lib/tabulatr/generators/tabulatr/templates/tabulatr_data.rb +18 -0
- data/lib/tabulatr/json_builder.rb +94 -0
- data/lib/tabulatr/rails/action_controller.rb +36 -0
- data/lib/{initializers → tabulatr/rails}/action_view.rb +6 -3
- data/lib/{initializers → tabulatr/rails}/active_record.rb +11 -19
- data/lib/tabulatr/renderer/action.rb +32 -0
- data/lib/tabulatr/{tabulatr/formattr.rb → renderer/association.rb} +19 -30
- data/lib/tabulatr/renderer/checkbox.rb +36 -0
- data/lib/tabulatr/renderer/column.rb +113 -0
- data/lib/{initializers/mark_as_localizable.rb → tabulatr/renderer/columns.rb} +13 -15
- data/lib/tabulatr/renderer/columns_from_block.rb +56 -0
- data/lib/tabulatr/renderer/renderer.rb +96 -0
- data/lib/tabulatr/utility/utility.rb +46 -0
- data/lib/tabulatr/version.rb +25 -2
- data/lib/tabulatr.rb +45 -4
- data/lib/tabulatr2.rb +1 -0
- data/spec/dummy/app/assets/stylesheets/application.css.scss +2 -2
- data/spec/dummy/app/controllers/products_controller.rb +27 -3
- data/spec/dummy/app/models/vendor.rb +1 -0
- data/spec/dummy/app/tabulatr_data/product_tabulatr_data.rb +29 -0
- data/spec/dummy/app/views/products/implicit_columns.html.erb +1 -0
- data/spec/dummy/app/views/products/one_item_per_page.html.erb +1 -1
- data/spec/dummy/app/views/products/simple_index.html.erb +6 -4
- data/spec/dummy/app/views/products/stupid_array.html.erb +1 -1
- data/spec/dummy/app/views/products/with_batch_actions.html.erb +10 -0
- data/spec/dummy/config/locales/tabulatr.yml +22 -1
- data/spec/dummy/config/routes.rb +3 -1
- data/spec/features/tabulatrs_spec.rb +53 -11
- data/tabulatr.gemspec +1 -1
- metadata +50 -42
- data/app/assets/images/tabulatr/buttons_lite_background.png +0 -0
- data/app/assets/images/tabulatr/pager_arrow_left.gif +0 -0
- data/app/assets/images/tabulatr/pager_arrow_left_off.gif +0 -0
- data/app/assets/images/tabulatr/pager_arrow_right.gif +0 -0
- data/app/assets/images/tabulatr/pager_arrow_right_off.gif +0 -0
- data/app/assets/images/tabulatr/sort_arrow_down.gif +0 -0
- data/app/assets/images/tabulatr/sort_arrow_down_off.gif +0 -0
- data/app/assets/images/tabulatr/sort_arrow_up.gif +0 -0
- data/app/assets/images/tabulatr/sort_arrow_up_off.gif +0 -0
- data/app/assets/stylesheets/tabulatr/application.css +0 -40
- data/lib/initializers/action_controller.rb +0 -13
- data/lib/tabulatr/tabulatr/adapter/active_record.rb +0 -84
- data/lib/tabulatr/tabulatr/adapter.rb +0 -55
- data/lib/tabulatr/tabulatr/data_cell.rb +0 -132
- data/lib/tabulatr/tabulatr/dummy_record.rb +0 -40
- data/lib/tabulatr/tabulatr/empty_cell.rb +0 -44
- data/lib/tabulatr/tabulatr/filter_cell.rb +0 -145
- data/lib/tabulatr/tabulatr/filter_icon.rb +0 -6
- data/lib/tabulatr/tabulatr/finder/find_for_table.rb +0 -187
- data/lib/tabulatr/tabulatr/finder.rb +0 -64
- data/lib/tabulatr/tabulatr/header_cell.rb +0 -146
- data/lib/tabulatr/tabulatr/json_builder.rb +0 -57
- data/lib/tabulatr/tabulatr/paginator.rb +0 -76
- data/lib/tabulatr/tabulatr/row_builder.rb +0 -128
- data/lib/tabulatr/tabulatr/security.rb +0 -21
- data/lib/tabulatr/tabulatr/settings.rb +0 -158
- data/lib/tabulatr/tabulatr.rb +0 -343
- data/spec/lib/tabulatr/tabulatr/finder/find_for_table_spec.rb +0 -187
- /data/lib/{generators → tabulatr/generators}/tabulatr/templates/tabulatr.rb +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8afaef013263f069bdbfe086da580b2bd33449fb
|
4
|
+
data.tar.gz: edaee24b2c81c45043ee7876dbe6ba6136278159
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f7493f7ed0672f2795c5942dbe18a117b185d6bd9263ca212119c657305624602885fdb2687b1f9157b5d54ba374c659f1a5dcb151277f6a6d11a38b377913d
|
7
|
+
data.tar.gz: b6c653fb666e1d8a6135c627fa86c6992062cede9796e056824e82461e813af9a59722d9fbbbd13407c0ca71f422a3a7e1cd1964ff04eb088088c01ac8cde31c
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -9,9 +9,19 @@ Require tabulatr2 in your Gemfile:
|
|
9
9
|
```ruby
|
10
10
|
gem 'tabulatr2', github: 'provideal/tabulatr2', require: 'tabulatr'
|
11
11
|
```
|
12
|
-
After that run `bundle
|
12
|
+
After that run `bundle install`.
|
13
13
|
|
14
|
-
Also add `//= require tabulatr` to your application js file
|
14
|
+
Also add `//= require tabulatr` to your application js file and `*= require tabulatr` to your CSS asset
|
15
|
+
pipeline.
|
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`
|
15
25
|
|
16
26
|
### Security
|
17
27
|
|
@@ -33,10 +43,57 @@ end
|
|
33
43
|
|
34
44
|
### Models
|
35
45
|
|
36
|
-
We suppose we have
|
37
|
-
|
38
|
-
|
39
|
-
|
46
|
+
We suppose we have these three models:
|
47
|
+
```ruby
|
48
|
+
class Tag < ActiveRecord::Base
|
49
|
+
has_and_belongs_to_many :products
|
50
|
+
end
|
51
|
+
```
|
52
|
+
```ruby
|
53
|
+
class Product < ActiveRecord::Base
|
54
|
+
belongs_to :vendor
|
55
|
+
has_and_belongs_to_many :tags
|
56
|
+
end
|
57
|
+
```
|
58
|
+
```ruby
|
59
|
+
class Vendor < ActiveRecord::Base
|
60
|
+
has_many :products
|
61
|
+
end
|
62
|
+
```
|
63
|
+
|
64
|
+
and we want to display information about products in the `ProductsController#index` action.
|
65
|
+
|
66
|
+
## ProductTabulatrData
|
67
|
+
|
68
|
+
In this class we define which information should be available for the table and how it is formatted.
|
69
|
+
```ruby
|
70
|
+
class ProductTabulatrData < Tabulatr::Data
|
71
|
+
|
72
|
+
search :vendor_address, :title
|
73
|
+
|
74
|
+
# search do |query|
|
75
|
+
# "products.title LIKE '#{query}'"
|
76
|
+
# end
|
77
|
+
|
78
|
+
column :id
|
79
|
+
column :title { title.capitalize }
|
80
|
+
column :price do "#{price} EUR" end
|
81
|
+
column :vendor_address, sort_sql: "vendors.zipcode || '' || vendors.city",
|
82
|
+
filter_sql: "vendors.street || '' || vendors.zipcode || '' vendors.city" do
|
83
|
+
"#{vendor.house_number} #{vendor.street}, #{vendor.zipcode} #{vendor.city}"
|
84
|
+
end
|
85
|
+
column :edit_link do
|
86
|
+
link_to "edit #{title}", product_path(id)
|
87
|
+
end
|
88
|
+
column :updated_at do
|
89
|
+
"#{updated_at.strftime('%H:%M %Y/%m/%d')}"
|
90
|
+
end
|
91
|
+
association :vendor, :name
|
92
|
+
association :tags, :title do "'#{tags.map(&:title).map(&:upcase).join(', ')}'" end
|
93
|
+
|
94
|
+
end
|
95
|
+
```
|
96
|
+
The search method is used for a fuzzy search field.
|
40
97
|
|
41
98
|
## Controller
|
42
99
|
|
@@ -57,33 +114,26 @@ _Hint:_ If you want to prefilter your table, you can do that too! Just pass an `
|
|
57
114
|
|
58
115
|
### View
|
59
116
|
|
60
|
-
|
117
|
+
In the view we can use all the attributes which are defined in our `ProductTabulatrData` class.
|
61
118
|
|
62
119
|
```erb
|
63
120
|
<%= table_for Product do |t|
|
64
121
|
t.column :title
|
65
122
|
t.column :price
|
66
|
-
t.column :active
|
67
123
|
t.association :vendor, :name
|
124
|
+
t.column :vendor_address
|
125
|
+
t.column :updated_at
|
68
126
|
t.association :tags, :title
|
127
|
+
t.column :edit_link
|
69
128
|
end %>
|
70
129
|
```
|
71
130
|
|
72
131
|
To add a checkbox column just add
|
73
|
-
```ruby
|
74
|
-
t.checkbox
|
75
|
-
```
|
76
|
-
|
77
|
-
|
78
|
-
To add e.g. edit-buttons, we would specify
|
79
|
-
|
80
132
|
```erb
|
81
|
-
|
82
|
-
link_to "Edit", edit_product_path(record.id)
|
83
|
-
end
|
133
|
+
t.checkbox
|
84
134
|
```
|
85
135
|
|
86
|
-
To add a select box with batch-actions (
|
136
|
+
To add a select box with batch-actions (actions that should be performed on all selected rows),
|
87
137
|
we add an option to the table_for:
|
88
138
|
|
89
139
|
```erb
|
@@ -140,20 +190,15 @@ Tabulatr tries to make these common tasks as simple/transparent as possible:
|
|
140
190
|
|
141
191
|
### Table Options
|
142
192
|
|
143
|
-
These options
|
193
|
+
These options should be specified at the view level as parameters to the `table_for` call.
|
194
|
+
They change the appearance and behaviour of the table.
|
144
195
|
|
145
196
|
```ruby
|
146
|
-
:table_class => 'tabulatr_table', # class for the actual data table
|
147
|
-
:control_div_class_before => 'table-controls', # class of upper div containing the paging and batch action controls
|
148
|
-
:control_div_class_after => 'table-controls', # class of lower div containing the paging and batch action controls
|
149
|
-
:paginator_div_class => 'pagination', # class of the div containing the paging controls
|
150
|
-
|
151
197
|
# which controls to be rendered above and below the table and in which order
|
152
198
|
:before_table_controls => [:filter, :paginator],
|
153
199
|
:after_table_controls => [],
|
154
200
|
|
155
201
|
:table_html => false, # a hash with html attributes for the table
|
156
|
-
:row_html => false, # a hash with html attributes for the normal trs
|
157
202
|
:header_html => false, # a hash with html attributes for the header trs
|
158
203
|
:filter_html => false, # a hash with html attributes for the filter trs
|
159
204
|
:filter => true, # false for no filter row at all
|
@@ -161,7 +206,6 @@ These options are to be specified at the `table_for` level and change the appear
|
|
161
206
|
# number for limit of items to show via pagination
|
162
207
|
:sortable => true, # true to allow sorting (can be specified for every sortable column)
|
163
208
|
:batch_actions => false, # :name => value hash of batch action stuff
|
164
|
-
:footer_content => false, # if given, add a <%= content_for <footer_content> %> before the </table>
|
165
209
|
:path => '#' # where to send the AJAX-requests to
|
166
210
|
```
|
167
211
|
|
@@ -1,3 +1,24 @@
|
|
1
|
+
// Copyright (c) 2010-2014 Peter Horn & Florian Thomas, Provideal GmbH
|
2
|
+
//
|
3
|
+
// Permission is hereby granted, free of charge, to any person obtaining
|
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
|
+
|
1
22
|
Tabulatr = {
|
2
23
|
moreResults: true,
|
3
24
|
storePage: false,
|
@@ -110,9 +131,10 @@ Tabulatr = {
|
|
110
131
|
},
|
111
132
|
|
112
133
|
insertTabulatrData: function(response){
|
113
|
-
columns = [];
|
114
|
-
tableId = response.meta.table_id;
|
115
|
-
tableName = tableId.split('_')[0];
|
134
|
+
var columns = [];
|
135
|
+
var tableId = response.meta.table_id;
|
136
|
+
var tableName = tableId.split('_')[0];
|
137
|
+
var tbody = $('#'+ tableId +' tbody');
|
116
138
|
if(!response.meta.append){
|
117
139
|
if(Tabulatr.storePage){
|
118
140
|
$('#'+ tableId +' tbody tr').hide();
|
@@ -122,83 +144,35 @@ Tabulatr = {
|
|
122
144
|
}
|
123
145
|
if(response.data.length == 0){
|
124
146
|
Tabulatr.moreResults = false;
|
125
|
-
$('.
|
147
|
+
$('.pagination_trigger[data-table='+ tableId +']').unbind('inview');
|
126
148
|
}else{
|
127
149
|
if(response.data.length < response.meta.pagesize){
|
128
150
|
Tabulatr.moreResults = false;
|
129
|
-
$('.
|
151
|
+
$('.pagination_trigger[data-table='+ tableId + ']').unbind('inview');
|
130
152
|
}else{
|
131
153
|
Tabulatr.moreResults = true;
|
132
154
|
}
|
133
|
-
$('#'+ tableId +' th').each(function(ix,el){
|
134
|
-
var column_name = $(el).data('tabulatr-column-name');
|
135
|
-
var association = $(el).data('tabulatr-association');
|
136
|
-
var column_type = $(el).data('tabulatr-column-type');
|
137
|
-
var action = $(el).data('tabulatr-action');
|
138
|
-
var callback_methods = $(el).data('tabulatr-methods').split(',');
|
139
|
-
columns.push({ name: column_name,
|
140
|
-
methods: callback_methods,
|
141
|
-
type: column_type,
|
142
|
-
association: association,
|
143
|
-
action: action });
|
144
|
-
});
|
145
|
-
$('.empty_row').remove();
|
146
|
-
|
147
155
|
|
156
|
+
// insert the actual data
|
148
157
|
for(var i = 0; i < response.data.length; i++){
|
149
|
-
|
150
|
-
var
|
151
|
-
var
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
arry.push(assoc[j][column.name]);
|
163
|
-
}
|
164
|
-
var value = arry.join(', ');
|
165
|
-
}else{
|
166
|
-
var value = response.data[i][column.association][column.name];
|
167
|
-
}
|
168
|
-
}catch(e){
|
169
|
-
var value = '';
|
170
|
-
}
|
158
|
+
var data = response.data[i];
|
159
|
+
var id = data.id;
|
160
|
+
var tr = $('tr.empty_row').clone();
|
161
|
+
tr.removeClass('empty_row');
|
162
|
+
tr.attr('data-page', response.meta.page);
|
163
|
+
tr.attr('data-id', id);
|
164
|
+
tr.find('td').each(function(i,td_raw) {
|
165
|
+
var td = $(td_raw);
|
166
|
+
var coltype = td.data('tabulatr-type');
|
167
|
+
var name = td.data('tabulatr-column-name');
|
168
|
+
var cont = data[name]
|
169
|
+
if(coltype === 'checkbox') {
|
170
|
+
cont = $("<input>").attr('type', 'checkbox').val(id).addClass('tabulatr-checkbox');
|
171
171
|
}
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
}else if(column.type == 'action'){
|
177
|
-
$td.html(Tabulatr.makeAction(column.action, response.data[i]));
|
178
|
-
}else{
|
179
|
-
if(value === false){
|
180
|
-
value = "false"; // because false won't be displayed
|
181
|
-
}
|
182
|
-
$td.html(value);
|
183
|
-
for(var j = 0; j < formatters.length; j++){
|
184
|
-
var fn = Tabulatr[formatters[j]];
|
185
|
-
if(typeof fn === 'function'){
|
186
|
-
try{
|
187
|
-
var result = fn(value, $td, $tr, response.data[i]);
|
188
|
-
if(result != null && result !== undefined){
|
189
|
-
$td.html(result);
|
190
|
-
value = result;
|
191
|
-
}
|
192
|
-
}catch(e){
|
193
|
-
$td.html('<span class="error">#ERROR</span>');
|
194
|
-
}
|
195
|
-
}
|
196
|
-
}
|
197
|
-
}
|
198
|
-
td += $td[0].outerHTML;
|
199
|
-
}
|
200
|
-
$tr.append(td);
|
201
|
-
$('#'+ tableId +' tbody').append($tr);
|
172
|
+
td.html(cont);
|
173
|
+
|
174
|
+
});
|
175
|
+
tbody.append(tr);
|
202
176
|
}
|
203
177
|
}
|
204
178
|
var count_string = $('.tabulatr_count[data-table='+ tableId +']').data('format-string');
|
@@ -207,12 +181,6 @@ Tabulatr = {
|
|
207
181
|
count_string = count_string.replace(/%\{per_page\}/,
|
208
182
|
response.meta.pagesize);
|
209
183
|
$('.tabulatr_count[data-table='+ tableId +']').html(count_string);
|
210
|
-
|
211
|
-
},
|
212
|
-
|
213
|
-
makeCheckboxFor: function(data){
|
214
|
-
return "<input type='checkbox' value='"+ data.id +
|
215
|
-
"' class='tabulatr-checkbox' />";
|
216
184
|
},
|
217
185
|
|
218
186
|
replacer: function(match, attribute, offset, string){
|
@@ -226,22 +194,16 @@ Tabulatr = {
|
|
226
194
|
},
|
227
195
|
|
228
196
|
createParameterString: function(hash, tableId){
|
229
|
-
tableName = tableId.split('_')[0];
|
197
|
+
var tableName = tableId.split('_')[0];
|
230
198
|
if(hash === undefined){
|
231
199
|
hash = {};
|
232
200
|
hash.append = false;
|
233
201
|
}
|
234
|
-
if($('#'+ tableId +' i.sorted').length == 1){
|
235
|
-
hash.sort_by = $('#'+ tableId +' i.sorted').closest('th').data('tabulatr-sorting-name');
|
236
|
-
if($('#'+ tableId +' i.sorted').data('sort') == 'asc'){
|
237
|
-
hash.orientation = 'desc';
|
238
|
-
}else{
|
239
|
-
hash.orientation = 'asc';
|
240
|
-
}
|
241
|
-
}
|
242
202
|
if(hash.pagesize === undefined){
|
243
|
-
var pagesize = $('
|
244
|
-
if(pagesize == null){
|
203
|
+
var pagesize = $('table#'+ tableId).data('pagesize');
|
204
|
+
if(pagesize == null) {
|
205
|
+
console.log('Tabulatr: No pagesize specified')
|
206
|
+
}
|
245
207
|
}
|
246
208
|
if(hash.page === undefined){
|
247
209
|
hash.page = Math.floor($('#'+ tableId +' tbody tr[class!=empty_row]').length/pagesize) + 1;
|
@@ -250,12 +212,13 @@ Tabulatr = {
|
|
250
212
|
}
|
251
213
|
}
|
252
214
|
hash.pagesize = pagesize;
|
253
|
-
hash.arguments = $.map($('#'+ tableId +' th'), function(n){
|
254
|
-
|
255
|
-
|
256
|
-
hash.salt = $('#tabulatr_security_'+ tableName).data('salt');
|
215
|
+
hash.arguments = $.map($('#'+ tableId +' th'), function(n){
|
216
|
+
return $(n).data('tabulatr-column-name')
|
217
|
+
}).filter(function(n){return n}).join();
|
257
218
|
hash.table_id = tableId;
|
258
|
-
|
219
|
+
hash[tableName + '_search'] = $('input#'+ tableName +'_fuzzy_search_query').val();
|
220
|
+
var form_array = $('.tabulatr_filter_form[data-table="'+ tableId +'"]')
|
221
|
+
.find('input:visible,select:visible,input[type=hidden]').serializeArray();
|
259
222
|
for(var i = 0; i < form_array.length; i++){
|
260
223
|
hash[form_array[i].name] = form_array[i].value;
|
261
224
|
}
|
@@ -269,29 +232,24 @@ Tabulatr = {
|
|
269
232
|
|
270
233
|
$(document).on('ready page:load', function(){
|
271
234
|
|
272
|
-
$('.tabulatr-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
var
|
235
|
+
$('th.tabulatr-sortable').click(function(){
|
236
|
+
var th = $(this);
|
237
|
+
var sort_by = th.data('tabulatr-column-name');
|
238
|
+
var dir = th.attr('data-sorted');
|
239
|
+
var table = th.parents('table');
|
240
|
+
var tableId = table.attr('id');
|
277
241
|
var tableName = tableId.split('_')[0];
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
$('.tabulatr_filter_form[data-table='+ tableId +'] input[name=
|
282
|
-
if(orientation == 'asc'){
|
283
|
-
$(this).removeClass('icon-arrow-down').addClass('icon-arrow-up');
|
284
|
-
$(this).data('sort', 'desc');
|
285
|
-
}else{
|
286
|
-
$(this).addClass('icon-arrow-up').addClass('icon-arrow-down');
|
287
|
-
$(this).data('sort', 'asc');
|
288
|
-
}
|
242
|
+
table.find('th.tabulatr-sortable.sorted').removeClass('sorted').removeAttr('data-sorted');
|
243
|
+
dir = (dir === 'asc') ? 'desc' : 'asc';
|
244
|
+
th.addClass('sorted').attr('data-sorted', dir);
|
245
|
+
$('.tabulatr_filter_form[data-table='+ tableId +'] input[name='+ tableName +'_sort]').val(sort_by + ' '+ dir);
|
289
246
|
if(!Tabulatr.moreResults){
|
290
247
|
Tabulatr.moreResults = true;
|
291
248
|
if($('.pagination[data-table='+ tableId +']').length == 0){
|
292
|
-
$('.
|
249
|
+
$('.pagination_trigger[data-table='+ tableId +']').bind('inview', cbfn);
|
293
250
|
}
|
294
251
|
}
|
252
|
+
$($(this).parents('table').find('tbody tr')).remove();
|
295
253
|
|
296
254
|
$('.tabulatr_mark_all[data-table='+ tableName +']').prop('checked', false).prop('indeterminate', false);
|
297
255
|
Tabulatr.updateTable({}, tableId);
|
@@ -312,41 +270,40 @@ $(document).on('ready page:load', function(){
|
|
312
270
|
|
313
271
|
$('.tabulatr_table').each(function(ix, el){
|
314
272
|
if($('.pagination[data-table='+ $(el).attr('id') +']').length == 0){
|
315
|
-
$('.
|
273
|
+
$('.pagination_trigger[data-table='+ $(el).attr('id') +']').bind('inview', cbfn);
|
316
274
|
}
|
317
275
|
});
|
318
276
|
|
319
277
|
$('.batch-action-inputs').click(function(){
|
320
|
-
|
321
|
-
|
322
|
-
var
|
278
|
+
var a = $(this);
|
279
|
+
var name = a.data('do-batch-action-name');
|
280
|
+
var key = a.data('do-batch-action');
|
281
|
+
var tableId = a.data('table-id');
|
282
|
+
var params = {page: 1};
|
283
|
+
params[name] = key;
|
323
284
|
params['tabulatr_checked'] = {checked_ids: jQuery.map($('#'+ tableId +' .tabulatr-checkbox:checked'), function(el){return $(el).val();}).join(',')};
|
324
285
|
$('.tabulatr_mark_all[data-table='+ tableId +']').prop('indeterminate', false).prop('checked', false);
|
325
286
|
$('#'+ tableId +' .tabulatr-wrench').addClass('disabled');
|
326
287
|
Tabulatr.updateTable(params, tableId, true);
|
327
288
|
});
|
328
289
|
|
329
|
-
$('form.
|
290
|
+
$('form.tabulatr-fuzzy-search').submit(function(){
|
330
291
|
var tableId = $(this).data('table');
|
292
|
+
if($('.pagination[data-table='+ tableId +']').length == 0){
|
293
|
+
$('.pagination_trigger[data-table='+ tableId +']').unbind('inview', cbfn);
|
294
|
+
$('.pagination_trigger[data-table='+ tableId +']').bind('inview', cbfn);
|
295
|
+
}
|
331
296
|
Tabulatr.updateTable({page: 1, append: false}, tableId, true);
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
340
|
-
var $col = $('#'+ tableId +' th[data-tabulatr-form-name^='+ name +']');
|
341
|
-
if($col.length > 0){
|
342
|
-
$col.addClass('tabulatr_filtered_column');
|
343
|
-
// icon-remove-sign
|
344
|
-
$col.append('<i class="icon-remove-sign '+
|
345
|
-
'tabulatr_remove_filter" ></i>');
|
346
|
-
}
|
347
|
-
}
|
297
|
+
return false;
|
298
|
+
});
|
299
|
+
|
300
|
+
$('form.tabulatr_filter_form').submit(function(ev){
|
301
|
+
var tableId = $(this).data('table');
|
302
|
+
if($('.pagination[data-table='+ tableId +']').length == 0){
|
303
|
+
$('.pagination_trigger[data-table='+ tableId +']').unbind('inview', cbfn);
|
304
|
+
$('.pagination_trigger[data-table='+ tableId +']').bind('inview', cbfn);
|
348
305
|
}
|
349
|
-
|
306
|
+
Tabulatr.updateTable({page: 1, append: false}, tableId, true);
|
350
307
|
return false;
|
351
308
|
});
|
352
309
|
|
@@ -363,6 +320,9 @@ $(document).on('ready page:load', function(){
|
|
363
320
|
}
|
364
321
|
var tableId = $(this).closest('.tabulatr_table').attr('id');
|
365
322
|
$(this).remove();
|
323
|
+
if($('.pagination[data-table='+ tableId +']').length == 0){
|
324
|
+
$('.pagination_trigger[data-table='+ tableId +']').bind('inview', cbfn);
|
325
|
+
}
|
366
326
|
Tabulatr.updateTable({}, tableId);
|
367
327
|
return false;
|
368
328
|
});
|
@@ -415,7 +375,7 @@ $(document).on('ready page:load', function(){
|
|
415
375
|
var tableId = $(this).closest('div').data('table');
|
416
376
|
Tabulatr.moreResults = true;
|
417
377
|
if($('.pagination[data-table='+ tableId +']').length == 0){
|
418
|
-
$('.
|
378
|
+
$('.pagination_trigger[data-table='+ tableId +']').bind('inview', cbfn);
|
419
379
|
}
|
420
380
|
if(typeof(Storage) !== undefined){
|
421
381
|
localStorage.tabulatr_page_display_count = $(this).data('items-per-page');
|
@@ -450,3 +410,40 @@ $(document).on('click', '.pagination a', function(){
|
|
450
410
|
Tabulatr.updateTable({append: false, page: a.data('page')}, tableId);
|
451
411
|
return false;
|
452
412
|
});
|
413
|
+
|
414
|
+
|
415
|
+
// TODO: We absolutely need to clean that up!
|
416
|
+
|
417
|
+
$(document).on('click', 'a[data-show-table-filter]', function(){
|
418
|
+
var a = $(this);
|
419
|
+
var nam = a.data('show-table-filter');
|
420
|
+
$('div[data-filter-column-name="'+nam+'"]').show('blind');
|
421
|
+
$('div[data-filter-column-name="_submit"]').show('blind');
|
422
|
+
|
423
|
+
a.hide();
|
424
|
+
return false;
|
425
|
+
})
|
426
|
+
|
427
|
+
$(document).on('click', 'a[data-hide-table-filter]', function(){
|
428
|
+
var a = $(this);
|
429
|
+
var nam = a.data('hide-table-filter');
|
430
|
+
var t = $('div[data-filter-column-name="'+nam+'"]');
|
431
|
+
t.hide('blind');
|
432
|
+
t.find('input[type=text]').val("");
|
433
|
+
$('a[data-show-table-filter="'+nam+'"]').show();
|
434
|
+
if ($('div[data-filter-column-name]:visible').length <= 2)
|
435
|
+
$('div[data-filter-column-name="_submit"]').hide('blind');
|
436
|
+
return false;
|
437
|
+
})
|
438
|
+
|
439
|
+
$(document).on('change', 'select[data-tabulatr-date-filter]', function() {
|
440
|
+
var select = $(this);
|
441
|
+
var option = select.find('option:selected');
|
442
|
+
var val = option.val();
|
443
|
+
console.log(val);
|
444
|
+
if (val === 'from_to') {
|
445
|
+
select.parents('.controls').find(".from_to").show().removeClass('hidden');
|
446
|
+
} else {
|
447
|
+
select.parents('.controls').find(".from_to").hide().val('');
|
448
|
+
}
|
449
|
+
});
|