effective_datatables 4.8.14 → 4.9.2
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 +4 -4
- data/MIT-LICENSE +1 -1
- data/README.md +215 -24
- data/app/assets/javascripts/effective_datatables/bulk_actions.js.coffee +13 -3
- data/app/assets/javascripts/effective_datatables/flash.js.coffee +1 -1
- data/app/assets/javascripts/effective_datatables/initialize.js.coffee +1 -0
- data/app/assets/javascripts/effective_datatables/inline_crud.js.coffee +0 -2
- data/app/helpers/effective_datatables_helper.rb +2 -1
- data/app/models/effective/datatable_value_tool.rb +0 -6
- data/app/models/effective/effective_datatable/cookie.rb +2 -2
- data/app/views/effective/datatables/_bulk_actions_dropdown.html.haml +3 -2
- data/config/locales/en.yml +1 -0
- data/config/locales/es.yml +1 -0
- data/config/locales/nl.yml +1 -0
- data/lib/effective_datatables/version.rb +1 -1
- metadata +3 -6
- data/app/datatables/effective_style_guide_datatable.rb +0 -45
- data/app/models/effective/access_denied.rb +0 -17
- data/app/views/effective/style_guide/_effective_datatables.html.haml +0 -1
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/MIT-LICENSE
CHANGED
data/README.md
CHANGED
@@ -8,7 +8,7 @@ Does the right thing with searching sql columns as well as computed values from
|
|
8
8
|
|
9
9
|
Displays links to associated edit/show/destroy actions based on `current_user` authorized actions.
|
10
10
|
|
11
|
-
Other features include aggregate (total/average) footer rows, bulk actions, show/hide columns, responsive collapsing columns and
|
11
|
+
Other features include aggregate (total/average) footer rows, bulk actions, show/hide columns, responsive collapsing columns, google charts, and inline crud.
|
12
12
|
|
13
13
|
This gem includes the jQuery DataTables assets.
|
14
14
|
|
@@ -54,7 +54,8 @@ Please check out [Effective Datatables 3.x](https://github.com/code-and-effect/e
|
|
54
54
|
* [bulk_action](#bulk_action_divider)
|
55
55
|
* [bulk_download](#bulk_download)
|
56
56
|
* [bulk_action_content](#bulk_action_content)
|
57
|
-
* [
|
57
|
+
* [Charts](#charts)
|
58
|
+
* [Inline](#inline)
|
58
59
|
* [Extras](#extras)
|
59
60
|
* [Advanced Search and Sort](#advanced-search-and-sort)
|
60
61
|
* [Addtional Functionality](#additional-functionality)
|
@@ -196,6 +197,13 @@ class PostsDatatable < Effective::Datatable
|
|
196
197
|
# POSTs to the given url with params[:ids], an Array of ids for all selected rows
|
197
198
|
# These actions are assumed to change the underlying collection
|
198
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 }
|
199
207
|
bulk_action_divider
|
200
208
|
bulk_action 'Destroy all', bulk_destroy_posts_path, data: { confirm: 'Destroy all selected posts?' }
|
201
209
|
end
|
@@ -453,7 +461,7 @@ The `datatable do ... end` block configures a table of data.
|
|
453
461
|
|
454
462
|
Initialize the datatable in your controller or view, `@datatable = PostsDatatable.new(self)`, and render it in your view `<%= render_datatable(@datatable) %>`
|
455
463
|
|
456
|
-
|
464
|
+
## col
|
457
465
|
|
458
466
|
This is the main DSL method that you will interact with.
|
459
467
|
|
@@ -526,7 +534,7 @@ You can also use the joined syntax, `col 'user.email'` to create a column for ju
|
|
526
534
|
|
527
535
|
This feature is only working with `belongs_to` and you need to add the `.joins(:user)` to the collection do ... end block yourself.
|
528
536
|
|
529
|
-
|
537
|
+
## val
|
530
538
|
|
531
539
|
Shorthand for value, this command also creates a column on the datatable.
|
532
540
|
|
@@ -548,7 +556,7 @@ This is implemented as a full Array search/sort and is much slower for large dat
|
|
548
556
|
|
549
557
|
The `.format do ... end` block can then be used to apply custom formatting.
|
550
558
|
|
551
|
-
|
559
|
+
## bulk_actions_col
|
552
560
|
|
553
561
|
Creates a column of checkboxes for use with the `bulk_actions` section.
|
554
562
|
|
@@ -558,7 +566,7 @@ Use these checkboxes to select all / none / one or more rows for the `bulk_actio
|
|
558
566
|
|
559
567
|
You can only have one `bulk_actions_col` per datatable.
|
560
568
|
|
561
|
-
|
569
|
+
## actions_col
|
562
570
|
|
563
571
|
When working with an ActiveRecord based collection, this column will consider the `current_user`'s authorization, and generate links to edit, show and destroy actions for any collection class.
|
564
572
|
|
@@ -596,7 +604,7 @@ Any `data-remote` actions will be hijacked and performed as inline ajax by datat
|
|
596
604
|
|
597
605
|
If you'd like to opt-out of this behavior, use `actions_col(inline: false)` or add `data-inline: false` to your action link.
|
598
606
|
|
599
|
-
|
607
|
+
## length
|
600
608
|
|
601
609
|
Sets the default number of rows per page. Valid lengths are `5`, `10`, `25`, `50`, `100`, `250`, `500`, `:all`
|
602
610
|
|
@@ -606,7 +614,7 @@ When not specified, effective_datatables uses the default as per the `config/ini
|
|
606
614
|
length 100
|
607
615
|
```
|
608
616
|
|
609
|
-
|
617
|
+
## order
|
610
618
|
|
611
619
|
Sets the default order of table rows. The first argument is the column, the second the direction.
|
612
620
|
|
@@ -618,7 +626,7 @@ When not specified, effective_datatables will sort by the first defined column.
|
|
618
626
|
order :created_at, :asc|:desc
|
619
627
|
```
|
620
628
|
|
621
|
-
|
629
|
+
## reorder
|
622
630
|
|
623
631
|
Enables drag-and-drop row re-ordering.
|
624
632
|
|
@@ -636,7 +644,7 @@ reorder :position
|
|
636
644
|
|
637
645
|
Using `reorder` will sort the collection by this field and disable all other column sorting.
|
638
646
|
|
639
|
-
|
647
|
+
## aggregate
|
640
648
|
|
641
649
|
The `aggregate` command inserts a row in the table's `tfoot`.
|
642
650
|
|
@@ -681,7 +689,7 @@ The form is submitted by an AJAX POST action, or, in some advanced circumstances
|
|
681
689
|
|
682
690
|
Initialize the datatable in your controller or view, `@datatable = PostsDatatable.new(self)`, and render its filters anywhere with `<%= render_datatable_filters(@datatable) %>`.
|
683
691
|
|
684
|
-
|
692
|
+
## scope
|
685
693
|
|
686
694
|
All defined scopes are rendered as a single radio button form field. Works great with the [effective_form_inputs](https://github.com/code-and-effect/effective_form_inputs) gem.
|
687
695
|
|
@@ -705,7 +713,7 @@ class Post < ApplicationRecord | ActiveRecord::Base
|
|
705
713
|
end
|
706
714
|
```
|
707
715
|
|
708
|
-
|
716
|
+
## filter
|
709
717
|
|
710
718
|
Each filter has a name and a default/fallback value. If the form is submitted blank, the default values are used.
|
711
719
|
|
@@ -758,7 +766,7 @@ Creates a single dropdown menu with a link to each action, download or content.
|
|
758
766
|
|
759
767
|
Along with this section, you must put a `bulk_actions_col` somewhere in your `datatable do ... end` section.
|
760
768
|
|
761
|
-
|
769
|
+
## bulk_action
|
762
770
|
|
763
771
|
Creates a link that becomes clickable when one or more checkbox/rows are selected as per the `bulk_actions_col` column.
|
764
772
|
|
@@ -771,6 +779,12 @@ You can also specify `data-method: :get` to instead make a `GET` request with th
|
|
771
779
|
```ruby
|
772
780
|
bulk_actions do
|
773
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 }
|
774
788
|
end
|
775
789
|
```
|
776
790
|
|
@@ -780,6 +794,9 @@ In your `routes` file:
|
|
780
794
|
resources :posts do
|
781
795
|
collection do
|
782
796
|
post :bulk_approve
|
797
|
+
get :action_1
|
798
|
+
get :action_2
|
799
|
+
get :action_3
|
783
800
|
end
|
784
801
|
end
|
785
802
|
```
|
@@ -798,6 +815,22 @@ def bulk_approve
|
|
798
815
|
render json: { status: 500, message: 'An error occured while approving a post.' }
|
799
816
|
end
|
800
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
|
801
834
|
```
|
802
835
|
|
803
836
|
or if using [effective_resources](https://github.com/code-and-effect/effective_resources):
|
@@ -814,11 +847,11 @@ def approve!
|
|
814
847
|
end
|
815
848
|
```
|
816
849
|
|
817
|
-
|
850
|
+
## bulk_action_divider
|
818
851
|
|
819
852
|
Inserts a menu divider `<li class='divider' role='separator'></li>`
|
820
853
|
|
821
|
-
|
854
|
+
## bulk_download
|
822
855
|
|
823
856
|
So it turns out there are some http issues with using an AJAX action to download a file.
|
824
857
|
|
@@ -859,7 +892,7 @@ def bulk_export_report
|
|
859
892
|
end
|
860
893
|
```
|
861
894
|
|
862
|
-
|
895
|
+
## bulk_action_content
|
863
896
|
|
864
897
|
Blindly inserts content into the dropdown.
|
865
898
|
|
@@ -873,7 +906,7 @@ end
|
|
873
906
|
|
874
907
|
Don't actually use this.
|
875
908
|
|
876
|
-
|
909
|
+
# Charts
|
877
910
|
|
878
911
|
Create a [Google Chart](https://developers.google.com/chart/interactive/docs/quick_start) based on your searched collection, filters and attributes.
|
879
912
|
|
@@ -930,11 +963,169 @@ All options passed to `chart` are used to initialize the chart javascript.
|
|
930
963
|
|
931
964
|
By default, the only package that is loaded is `corechart`, see the `config/initializers/effective_datatables.rb` file to add more packages.
|
932
965
|
|
933
|
-
|
966
|
+
# Inline
|
967
|
+
|
968
|
+
Any datatable can be used as an inline datatable, to create, update and destroy resources without leaving the current page.
|
969
|
+
|
970
|
+
If your datatable is already working with `actions_col` and being rendered from an `Effective::CrudController` controller, all you need to do is change your view from `render_datatable(@datatable)` to `render_datatable(@datatable, inline: true)`.
|
971
|
+
|
972
|
+
Click here for a [Inline Live Demo](https://effective-datatables-demo.herokuapp.com/things) and here for an [Inline Code Example](https://github.com/code-and-effect/effective_datatables_demo)
|
973
|
+
(only the `thing` data model and `things_datatable` are being used inline)
|
974
|
+
|
975
|
+
To use effective_datatables as an inline CRUD builder, you will be relying heavily on [effective_resources](https://github.com/code-and-effect/effective_resources) which is a dependency of this gem. I would also recommend you install [effective_developer](https://github.com/code-and-effect/effective_developer) to get access to some scaffolds and generators. It's not required but I'm gonna use them in this example.
|
976
|
+
|
977
|
+
Here is how I build rails models for inline datatable CRUD operations:
|
978
|
+
|
979
|
+
1. Create a new model file `app/models/thing.rb`:
|
980
|
+
|
981
|
+
```ruby
|
982
|
+
class Thing < ApplicationRecord
|
983
|
+
belongs_to :user
|
984
|
+
|
985
|
+
effective_resource do
|
986
|
+
title :string
|
987
|
+
description :text
|
988
|
+
timestamps
|
989
|
+
end
|
990
|
+
|
991
|
+
scope :deep, -> { includes(:user) }
|
992
|
+
scope :sorted, -> { order(:title) }
|
993
|
+
|
994
|
+
def to_s
|
995
|
+
title
|
996
|
+
end
|
997
|
+
end
|
998
|
+
```
|
999
|
+
|
1000
|
+
The `effective_resource do` block comes from the [effective_resources](https://github.com/code-and-effect/effective_resources) gem and is used to build any permitted_params.
|
1001
|
+
|
1002
|
+
2. Generate a migration. Run `rails generate effective:migration things` to create a migration based off the model file then `rails db:migrate`.
|
1003
|
+
|
1004
|
+
3. Scaffold the rest. Run `rails generate effective:scaffold_controller things` which will create:
|
1005
|
+
|
1006
|
+
- A controller `app/controllers/things_controller.rb`:
|
1007
|
+
|
1008
|
+
```ruby
|
1009
|
+
class ThingsController < ApplicationController
|
1010
|
+
include Effective::CrudController
|
1011
|
+
end
|
1012
|
+
```
|
1013
|
+
|
1014
|
+
The Effective::CrudController comes from [effective_resources](https://github.com/code-and-effect/effective_resources) gem and handles the standard 7 CRUD actions and member and collection actions. It is opinionated code that follows rails conventions. It considers the `routes.rb` and `ability.rb` or other authorization, to find all available actions.
|
1015
|
+
|
1016
|
+
- A datatable `app/datatables/things_datatable.rb`:
|
1017
|
+
|
1018
|
+
```ruby
|
1019
|
+
class ThingsDatatable < Effective::Datatable
|
1020
|
+
datatable do
|
1021
|
+
col :title
|
1022
|
+
col :description
|
1023
|
+
actions_col
|
1024
|
+
end
|
1025
|
+
|
1026
|
+
collection do
|
1027
|
+
Thing.deep.all
|
1028
|
+
end
|
1029
|
+
end
|
1030
|
+
```
|
1031
|
+
|
1032
|
+
This is an ordinary datatable. As long as it's an ActiveRecord collection, inline crud will work.
|
1033
|
+
|
1034
|
+
- A view partial `app/views/things/_thing.html.haml`:
|
1035
|
+
|
1036
|
+
```ruby
|
1037
|
+
%table.table
|
1038
|
+
%tbody
|
1039
|
+
%tr
|
1040
|
+
%th Title
|
1041
|
+
%td= thing.title
|
1042
|
+
%tr
|
1043
|
+
%th Description
|
1044
|
+
%td= thing.description
|
1045
|
+
```
|
1046
|
+
|
1047
|
+
This file is what rails uses when you call `render(thing)` and what datatables uses for the inline `show` action. It's important that its called `_thing.html`.
|
1048
|
+
|
1049
|
+
- A form partial `app/views/things/_form.html.haml`:
|
1050
|
+
|
1051
|
+
```ruby
|
1052
|
+
= effective_form_with(model: thing) do |f|
|
1053
|
+
= f.text_field :title
|
1054
|
+
= f.text_area :description
|
1055
|
+
= f.submit
|
1056
|
+
```
|
1057
|
+
|
1058
|
+
The `effective_form_with` comes from [effective_bootstrap](https://github.com/code-and-effect/effective_bootstrap) gem and is a drop-in replacement for the newer `form_with` syntax. It's really good, you should use it, but an ordinary `form_with` will work here just fine.
|
1059
|
+
|
1060
|
+
This `_form.html` is an effective gems convention. This file must exist for your resource.
|
1061
|
+
|
1062
|
+
- A resources entry in `config/routes.rb`:
|
1063
|
+
|
1064
|
+
```ruby
|
1065
|
+
Rails.application.routes.draw do
|
1066
|
+
resources :things do
|
1067
|
+
post :approve, on: :member
|
1068
|
+
post :reject, on: :member
|
1069
|
+
end
|
1070
|
+
end
|
1071
|
+
```
|
1072
|
+
|
1073
|
+
Above we have `resources :things` for the 7 crud actions. And we add two more member actions, which datatables will call `approve!` or `reject!` on thing.
|
1074
|
+
|
1075
|
+
|
1076
|
+
4. Render in the view. Create an `app/views/things/index.html.haml` and call `render_datatable(@datatable, inline: true)` or `render_inline_datatable(@datatable).
|
1077
|
+
|
1078
|
+
```ruby
|
1079
|
+
= render_datatable(@datatable, inline: true)
|
1080
|
+
```
|
1081
|
+
|
1082
|
+
Your datatable should now have New, Show, Edit, Approve and Reject buttons. Click them for inline functionality.
|
1083
|
+
|
1084
|
+
## Troubleshooting Inline
|
1085
|
+
|
1086
|
+
If things aren't working, try the following:
|
1087
|
+
|
1088
|
+
- Double check your javascripts:
|
1089
|
+
|
1090
|
+
```ruby
|
1091
|
+
//= require jquery3
|
1092
|
+
//= require popper
|
1093
|
+
//= require bootstrap
|
1094
|
+
//= require effective_bootstrap
|
1095
|
+
//= require effective_datatables
|
1096
|
+
//= require jquery_ujs
|
1097
|
+
```
|
1098
|
+
|
1099
|
+
The inline functionality requires one of sprockets jquery_ujs, sprockets rails_ujs or webpack @rails/ujs libraries.
|
1100
|
+
|
1101
|
+
- Double check your stylesheets:
|
1102
|
+
|
1103
|
+
```ruby
|
1104
|
+
@import 'bootstrap';
|
1105
|
+
@import 'effective_bootstrap';
|
1106
|
+
@import 'effective_datatables';
|
1107
|
+
```
|
1108
|
+
|
1109
|
+
- Make sure your datatable is not being rendered inside a `<form>...</form>` tag. It will display a javascript console error and won't work.
|
1110
|
+
|
1111
|
+
- Double check your `resources :things` are in `routes.rb` in the same namespace as the controller, and that you have authorization for those actions in `ability.rb` or whatever your `config/initializers/effective_datatables.rb` `config.authorization_method` returns.
|
1112
|
+
|
1113
|
+
## A note on how it works
|
1114
|
+
|
1115
|
+
We use good old `rails_ujs` for all inline actions.
|
1116
|
+
|
1117
|
+
When inline, any of the actions_col actions, as well as the New button, will be changed into `data-remote: true` actions.
|
1118
|
+
|
1119
|
+
The [inline_crud javascript](https://github.com/code-and-effect/effective_datatables/blob/master/app/assets/javascripts/effective_datatables/inline_crud.js.coffee) handles fetching the form, or view partial and expanding/collapsing the appropriate row of the datatable.
|
1120
|
+
|
1121
|
+
When an inline action is clicked, effective_datatables will make an AJAX request to the server, which could be received by an `Effective::CrudController` that will handle the `.js` format, and respond_with the appropriate [rails_ujs .js.erb views](https://github.com/code-and-effect/effective_resources/tree/master/app/views/application).
|
1122
|
+
|
1123
|
+
|
1124
|
+
# Extras
|
934
1125
|
|
935
1126
|
The following commands don't quite fit into the DSL, but are present nonetheless.
|
936
1127
|
|
937
|
-
|
1128
|
+
## simple
|
938
1129
|
|
939
1130
|
To render a simple table, without pagination, sorting, filtering, export buttons, per page, and default visibility:
|
940
1131
|
|
@@ -942,7 +1133,7 @@ To render a simple table, without pagination, sorting, filtering, export buttons
|
|
942
1133
|
<%= render_datatable(@datatable, simple: true) %>
|
943
1134
|
```
|
944
1135
|
|
945
|
-
|
1136
|
+
## index
|
946
1137
|
|
947
1138
|
If you just want to render a datatable and nothing else, there is a quick way to skip creating a view:
|
948
1139
|
|
@@ -956,13 +1147,13 @@ end
|
|
956
1147
|
|
957
1148
|
will render `views/effective/datatables/index` with the assigned datatable.
|
958
1149
|
|
959
|
-
|
1150
|
+
# Advanced Search and Sort
|
960
1151
|
|
961
1152
|
The built-in search and ordering can be overridden on a per-column basis.
|
962
1153
|
|
963
1154
|
The only gotcha here is that you must be aware of the type of collection.
|
964
1155
|
|
965
|
-
|
1156
|
+
## With ActiveRecord collection
|
966
1157
|
|
967
1158
|
In the case of a `col` and an ActiveRecord collection:
|
968
1159
|
|
@@ -994,7 +1185,7 @@ If `column[:sql_column].blank?` then this `col` has fallen back to being a `val`
|
|
994
1185
|
|
995
1186
|
Try adding `col :post_category, sql_column: 'post_categories.title'`
|
996
1187
|
|
997
|
-
|
1188
|
+
## With Array collection
|
998
1189
|
|
999
1190
|
And in the case of a `col` with an Array collection, or any `val`:
|
1000
1191
|
|
@@ -1033,7 +1224,7 @@ end
|
|
1033
1224
|
|
1034
1225
|
The search and sort for each column will be merged together to form the final results.
|
1035
1226
|
|
1036
|
-
|
1227
|
+
## Default search collection
|
1037
1228
|
|
1038
1229
|
When using a `col :comments` type belongs_to or has_many column, a search collection for that class will be loaded.
|
1039
1230
|
|
@@ -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
|
|
@@ -16,7 +16,7 @@ flash = (message, status = '') ->
|
|
16
16
|
timeout = $processing.data('timeout')
|
17
17
|
clearTimeout(timeout) if timeout
|
18
18
|
|
19
|
-
delay = (if status == 'danger' then 4000 else
|
19
|
+
delay = (if status == 'danger' then 4000 else 1000)
|
20
20
|
|
21
21
|
$processing.html(message).data('timeout', setTimeout( =>
|
22
22
|
$processing.html('Processing...')
|
@@ -123,7 +123,6 @@ beforeNew = ($action) ->
|
|
123
123
|
|
124
124
|
# Append spinner and show Processing
|
125
125
|
$th.append($table.data('spinner'))
|
126
|
-
$table.DataTable().flash()
|
127
126
|
$table.one 'draw.dt', (event) ->
|
128
127
|
$th.find('a').show().siblings('svg').remove() if event.target == event.currentTarget
|
129
128
|
|
@@ -152,7 +151,6 @@ beforeEdit = ($action) ->
|
|
152
151
|
|
153
152
|
# Append spinner and show Processing
|
154
153
|
$td.append($table.data('spinner'))
|
155
|
-
$table.DataTable().flash()
|
156
154
|
|
157
155
|
afterEdit = ($action) ->
|
158
156
|
$tr = $action.closest('tr')
|
@@ -1,6 +1,6 @@
|
|
1
1
|
# These are expected to be called by a developer. They are part of the datatables DSL.
|
2
2
|
module EffectiveDatatablesHelper
|
3
|
-
def render_datatable(datatable, input_js: {}, buttons: true, charts: true, entries: true, filters: true, inline: false, pagination: true, search: true, simple: false, sort: true)
|
3
|
+
def render_datatable(datatable, input_js: {}, buttons: true, charts: true, entries: true, filters: true, inline: false, namespace: nil, pagination: true, search: true, simple: false, sort: true)
|
4
4
|
raise 'expected datatable to be present' unless datatable
|
5
5
|
raise 'expected input_js to be a Hash' unless input_js.kind_of?(Hash)
|
6
6
|
|
@@ -10,6 +10,7 @@ module EffectiveDatatablesHelper
|
|
10
10
|
|
11
11
|
datatable.attributes[:inline] = true if inline
|
12
12
|
datatable.attributes[:sortable] = false unless sort
|
13
|
+
datatable.attributes[:namespace] = namespace if namespace
|
13
14
|
|
14
15
|
datatable.view ||= self
|
15
16
|
|
@@ -10,7 +10,7 @@ module Effective
|
|
10
10
|
|
11
11
|
def load_cookie!
|
12
12
|
return unless EffectiveDatatables.save_state
|
13
|
-
return unless view.respond_to?(:cookies)
|
13
|
+
return unless (view.cookies rescue false) # Rails 6.1 view doesn't respond_to?(:cookies)
|
14
14
|
|
15
15
|
@dt_cookie = view.cookies.signed['_effective_dt']
|
16
16
|
|
@@ -34,7 +34,7 @@ module Effective
|
|
34
34
|
|
35
35
|
def save_cookie!
|
36
36
|
return unless EffectiveDatatables.save_state
|
37
|
-
return unless view.
|
37
|
+
return unless (view.cookies rescue false)
|
38
38
|
|
39
39
|
@dt_cookie ||= []
|
40
40
|
@dt_cookie << [cookie_key, cookie_payload]
|
@@ -1,8 +1,9 @@
|
|
1
1
|
.btn-group.buttons-bulk-actions
|
2
2
|
%button.btn.btn-link.btn-sm.dropdown-toggle{'type': 'button', 'data-toggle': 'dropdown', 'aria-haspopup': true, 'aria-expanded': false, 'disabled': 'disabled'}
|
3
|
-
|
3
|
+
= t('effective_datatables.bulk_actions')
|
4
4
|
.dropdown-menu
|
5
5
|
- if datatable._bulk_actions.present?
|
6
6
|
= datatable._bulk_actions.join.html_safe
|
7
7
|
- else
|
8
|
-
%a.dropdown-item{href: '#'}
|
8
|
+
%a.dropdown-item{href: '#'}
|
9
|
+
= t('effective_datatables.no_bulk_actions')
|
data/config/locales/en.yml
CHANGED
data/config/locales/es.yml
CHANGED
data/config/locales/nl.yml
CHANGED
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.
|
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
|
@@ -67,7 +67,7 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: sassc
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
@@ -129,11 +129,9 @@ files:
|
|
129
129
|
- app/assets/stylesheets/effective_datatables.scss
|
130
130
|
- app/assets/stylesheets/effective_datatables/_overrides.bootstrap4.scss
|
131
131
|
- app/controllers/effective/datatables_controller.rb
|
132
|
-
- app/datatables/effective_style_guide_datatable.rb
|
133
132
|
- app/helpers/effective_datatables_controller_helper.rb
|
134
133
|
- app/helpers/effective_datatables_helper.rb
|
135
134
|
- app/helpers/effective_datatables_private_helper.rb
|
136
|
-
- app/models/effective/access_denied.rb
|
137
135
|
- app/models/effective/datatable.rb
|
138
136
|
- app/models/effective/datatable_column.rb
|
139
137
|
- app/models/effective/datatable_column_tool.rb
|
@@ -163,7 +161,6 @@ files:
|
|
163
161
|
- app/views/effective/datatables/_resource_column.html.haml
|
164
162
|
- app/views/effective/datatables/_spacer_template.html
|
165
163
|
- app/views/effective/datatables/index.html.haml
|
166
|
-
- app/views/effective/style_guide/_effective_datatables.html.haml
|
167
164
|
- config/effective_datatables.rb
|
168
165
|
- config/locales/en.yml
|
169
166
|
- config/locales/es.yml
|
@@ -1,45 +0,0 @@
|
|
1
|
-
class EffectiveStyleGuideDatatable < Effective::Datatable
|
2
|
-
datatable do
|
3
|
-
length 10
|
4
|
-
|
5
|
-
col :id
|
6
|
-
col :material, search: { collection: ['Stainless Steel', 'Copper', 'Cast Iron', 'Composite'] }
|
7
|
-
col :bowl, search: { collection: ['Single Bowl', 'Double Bowl', 'Triple Bowl'] }
|
8
|
-
col :name
|
9
|
-
col :date, as: :date
|
10
|
-
end
|
11
|
-
|
12
|
-
# Set the permission check to the same as Effective::StyleGuide
|
13
|
-
def collection_class
|
14
|
-
defined?(Effective::StyleGuide) ? Effective::StyleGuide : super
|
15
|
-
end
|
16
|
-
|
17
|
-
collection do
|
18
|
-
now = Time.zone.now
|
19
|
-
[
|
20
|
-
[1, 'Stainless Steel', 'Single Bowl', 'KOHLER Staccato', (now + 1.day)],
|
21
|
-
[2, 'Stainless Steel', 'Double Bowl', 'KOHLER Vault Undercounter', (now + 1.day)],
|
22
|
-
[3, 'Stainless Steel', 'Triple Bowl', 'KRAUS All-In-One', (now + 1.day)],
|
23
|
-
[4, 'Stainless Steel', 'Single Bowl', 'KOHLER Vault Dual Mount', (now + 1.day)],
|
24
|
-
[5, 'Stainless Steel', 'Single Bowl', 'KRAUS All-In-One Undermount', (now + 2.days)],
|
25
|
-
[6, 'Stainless Steel', 'Double Bowl', 'Glacier Bay All-in-One', (now + 2.days)],
|
26
|
-
[7, 'Stainless Steel', 'Single Bowl', 'Elkay Neptune', (now + 2.days)],
|
27
|
-
[8, 'Copper', 'Single Bowl', 'ECOSINKS Apron Front Dual Mount', (now + 2.days)],
|
28
|
-
[9, 'Copper', 'Double Bowl', 'ECOSINKS Dual Mount Front Hammered', (now + 2.days)],
|
29
|
-
[10, 'Copper', 'Triple Bowl', 'Glarier Bay Undermount', (now + 3.days)],
|
30
|
-
[11, 'Copper', 'Single Bowl', 'Whitehaus Undermount', (now + 3.days)],
|
31
|
-
[12, 'Copper', 'Double Bowl', 'Belle Foret Apron Front', (now + 3.days)],
|
32
|
-
[13, 'Copper', 'Double Bowl', 'Pegasus Dual Mount', (now + 3.days)],
|
33
|
-
[14, 'Cast Iron', 'Double Bowl', 'KOHLER Whitehaven', (now + 3.days)],
|
34
|
-
[15, 'Cast Iron', 'Triple Bowl', 'KOHLER Hartland', (now + 3.days)],
|
35
|
-
[16, 'Cast Iron', 'Single Bowl', 'KOHLER Cape Dory Undercounter', (now + 4.days)],
|
36
|
-
[17, 'Cast Iron', 'Double Bowl', 'KOLER Bakersfield', (now + 4.days)],
|
37
|
-
[18, 'Cast Iron', 'Double Bowl', 'American Standard Offset', (now + 4.days)],
|
38
|
-
[19, 'Cast Iron', 'Single Bowl', 'Brookfield Top', (now + 4.days)],
|
39
|
-
[20, 'Composite', 'Single Bowl', 'Blanco Diamond Undermount', (now + 5.days)],
|
40
|
-
[21, 'Composite', 'Double Bowl', 'Mont Blanc Waterbrook', (now + 5.days)],
|
41
|
-
[22, 'Composite', 'Triple Bowl', 'Pegasus Triple Mount', (now + 5.days)],
|
42
|
-
[23, 'Composite', 'Single Bowl', 'Swanstone Dual Mount', (now + 5.days)]
|
43
|
-
]
|
44
|
-
end
|
45
|
-
end
|
@@ -1,17 +0,0 @@
|
|
1
|
-
unless defined?(Effective::AccessDenied)
|
2
|
-
module Effective
|
3
|
-
class AccessDenied < StandardError
|
4
|
-
attr_reader :action, :subject
|
5
|
-
|
6
|
-
def initialize(message = nil, action = nil, subject = nil)
|
7
|
-
@message = message
|
8
|
-
@action = action
|
9
|
-
@subject = subject
|
10
|
-
end
|
11
|
-
|
12
|
-
def to_s
|
13
|
-
@message || I18n.t(:'unauthorized.default', :default => 'Access Denied')
|
14
|
-
end
|
15
|
-
end
|
16
|
-
end
|
17
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
= render_datatable(EffectiveStyleGuideDatatable.new)
|