effective_datatables 4.2.0 → 4.3.0

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.
Files changed (31) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -0
  3. data/app/assets/javascripts/dataTables/buttons/buttons.colVis.js +4 -8
  4. data/app/assets/javascripts/dataTables/buttons/buttons.html5.js +33 -19
  5. data/app/assets/javascripts/dataTables/buttons/buttons.print.js +14 -3
  6. data/app/assets/javascripts/dataTables/buttons/dataTables.buttons.js +128 -61
  7. data/app/assets/javascripts/dataTables/dataTables.bootstrap4.js +5 -5
  8. data/app/assets/javascripts/dataTables/jquery.dataTables.js +2078 -2025
  9. data/app/assets/javascripts/dataTables/responsive/dataTables.responsive.js +46 -22
  10. data/app/assets/javascripts/effective_datatables.js +1 -0
  11. data/app/assets/javascripts/effective_datatables/bulk_actions.js.coffee +40 -41
  12. data/app/assets/javascripts/effective_datatables/events.js.coffee +1 -1
  13. data/app/assets/javascripts/effective_datatables/filters.js.coffee +1 -1
  14. data/app/assets/javascripts/effective_datatables/initialize.js.coffee +11 -33
  15. data/app/assets/javascripts/effective_datatables/inline_crud.js.coffee +158 -0
  16. data/app/assets/javascripts/effective_datatables/overrides.js.coffee +40 -0
  17. data/app/assets/javascripts/effective_datatables/reset.js.coffee +1 -1
  18. data/app/assets/stylesheets/dataTables/dataTables.bootstrap4.css +5 -1
  19. data/app/assets/stylesheets/effective_datatables/_overrides.scss +47 -1
  20. data/app/helpers/effective_datatables_helper.rb +1 -0
  21. data/app/helpers/effective_datatables_private_helper.rb +10 -1
  22. data/app/models/effective/effective_datatable/dsl/bulk_actions.rb +11 -22
  23. data/app/models/effective/effective_datatable/dsl/datatable.rb +2 -1
  24. data/app/models/effective/effective_datatable/format.rb +15 -4
  25. data/app/views/effective/datatables/_bulk_actions_column.html.haml +1 -1
  26. data/config/effective_datatables.rb +0 -13
  27. data/lib/effective_datatables.rb +0 -1
  28. data/lib/effective_datatables/version.rb +1 -1
  29. metadata +5 -5
  30. data/app/assets/javascripts/effective_datatables/overrides.js +0 -12
  31. data/app/views/effective/datatables/_actions_column.html.haml +0 -1
@@ -0,0 +1,40 @@
1
+ $.extend(true, $.fn.dataTable.Buttons.defaults, {
2
+ dom: {
3
+ button: {
4
+ className: 'btn btn-link btn-sm'
5
+ }
6
+ }
7
+ });
8
+
9
+ # DataTable is the API
10
+ # dataTable is the object fnStuff
11
+
12
+ flash = (message) ->
13
+ @context[0].oFeatures.bProcessing = false
14
+
15
+ message ||= 'Processing...'
16
+
17
+ $processing = $(@table().node()).siblings('.dataTables_processing')
18
+ $processing.html(message).show()
19
+
20
+ timeout = $processing.data('timeout')
21
+ clearTimeout(timeout) if timeout
22
+
23
+ $processing.html(message).data('timeout', setTimeout( =>
24
+ $processing.html('Processing...').hide()
25
+ @context[0].oFeatures.bProcessing = true
26
+ , 1500)
27
+ )
28
+
29
+ return @
30
+
31
+ turboDestroy = ->
32
+ @iterator('table', (settings) ->
33
+ $(window).off('.DT-' + settings.sInstance)
34
+
35
+ index = $.inArray(settings, $.fn.DataTable.settings)
36
+ $.fn.DataTable.settings.splice(index, 1) if index > -1
37
+ )
38
+
39
+ $.fn.DataTable.Api.register('flash()', flash);
40
+ $.fn.DataTable.Api.register('turboDestroy()', turboDestroy);
@@ -1,4 +1,4 @@
1
- $(document).on 'click', 'a.buttons-reset-search', (event) ->
1
+ $(document).on 'click', '.dataTables_wrapper a.buttons-reset-search', (event) ->
2
2
  event.preventDefault() # prevent the click
