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.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/app/assets/javascripts/dataTables/buttons/buttons.colVis.js +4 -8
- data/app/assets/javascripts/dataTables/buttons/buttons.html5.js +33 -19
- data/app/assets/javascripts/dataTables/buttons/buttons.print.js +14 -3
- data/app/assets/javascripts/dataTables/buttons/dataTables.buttons.js +128 -61
- data/app/assets/javascripts/dataTables/dataTables.bootstrap4.js +5 -5
- data/app/assets/javascripts/dataTables/jquery.dataTables.js +2078 -2025
- data/app/assets/javascripts/dataTables/responsive/dataTables.responsive.js +46 -22
- data/app/assets/javascripts/effective_datatables.js +1 -0
- data/app/assets/javascripts/effective_datatables/bulk_actions.js.coffee +40 -41
- data/app/assets/javascripts/effective_datatables/events.js.coffee +1 -1
- data/app/assets/javascripts/effective_datatables/filters.js.coffee +1 -1
- data/app/assets/javascripts/effective_datatables/initialize.js.coffee +11 -33
- data/app/assets/javascripts/effective_datatables/inline_crud.js.coffee +158 -0
- data/app/assets/javascripts/effective_datatables/overrides.js.coffee +40 -0
- data/app/assets/javascripts/effective_datatables/reset.js.coffee +1 -1
- data/app/assets/stylesheets/dataTables/dataTables.bootstrap4.css +5 -1
- data/app/assets/stylesheets/effective_datatables/_overrides.scss +47 -1
- data/app/helpers/effective_datatables_helper.rb +1 -0
- data/app/helpers/effective_datatables_private_helper.rb +10 -1
- data/app/models/effective/effective_datatable/dsl/bulk_actions.rb +11 -22
- data/app/models/effective/effective_datatable/dsl/datatable.rb +2 -1
- data/app/models/effective/effective_datatable/format.rb +15 -4
- data/app/views/effective/datatables/_bulk_actions_column.html.haml +1 -1
- data/config/effective_datatables.rb +0 -13
- data/lib/effective_datatables.rb +0 -1
- data/lib/effective_datatables/version.rb +1 -1
- metadata +5 -5
- data/app/assets/javascripts/effective_datatables/overrides.js +0 -12
- data/app/views/effective/datatables/_actions_column.html.haml +0 -1
@@ -1,15 +1,15 @@
|
|
1
|
-
/*! Responsive 2.2.
|
2
|
-
* 2014-
|
1
|
+
/*! Responsive 2.2.2
|
2
|
+
* 2014-2018 SpryMedia Ltd - datatables.net/license
|
3
3
|
*/
|
4
4
|
|
5
5
|
/**
|
6
6
|
* @summary Responsive
|
7
7
|
* @description Responsive tables plug-in for DataTables
|
8
|
-
* @version 2.2.
|
8
|
+
* @version 2.2.2
|
9
9
|
* @file dataTables.responsive.js
|
10
10
|
* @author SpryMedia Ltd (www.sprymedia.co.uk)
|
11
11
|
* @contact www.sprymedia.co.uk/contact
|
12
|
-
* @copyright Copyright 2014-
|
12
|
+
* @copyright Copyright 2014-2018 SpryMedia Ltd.
|
13
13
|
*
|
14
14
|
* This source file is free software, available under the following license:
|
15
15
|
* MIT license - http://datatables.net/license/mit
|
@@ -208,12 +208,21 @@ $.extend( Responsive.prototype, {
|
|
208
208
|
|
209
209
|
// DataTables will trigger this event on every column it shows and
|
210
210
|
// hides individually
|
211
|
-
dt.on( 'column-visibility.dtr', function (
|
212
|
-
|
211
|
+
dt.on( 'column-visibility.dtr', function () {
|
212
|
+
// Use a small debounce to allow multiple columns to be set together
|
213
|
+
if ( that._timer ) {
|
214
|
+
clearTimeout( that._timer );
|
215
|
+
}
|
216
|
+
|
217
|
+
that._timer = setTimeout( function () {
|
218
|
+
that._timer = null;
|
219
|
+
|
213
220
|
that._classLogic();
|
214
221
|
that._resizeAuto();
|
215
222
|
that._resize();
|
216
|
-
|
223
|
+
|
224
|
+
that._redrawChildren();
|
225
|
+
}, 100 );
|
217
226
|
} );
|
218
227
|
|
219
228
|
// Redraw the details box on each draw which will happen if the data
|
@@ -316,7 +325,10 @@ $.extend( Responsive.prototype, {
|
|
316
325
|
// Class logic - determine which columns are in this breakpoint based
|
317
326
|
// on the classes. If no class control (i.e. `auto`) then `-` is used
|
318
327
|
// to indicate this to the rest of the function
|
319
|
-
var display = $.map( columns, function ( col ) {
|
328
|
+
var display = $.map( columns, function ( col, i ) {
|
329
|
+
if ( dt.column(i).visible() === false ) {
|
330
|
+
return 'not-visible';
|
331
|
+
}
|
320
332
|
return col.auto && col.minWidth === null ?
|
321
333
|
false :
|
322
334
|
col.auto === true ?
|
@@ -384,7 +396,7 @@ $.extend( Responsive.prototype, {
|
|
384
396
|
var showControl = false;
|
385
397
|
|
386
398
|
for ( i=0, ien=columns.length ; i<ien ; i++ ) {
|
387
|
-
if ( ! columns[i].control && ! columns[i].never &&
|
399
|
+
if ( ! columns[i].control && ! columns[i].never && display[i] === false ) {
|
388
400
|
showControl = true;
|
389
401
|
break;
|
390
402
|
}
|
@@ -394,6 +406,11 @@ $.extend( Responsive.prototype, {
|
|
394
406
|
if ( columns[i].control ) {
|
395
407
|
display[i] = showControl;
|
396
408
|
}
|
409
|
+
|
410
|
+
// Replace not visible string with false from the control column detection above
|
411
|
+
if ( display[i] === 'not-visible' ) {
|
412
|
+
display[i] = false;
|
413
|
+
}
|
397
414
|
}
|
398
415
|
|
399
416
|
// Finally we need to make sure that there is at least one column that
|
@@ -758,7 +775,7 @@ $.extend( Responsive.prototype, {
|
|
758
775
|
// any columns that are not visible but can be shown
|
759
776
|
var collapsedClass = false;
|
760
777
|
for ( i=0, ien=columns.length ; i<ien ; i++ ) {
|
761
|
-
if ( columnsVis[i] === false && ! columns[i].never && ! columns[i].control ) {
|
778
|
+
if ( columnsVis[i] === false && ! columns[i].never && ! columns[i].control && ! dt.column(i).visible() === false ) {
|
762
779
|
collapsedClass = true;
|
763
780
|
break;
|
764
781
|
}
|
@@ -885,6 +902,10 @@ $.extend( Responsive.prototype, {
|
|
885
902
|
// clears the chcecked state of the original radio.
|
886
903
|
$( clonedTable ).find( '[name]' ).removeAttr( 'name' );
|
887
904
|
|
905
|
+
// A position absolute table would take the table out of the flow of
|
906
|
+
// our container element, bypassing the height and width (Scroller)
|
907
|
+
$( clonedTable ).css( 'position', 'relative' )
|
908
|
+
|
888
909
|
var inserted = $('<div/>')
|
889
910
|
.css( {
|
890
911
|
width: 1,
|
@@ -953,19 +974,22 @@ $.extend( Responsive.prototype, {
|
|
953
974
|
|
954
975
|
cells.filter( '[data-dtr-keyboard]' ).removeData( '[data-dtr-keyboard]' );
|
955
976
|
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
// This is a bit of a hack - we need to limit the selected nodes to just
|
961
|
-
// those of this table
|
962
|
-
if ( selector === 'td:first-child, th:first-child' ) {
|
963
|
-
selector = '>td:first-child, >th:first-child';
|
977
|
+
if ( typeof target === 'number' ) {
|
978
|
+
dt.cells( null, target, { page: 'current' } ).nodes().to$()
|
979
|
+
.attr( 'tabIndex', ctx.iTabIndex )
|
980
|
+
.data( 'dtr-keyboard', 1 );
|
964
981
|
}
|
982
|
+
else {
|
983
|
+
// This is a bit of a hack - we need to limit the selected nodes to just
|
984
|
+
// those of this table
|
985
|
+
if ( target === 'td:first-child, th:first-child' ) {
|
986
|
+
target = '>td:first-child, >th:first-child';
|
987
|
+
}
|
965
988
|
|
966
|
-
|
967
|
-
|
968
|
-
|
989
|
+
$( target, dt.rows( { page: 'current' } ).nodes() )
|
990
|
+
.attr( 'tabIndex', ctx.iTabIndex )
|
991
|
+
.data( 'dtr-keyboard', 1 );
|
992
|
+
}
|
969
993
|
}
|
970
994
|
} );
|
971
995
|
|
@@ -1338,7 +1362,7 @@ Api.registerPlural( 'columns().responsiveHidden()', 'column().responsiveHidden()
|
|
1338
1362
|
* @name Responsive.version
|
1339
1363
|
* @static
|
1340
1364
|
*/
|
1341
|
-
Responsive.version = '2.2.
|
1365
|
+
Responsive.version = '2.2.2';
|
1342
1366
|
|
1343
1367
|
|
1344
1368
|
$.fn.dataTable.Responsive = Responsive;
|
@@ -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/inline_crud
|
18
19
|
//= require effective_datatables/reset
|
19
20
|
//= require effective_datatables/responsive
|
20
21
|
//= require effective_datatables/overrides
|
@@ -1,50 +1,65 @@
|
|
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
|
token = $bulkAction.parent('li').data('authenticity-token')
|
42
57
|
values = $.map($selected, (input) -> input.getAttribute('value'))
|
43
|
-
|
58
|
+
method = $bulkAction.data('ajax-method')
|
44
59
|
|
45
60
|
return unless url && values
|
46
61
|
|
47
|
-
if
|
62
|
+
if method == 'GET'
|
48
63
|
if url.includes('?')
|
49
64
|
window.location.assign(url + '&' + $.param({ids: values}))
|
50
65
|
else
|
@@ -55,8 +70,7 @@ $(document).on 'click', '.buttons-bulk-actions a', (event) ->
|
|
55
70
|
# Disable the Bulk Actions dropdown, so only one can be run at a time
|
56
71
|
$bulkAction.closest('button').attr('disabled', 'disabled')
|
57
72
|
|
58
|
-
|
59
|
-
$processing.show().data('bulk-actions-processing', true)
|
73
|
+
$table.dataTable().data('bulk-actions-restore-selected-values', values)
|
60
74
|
|
61
75
|
if token # This is a file download
|
62
76
|
$.fileDownload(url,
|
@@ -64,43 +78,28 @@ $(document).on 'click', '.buttons-bulk-actions a', (event) ->
|
|
64
78
|
data: { ids: values, authenticity_token: token }
|
65
79
|
successCallback: ->
|
66
80
|
success = "Successfully completed #{title} bulk action"
|
67
|
-
$
|
68
|
-
$table.dataTable().data('bulk-actions-restore-selected-values', values)
|
81
|
+
$table.one 'draw.dt', (e) -> $(e.target).DataTable().flash(success)
|
69
82
|
$table.DataTable().draw()
|
70
83
|
failCallback: ->
|
71
84
|
error = "An error occured while attempting #{title} bulk action"
|
72
|
-
$
|
73
|
-
alert(error)
|
74
|
-
$table.dataTable().data('bulk-actions-restore-selected-values', values)
|
85
|
+
$table.one 'draw.dt', (e) -> $(e.target).DataTable().flash(error)
|
75
86
|
$table.DataTable().draw()
|
76
87
|
)
|
77
88
|
else # Normal AJAX post
|
78
|
-
|
79
|
-
|
89
|
+
$table.dataTable().data('bulk-actions-restore-selected-values', values)
|
90
|
+
|
91
|
+
$.ajax(
|
92
|
+
method: method,
|
93
|
+
url: url,
|
94
|
+
data: { ids: values }
|
80
95
|
).done((response) ->
|
81
96
|
success = response['message'] || "Successfully completed #{title} bulk action"
|
82
|
-
$
|
97
|
+
$table.one 'draw.dt', (e) -> $(e.target).DataTable().flash(success) and restoreSelected($(e.target), values)
|
98
|
+
|
83
99
|
).fail((response) ->
|
84
100
|
error = response['message'] || "An error occured while attempting #{title} bulk action: #{response.statusText}"
|
85
|
-
$
|
86
|
-
|
101
|
+
$table.one 'draw.dt', (e) -> $(e.target).DataTable().flash(error) and restoreSelected($(e.target), values)
|
102
|
+
|
87
103
|
).always((response) ->
|
88
|
-
$table.dataTable().data('bulk-actions-restore-selected-values', values)
|
89
104
|
$table.DataTable().draw()
|
90
105
|
)
|
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
|
-
)
|
@@ -14,7 +14,7 @@ $(document).on 'column-visibility.dt', (event, settings, index, state) ->
|
|
14
14
|
true
|
15
15
|
|
16
16
|
# Remove empty label (bulk actions) from ColVis dropdown
|
17
|
-
$(document).on 'click', 'a.buttons-colvis:not(.initialized)', (event) ->
|
17
|
+
$(document).on 'click', '.dataTables_wrapper a.buttons-colvis:not(.initialized)', (event) ->
|
18
18
|
$colvis = $('.dt-button-collection')
|
19
19
|
return if $colvis.length == 0
|
20
20
|
|
@@ -1,4 +1,4 @@
|
|
1
|
-
$(document).on 'click', 'a[data-apply-effective-datatables-filters]', (event) ->
|
1
|
+
$(document).on 'click', '.dataTables_wrapper a[data-apply-effective-datatables-filters]', (event) ->
|
2
2
|
event.preventDefault()
|
3
3
|
$form = $(event.currentTarget).closest('.effective-datatables-filters')
|
4
4
|
$table = $('#' + $form.attr('aria-controls'))
|
@@ -1,7 +1,5 @@
|
|
1
1
|
initializeDataTables = ->
|
2
|
-
$('table.effective-datatable').each ->
|
3
|
-
return if $.fn.DataTable.fnIsDataTable(this)
|
4
|
-
|
2
|
+
$('table.effective-datatable:not(.initialized)').each ->
|
5
3
|
datatable = $(this)
|
6
4
|
options = datatable.data('options') || {}
|
7
5
|
buttons_export_columns = options['buttons_export_columns'] || ':not(.col-actions)'
|
@@ -78,8 +76,7 @@ initializeDataTables = ->
|
|
78
76
|
scrollCollapse: true
|
79
77
|
pagingType: 'simple_numbers'
|
80
78
|
initComplete: (settings) ->
|
81
|
-
|
82
|
-
initializeBulkActions(this.api())
|
79
|
+
initializeButtons(this.api())
|
83
80
|
initializeSearch(this.api())
|
84
81
|
drawCallback: (settings) ->
|
85
82
|
$table = $(this.api().table().node())
|
@@ -95,36 +92,16 @@ initializeDataTables = ->
|
|
95
92
|
if settings['json']['charts']
|
96
93
|
drawCharts($table, settings['json']['charts'])
|
97
94
|
|
98
|
-
drawBulkActions($table)
|
99
|
-
|
100
95
|
# Copies the bulk actions html, stored in a data attribute on the table, into the buttons area
|
101
|
-
|
102
|
-
$table = $(api.table().node())
|
103
|
-
|
104
|
-
if $table.data('bulk-actions')
|
105
|
-
$table.closest('.dataTables_wrapper').children().first().find('.dt-buttons').prepend($table.data('bulk-actions'))
|
106
|
-
|
107
|
-
initializeReset = (api) ->
|
96
|
+
initializeButtons = (api) ->
|
108
97
|
$table = $(api.table().node())
|
98
|
+
$buttons = $table.closest('.dataTables_wrapper').children().first().find('.dt-buttons')
|
109
99
|
|
110
100
|
if $table.data('reset')
|
111
|
-
$
|
101
|
+
$buttons.prepend($table.data('reset'))
|
112
102
|
|
113
|
-
|
114
|
-
|
115
|
-
selected = $table.data('bulk-actions-restore-selected-values')
|
116
|
-
|
117
|
-
$bulkActions = $table.closest('.dataTables_wrapper').children().first().find('.buttons-bulk-actions').children('button')
|
118
|
-
|
119
|
-
if selected && selected.length > 0
|
120
|
-
$table.find("input[data-role='bulk-actions-resource']").each (_, input) ->
|
121
|
-
$input = $(input)
|
122
|
-
$input.prop('checked', selected.indexOf($input.val()) > -1)
|
123
|
-
|
124
|
-
$bulkActions.removeAttr('disabled')
|
125
|
-
$table.data('bulk-actions-restore-selected-values', [])
|
126
|
-
else
|
127
|
-
$bulkActions.attr('disabled', 'disabled')
|
103
|
+
if $table.data('bulk-actions')
|
104
|
+
$buttons.prepend($table.data('bulk-actions'))
|
128
105
|
|
129
106
|
drawAggregates = ($table, aggregates) ->
|
130
107
|
$tfoot = $table.find('tfoot').first()
|
@@ -187,10 +164,11 @@ initializeDataTables = ->
|
|
187
164
|
# Apply EffectiveFormInputs to the Show x per page dropdown
|
188
165
|
try table.closest('.dataTables_wrapper').find('.dataTables_length select').removeAttr('name').select2(minimumResultsForSearch: 100)
|
189
166
|
|
167
|
+
table.addClass('initialized')
|
168
|
+
|
190
169
|
destroyDataTables = ->
|
191
|
-
$('
|
192
|
-
|
193
|
-
$(this).DataTable().destroy()
|
170
|
+
$('.effective-datatables-inline-expanded').removeClass('effective-datatables-inline-expanded')
|
171
|
+
$('table.effective-datatable').each -> $(this).DataTable().turboDestroy()
|
194
172
|
|
195
173
|
$ -> initializeDataTables()
|
196
174
|
$(document).on 'page:change', -> initializeDataTables()
|
@@ -0,0 +1,158 @@
|
|
1
|
+
# To achieve inline crud, we use rails' data-remote links, and override their behaviour when inside a datatable
|
2
|
+
# This works with EffectiveForm.remote_form which is part of the effective_bootstrap gem.
|
3
|
+
|
4
|
+
# About to do a resource action, or fetch a partial. Show loading.
|
5
|
+
$(document).on 'ajax:beforeSend', '.dataTables_wrapper', (e) ->
|
6
|
+
$action = $(e.target)
|
7
|
+
|
8
|
+
if $action.closest('.effective-datatables-inline-row').length > 0
|
9
|
+
# Nothing. This is a save action from within the inline form.
|
10
|
+
else if $action.closest('tr').parent().prop('tagName') == 'THEAD'
|
11
|
+
beforeNew($action)
|
12
|
+
else
|
13
|
+
beforeEdit($action)
|
14
|
+
|
15
|
+
true
|
16
|
+
|
17
|
+
# We have either completed the resource action, or fetched the inline form to load.
|
18
|
+
$(document).on 'ajax:success', '.dataTables_wrapper', (e) ->
|
19
|
+
$action = $(e.target)
|
20
|
+
|
21
|
+
if ($action.data('method') || 'get') == 'get'
|
22
|
+
if $action.closest('tr').parent().prop('tagName') == 'THEAD' then afterNew($action) else afterEdit($action)
|
23
|
+
else
|
24
|
+
afterAction($action)
|
25
|
+
|
26
|
+
EffectiveForm.remote_form_payload = ''
|
27
|
+
EffectiveForm.remote_form_flash = ''
|
28
|
+
true
|
29
|
+
|
30
|
+
# The inline form has been submitted successfully
|
31
|
+
$(document).on '.dataTables_wrapper effective-form:success', (event, flash) ->
|
32
|
+
$tr = $(event.target).closest('tr')
|
33
|
+
$table = $tr.closest('table')
|
34
|
+
|
35
|
+
if $tr.hasClass('effective-datatables-new-resource')
|
36
|
+
$table.DataTable().flash(flash || 'Item created').draw()
|
37
|
+
$tr.fadeOut('slow')
|
38
|
+
|
39
|
+
$actions = $table.children('thead').find('th.col-actions')
|
40
|
+
$actions.children('svg').remove()
|
41
|
+
$actions.children('a').fadeIn()
|
42
|
+
else
|
43
|
+
$table.DataTable().flash(flash || 'Item updated').draw()
|
44
|
+
$tr.fadeOut('slow')
|
45
|
+
|
46
|
+
# There was an error completing something
|
47
|
+
$(document).on 'ajax:error', '.dataTables_wrapper', (e) ->
|
48
|
+
$action = $(e.target)
|
49
|
+
$table = $action.closest('table')
|
50
|
+
$table.DataTable().flash('Error: unable to ' + ($action.attr('title') || 'complete action')).draw()
|
51
|
+
|
52
|
+
beforeNew = ($action) ->
|
53
|
+
$table = $action.closest('table')
|
54
|
+
$th = $action.closest('th')
|
55
|
+
|
56
|
+
# Hide New Button
|
57
|
+
$th.children('a').hide()
|
58
|
+
|
59
|
+
# Append spinner and show Processing
|
60
|
+
$th.append($table.data('spinner'))
|
61
|
+
$table.DataTable().flash()
|
62
|
+
$table.one 'draw.dt', (event) -> $th.find('a').show().siblings('svg').remove()
|
63
|
+
|
64
|
+
afterNew = ($action) ->
|
65
|
+
$tr = $action.closest('tr')
|
66
|
+
$table = $tr.closest('table')
|
67
|
+
$action.siblings('svg').remove()
|
68
|
+
|
69
|
+
html = buildRow($tr.children('th').length, EffectiveForm.remote_form_payload)
|
70
|
+
|
71
|
+
$tr = $("<tr class='effective-datatables-inline-row effective-datatables-new-resource' role='row'>#{html}</tr>")
|
72
|
+
$table.children('tbody').prepend($tr)
|
73
|
+
|
74
|
+
expand($table)
|
75
|
+
$tr.find('form').attr('data-remote', true).trigger('effective-bootstrap:initialize')
|
76
|
+
$tr.hide().fadeIn()
|
77
|
+
|
78
|
+
beforeEdit = ($action) ->
|
79
|
+
$table = $action.closest('table')
|
80
|
+
$td = $action.closest('td')
|
81
|
+
|
82
|
+
# Hide dropdown
|
83
|
+
$td.find('.dropdown-toggle').dropdown('toggle')
|
84
|
+
$td.children('.btn-group').hide()
|
85
|
+
$td.children('a').hide()
|
86
|
+
|
87
|
+
# Append spinner and show Processing
|
88
|
+
$td.append($table.data('spinner'))
|
89
|
+
$table.DataTable().flash()
|
90
|
+
|
91
|
+
afterEdit = ($action) ->
|
92
|
+
$tr = $action.closest('tr')
|
93
|
+
$table = $tr.closest('table')
|
94
|
+
$tr.data('inline-form-original-html', $tr.html())
|
95
|
+
|
96
|
+
html = buildRow($tr.children('td').length, EffectiveForm.remote_form_payload)
|
97
|
+
|
98
|
+
$tr.html(html)
|
99
|
+
$tr.addClass('effective-datatables-inline-row')
|
100
|
+
|
101
|
+
expand($table)
|
102
|
+
$tr.find('form').attr('data-remote', true).trigger('effective-bootstrap:initialize')
|
103
|
+
$tr.hide().fadeIn()
|
104
|
+
|
105
|
+
# This is when one of the resource actions completes
|
106
|
+
afterAction = ($action) ->
|
107
|
+
$table = $action.closest('table')
|
108
|
+
$table.DataTable().flash('Successful ' + $action.attr('title')).draw()
|
109
|
+
|
110
|
+
buildRow = (length, payload) ->
|
111
|
+
"<td class='col-inline-form' colspan='#{length-1}'><div class='container'>#{payload}</div></td>" +
|
112
|
+
"<td class='col-actions col-actions-inline-form'>" +
|
113
|
+
"<a href='#' class='btn btn-outline-primary' title='Cancel' data-role='inline-form-cancel'>Cancel</a>" +
|
114
|
+
"</td>"
|
115
|
+
|
116
|
+
expand = ($table) ->
|
117
|
+
$wrapper = $table.closest('.dataTables_wrapper').addClass('effective-datatables-inline-expanded')
|
118
|
+
$table.one 'draw.dt', (event) -> $wrapper.removeClass('effective-datatables-inline-expanded')
|
119
|
+
|
120
|
+
cancel = ($table) ->
|
121
|
+
$wrapper = $table.closest('.dataTables_wrapper')
|
122
|
+
$wrapper.removeClass('effective-datatables-inline-expanded') if $wrapper.find('.effective-datatables-inline-row').length == 0
|
123
|
+
|
124
|
+
# Cancel button clicked. Blow away new tr, or restore edit tr
|
125
|
+
# No data will have changed at this point
|
126
|
+
$(document).on 'click', ".dataTables_wrapper a[data-role='inline-form-cancel']", (event) ->
|
127
|
+
$tr = $(event.currentTarget).closest('tr')
|
128
|
+
|
129
|
+
if $tr.hasClass('effective-datatables-new-resource')
|
130
|
+
$tr.fadeOut('slow', ->
|
131
|
+
$table = $(this).closest('table')
|
132
|
+
|
133
|
+
$actions = $table.children('thead').find('th.col-actions')
|
134
|
+
$actions.children('svg').remove()
|
135
|
+
$actions.children('a').fadeIn()
|
136
|
+
|
137
|
+
$(this).remove()
|
138
|
+
cancel($table)
|
139
|
+
)
|
140
|
+
else
|
141
|
+
$tr.fadeOut('slow', ->
|
142
|
+
$table = $(this).closest('table')
|
143
|
+
$tr.html($tr.data('inline-form-original-html'))
|
144
|
+
|
145
|
+
$td = $tr.children('.col-actions').first()
|
146
|
+
$td.children('svg').remove()
|
147
|
+
|
148
|
+
$td.find('.dropdown-toggle').dropdown('toggle')
|
149
|
+
$td.children('.btn-group').show()
|
150
|
+
$td.children('a').show()
|
151
|
+
|
152
|
+
$tr.removeClass('effective-datatables-inline-row').fadeIn()
|
153
|
+
cancel($table)
|
154
|
+
)
|
155
|
+
|
156
|
+
false
|
157
|
+
|
158
|
+
|