snaptable 0.7.0 → 0.8.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: bd5707fb6a6871a707b3b2095567822544faae13
4
- data.tar.gz: dbda33e1a86f517f1998fef91d2eb4fcdeef02e3
3
+ metadata.gz: 1e55f9bfbf938219e391653ebc8a7f75c81fa899
4
+ data.tar.gz: e54c06773f1c757728000a32926d6bb0d378c11f
5
5
  SHA512:
6
- metadata.gz: 114378e7e6a081630dc2984d2819ff6783808ebe5bee8397efc51bdb00de5ea79bff2a88d15fd294d68e7f67a08dd92ff1104bba5916d804b8d6760c3d97f257
7
- data.tar.gz: 5ef7c86038ebb7a5e24594d930aaf19da705cce111e430ce6c8838af4b8e9a7a94010627814735098d9244c1bdce5b094c712ae6fb7160ec01c224b4959f5732
6
+ metadata.gz: 471689c2fc415d3120de3fac9c366f2b7b6f1310e5397e607de354be14fb3aa53c96fbbeb019842df488926e75d87b74e8585a4d83cb682c1945bd3c63292a41
7
+ data.tar.gz: fb46a059da5e39b0d1330795a0af3b0a5fe5d622388ec013b6b5d8cca7bfa939519571723d91309c0e8e115122a686e815c476e1525f80422a41eda3a2a9e6ac
@@ -1,13 +1,17 @@
1
+ /* global $ */
2
+ "use strict";
3
+
1
4
  /* Admin table */
2
5
 
3
6
  function snapifyTable() {
4
7
 
5
- var snaptable = $('#snaptable')
8
+ var snaptable = $("#snaptable");
6
9
 
7
- var tableButtons = snaptable.find('.table_buttons'),
8
- editButton = tableButtons.find('a[class="edit"]'),
9
- deleteButton = tableButtons.find('a[class="delete"]'),
10
- path = window.location.pathname + '/';
10
+ var tableButtons = snaptable.find(".table_buttons"),
11
+ editButton = tableButtons.find("a[class='edit']"),
12
+ deleteButton = tableButtons.find("a[class='delete']"),
13
+ showButton = tableButtons.find("a[class='show']"),
14
+ path = window.location.pathname + "/";
11
15
 
12
16
  // add ajax to the pagination
13
17
  snaptable.on("click", ".pagination a", function() {
@@ -17,21 +21,22 @@ function snapifyTable() {
17
21
 
18
22
  // line clickable
19
23
  snaptable.on("click", "tbody tr", function(e) {
20
- var id = $(this).data('url') ;
21
- if ( typeof id !== 'undefined' && !$(this).hasClass('selected') ) {
22
- $('tr.selected').removeClass('selected');
23
- $(this).addClass('selected');
24
- deleteButton.add(editButton).addClass("on");
25
- editButton.attr('href', path + id + '/edit');
26
- deleteButton.attr('href', path + id);
24
+ var id = $(this).data("url") ;
25
+ if ( typeof id !== "undefined" && !$(this).hasClass("selected") ) {
26
+ $("tr.selected").removeClass("selected");
27
+ $(this).addClass("selected");
28
+ deleteButton.add(editButton).add(showButton).addClass("on");
29
+ editButton.attr("href", path + id + "/edit");
30
+ deleteButton.attr("href", path + id);
31
+ showButton.attr("href", path + id);
27
32
  }
28
33
  });
29
34
 
30
35
  // Double click
31
36
  snaptable.on("dblclick", "tbody tr", function() {
32
- var id = $(this).data('url');
33
- if ( typeof id !== 'undefined' ) {
34
- window.location = path + id + '/edit';
37
+ var id = $(this).data("url");
38
+ if ( typeof id !== "undefined" ) {
39
+ window.location = path + id + "/edit";
35
40
  }
36
41
  });
37
42
 
@@ -0,0 +1,27 @@
1
+ module ButtonsHelper
2
+
3
+ def add_button?
4
+ Snaptable.add_button &&
5
+ (!Snaptable.use_permission ||
6
+ current_permission.allow_create?(params[:controller]))
7
+ end
8
+
9
+ def edit_button?
10
+ Snaptable.edit_button &&
11
+ (!Snaptable.use_permission ||
12
+ current_permission.allow_modify?(params[:controller], "update"))
13
+ end
14
+
15
+ def show_button?
16
+ Snaptable.show_button &&
17
+ (!Snaptable.use_permission ||
18
+ current_permission.allow_modify?(params[:controller], "read"))
19
+ end
20
+
21
+ def delete_button?
22
+ Snaptable.delete_button &&
23
+ (!Snaptable.use_permission ||
24
+ current_permission.allow_modify?(params[:controller], "destroy"))
25
+ end
26
+
27
+ end
@@ -1,13 +1,16 @@
1
1
  <div class="table_buttons">
2
2
  <p>Actions</p>
3
3
  <p>
4
- <% if !Snaptable.use_permission || current_permission.allow_create?(params[:controller]) %>
4
+ <% if add_button? %>
5
5
  <%= link_to "Ajouter", request.path + "/new", class: "add" %>
6
6
  <% end %>
7
- <% if !Snaptable.use_permission || current_permission.allow_modify?(params[:controller], "update") %>
7
+ <% if edit_button? %>
8
8
  <a class="edit" href="#">Editer</a>
9
9
  <% end %>
10
- <% if !Snaptable.use_permission || current_permission.allow_modify?(params[:controller], "destroy") %>
10
+ <% if show_button? %>
11
+ <a class="show" href="#">Voir</a>
12
+ <% end %>
13
+ <% if delete_button? %>
11
14
  <a class="delete" href="#" data-method="delete"
12
15
  rel="nofollow" data-confirm="Etes-vous sûr de vouloir supprimer cette entrée ?">
13
16
  Supprimer
@@ -7,5 +7,9 @@ module Snaptable
7
7
  initializer 'Snaptable.tables' do
8
8
  ActionController::Base.send :include, Helpers
9
9
  end
10
+
11
+ initializer 'Snaptable.buttons_helper' do
12
+ ActionView::Base.send(:include, ButtonsHelper)
13
+ end
10
14
  end
11
15
  end
@@ -1,3 +1,3 @@
1
1
  module Snaptable
2
- VERSION = "0.7.0"
2
+ VERSION = "0.8.0"
3
3
  end
data/lib/snaptable.rb CHANGED
@@ -2,6 +2,10 @@ require 'snaptable/engine'
2
2
 
3
3
  module Snaptable
4
4
  @@use_permission = false
5
+ @@add_button = true
6
+ @@edit_button = true
7
+ @@delete_button = true
8
+ @@show_button = false
5
9
 
6
- mattr_accessor :use_permission
10
+ mattr_accessor :use_permission, :add_button, :edit_button, :delete_button, :show_button
7
11
  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: 0.7.0
4
+ version: 0.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - khcr
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-09-20 00:00:00.000000000 Z
11
+ date: 2015-09-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -94,6 +94,7 @@ files:
94
94
  - app/assets/javascripts/snaptable/table.js
95
95
  - app/assets/stylesheets/snaptable.css
96
96
  - app/assets/stylesheets/snaptable/table.css.scss
97
+ - app/helpers/buttons_helper.rb
97
98
  - app/views/snaptable/_buttons.html.erb
98
99
  - app/views/snaptable/_search_field.html.erb
99
100
  - app/views/snaptable/base.html.erb