effective_datatables 2.6.0 → 2.6.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3c540b23d9f98ea45c144088577103ea0c495ea7
4
- data.tar.gz: a61e210447bb08fe4c40282a283c4c9881e8b5f9
3
+ metadata.gz: 3597f4d25da2086e8dc75eadb9b7357dcc8d6f07
4
+ data.tar.gz: 0d9d78236679a654433fd819c8048ca790648f40
5
5
  SHA512:
6
- metadata.gz: a179b5653c8b9f07dd3b08fb2631da06e6d6d249241e17826b700e9b1ffca7efc5cf9b36f80dea09de4651934e69220f51404743ac05c228fb7077a994d43b4d
7
- data.tar.gz: 225185be2373c71dd8142791a7ccf059f4e2cf1f508d3edbdb1e57143832a286b9a28f7e410143990a5446523608d1eeb4459bb7f2bc19e0ef883c6227fb86c9
6
+ metadata.gz: 9c12a4f93799e423db3c1e2c01de77cb8da0466b20bc058dccdefc09c60215142a76c315133250869705e186f228b46a57790d07be5c1c9bbee3eb359d03e5de
7
+ data.tar.gz: 9bbafa5c6a4932195877834860073c4a9b28b1d27ca7a14526cedeaccf6ffc0fe4e6b5cac9fd3ce966d21aa103fcfa9bc243a3e361fbe381f5e1e7590ffe20d3
@@ -1,22 +1,23 @@
1
1
  #### Checkbox toggling and Bulk Actions dropdown disabling
2
2
 
3
3
  $(document).on 'change', "input[data-role='bulk-actions-resource']", (event) ->
4
- $("input[data-role='bulk-actions-all']").prop('checked', false)
5
- toggleClosestBulkActionsButton($(event.currentTarget))
4
+ $wrapper = $(event.currentTarget).closest('.dataTables_wrapper')
5
+
6
+ $wrapper.find("input[data-role='bulk-actions-all']").prop('checked', false)
7
+ toggleClosestBulkActionsButton($wrapper)
6
8
 
7
9
  $(document).on 'change', "input[data-role='bulk-actions-all']", (event) ->
8
- $checkAll = $(event.currentTarget)
9
- $resources = $("input[data-role='bulk-actions-resource']")
10
+ $wrapper = $(event.currentTarget).closest('.dataTables_wrapper')
11
+ $resources = $wrapper.find("input[data-role='bulk-actions-resource']")
10
12
 
11
- if $checkAll.is(':checked')
13
+ if $(event.currentTarget).is(':checked')
12
14
  $resources.prop('checked', true)
13
15
  else
14
16
  $resources.prop('checked', false)
15
17
 
16
- toggleClosestBulkActionsButton($checkAll)
18
+ toggleClosestBulkActionsButton($wrapper)
17
19
 
18
- toggleClosestBulkActionsButton = (element) ->
19
- $wrapper = element.closest('.dataTables_wrapper')
20
+ toggleClosestBulkActionsButton = ($wrapper) ->
20
21
  $bulkActions = $wrapper.children().first().find('.buttons-bulk-actions').children('button')
21
22
 
22
23
  if $wrapper.find("input[data-role='bulk-actions-resource']:checked").length > 0
@@ -140,15 +140,14 @@ initializeDataTables = ->
140
140
  $input.parent().on 'mousedown', (event) -> event.stopPropagation() # Dont order columns when you click inside the input
141
141
 
142
142
  if $input.is('select')
143
- $input.on 'change', (event) -> dataTableSearch(event)
143
+ $input.on 'change', (event) -> dataTableSearch($(event.currentTarget))
144
144
  else if $input.is('input')
145
- $input.keyup($.debounce(300, dataTableSearch))
145
+ $input.delayedChange ($input) -> dataTableSearch($input)
146
146
 
147
147
  # Do the actual search
148
- dataTableSearch = (event) -> # This is the function called by a select or input to run the search
149
- obj = $(event.currentTarget)
150
- table = obj.closest('table.dataTable')
151
- table.DataTable().column("#{obj.data('column-name')}:name").search(obj.val()).draw()
148
+ dataTableSearch = ($input) -> # This is the function called by a select or input to run the search
149
+ table = $input.closest('table.dataTable')
150
+ table.DataTable().column("#{$input.data('column-name')}:name").search($input.val()).draw()
152
151
 
153
152
  if simple