3
3
 
4
4
  $table = $(event.currentTarget).closest('.dataTables_wrapper').find('table.dataTable').first()
@@ -4,6 +4,7 @@ table.dataTable {
4
4
  margin-bottom: 6px !important;
5
5
  max-width: none !important;
6
6
  border-collapse: separate !important;
7
+ border-spacing: 0;
7
8
  }
8
9
  table.dataTable td,
9
10
  table.dataTable th {
@@ -25,7 +26,7 @@ div.dataTables_wrapper div.dataTables_length label {
25
26
  white-space: nowrap;
26
27
  }
27
28
  div.dataTables_wrapper div.dataTables_length select {
28
- width: 75px;
29
+ width: auto;
29
30
  display: inline-block;
30
31
  }
31
32
  div.dataTables_wrapper div.dataTables_filter {
@@ -132,6 +133,9 @@ div.dataTables_scrollBody table {
132
133
  margin-top: 0 !important;
133
134
  margin-bottom: 0 !important;
134
135
  }
136
+ div.dataTables_scrollBody table thead .sorting:before,
137
+ div.dataTables_scrollBody table thead .sorting_asc:before,
138
+ div.dataTables_scrollBody table thead .sorting_desc:before,
135
139
  div.dataTables_scrollBody table thead .sorting:after,
136
140
  div.dataTables_scrollBody table thead .sorting_asc:after,
137
141
  div.dataTables_scrollBody table thead .sorting_desc:after {
@@ -19,6 +19,38 @@ table.dataTable thead .sorting_desc:after,
19
19
  table.dataTable thead .sorting_asc_disabled:after,
20
20
  table.dataTable thead .sorting_desc_disabled:after { content: ''; }
21
21
 
22
+ table.dataTable > thead {
23
+ th.col-actions {
24
+ text-align: right;
25
+
26
+ span { display: block; height: 1.25em; }
27
+ }
28
+ }
29
+
30
+ .dataTables_wrapper {
31
+ table.dataTable {
32
+ tr.effective-datatables-inline-row { visibility: collapse; } // Turbolinks destroy fix
33
+ }
34
+ }
35
+
36
+ // When Inline Expanded
37
+ .dataTables_wrapper.effective-datatables-inline-expanded {
38
+ .dt-buttons { opacity: 0.4; }
39
+ .dataTables_entries { opacity: 0.4; }
40
+ .dataTables_paginate { opacity: 0.4; }
41
+
42
+ table.dataTable {
43
+ tr { opacity: 0.4; }
44
+
45
+ tr.effective-datatables-inline-row {
46
+ visibility: visible;
47
+ opacity: 1.0;
48
+
49
+ &:hover { background-color: inherit; }
50
+ }
51
+ }
52
+ }
53
+
22
54
  table.dataTable > thead th {
23
55
  vertical-align: top;
24
56
  background-repeat: no-repeat;
@@ -78,6 +110,18 @@ table.dataTable > thead {
78
110
  }
79
111
  }
80
112
 
113
+ // Processing div
114
+ div.dataTables_wrapper div.dataTables_processing {
115
+ position: absolute;
116
+ top: 1em;
117
+ left: 50%;
118
+ width: 300px;
119
+ margin-left: -150px;
120
+ margin-top: -26px;
121
+ text-align: center;
122
+ padding: 1em;
123
+ }
124
+
81
125
  // Simple styles
82
126
  table.dataTable.simple > thead {
83
127
  .sorting { background-image: none; cursor: default; }
@@ -93,6 +137,7 @@ table.dataTable.simple > thead {
93
137
  div.dataTables_wrapper div.dataTables_entries { text-align: center; }
94
138
  }
95
139
 
140
+ // Showing x to y of z entries with 25 per page
96
141
  .dataTables_wrapper .dataTables_entries {
97
142
  color: #909090;
98
143
  font-size: 12px;
@@ -148,5 +193,6 @@ table.dataTable {
148
193
  td {
149
194
  p { margin-bottom: 0em; }
150
195
  }
151
-
152
196
  }
197
+
198
+
@@ -30,6 +30,7 @@ module EffectiveDatatablesHelper
30
30
  'options' => (input_js || {}).to_json.html_safe,
31
31
  'reset' => datatable_reset(datatable),
32
32
  'simple' => datatable.simple?.to_s,
33
+ 'spinner' => icon('spinner'), # effective_bootstrap
33
34
  'source' => effective_datatables.datatable_path(datatable, {format: 'json'}),
34
35
  'total-records' => datatable.to_json[:recordsTotal]
35
36
  }
@@ -27,7 +27,16 @@ module EffectiveDatatablesPrivateHelper
27
27
  link_to(content_tag(:span, 'Reset'), '#', class: 'btn btn-link btn-sm buttons-reset-search')
28
28
  end
29
29
 
30
+ def datatable_new_resource_button(datatable, name, column)
31
+ if column[:inline] && column[:actions][:new] != false
32
+ actions = {'New' => { action: :new, class: 'btn btn-outline-primary', 'data-remote': true } }
33
+ render_resource_actions(datatable.resource.klass, actions: actions) # Will only work if permitted
34
+ end
35
+ end
36
+
30
37
  def datatable_search_tag(datatable, name, opts)
38
+ return datatable_new_resource_button(datatable, name, opts) if name == :_actions
39
+
31
40
  return if opts[:search] == false
32
41
 
33
42
  # Build the search
@@ -60,7 +69,7 @@ module EffectiveDatatablesPrivateHelper
60
69
  options[:input_js] = (options[:input_js] || {}).reverse_merge(placeholder: '')
61
70
  form.select name, collection, options
62
71
  when :bulk_actions
63
- options[:data]['role'] = 'bulk-actions-all'
72
+ options[:data]['role'] = 'bulk-actions'
64
73
  form.check_box name, options.merge(custom: false)
65
74
  end
66
75
  end
@@ -8,7 +8,7 @@ module Effective
8
8
  end
9
9
 
10
10
  def bulk_download(*args)
11
- datatable._bulk_actions.push(link_to_bulk_action(*args.merge('data-authenticity-token' => form_authenticity_token)))
11
+ datatable._bulk_actions.push(link_to_bulk_action(*args.merge('data-authenticity-token' => form_authenticity_token, 'data-method' => :post)))
12
12
  end
13
13
 
14
14
  def bulk_action_divider
@@ -22,30 +22,19 @@ module Effective
22
22
  private
23
23
 
24
24
  # We can't let any data-method be applied to the link, or jquery_ujs does the wrong thing with it
25
- def link_to_bulk_action(*args)
26
- args.map! do |arg|
27
- if arg.kind_of?(Hash)
28
- data_method = (
29
- arg.delete(:'data-method') ||
30
- arg.delete('data-method') ||
31
- (arg[:data] || {}).delete('method') ||
32
- (arg[:data] || {}).delete(:method)
33
- )
34
-
35
- # But if the data-method was :get, we add bulk-actions-get-link = true
36
- if data_method.to_s == 'get'
37
- arg[:data].present? ? arg[:data]['bulk-actions-get'] = true : arg['data-bulk-actions-get'] = true
38
- end
39
-
40
- arg[:class] = [arg[:class], 'dropdown-item'].compact.join(' ')
41
- end
42
-
43
- arg
25
+ def link_to_bulk_action(body, url, opts = {})
26
+
27
+ # Transform data: { ... } hash into 'data-' keys
28
+ if (data = opts.delete(:data))
29
+ data.each { |k, v| opts["data-#{k}"] ||= v }
44
30
  end
45
31
 
46
- args << { class: 'dropdown-item' } if args.none? { |arg| arg.kind_of?(Hash) }
32
+ verbs = {'DELETE' => 'DELETE', 'GET' => 'GET'}
33
+ opts['data-ajax-method'] = verbs[opts.delete('data-method').to_s.upcase] || 'POST'
34
+
35
+ opts[:class] = [opts[:class], 'dropdown-item'].compact.join(' ')
47
36
 
48
- link_to(*args)
37
+ link_to(body, url, opts)
49
38
  end
50
39
 
51
40
  end
@@ -97,7 +97,7 @@ module Effective
97
97
  )
98
98
  end
99
99
 
100
- def actions_col(col_class: nil, partial: nil, partial_as: nil, actions_partial: nil, responsive: 5000, visible: true, **actions, &format)
100
+ def actions_col(col_class: nil, inline: false, partial: nil, partial_as: nil, actions_partial: nil, responsive: 5000, visible: true, **actions, &format)
101
101
  raise 'You can only have one actions column' if datatable.columns[:_actions].present?
102
102
 
103
103
  datatable._columns[:_actions] = Effective::DatatableColumn.new(
@@ -107,6 +107,7 @@ module Effective
107
107
  col_class: col_class,
108
108
  format: (format if block_given?),
109
109
  index: nil,
110
+ inline: inline,
110
111
  label: false,
111
112
  name: :actions,
112
113
  partial: partial,
@@ -24,10 +24,9 @@ module Effective
24
24
  spacer_template: SPACER_TEMPLATE
25
25
  ) || '').split(SPACER)
26
26
  elsif opts[:as] == :actions # This is actions_col and actions_col do .. end, but not actions_col partial: 'something'
27
- locals = { datatable: self, column: columns[name], spacer_template: SPACER_TEMPLATE }
28
-
29
27
  resources = collection.map { |row| row[opts[:index]] }
30
- atts = opts[:actions].merge(effective_resource: resource, locals: locals, partial: opts[:actions_partial])
28
+ locals = { datatable: self, column: opts, spacer_template: SPACER_TEMPLATE }
29
+ atts = { actions: actions_col_actions(opts), effective_resource: resource, locals: locals, partial: opts[:actions_partial] }.merge(opts[:actions])
31
30
 
32
31
  rendered[name] = (view.render_resource_actions(resources, atts, &opts[:format]) || '').split(SPACER)
33
32
  end
@@ -67,7 +66,9 @@ module Effective
67
66
 
68
67
  case column[:as]
69
68
  when :actions
70
- view.render_resource_actions(value, **column[:actions].merge(effective_resource: resource, partial: column[:actions_partial]))
69
+ atts = { actions: actions_col_actions(column), effective_resource: resource, partial: column[:actions_partial] }.merge(column[:actions])
70
+
71
+ (view.render_resource_actions(value, atts) || '')
71
72
  when :boolean
72
73
  case value
73
74
  when true ; 'Yes'
@@ -110,6 +111,16 @@ module Effective
110
111
  end
111
112
  end
112
113
 
114
+ # Takes all default resource actions
115
+ # Applies data-remote to anything that's data-method post or delete
116
+ def actions_col_actions(column)
117
+ if column[:inline]
118
+ resource.resource_actions.transform_values { |opts| opts['data-remote'] = true; opts }
119
+ else
120
+ resource.resource_actions.transform_values { |opts| opts['data-remote'] = true if opts['data-method']; opts }
121
+ end
122
+ end
123
+
113
124
  def resource_col_locals(opts)
114
125
  return {} unless (resource = opts[:resource]).present?
115
126
 
@@ -1,2 +1,2 @@
1
1
  - id = (resource.try(:to_param) || resource.try(:id) || resource.object_id)
2
- = check_box_tag 'bulk_actions_resources[]', id, false, autocomplete: 'off', id: "datatable_bulk_actions_resource_#{id}", data: { role: 'bulk-actions-resource' }, onClick: 'event.stopPropagation();'
2
+ = check_box_tag 'bulk_actions_resources[]', id, false, autocomplete: 'off', id: "datatable_bulk_actions_resource_#{id}", data: { role: 'bulk-action' }
@@ -28,19 +28,6 @@ EffectiveDatatables.setup do |config|
28
28
  # Default class used on the <table> tag
29
29
  config.html_class = 'table table-hover'
30
30
 
31
- # When using the actions_column DSL method, apply the following behavior
32
- # Valid values for each action are:
33
- # true - display this action if authorized?(:show, Post)
34
- # false - do not display this action
35
- #
36
- # You can override these defaults on a per-table basis
37
- # by calling `actions_column(show: false, edit: true, destroy: false)`
38
- config.actions_column = {
39
- show: true,
40
- edit: true,
41
- destroy: true
42
- }
43
-
44
31
  # Log search/sort information to the console
45
32
  config.debug = true
46
33
 
@@ -9,7 +9,6 @@ module EffectiveDatatables
9
9
  mattr_accessor :default_length
10
10
  mattr_accessor :html_class
11
11
 
12
- mattr_accessor :actions_column # A Hash
13
12
  mattr_accessor :debug
14
13
 
15
14
  def self.setup
@@ -1,3 +1,3 @@
1
1
  module EffectiveDatatables
2
- VERSION = '4.2.0'.freeze
2
+ VERSION = '4.3.0'.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.2.0
4
+ version: 4.3.0
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: 2018-09-03 00:00:00.000000000 Z
11
+ date: 2018-09-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -109,7 +109,8 @@ files:
109
109
  - app/assets/javascripts/effective_datatables/events.js.coffee
110
110
  - app/assets/javascripts/effective_datatables/filters.js.coffee
111
111
  - app/assets/javascripts/effective_datatables/initialize.js.coffee
112
- - app/assets/javascripts/effective_datatables/overrides.js
112
+ - app/assets/javascripts/effective_datatables/inline_crud.js.coffee
113
+ - app/assets/javascripts/effective_datatables/overrides.js.coffee
113
114
  - app/assets/javascripts/effective_datatables/reset.js.coffee
114
115
  - app/assets/javascripts/effective_datatables/responsive.js.coffee
115
116
  - app/assets/javascripts/vendor/jquery.delayedChange.js
@@ -144,7 +145,6 @@ files:
144
145
  - app/models/effective/effective_datatable/params.rb
145
146
  - app/models/effective/effective_datatable/resource.rb
146
147
  - app/models/effective/effective_datatable/state.rb
147
- - app/views/effective/datatables/_actions_column.html.haml
148
148
  - app/views/effective/datatables/_bulk_actions_column.html.haml
149
149
  - app/views/effective/datatables/_bulk_actions_dropdown.html.haml
150
150
  - app/views/effective/datatables/_chart.html.haml
@@ -181,7 +181,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
181
181
  version: '0'
182
182
  requirements: []
183
183
  rubyforge_project:
184
- rubygems_version: 2.5.2.3
184
+ rubygems_version: 2.4.5.1
185
185
  signing_key:
186
186
  specification_version: 4
187
187
  summary: Uniquely powerful server-side searching, sorting and filtering of any ActiveRecord
@@ -1,12 +0,0 @@
1
- $.extend(true, $.fn.dataTable.Buttons.defaults, {
2
- dom: {
3
- button: {
4
- className: 'btn btn-link btn-sm'
5
- }
6
- }
7
- });
8
-
9
- /* Default class modification */
10
- $.extend($.fn.dataTable.ext.classes, {
11
- sWrapper: 'dataTables_wrapper dt-bootstrap4', // Remove container-fluid
12
- });
@@ -1 +0,0 @@
1
- = render_resource_actions(resource, **actions_col_locals)