snaptable 1.1.3 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/app/assets/javascripts/snaptable/table.js +12 -6
- data/app/assets/stylesheets/snaptable/table.css.scss +2 -2
- data/app/views/snaptable/base.html.erb +4 -4
- data/app/views/snaptable/sort.js.erb +4 -3
- data/lib/snaptable/constructor/base_table.rb +8 -0
- data/lib/snaptable/constructor/collection.rb +1 -1
- data/lib/snaptable/constructor/renderer.rb +5 -3
- data/lib/snaptable/constructor/sortable.rb +4 -4
- data/lib/snaptable/helpers/table_helper.rb +4 -0
- data/lib/snaptable/version.rb +1 -1
- data/lib/snaptable.rb +9 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6e6d31a3bf48463d9fad64040a6c053a8352757
|
4
|
+
data.tar.gz: db7155abe0b38fe29555df722f51fdc55483382c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4ecac7b1b9f5bf65e6cabfddb5ddb247370df44bf78fa62ea0de1e9ee8be0d47d89b574f4688380a7a00682fd934c2a45a51792306fc8eb79d10a2d5a481e90f
|
7
|
+
data.tar.gz: 094bf8bb9894d59f116e6eea93af95fc74324d3ee217e0c6fcdfc8e2f9d38833260650fbb14dd29e7993bd67edfa38f7d3386e53dbb46c2534636633465888d0
|
@@ -3,9 +3,7 @@
|
|
3
3
|
|
4
4
|
/* Admin table */
|
5
5
|
|
6
|
-
function snapifyTable() {
|
7
|
-
|
8
|
-
var snaptable = $("#snaptable");
|
6
|
+
function snapifyTable(snaptable) {
|
9
7
|
|
10
8
|
var tableButtons = snaptable.find(".table_buttons"),
|
11
9
|
editButton = tableButtons.find("a[class='edit']"),
|
@@ -23,7 +21,7 @@ function snapifyTable() {
|
|
23
21
|
snaptable.on("click", "tbody tr", function(e) {
|
24
22
|
var id = $(this).data("url") ;
|
25
23
|
if ( typeof id !== "undefined" && !$(this).hasClass("selected") ) {
|
26
|
-
|
24
|
+
snaptable.find("tr.selected").removeClass("selected");
|
27
25
|
$(this).addClass("selected");
|
28
26
|
deleteButton.add(editButton).add(showButton).addClass("on");
|
29
27
|
editButton.attr("href", path + id + "/edit");
|
@@ -44,8 +42,16 @@ function snapifyTable() {
|
|
44
42
|
|
45
43
|
}
|
46
44
|
|
45
|
+
function snapifyTables() {
|
46
|
+
|
47
|
+
$(".snaptable").each(function() {
|
48
|
+
snapifyTable($(this));
|
49
|
+
})
|
50
|
+
|
51
|
+
}
|
52
|
+
|
47
53
|
$(document).on("ready page:load", function() {
|
48
54
|
|
49
|
-
|
55
|
+
snapifyTables();
|
50
56
|
|
51
|
-
});
|
57
|
+
});
|
@@ -1,6 +1,6 @@
|
|
1
|
-
<div
|
1
|
+
<div class="snaptable <%= presenter.table_name %>">
|
2
2
|
<%= render 'snaptable/search_field' if presenter.options[:search] == true %>
|
3
|
-
|
3
|
+
|
4
4
|
<div class="table_buttons">
|
5
5
|
<%= render presenter.instance_variable_get(:@buttons) unless presenter.options[:buttons] == false %>
|
6
6
|
</div>
|
@@ -27,6 +27,6 @@
|
|
27
27
|
<% end %>
|
28
28
|
</tbody>
|
29
29
|
</table>
|
30
|
-
<%= will_paginate presenter.records %>
|
30
|
+
<%= will_paginate presenter.records, param_name: presenter.paginate_key, params: { table: presenter.table_name } %>
|
31
31
|
|
32
|
-
</div>
|
32
|
+
</div>
|
@@ -1,3 +1,4 @@
|
|
1
|
-
var
|
2
|
-
snaptable
|
3
|
-
|
1
|
+
var tableName = "<%= params[:table] %>";
|
2
|
+
var snaptable = $(".snaptable." + tableName);
|
3
|
+
snaptable.replaceWith('<%= j content %>');
|
4
|
+
snapifyTable($(".snaptable." + tableName));
|
@@ -7,7 +7,7 @@ module Snaptable
|
|
7
7
|
end
|
8
8
|
|
9
9
|
def records
|
10
|
-
@records ||= filter(collection).paginate(page: params[
|
10
|
+
@records ||= filter(collection).paginate(page: params[paginate_key], per_page: 30).order(sort_column + " " + sort_direction)
|
11
11
|
end
|
12
12
|
|
13
13
|
def filter(collection)
|
@@ -1,5 +1,5 @@
|
|
1
1
|
module Snaptable
|
2
|
-
module Constructor
|
2
|
+
module Constructor
|
3
3
|
module Renderer
|
4
4
|
|
5
5
|
def present(buttons: nil)
|
@@ -10,7 +10,9 @@ module Snaptable
|
|
10
10
|
def respond
|
11
11
|
respond_to do |format|
|
12
12
|
format.html
|
13
|
-
format.js
|
13
|
+
format.js do
|
14
|
+
render '/snaptable/sort', locals: { content: self.present(buttons: @buttons) }
|
15
|
+
end
|
14
16
|
end
|
15
17
|
end
|
16
18
|
|
@@ -51,4 +53,4 @@ module Snaptable
|
|
51
53
|
|
52
54
|
end
|
53
55
|
end
|
54
|
-
end
|
56
|
+
end
|
@@ -4,7 +4,7 @@ module Snaptable
|
|
4
4
|
|
5
5
|
def sortable(column)
|
6
6
|
if model.reflect_on_association(column.gsub /_id/, '').nil?
|
7
|
-
view_context.link_to({sort: column, direction: direction(column), query: params[:query],
|
7
|
+
view_context.link_to({sort: column, direction: direction(column), query: params[:query], paginate_key => page, table: table_name}, {remote: true, class: css_class(column)}) do
|
8
8
|
model.human_attribute_name(column)
|
9
9
|
end
|
10
10
|
else
|
@@ -15,13 +15,13 @@ module Snaptable
|
|
15
15
|
def sort_column
|
16
16
|
column_names.include?(params[:sort]) ? column_name(params[:sort]) : column_name("id")
|
17
17
|
end
|
18
|
-
|
18
|
+
|
19
19
|
def sort_direction
|
20
20
|
%w[asc desc].include?(params[:direction]) ? params[:direction] : "desc"
|
21
21
|
end
|
22
22
|
|
23
23
|
def page
|
24
|
-
params[
|
24
|
+
params[paginate_key] || 1
|
25
25
|
end
|
26
26
|
|
27
27
|
def css_class(column)
|
@@ -40,4 +40,4 @@ module Snaptable
|
|
40
40
|
|
41
41
|
end
|
42
42
|
end
|
43
|
-
end
|
43
|
+
end
|
data/lib/snaptable/version.rb
CHANGED
data/lib/snaptable.rb
CHANGED
@@ -8,4 +8,12 @@ module Snaptable
|
|
8
8
|
@@show_button = false
|
9
9
|
|
10
10
|
mattr_accessor :use_permission, :add_button, :edit_button, :delete_button, :show_button
|
11
|
-
|
11
|
+
|
12
|
+
def self.respond_with(controller, *args)
|
13
|
+
if name = controller.params[:table]
|
14
|
+
table = args.find { |table| table.table_name == name }
|
15
|
+
table.respond
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: snaptable
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- khcr
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-02-
|
11
|
+
date: 2016-02-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|