154
153
  init_options['dom'] = "<'row'<'col-sm-12'tr>>" # Just show the table
@@ -1,4 +1,4 @@
1
- //= require vendor/jquery.debounce.min
1
+ //= require vendor/jquery.delayedChange
2
2
  //= require vendor/jszip.min
3
3
 
4
4
  //= require dataTables/jquery.dataTables.min
@@ -0,0 +1,38 @@
1
+ // http://stackoverflow.com/questions/7373023/throttle-event-calls-in-jquery
2
+
3
+ (function($) {
4
+ $.fn.delayedChange = function(options) {
5
+ var timer; var o;
6
+
7
+ if (jQuery.isFunction(options)) {
8
+ o = { onChange: options };
9
+ } else {
10
+ o = options;
11
+ }
12
+
13
+ o = $.extend({}, $.fn.delayedChange.defaultOptions, o);
14
+
15
+ return this.each(function() {
16
+ var element = $(this);
17
+ element.keyup(function() {
18
+ clearTimeout(timer);
19
+ timer = setTimeout(function() {
20
+ var newVal = element.val();
21
+ newVal = $.trim(newVal);
22
+ if (element.delayedChange.oldVal != newVal) {
23
+ element.delayedChange.oldVal = newVal;
24
+ o.onChange.call(this, element);
25
+ }
26
+ }, o.delay);
27
+ });
28
+ });
29
+ };
30
+
31
+ $.fn.delayedChange.defaultOptions = {
32
+ delay: 700,
33
+ onChange: function(element) { }
34
+ }
35
+
36
+ $.fn.delayedChange.oldVal = '';
37
+
38
+ })(jQuery);
@@ -77,13 +77,10 @@ module EffectiveDatatablesHelper
77
77
  bulk_actions_column = datatable.table_columns.find { |_, options| options[:bulk_actions_column] }.try(:second)
78
78
  return false unless bulk_actions_column
79
79
 
80
- # This sets content_for(:effective_datatables_bulk_actions) as per the 3 bulk_action methods below
81
- instance_exec(&bulk_actions_column[:dropdown_block]) if bulk_actions_column[:dropdown_block].respond_to?(:call)
82
-
83
80
  {
84
81
  dropdownHtml: render(
85
82
  partial: bulk_actions_column[:dropdown_partial],
86
- locals: HashWithIndifferentAccess.new(datatable: datatable).merge(bulk_actions_column[:partial_locals])
83
+ locals: { datatable: datatable, dropdown_block: bulk_actions_column[:dropdown_block] }.merge(bulk_actions_column[:partial_locals])
87
84
  )
88
85
  }.to_json()
89
86
  end
@@ -156,17 +153,4 @@ module EffectiveDatatablesHelper
156
153
  attributes[:active_admin_path] rescue false
157
154
  end
158
155
 
159
- ### Bulk Actions DSL Methods
160
- def bulk_action(*args)
161
- content_for(:effective_datatables_bulk_actions) { content_tag(:li, link_to(*args)) }
162
- end
163
-
164
- def bulk_action_divider
165
- content_for(:effective_datatables_bulk_actions) { content_tag(:li, '', class: 'divider', role: 'separator') }
166
- end
167
-
168
- def bulk_action_content(&block)
169
- content_for(:effective_datatables_bulk_actions) { block.call }
170
- end
171
-
172
156
  end
@@ -8,6 +8,7 @@ module Effective
8
8
  delegate :render, :controller, :link_to, :mail_to, :number_to_currency, :number_to_percentage, :to => :@view
9
9
 
10
10
  extend Effective::EffectiveDatatable::Dsl
11
+ include Effective::EffectiveDatatable::Dsl::BulkActions
11
12
  include Effective::EffectiveDatatable::Dsl::Charts
12
13
  include Effective::EffectiveDatatable::Dsl::Datatable
13
14
  include Effective::EffectiveDatatable::Dsl::Scopes
@@ -145,14 +146,18 @@ module Effective
145
146
  @view.class.send(:attr_accessor, :effective_datatable)
146
147
  @view.effective_datatable = self
147
148
 
148
- (self.class.instance_methods(false) - [:collection, :search_column, :order_column]).each do |view_method|
149
- @view.class_eval { delegate view_method, to: :@effective_datatable }
149
+ unless @view.respond_to?(:bulk_action)
150
+ @view.class.send(:include, Effective::EffectiveDatatable::Dsl::BulkActions)
150
151
  end
151
152
 
