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: afc1825001f74c08289310c87a0e3ffa014a2e909c21487841103e3adf05e0a5
4
- data.tar.gz: 5318e53b07af9daa08cc4fd39f14cf9570620e30f9222beb70b830de47dd0f06
3
+ metadata.gz: cf3af682fec53ad7da6b239337166cf390c011e0623f1c4d033e955718cb5be9
4
+ data.tar.gz: 30dda463af35a4a8ae97deea4e51da5995d7b0d9d154f1177f47faf295dc2a23
5
5
  SHA512:
6
- metadata.gz: 9c882a77988f466ef89a54361abd2fa26953554b4a859999d05c462e88a8412966ab3292914d28ae22f9a550bcb3eaea85ffa76d24aa5fc6bb16a53c05352801
7
- data.tar.gz: 0a129c87f1bce4334570f80f10ca8ab2b432ede293f9ab34c0e135bdde99e936563864e4cc0abc6f0c679fca2498d3965f8ad5610d941b1512620774264b45e7
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 url.includes('?')
65
- window.location.assign(url + '&' + $.param({ids: values}))
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
- window.location.assign(url + '?' + $.param({ids: values}))
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
 
@@ -1,3 +1,3 @@
1
1
  module EffectiveDatatables
2
- VERSION = '4.9.1'.freeze
2
+ VERSION = '4.9.2'.freeze
3
3
  end
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.1
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-04-23 00:00:00.000000000 Z
11
+ date: 2021-05-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails