snaptable 1.1.3 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b477ff543871bf871b0674fd943583db4e98f004
4
- data.tar.gz: c1077f2ff07dafff52d02344b8648e7211309a88
3
+ metadata.gz: e6e6d31a3bf48463d9fad64040a6c053a8352757
4
+ data.tar.gz: db7155abe0b38fe29555df722f51fdc55483382c
5
5
  SHA512:
6
- metadata.gz: 388a0a6c1577c7bc5785894469b60b8bd59503fcce791341b94c41ac6035ce4bd75f0ae66eb10b8fcb272f9d6204f09c67d26b7a100a16f38ca5311e50a86b31
7
- data.tar.gz: d3097ec51087d5d2d02c8a065b3d355c163c5704a546b03c96065bf68be0db123772150723b51b2ff463639c00835c4d935a95b90fcd7253dbde6c141c7caab2
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
- $("tr.selected").removeClass("selected");
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
- snapifyTable();
55
+ snapifyTables();
50
56
 
51
- });
57
+ });
@@ -1,6 +1,6 @@
1
1
  /* Table */
2
2
 
3
- #snaptable {
3
+ .snaptable {
4
4
  * {
5
5
  padding: 0;
6
6
  margin: 0;
@@ -120,4 +120,4 @@
120
120
  }
121
121
  }
122
122
 
123
- }
123
+ }
@@ -1,6 +1,6 @@
1
- <div id="snaptable">
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 snaptable = $("#snaptable");
2
- snaptable.replaceWith('<%= j @table.present(buttons: params[:partial]) %>');
3
- snapifyTable();
1
+ var tableName = "<%= params[:table] %>";
2
+ var snaptable = $(".snaptable." + tableName);
3
+ snaptable.replaceWith('<%= j content %>');
4
+ snapifyTable($(".snaptable." + tableName));
@@ -25,6 +25,14 @@ module Snaptable
25
25
  :id
26
26
  end
27
27
 
28
+ def table_name
29
+ self.class.name.underscore
30
+ end
31
+
32
+ def paginate_key
33
+ "#{table_name}_page"
34
+ end
35
+
28
36
  private
29
37
 
30
38
  def stored_token
@@ -7,7 +7,7 @@ module Snaptable
7
7
  end
8
8
 
9
9
  def records
10
- @records ||= filter(collection).paginate(page: params[:page], per_page: 30).order(sort_column + " " + sort_direction)
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 { render '/snaptable/sort' }
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], page: page, partial: @buttons}, {remote: true, class: css_class(column)}) do
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[:page] || 1
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
@@ -14,6 +14,10 @@ module Snaptable
14
14
  @model
15
15
  end
16
16
 
17
+ def table_name
18
+ model.model_name.singular
19
+ end
20
+
17
21
  end
18
22
  end
19
23
  end
@@ -1,3 +1,3 @@
1
1
  module Snaptable
2
- VERSION = "1.1.3"
2
+ VERSION = "1.2.0"
3
3
  end
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
- end
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.1.3
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-05 00:00:00.000000000 Z
11
+ date: 2016-02-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails