effective_datatables 4.4.5 → 4.4.6

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
  SHA1:
3
- metadata.gz: 158ddf59a09940c2dee6187aa2e206104f8552e8
4
- data.tar.gz: ea19c893a0e184003d5f60007a171efd07417003
3
+ metadata.gz: 06f51c05dbf844ec08e797fc26723a9e680b7b01
4
+ data.tar.gz: f1c9c9e23fb8199df78cf2d5059d4d520fe42c77
5
5
  SHA512:
6
- metadata.gz: 86fe5b9307c518671509dce63bdc6e4b9e99c9a6af22fb992aca3eeee61fba645f3028f1d89702ae0578ae0961dab091b15758e8f81c61c29a9b611ba4b2f86f
7
- data.tar.gz: c775b5445a7a328e04b48c24ca6bf9fc2da86c6fdc7cf0860d6dd69d75379e200f5d104085a7a6c9256ba96041e9c322971e1669db61315c86691efd9c9db94e
6
+ metadata.gz: c0fc7e3f321ebb3c873ecdba4d4cba89d2590a449b5591ed42a7ac3a72a937e87d40c3f33ba00baac6d1221538aee48964ac9f9d1af3e9397ea8188b8f530874
7
+ data.tar.gz: 098d5a6eee6e134b024c9fd7ec588353071f0b94a4a7c7b62cfdb26e0f8cf03b40bbe7b7de67e753f5915b3c8bcd9e08b4eb5ff27d6eaaf2c46d7185eb8ef3bc
@@ -68,10 +68,20 @@ initializeDataTables = (target) ->
68
68
  params['scope'] = $form.find("input[name='filters[scope]']:checked").val() || ''
69
69
  params['filter'] = {}
70
70
 
71
- $form.find("select,textarea,input:not([type=submit]):not([name='filters[scope]'])").each ->
71
+ $form.find("select,textarea,input:not([type=submit])").each ->
72
72
  $input = $(this)
73
- if $input.attr('id')
74
- params['filter'][$input.attr('id').substring(8, $input.attr('id').length)] = $input.val()
73
+
74
+ if ['utf8', 'authenticity_token', 'filters[scope]'].includes($input.attr('name'))
75
+ # Skipped
76
+ else if $input.attr('type') == 'radio'
77
+ name = $input.attr('name')
78
+ filter_name = name.replace('filters[', '').substring(0, name.length-9)
79
+
80
+ params['filter'][filter_name] = $form.find("input[name='#{name}']:checked").val()
81
+
82
+ else if $input.attr('id')
83
+ filter_name = $input.attr('id').replace('filters_', '')
84
+ params['filter'][filter_name] = $input.val()
75
85
 
76
86
  serverSide: true
77
87
  scrollCollapse: true
@@ -114,44 +114,40 @@ module EffectiveDatatablesPrivateHelper
114
114
  end
115
115
 
116
116
  def datatable_filter_tag(form, datatable, name, opts)
117
- placeholder = opts.delete(:label)
118
-
117
+ as = opts.delete(:as).to_s.chomp('_field').to_sym
119
118
  collection = opts.delete(:collection)
120
119
  value = datatable.state[:filter][name]
121
120
 
122
- options = opts.except(:parse).merge(
121
+ options = {
123
122
  autocomplete: 'off',
124
123
  feedback: false,
125
124
  label: false,
126
- placeholder: placeholder,
125
+ placeholder: (opts[:label] || name.to_s.titleize),
127
126
  value: value,
128
127
  wrapper: { class: 'form-group col-auto'}
129
- )
128
+ }.merge(opts.except(:parse))
130
129
 
131
130
  options[:name] = '' unless datatable._filters_form_required?
132
131
 
133
- case options.delete(:as)
134
- when :date
135
- form.date_field name, options
136
- when :datetime
137
- form.datetime_field name, options
138
- when :time
139
- form.time_field name, options
140
- when :select, :boolean
141
- options[:input_js] = (options[:input_js] || {}).reverse_merge(placeholder: placeholder)
142
- form.select name, collection, options
132
+ if collection.present?
133
+ options.delete(:name) unless as == :select
134
+ form.public_send(as, name, collection, options) # select, radios, checks
135
+ elsif form.respond_to?(as)
136
+ form.public_send(as, name, options) # check_box, text_area
143
137
  else
144
- form.text_field name, options
138
+ form.public_send("#{as}_field", name, options) # text_field, number_field, all the rest.
145
139
  end
140
+
146
141
  end
147
142
 
148
143
  def datatable_scope_tag(form, datatable, opts = {})
149
144
  collection = datatable._scopes.map { |name, opts| [opts[:label], name] }
145
+ value = datatable.state[:scope]
150
146
 
151
147
  options = {
152
148
  autocomplete: 'off',
153
149
  buttons: true,
154
- checked: datatable.state[:scope],
150
+ checked: value,
155
151
  feedback: false,
156
152
  label: false,
157
153
  required: false,
@@ -25,11 +25,11 @@ module Effective
25
25
  datatable._filters[name.to_sym] = {
26
26
  value: value,
27
27
  as: as,
28
- label: label || (label == false ? false : name.to_s.titleize),
28
+ label: label,
29
29
  name: name.to_sym,
30
30
  parse: parse,
31
31
  required: required,
32
- }.reverse_merge(input_html)
32
+ }.compact.reverse_merge(input_html)
33
33
  end
34
34
 
35
35
  def scope(name = nil, *args, default: nil, label: nil)
@@ -1,5 +1,5 @@
1
1
  .effective-datatables-filters{'aria-controls': datatable.to_param}
2
- = effective_form_with(scope: :filters, url: (datatable._form[:url] || '#'), method: datatable._form[:verb]) do |form|
2
+ = effective_form_with(scope: :filters, url: (datatable._form[:url] || '#'), method: datatable._form[:verb], id: nil) do |form|
3
3
  .form-row.align-items-center
4
4
  - if datatable._scopes.present?
5
5
  = datatable_scope_tag(form, datatable)
@@ -1,3 +1,3 @@
1
1
  module EffectiveDatatables
2
- VERSION = '4.4.5'.freeze
2
+ VERSION = '4.4.6'.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.4.5
4
+ version: 4.4.6
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-04-19 00:00:00.000000000 Z
11
+ date: 2019-04-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails