effective_datatables 4.9.1 → 4.9.2
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf3af682fec53ad7da6b239337166cf390c011e0623f1c4d033e955718cb5be9
|
4
|
+
data.tar.gz: 30dda463af35a4a8ae97deea4e51da5995d7b0d9d154f1177f47faf295dc2a23
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9ea5a20c66f27fb86f219dfdf312eec1196f3d798d58b15ea1092af964f995bdb3fb88371d14d1c0c73d88812d941942231fdea571e8a58c9bae3873aecaab71
|
7
|
+
data.tar.gz: f959a311d9ff0ca01b0a461cd0344a2f1a77f5f6e1a7aeb4652e5577e565c6100ce3f6580b8c12450e7538efed4267b087e5ca6945c9caa1a8175bd933415ebd
|
data/README.md
CHANGED
@@ -197,6 +197,13 @@ class PostsDatatable < Effective::Datatable
|
|
197
197
|
# POSTs to the given url with params[:ids], an Array of ids for all selected rows
|
198
198
|
# These actions are assumed to change the underlying collection
|
199
199
|
bulk_action 'Approve all', bulk_approve_posts_path, data: { confirm: 'Approve all selected posts?' }
|
200
|
+
# GETs to the given url. Pass the ids via cookie, encoded in url, or LocalStorage.
|
201
|
+
# These actions are assumed to redirect the user to some other page.
|
202
|
+
bulk_action 'Action 1 | ids encoded in params', action_1_posts_path, data: { method: :get }
|
203
|
+
|
204
|
+
bulk_action 'Action 2 | ids stored in _ids_ field in local storage', action_2_posts_path, data: { 'payload-mode' => 'local-storage', method: :get }
|
205
|
+
|
206
|
+
bulk_action 'Action 3 | ids stored in _ids_ field in a cookie', action_3_posts_path, data: { 'payload-mode' => 'cookie', method: :get }
|
200
207
|
bulk_action_divider
|
201
208
|
bulk_action 'Destroy all', bulk_destroy_posts_path, data: { confirm: 'Destroy all selected posts?' }
|
202
209
|
end
|
@@ -772,6 +779,12 @@ You can also specify `data-method: :get` to instead make a `GET` request with th
|
|
772
779
|
```ruby
|
773
780
|
bulk_actions do
|
774
781
|
bulk_action 'Approve all', bulk_approve_posts_path, data: { confirm: 'Approve all selected posts?' }
|
782
|
+
|
783
|
+
bulk_action 'Action 1 | ids encoded in params', action_1_posts_path, data: { method: :get }
|
784
|
+
|
785
|
+
bulk_action 'Action 2 | ids stored in _ids_ field in local storage', action_2_posts_path, data: { 'payload-mode' => 'local-storage', method: :get }
|
786
|
+
|
787
|
+
bulk_action 'Action 3 | ids stored in _ids_ field in a cookie', action_3_posts_path, data: { 'payload-mode' => 'cookie', method: :get }
|
775
788
|
end
|
776
789
|
```
|
777
790
|
|
@@ -781,6 +794,9 @@ In your `routes` file:
|
|
781
794
|
resources :posts do
|
782
795
|
collection do
|
783
796
|
post :bulk_approve
|
797
|
+
get :action_1
|
798
|
+
get :action_2
|
799
|
+
get :action_3
|
784
800
|
end
|
785
801
|
end
|
786
802
|
```
|
@@ -799,6 +815,22 @@ def bulk_approve
|
|
799
815
|
render json: { status: 500, message: 'An error occured while approving a post.' }
|
800
816
|
end
|
801
817
|
end
|
818
|
+
|
819
|
+
def action_1
|
820
|
+
@posts = Post.where(id: params[:ids])
|
821
|
+
|
822
|
+
render :some_partial
|
823
|
+
end
|
824
|
+
|
825
|
+
def action_2
|
826
|
+
@posts = Post.where(id: cookies[:ids].split(','))
|
827
|
+
|
828
|
+
render :some_partial
|
829
|
+
end
|
830
|
+
|
831
|
+
def action_3
|
832
|
+
render :some_partial # and get ids via JS: localStorage.getItem('ids');
|
833
|
+
end
|
802
834
|
```
|
803
835
|
|
804
836
|
or if using [effective_resources](https://github.com/code-and-effect/effective_resources):
|
@@ -44,6 +44,8 @@ restoreSelected = ($table, selected) ->
|
|
44
44
|
#### Bulk Action link behaviour
|
45
45
|
$(document).on 'click', '.dataTables_wrapper .buttons-bulk-actions a', (event) ->
|
46
46
|
event.preventDefault() # prevent the click
|
47
|
+
document.cookie = 'ids=; expires = Thu, 01 Jan 1970 00:00:00 GMT'
|
48
|
+
localStorage.removeItem('ids')
|
47
49
|
|
48
50
|
$bulkAction = $(event.currentTarget) # This is a regular <a href=...> tag
|
49
51
|
$wrapper = $bulkAction.closest('.dataTables_wrapper')
|
@@ -54,6 +56,7 @@ $(document).on 'click', '.dataTables_wrapper .buttons-bulk-actions a', (event) -
|
|
54
56
|
url = $bulkAction.attr('href')
|
55
57
|
title = $bulkAction.text()
|
56
58
|
download = $bulkAction.data('bulk-download')
|
59
|
+
payload_mode = $bulkAction.data('payload-mode')
|
57
60
|
token = $table.data('authenticity-token')
|
58
61
|
values = $.map($selected, (input) -> input.getAttribute('value'))
|
59
62
|
method = $bulkAction.data('ajax-method')
|
@@ -61,10 +64,17 @@ $(document).on 'click', '.dataTables_wrapper .buttons-bulk-actions a', (event) -
|
|
61
64
|
return unless url && values
|
62
65
|
|
63
66
|
if method == 'GET'
|
64
|
-
if
|
65
|
-
|
67
|
+
if payload_mode == 'cookie'
|
68
|
+
document.cookie = "ids=#{values}";
|
69
|
+
window.location.assign(url)
|
70
|
+
else if payload_mode == 'local-storage'
|
71
|
+
localStorage.setItem('ids', values);
|
72
|
+
window.location.assign(url)
|
66
73
|
else
|
67
|
-
|
74
|
+
if url.includes('?')
|
75
|
+
window.location.assign(url + '&' + $.param({ids: values}))
|
76
|
+
else
|
77
|
+
window.location.assign(url + '?' + $.param({ids: values}))
|
68
78
|
|
69
79
|
return
|
70
80
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_datatables
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.9.
|
4
|
+
version: 4.9.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-05-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|