152
153
  Effective::EffectiveDatatable::Helpers.instance_methods(false).each do |helper_method|
153
154
  @view.class_eval { delegate helper_method, to: :@effective_datatable }
154
155
  end
155
156
 
157
+ (self.class.instance_methods(false) - [:collection, :search_column, :order_column]).each do |view_method|
158
+ @view.class_eval { delegate view_method, to: :@effective_datatable }
159
+ end
160
+
156
161
  # Clear the search_terms memoization
157
162
  @search_terms = nil
158
163
  @order_name = nil
@@ -0,0 +1,22 @@
1
+ module Effective
2
+ module EffectiveDatatable
3
+ module Dsl
4
+ module BulkActions
5
+ # These get added into the view as helpers
6
+ # To be called inside datatable { bulk_actions_column do .. end }
7
+ def bulk_action(*args)
8
+ concat content_tag(:li, link_to(*args))
9
+ end
10
+
11
+ def bulk_action_divider
12
+ concat content_tag(:li, '', class: 'divider', role: 'separator')
13
+ end
14
+
15
+ def bulk_action_content(&block)
16
+ concat block.call
17
+ end
18
+
19
+ end
20
+ end
21
+ end
22
+ end
@@ -3,8 +3,9 @@
3
3
  Bulk Actions
4
4
  %span.caret
5
5
  %ul.dropdown-menu
6
- - if content_for?(:effective_datatables_bulk_actions)
7
- = yield :effective_datatables_bulk_actions
6
+ - if dropdown_block.respond_to?(:call)
7
+ = capture do
8
+ - instance_exec(&dropdown_block)
8
9
  - else
9
10
  %li
10
11
  %a{href: '#'} No bulk actions
@@ -1,3 +1,3 @@
1
1
  module EffectiveDatatables
2
- VERSION = '2.6.0'.freeze
2
+ VERSION = '2.6.1'.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: 2.6.0
4
+ version: 2.6.1
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: 2016-06-24 00:00:00.000000000 Z
11
+ date: 2016-07-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -125,7 +125,7 @@ files:
125
125
  - app/assets/javascripts/effective_datatables/initialize.js.coffee
126
126
  - app/assets/javascripts/effective_datatables/responsive.js.coffee
127
127
  - app/assets/javascripts/effective_datatables/scopes.js.coffee
128
- - app/assets/javascripts/vendor/jquery.debounce.min.js
128
+ - app/assets/javascripts/vendor/jquery.delayedChange.js
129
129
  - app/assets/javascripts/vendor/jszip.min.js
130
130
  - app/assets/stylesheets/dataTables/buttons/buttons.bootstrap.min.css
131
131
  - app/assets/stylesheets/dataTables/buttons/buttons.dataTables.min.css
@@ -146,6 +146,7 @@ files:
146
146
  - app/models/effective/effective_datatable/ajax.rb
147
147
  - app/models/effective/effective_datatable/charts.rb
148
148
  - app/models/effective/effective_datatable/dsl.rb
149
+ - app/models/effective/effective_datatable/dsl/bulk_actions.rb
149
150
  - app/models/effective/effective_datatable/dsl/charts.rb
150
151
  - app/models/effective/effective_datatable/dsl/datatable.rb
151
152
  - app/models/effective/effective_datatable/dsl/scopes.rb
@@ -1,9 +0,0 @@
1
- /*
2
- * jQuery throttle / debounce - v1.1 - 3/7/2010
3
- * http://benalman.com/projects/jquery-throttle-debounce-plugin/
4
- *
5
- * Copyright (c) 2010 "Cowboy" Ben Alman
6
- * Dual licensed under the MIT and GPL licenses.
7
- * http://benalman.com/about/license/
8
- */
9
- (function(b,c){var $=b.jQuery||b.Cowboy||(b.Cowboy={}),a;$.throttle=a=function(e,f,j,i){var h,d=0;if(typeof f!=="boolean"){i=j;j=f;f=c}function g(){var o=this,m=+new Date()-d,n=arguments;function l(){d=+new Date();j.apply(o,n)}function k(){h=c}if(i&&!h){l()}h&&clearTimeout(h);if(i===c&&m>e){l()}else{if(f!==true){h=setTimeout(i?k:l,i===c?e-m:e)}}}if($.guid){g.guid=j.guid=j.guid||$.guid++}return g};$.debounce=function(d,e,f){return f===c?a(d,e,false):a(d,f,e!==false)}})(this);