effective_datatables 3.7.2 → 3.7.3

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: 4d5eaea728195f4aa7b178d88ecf9c09766c7a1649ec83b99d2bc40f8189ce65
4
- data.tar.gz: 22962b113d52aa1d0c6db01b9f818c6754c6d31c95fd78f6f7241f7549f2ac98
3
+ metadata.gz: 10c87c87d54529b6e4952b9abc58512f1ab9c2dc3e9f6d6e03c5ed141a388dd3
4
+ data.tar.gz: c2a7fd23d6f7790e6e083af1084e61f969793fe587ed9722811e6197a4516465
5
5
  SHA512:
6
- metadata.gz: ca7193b812467f8ac7a82338969b92ec0e115cb0aef92bb4b7debb84c3754db82958d9dc9b54af9141fb62271ae0a58a63ffa8c01c0edef6465aefd7f5642c62
7
- data.tar.gz: 340c24d9f3e9432bfd9c35fefb9873a262c1c0132c42bc21d000b38b2d7b38cfb294b5ad12a8ad7f6a0863d0395d7e19443d9f5e69805ada28451396fd4d687a
6
+ metadata.gz: 3bb3d7ab4f1ed0642f972bfdfd0828333b5149af4dc474fa1d9ecedb5a009ef20cd3ea2b29ab4bb71e8c7e85c7236edd4a22cce63503383acab3e40a25644407
7
+ data.tar.gz: 76b83708cb8b0d2cdd6f67c608a9892d473be9d0f58b29438c1d445015aedc3b2b345b027811cbb4957b1154d9a057e3ed8151bb28ae8dc7f7ad9066341c31a1
@@ -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-actions-resource']", (event) ->
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-all']").prop('checked', false)
7
- toggleClosestBulkActionsButton($wrapper)
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-all']", (event) ->
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-actions-resource']")
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
- toggleClosestBulkActionsButton($wrapper)
18
+ toggleDropdown($wrapper)
19
19
 
20
- toggleClosestBulkActionsButton = ($wrapper) ->
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-actions-resource']:checked").length > 0
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-actions-resource']:checked")
52
+ $selected = $table.find("input[data-role='bulk-action']:checked")
38
53
 
39
54
  url = $bulkAction.attr('href')
40
55
  title = $bulkAction.text()
41
- token = $bulkAction.parent('li').data('authenticity-token')
56
+ download = $bulkAction.data('bulk-download')
57
+ token = $table.data('authenticity-token')
42
58
  values = $.map($selected, (input) -> input.getAttribute('value'))
43
- get_link = $bulkAction.data('bulk-actions-get')
59
+ method = $bulkAction.data('ajax-method')
44
60
 
45
61
  return unless url && values
46
62
 
47
- if get_link
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
- # Show Processing...
59
- $processing.show().data('bulk-actions-processing', true)
74
+ $table.dataTable().data('bulk-actions-restore-selected-values', values)
60
75
 
61
- if token # This is a file download
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
- $processing.html(success)
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
- $processing.html(error)
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
- $.post(
79
- url, { ids: values }
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
- $processing.html(success)
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
- $processing.html(error)
86
- alert(error)
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('.search-label').first().text()
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('.search-label').first().text()
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('.search-label').first().text()
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[id^='filters_scope']:checked").val() || ''
67
+ params['scope'] = $form.find("input[name='filters[scope]']:checked").val() || ''
68
68
  params['filter'] = {}
69
69
 
70
- $form.find("[id^='filters_']:not(input[id^='filters_scope'])").each ->
70
+ $form.find("select,textarea,input:not([type=submit])").each ->
71
71
  $input = $(this)
72
- params['filter'][$input.attr('id').substring(8, $input.attr('id').length)] = $input.val()
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
@@ -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-all'
151
+ input_html[:data]['role'] = 'bulk-actions'
152
152
 
153
153
  form.input name, label: false, required: false, value: nil,
154
154
  as: :boolean,
@@ -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' }, onClick: 'event.stopPropagation();'
@@ -1,3 +1,3 @@
1
1
  module EffectiveDatatables
2
- VERSION = '3.7.2'.freeze
2
+ VERSION = '3.7.3'.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: 3.7.2
4
+ version: 3.7.3
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: 2019-09-23 00:00:00.000000000 Z
11
+ date: 2019-10-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails