effective_datatables 3.7.1 → 3.7.7
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/app/assets/javascripts/effective_datatables.js +1 -0
- data/app/assets/javascripts/effective_datatables/bulk_actions.js.coffee +43 -43
- data/app/assets/javascripts/effective_datatables/initialize.js.coffee +18 -6
- data/app/helpers/effective_datatables_private_helper.rb +10 -7
- data/app/models/effective/datatable_value_tool.rb +3 -3
- data/app/models/effective/effective_datatable/format.rb +5 -5
- data/app/views/effective/datatables/_bulk_actions_column.html.haml +1 -1
- data/config/effective_datatables.rb +4 -0
- data/lib/effective_datatables.rb +4 -0
- data/lib/effective_datatables/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 173590e66ff34a72a7aaed989391a718e25eaca196fae4981f295bf4a73a6bf0
|
4
|
+
data.tar.gz: 8330bb5487288950f107f6dc79dedde2b2298e77c059d98bdf4d7f095ca8c353
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 242e5bf78a1f1aef37f3864e76d8cf90e98141a84ff4408b9fb5fed72a51115c15a5d19ca1fa79a692401ff6abc29d1f40dae4d781f217add15509f09217c810
|
7
|
+
data.tar.gz: 569226fd1c6c32e498efc9ee7728a070f971d54ee10ef353777712a7ccf891337d2061cbceec3366a5d627daa84841eb8a70bea3a81ee32a2e1fdc9c03809576
|
@@ -15,6 +15,7 @@
|
|
15
15
|
//= require effective_datatables/bulk_actions
|
16
16
|
//= require effective_datatables/events
|
17
17
|
//= require effective_datatables/filters
|
18
|
+
//= require effective_datatables/flash
|
18
19
|
//= require effective_datatables/reset
|
19
20
|
//= require effective_datatables/responsive
|
20
21
|
|
@@ -1,50 +1,66 @@
|
|
1
1
|
#### Checkbox toggling and Bulk Actions dropdown disabling
|
2
2
|
|
3
|
-
$(document).on 'change', "input[data-role='bulk-
|
3
|
+
$(document).on 'change', ".dataTables_wrapper input[data-role='bulk-action']", (event) ->
|
4
4
|
$wrapper = $(event.currentTarget).closest('.dataTables_wrapper')
|
5
5
|
|
6
|
-
$wrapper.find("input[data-role='bulk-actions
|
7
|
-
|
6
|
+
$wrapper.find("input[data-role='bulk-actions']").prop('checked', false)
|
7
|
+
toggleDropdown($wrapper)
|
8
8
|
|
9
|
-
$(document).on 'change', "input[data-role='bulk-actions
|
9
|
+
$(document).on 'change', ".dataTables_wrapper input[data-role='bulk-actions']", (event) ->
|
10
10
|
$wrapper = $(event.currentTarget).closest('.dataTables_wrapper')
|
11
|
-
$resources = $wrapper.find("input[data-role='bulk-
|
11
|
+
$resources = $wrapper.find("input[data-role='bulk-action']")
|
12
12
|
|
13
13
|
if $(event.currentTarget).is(':checked')
|
14
14
|
$resources.prop('checked', true)
|
15
15
|
else
|
16
16
|
$resources.prop('checked', false)
|
17
17
|
|
18
|
-
|
18
|
+
toggleDropdown($wrapper)
|
19
19
|
|
20
|
-
|
20
|
+
toggleDropdown = ($wrapper) ->
|
21
21
|
$bulkActions = $wrapper.children().first().find('.buttons-bulk-actions').children('button')
|
22
22
|
|
23
|
-
if $wrapper.find("input[data-role='bulk-
|
23
|
+
if $wrapper.find("input[data-role='bulk-action']:checked").length > 0
|
24
24
|
$bulkActions.removeAttr('disabled')
|
25
25
|
else
|
26
26
|
$bulkActions.attr('disabled', 'disabled')
|
27
27
|
|
28
|
+
restoreSelected = ($table, selected) ->
|
29
|
+
$bulkActions = $table.closest('.dataTables_wrapper').children().first().find('.buttons-bulk-actions').children('button')
|
30
|
+
present = false
|
31
|
+
|
32
|
+
if selected && selected.length > 0
|
33
|
+
$table.find("input[data-role='bulk-action']").each (_, input) ->
|
34
|
+
$input = $(input)
|
35
|
+
|
36
|
+
if selected.indexOf($input.val()) > -1
|
37
|
+
$input.prop('checked', true)
|
38
|
+
present = true
|
39
|
+
else
|
40
|
+
$input.prop('checked', false)
|
41
|
+
|
42
|
+
if present then $bulkActions.removeAttr('disabled') else $bulkActions.attr('disabled', 'disabled')
|
28
43
|
|
29
44
|
#### Bulk Action link behaviour
|
30
|
-
$(document).on 'click', '.buttons-bulk-actions a', (event) ->
|
45
|
+
$(document).on 'click', '.dataTables_wrapper .buttons-bulk-actions a', (event) ->
|
31
46
|
event.preventDefault() # prevent the click
|
32
47
|
|
33
48
|
$bulkAction = $(event.currentTarget) # This is a regular <a href=...> tag
|
34
49
|
$wrapper = $bulkAction.closest('.dataTables_wrapper')
|
35
50
|
$table = $wrapper.find('table.dataTable').first()
|
36
51
|
$processing = $table.siblings('.dataTables_processing').first()
|
37
|
-
$selected = $table.find("input[data-role='bulk-
|
52
|
+
$selected = $table.find("input[data-role='bulk-action']:checked")
|
38
53
|
|
39
54
|
url = $bulkAction.attr('href')
|
40
55
|
title = $bulkAction.text()
|
41
|
-
|
56
|
+
download = $bulkAction.data('bulk-download')
|
57
|
+
token = $table.data('authenticity-token')
|
42
58
|
values = $.map($selected, (input) -> input.getAttribute('value'))
|
43
|
-
|
59
|
+
method = $bulkAction.data('ajax-method')
|
44
60
|
|
45
61
|
return unless url && values
|
46
62
|
|
47
|
-
if
|
63
|
+
if method == 'GET'
|
48
64
|
if url.includes('?')
|
49
65
|
window.location.assign(url + '&' + $.param({ids: values}))
|
50
66
|
else
|
@@ -55,52 +71,36 @@ $(document).on 'click', '.buttons-bulk-actions a', (event) ->
|
|
55
71
|
# Disable the Bulk Actions dropdown, so only one can be run at a time
|
56
72
|
$bulkAction.closest('button').attr('disabled', 'disabled')
|
57
73
|
|
58
|
-
|
59
|
-
$processing.show().data('bulk-actions-processing', true)
|
74
|
+
$table.dataTable().data('bulk-actions-restore-selected-values', values)
|
60
75
|
|
61
|
-
if
|
76
|
+
if download # This is a file download
|
62
77
|
$.fileDownload(url,
|
63
78
|
httpMethod: 'POST',
|
64
79
|
data: { ids: values, authenticity_token: token }
|
65
80
|
successCallback: ->
|
66
81
|
success = "Successfully completed #{title} bulk action"
|
67
|
-
$
|
68
|
-
$table.dataTable().data('bulk-actions-restore-selected-values', values)
|
82
|
+
$table.one 'draw.dt', (e) -> $(e.target).DataTable().flash(success, 'success') and restoreSelected($(e.target), values)
|
69
83
|
$table.DataTable().draw()
|
70
84
|
failCallback: ->
|
71
85
|
error = "An error occured while attempting #{title} bulk action"
|
72
|
-
$
|
73
|
-
alert(error)
|
74
|
-
$table.dataTable().data('bulk-actions-restore-selected-values', values)
|
86
|
+
$table.one 'draw.dt', (e) -> $(e.target).DataTable().flash(error, 'danger') and restoreSelected($(e.target), values)
|
75
87
|
$table.DataTable().draw()
|
76
88
|
)
|
77
89
|
else # Normal AJAX post
|
78
|
-
|
79
|
-
|
90
|
+
$table.dataTable().data('bulk-actions-restore-selected-values', values)
|
91
|
+
|
92
|
+
$.ajax(
|
93
|
+
method: method,
|
94
|
+
url: url,
|
95
|
+
data: { ids: values, authenticity_token: token }
|
80
96
|
).done((response) ->
|
81
97
|
success = response['message'] || "Successfully completed #{title} bulk action"
|
82
|
-
$
|
98
|
+
$table.one 'draw.dt', (e) -> $(e.target).DataTable().flash(success, 'success') and restoreSelected($(e.target), values)
|
99
|
+
|
83
100
|
).fail((response) ->
|
84
101
|
error = response['message'] || "An error occured while attempting #{title} bulk action: #{response.statusText}"
|
85
|
-
$
|
86
|
-
|
102
|
+
$table.one 'draw.dt', (e) -> $(e.target).DataTable().flash(error, 'danger') and restoreSelected($(e.target), values)
|
103
|
+
|
87
104
|
).always((response) ->
|
88
|
-
$table.dataTable().data('bulk-actions-restore-selected-values', values)
|
89
105
|
$table.DataTable().draw()
|
90
106
|
)
|
91
|
-
|
92
|
-
# We borrow the Processing div for our bulk action success/error messages
|
93
|
-
# This makes sure that the message is displayed for 1500ms
|
94
|
-
$(document).on 'processing.dt', (event, settings, visible) ->
|
95
|
-
return if settings.bDestroying
|
96
|
-
|
97
|
-
$processing = $(event.target).siblings('.dataTables_processing').first()
|
98
|
-
return unless $processing.data('bulk-actions-processing')
|
99
|
-
|
100
|
-
timeout = $processing.show().data('timeout')
|
101
|
-
clearTimeout(timeout) if timeout
|
102
|
-
$processing.data('timeout', setTimeout( =>
|
103
|
-
$processing.html('Processing...').hide()
|
104
|
-
$processing.data('bulk-actions-processing', null)
|
105
|
-
, 1500)
|
106
|
-
)
|
@@ -24,14 +24,14 @@ initializeDataTables = (target) ->
|
|
24
24
|
extend: 'copy',
|
25
25
|
exportOptions:
|
26
26
|
format:
|
27
|
-
header: (str) -> $("<div>#{str}</div>").children('
|
27
|
+
header: (str) -> $("<div>#{str}</div>").children('span').first().text()
|
28
28
|
columns: buttons_export_columns
|
29
29
|
},
|
30
30
|
{
|
31
31
|
extend: 'csv',
|
32
32
|
exportOptions:
|
33
33
|
format:
|
34
|
-
header: (str) -> $("<div>#{str}</div>").children('
|
34
|
+
header: (str) -> $("<div>#{str}</div>").children('span').first().text()
|
35
35
|
columns: buttons_export_columns
|
36
36
|
},
|
37
37
|
{
|
@@ -39,7 +39,7 @@ initializeDataTables = (target) ->
|
|
39
39
|
footer: true,
|
40
40
|
exportOptions:
|
41
41
|
format:
|
42
|
-
header: (str) -> $("<div>#{str}</div>").children('
|
42
|
+
header: (str) -> $("<div>#{str}</div>").children('span').first().text()
|
43
43
|
columns: ':visible:not(.col-actions)'
|
44
44
|
},
|
45
45
|
]
|
@@ -64,12 +64,23 @@ initializeDataTables = (target) ->
|
|
64
64
|
params['authenticity_token'] = $table.data('authenticity-token')
|
65
65
|
|
66
66
|
if $form.length > 0
|
67
|
-
params['scope'] = $form.find("input[
|
67
|
+
params['scope'] = $form.find("input[name='filters[scope]']:checked").val() || ''
|
68
68
|
params['filter'] = {}
|
69
69
|
|
70
|
-
$form.find("
|
70
|
+
$form.find("select,textarea,input:not([type=submit])").each ->
|
71
71
|
$input = $(this)
|
72
|
-
|
72
|
+
|
73
|
+
if ['utf8', 'authenticity_token', 'filters[scope]'].includes($input.attr('name'))
|
74
|
+
# Skipped
|
75
|
+
else if $input.attr('type') == 'radio'
|
76
|
+
name = $input.attr('name')
|
77
|
+
filter_name = name.replace('filters[', '').substring(0, name.length-9)
|
78
|
+
|
79
|
+
params['filter'][filter_name] = $form.find("input[name='#{name}']:checked").val()
|
80
|
+
|
81
|
+
else if $input.attr('id')
|
82
|
+
filter_name = $input.attr('id').replace('filters_', '')
|
83
|
+
params['filter'][filter_name] = $input.val()
|
73
84
|
|
74
85
|
serverSide: true
|
75
86
|
scrollCollapse: true
|
@@ -145,6 +156,7 @@ initializeDataTables = (target) ->
|
|
145
156
|
|
146
157
|
$input.parent().on 'click', (event) -> false # Dont order columns when you click inside the input
|
147
158
|
$input.parent().on 'mousedown', (event) -> event.stopPropagation() # Dont order columns when you click inside the input
|
159
|
+
$input.parent().on 'keypress', (event) -> event.stopPropagation() # Don't order columns when you type inside the input
|
148
160
|
|
149
161
|
if $input.is('select')
|
150
162
|
$input.on 'change', (event) -> dataTableSearch($(event.currentTarget))
|
@@ -48,8 +48,8 @@ module EffectiveDatatablesPrivateHelper
|
|
48
48
|
action = action.merge(column[:actions][:new])
|
49
49
|
|
50
50
|
effective_resource = (datatable.effective_resource || datatable.fallback_effective_resource)
|
51
|
-
klass = (column[:actions][:new][:klass] || effective_resource
|
52
|
-
elsif Array(datatable.effective_resource
|
51
|
+
klass = (column[:actions][:new][:klass] || effective_resource.try(:klass) || datatable.collection_class)
|
52
|
+
elsif Array(datatable.effective_resource.try(:actions)).include?(:new)
|
53
53
|
effective_resource = datatable.effective_resource
|
54
54
|
klass = effective_resource.klass
|
55
55
|
else
|
@@ -148,7 +148,7 @@ module EffectiveDatatablesPrivateHelper
|
|
148
148
|
input_html: input_html,
|
149
149
|
input_js: { placeholder: placeholder }
|
150
150
|
when :bulk_actions
|
151
|
-
input_html[:data]['role'] = 'bulk-actions
|
151
|
+
input_html[:data]['role'] = 'bulk-actions'
|
152
152
|
|
153
153
|
form.input name, label: false, required: false, value: nil,
|
154
154
|
as: :boolean,
|
@@ -176,15 +176,15 @@ module EffectiveDatatablesPrivateHelper
|
|
176
176
|
collection = opts[:collection]
|
177
177
|
input_html = opts[:input_html] || {}
|
178
178
|
|
179
|
-
|
179
|
+
attributes = {
|
180
180
|
value: value,
|
181
181
|
selected: value,
|
182
182
|
as: as,
|
183
183
|
collection: collection,
|
184
184
|
label: opts[:label],
|
185
|
-
required: input_html.delete(:required),
|
186
|
-
multiple: input_html.delete(:multiple),
|
187
|
-
include_blank: input_html.delete(:include_blank),
|
185
|
+
required: input_html.delete(:required) || opts[:required],
|
186
|
+
multiple: input_html.delete(:multiple) || opts[:multiple],
|
187
|
+
include_blank: input_html.delete(:include_blank) || opts[:include_blank],
|
188
188
|
group_method: input_html.delete(:group_method),
|
189
189
|
group_label_method: input_html.delete(:group_label_method),
|
190
190
|
value_method: input_html.delete(:value_method),
|
@@ -192,6 +192,9 @@ module EffectiveDatatablesPrivateHelper
|
|
192
192
|
input_html: (({name: ''} unless datatable._filters_form_required?) || {}).merge(input_html),
|
193
193
|
input_js: ({ placeholder: ''} if as == :effective_select),
|
194
194
|
wrapper_html: {class: 'form-group-sm'}
|
195
|
+
}.compact
|
196
|
+
|
197
|
+
form.input name, **attributes
|
195
198
|
end
|
196
199
|
|
197
200
|
def datatable_scope_tag(form, datatable, opts = {})
|
@@ -94,10 +94,10 @@ module Effective
|
|
94
94
|
|
95
95
|
case column[:as]
|
96
96
|
when :boolean
|
97
|
-
if
|
98
|
-
|
97
|
+
if term
|
98
|
+
['Yes', 'yes', true, 'true', '1'].include?(value)
|
99
99
|
else
|
100
|
-
|
100
|
+
['No', 'no', false, 'false', '0'].include?(value)
|
101
101
|
end
|
102
102
|
when :datetime, :date
|
103
103
|
end_at = (
|
@@ -88,9 +88,9 @@ module Effective
|
|
88
88
|
when :currency
|
89
89
|
view.number_to_currency(value)
|
90
90
|
when :date
|
91
|
-
(value.strftime(
|
91
|
+
value.respond_to?(:strftime) ? value.strftime(EffectiveDatatables.format_date) : BLANK
|
92
92
|
when :datetime
|
93
|
-
(value.strftime(
|
93
|
+
value.respond_to?(:strftime) ? value.strftime(EffectiveDatatables.format_datetime) : BLANK
|
94
94
|
when :decimal
|
95
95
|
value
|
96
96
|
when :duration
|
@@ -116,7 +116,7 @@ module Effective
|
|
116
116
|
when Numeric ; view.number_to_currency(value)
|
117
117
|
end
|
118
118
|
when :time
|
119
|
-
(value.strftime(
|
119
|
+
value.respond_to?(:strftime) ? value.strftime(EffectiveDatatables.format_time) : BLANK
|
120
120
|
else
|
121
121
|
value.to_s
|
122
122
|
end
|
@@ -126,7 +126,7 @@ module Effective
|
|
126
126
|
# Applies data-remote to anything that's data-method post or delete
|
127
127
|
# Merges in any extra attributes when passed as a Hash
|
128
128
|
def actions_col_actions(column)
|
129
|
-
resource_actions = (effective_resource
|
129
|
+
resource_actions = (effective_resource.try(:resource_actions) || fallback_effective_resource.fallback_resource_actions)
|
130
130
|
|
131
131
|
actions = if column[:inline]
|
132
132
|
resource_actions.transform_values { |opts| opts['data-remote'] = true; opts }
|
@@ -139,7 +139,7 @@ module Effective
|
|
139
139
|
column[:actions].each do |action, opts|
|
140
140
|
next unless opts.kind_of?(Hash)
|
141
141
|
|
142
|
-
existing = actions.find { |_, v| v[:action] == action }
|
142
|
+
existing = actions.find { |_, v| v[:action] == action }.try(:first)
|
143
143
|
next unless existing.present?
|
144
144
|
|
145
145
|
actions[existing]['data-remote'] = opts[:remote] if opts.key?(:remote)
|
@@ -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-
|
2
|
+
= check_box_tag 'bulk_actions_resources[]', id, false, autocomplete: 'off', id: "datatable_bulk_actions_resource_#{id}", data: { role: 'bulk-action' }, onClick: 'event.stopPropagation();'
|
@@ -39,4 +39,8 @@ EffectiveDatatables.setup do |config|
|
|
39
39
|
config.cookie_domain = :all # Should usually be :all
|
40
40
|
config.cookie_tld_length = nil # Leave nil to autodetect, or set to probably 2
|
41
41
|
|
42
|
+
# Date formatting
|
43
|
+
config.format_datetime = '%F %H:%M'
|
44
|
+
config.format_date = '%F'
|
45
|
+
config.format_time = '%H:%M'
|
42
46
|
end
|
data/lib/effective_datatables.rb
CHANGED
@@ -16,6 +16,10 @@ module EffectiveDatatables
|
|
16
16
|
mattr_accessor :cookie_domain
|
17
17
|
mattr_accessor :cookie_tld_length
|
18
18
|
|
19
|
+
mattr_accessor :format_datetime
|
20
|
+
mattr_accessor :format_date
|
21
|
+
mattr_accessor :format_time
|
22
|
+
|
19
23
|
mattr_accessor :debug
|
20
24
|
|
21
25
|
alias_method :max_cookie_size, :cookie_max_size
|
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: 3.7.
|
4
|
+
version: 3.7.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-10-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -176,7 +176,7 @@ homepage: https://github.com/code-and-effect/effective_datatables
|
|
176
176
|
licenses:
|
177
177
|
- MIT
|
178
178
|
metadata: {}
|
179
|
-
post_install_message:
|
179
|
+
post_install_message:
|
180
180
|
rdoc_options: []
|
181
181
|
require_paths:
|
182
182
|
- lib
|
@@ -191,8 +191,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
191
191
|
- !ruby/object:Gem::Version
|
192
192
|
version: '0'
|
193
193
|
requirements: []
|
194
|
-
rubygems_version: 3.
|
195
|
-
signing_key:
|
194
|
+
rubygems_version: 3.1.4
|
195
|
+
signing_key:
|
196
196
|
specification_version: 4
|
197
197
|
summary: Uniquely powerful server-side searching, sorting and filtering of any ActiveRecord
|
198
198
|
or Array collection as well as post-rendered content displayed as a frontend jQuery
|