snaptable 2.2.4 → 3.0.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
  SHA256:
3
- metadata.gz: 116494e78d771e3bfc4e6e354a11dc0b96cd4da7b265135f4382c00a204c4cc1
4
- data.tar.gz: 1978b61ee80c3405e2075b2f4f69a533218b2112e44e74bed0343c4f7a2c2907
3
+ metadata.gz: 277fe830bde38834c01c0cedf76baf9fdfd1f884823c052cbe480bf840a982c6
4
+ data.tar.gz: 955421611309c919843daf076892f086baf25a09ccbe3b8f0eab4df78fba33ed
5
5
  SHA512:
6
- metadata.gz: 56b0ef96cae11ce4f2c485fef01185a962881f33054d783d273b4f8c953738a41c69bd29a33c24e9bcb90dc0a01c6d247e4063a8bc9dba29137dd5d731e1807e
7
- data.tar.gz: 248667837e08cea9bb4748c8fc633c8cb798bce2f6efcb9d45ba8a1ac6313fb5dfbd4e33074b8bce2518e387fba48419c38e31c95a57fa2bd96c4d210f46145b
6
+ metadata.gz: d06b3919053af0a68e8c825238d4e9d72ca08a6e8da650528ecbfd30d447f0ef304575f0b97f35143f5fa748e719ea64dfe899f1a42a658d717a6ac2b64bbdc0
7
+ data.tar.gz: b5ceb7fdf56348f5346fcd288c419d4cc6475ca9ae55b877006cac052143fdd768eeb4cb9e9a32ecaa4d2a21dd5e5037ea9124661daec20df2da45bbcc2e6ab7
data/README.md CHANGED
@@ -171,7 +171,7 @@ class ArticleTable < BaseTable
171
171
  end
172
172
 
173
173
  def self.fields
174
- { articles: [:title, :content], user: [:name, :email], category: [:name] }
174
+ { articles: [:title, :content], users: [:name, :email], categories: [:name] }
175
175
  end
176
176
 
177
177
  end
@@ -10,6 +10,4 @@
10
10
  // Read Sprockets README (https://github.com/sstephenson/sprockets#sprockets-directives) for details
11
11
  // about supported directives.
12
12
  //
13
- //= require jquery
14
- //= require jquery_ujs
15
13
  //= require_tree ./snaptable
@@ -3,43 +3,53 @@
3
3
 
4
4
  /* Admin table */
5
5
 
6
+ /* Admin table */
7
+
6
8
  function snapifyTable(snaptable) {
7
9
 
8
- var tableButtons = snaptable.find(".table_buttons"),
9
- editButton = tableButtons.find("a[class='edit']"),
10
- deleteButton = tableButtons.find("a[class='delete']"),
11
- showButton = tableButtons.find("a[class='show']"),
10
+ var tableButtons = snaptable.querySelector(".table_buttons"),
11
+ editButton = tableButtons.querySelector("a.edit"),
12
+ deleteButton = tableButtons.querySelector("a.delete"),
13
+ showButton = tableButtons.querySelector("a.show"),
12
14
  path = window.location.pathname + "/",
13
15
  urlParams = new URLSearchParams(location.search),
14
16
  token = urlParams.get('token');
15
17
 
16
18
  var paramsStr = (token ? ("?token=" + token) : "")
17
19
 
18
- // add ajax to the pagination
19
- snaptable.on("click", ".pagination a", function() {
20
- $.getScript(this.href);
21
- return false;
22
- });
23
-
24
20
  // line clickable
25
- snaptable.on("click", "tbody tr", function(e) {
26
- var id = $(this).data("url");
27
- if ( typeof id !== "undefined" && !$(this).hasClass("selected") ) {
28
- snaptable.find("tr.selected").removeClass("selected");
29
- $(this).addClass("selected");
30
- deleteButton.add(editButton).add(showButton).addClass("on");
31
- editButton.attr("href", path + id + "/edit" + paramsStr);
32
- deleteButton.attr("href", path + id + paramsStr);
33
- showButton.attr("href", path + id + paramsStr);
21
+ snaptable.querySelector("tbody").addEventListener("click", function(e) {
22
+ var target = e.target.parentElement; // td is clicked, tr is the direct parent
23
+ var id = target.dataset.url;
24
+ if (typeof id !== "undefined" && !target.classList.contains("selected")) {
25
+ // change selected row
26
+ var selected = snaptable.querySelector("tr.selected");
27
+ if (selected) {
28
+ snaptable.querySelector("tr.selected").classList.remove("selected");
29
+ }
30
+ target.classList.add("selected");
31
+ // update the buttons
32
+ if (showButton) {
33
+ showButton.classList.add("on");
34
+ showButton.setAttribute("href", path + id + paramsStr);
35
+ }
36
+ if (editButton) {
37
+ editButton.classList.add("on");
38
+ editButton.setAttribute("href", path + id + "/edit" + paramsStr);
39
+ }
40
+ if (deleteButton) {
41
+ deleteButton.classList.add("on");
42
+ deleteButton.setAttribute("href", path + id + paramsStr);
43
+ }
34
44
  }
35
45
  });
36
46
 
37
- // Double click
38
- if(editButton.length) {
39
- snaptable.on("dblclick", "tbody tr", function() {
40
- var id = $(this).data("url");
47
+ if(editButton) {
48
+ snaptable.querySelector("tbody").addEventListener("dblclick", function(e) {
49
+ var target = e.target.parentElement; // td is clicked, tr is the direct parent
50
+ var id = target.dataset.url;
41
51
  if ( typeof id !== "undefined" ) {
42
- window.location = path + id + "/edit";
52
+ window.location = path + id + "/edit" + paramsStr;
43
53
  }
44
54
  });
45
55
  }
@@ -48,14 +58,11 @@ function snapifyTable(snaptable) {
48
58
 
49
59
  function snapifyTables() {
50
60
 
51
- $(".snaptable").each(function() {
52
- snapifyTable($(this));
61
+ document.querySelectorAll(".snaptable").forEach(function(table) {
62
+ snapifyTable(table);
53
63
  })
54
64
 
55
65
  }
56
66
 
57
- $(document).on("ready turbolinks:load", function() {
58
-
59
- snapifyTables();
60
-
61
- });
67
+ document.addEventListener("ready", snapifyTables);
68
+ document.addEventListener("turbolinks:load", snapifyTables);
@@ -1,6 +1,6 @@
1
1
  <div class="search">
2
2
  <p><%= t("table.search.title") %></p>
3
- <%= form_tag request.fullpath, method: :get, remote: true do %>
3
+ <%= form_tag request.fullpath, method: :get do %>
4
4
  <%= hidden_field_tag :table, presenter.table_name %>
5
5
  <%= hidden_field_tag :buttons, presenter.instance_variable_get(:@buttons) %>
6
6
  <%= search_field_tag :query, params[:query] %>
@@ -10,9 +10,6 @@ module Snaptable
10
10
  def respond
11
11
  respond_to do |format|
12
12
  format.html
13
- format.js do
14
- render '/snaptable/sort', locals: { content: self.present(buttons: params[:buttons]) }
15
- end
16
13
  end
17
14
  end
18
15
 
@@ -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], paginate_key => page, table: table_name, buttons: @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, buttons: @buttons}, {class: css_class(column)}) do
8
8
  model.human_attribute_name(column)
9
9
  end
10
10
  else
@@ -4,7 +4,6 @@ require 'snaptable/helpers/buttons_helper'
4
4
  module Snaptable
5
5
  class Engine < ::Rails::Engine
6
6
  require 'will_paginate'
7
- require 'jquery-rails'
8
7
 
9
8
  initializer 'Snaptable.tables' do
10
9
  ActionController::Base.send :include, Helpers::TableHelper
@@ -1,3 +1,3 @@
1
1
  module Snaptable
2
- VERSION = "2.2.4"
2
+ VERSION = "3.0.0"
3
3
  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: 2.2.4
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - khcr
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2019-02-08 00:00:00.000000000 Z
11
+ date: 2020-02-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -39,21 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
- name: sass-rails
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
45
- - - ">="
46
- - !ruby/object:Gem::Version
47
- version: '0'
48
- type: :runtime
49
- prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
52
- - - ">="
53
- - !ruby/object:Gem::Version
54
- version: '0'
55
- - !ruby/object:Gem::Dependency
56
- name: jquery-rails
42
+ name: sassc-rails
57
43
  requirement: !ruby/object:Gem::Requirement
58
44
  requirements:
59
45
  - - ">="
@@ -98,7 +84,6 @@ files:
98
84
  - app/views/snaptable/_buttons.html.erb
99
85
  - app/views/snaptable/_search_field.html.erb
100
86
  - app/views/snaptable/base.html.erb
101
- - app/views/snaptable/sort.js.erb
102
87
  - config/locales/en.yml
103
88
  - config/locales/fr.yml
104
89
  - lib/snaptable.rb
@@ -129,8 +114,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
114
  - !ruby/object:Gem::Version
130
115
  version: '0'
131
116
  requirements: []
132
- rubyforge_project:
133
- rubygems_version: 2.7.7
117
+ rubygems_version: 3.0.3
134
118
  signing_key:
135
119
  specification_version: 4
136
120
  summary: A gem that generate HTML tables from your models in order to display them
@@ -1,4 +0,0 @@
1
- var tableName = "<%= params[:table] %>";
2
- var snaptable = $(".snaptable." + tableName);
3
- snaptable.replaceWith('<%= j content %>');
4
- snapifyTable($(".snaptable." + tableName));