filter_form 0.3.2 → 0.3.4
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ec225cccac2f53560a86cf1547c0cda96bb1eb02
|
4
|
+
data.tar.gz: 88eec85cf485d5d6dea24a750c76adf5b76ac438
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5f51d1760f2ea0cd3783cc77a1e4aafc0ce3d020b70ab1f0e0d35e2cadbaba239779e7206bb5ceb9cb611493d20f121398fe4933e12567c73fb31daf4d76a973
|
7
|
+
data.tar.gz: 8e7e507e2ad44f545339961cdca23edeee59d86d23b60d729e586ddafeb7c90a76b9b86afba0de9aa336f2c37cd2bf1e4801b3f1110d3f3c30c289f049509ef0
|
data/README.md
CHANGED
@@ -59,7 +59,8 @@ Of course you can customize your filter, like:
|
|
59
59
|
|
60
60
|
```erb
|
61
61
|
<%= filter_form_for @q do |f| %>
|
62
|
-
<%= f.filter_input :
|
62
|
+
<%= f.filter_input :id, with: :predicate_selector # will add select to change predicates in your form %>
|
63
|
+
<%= f.filter_input :title, as: :select, in: :select2 # wraps select in select2 %>
|
63
64
|
<%= f.filter_input :year, as: :select, collection: (2000..2013).to_a, predicate: :not_eq %>
|
64
65
|
<%= f.button :submit %>
|
65
66
|
<% end %>
|
@@ -80,6 +81,8 @@ And application.css:
|
|
80
81
|
```css
|
81
82
|
*= require jquery.ui.datepicker
|
82
83
|
*= require select2
|
84
|
+
|
85
|
+
*= require filter_form
|
83
86
|
```
|
84
87
|
|
85
88
|
### Other sources
|
@@ -1,6 +1,58 @@
|
|
1
|
+
class PredicateSelector
|
2
|
+
_select: null
|
3
|
+
|
4
|
+
_predicates: [
|
5
|
+
{ name: '=', value: 'eq' },
|
6
|
+
{ name: '>', value: 'gt' },
|
7
|
+
{ name: '<', value: 'lt' }
|
8
|
+
]
|
9
|
+
|
10
|
+
@element_for_attribute: ->
|
11
|
+
{ name: 'with', value: 'predicate_selector' }
|
12
|
+
|
13
|
+
@class_name: ->
|
14
|
+
'predicate_selector'
|
15
|
+
|
16
|
+
constructor: (@element) ->
|
17
|
+
@insert_selector()
|
18
|
+
@set_onchange_listener()
|
19
|
+
@set_current_predicate()
|
20
|
+
|
21
|
+
insert_selector: ->
|
22
|
+
@_select = $("<select for='#{ $(@element).attr('id') }' class='#{ @constructor.class_name() }'><select>")
|
23
|
+
for predicate in @_predicates
|
24
|
+
$(@_select).append("<option value='#{ predicate.name }'>#{ predicate.name }</option>")
|
25
|
+
$(@_select).insertBefore(@element)
|
26
|
+
|
27
|
+
set_onchange_listener: ->
|
28
|
+
self = @
|
29
|
+
$(@_select).change ->
|
30
|
+
predicate = self.find_predicate_by_name $(@).val()
|
31
|
+
self.set_name_to_element(predicate)
|
32
|
+
|
33
|
+
set_name_to_element: (predicate) ->
|
34
|
+
new_name = "q[#{ $(@element).attr('id').replace('q_', '') }_#{ predicate.value }]"
|
35
|
+
$(@element).attr('name', new_name)
|
36
|
+
|
37
|
+
find_predicate_by_name: (name) ->
|
38
|
+
for predicate in @_predicates
|
39
|
+
return predicate if predicate.name is name
|
40
|
+
|
41
|
+
set_current_predicate: ->
|
42
|
+
if @current_predicate()
|
43
|
+
$(@_select).val(@current_predicate().name).change()
|
44
|
+
|
45
|
+
current_predicate: ->
|
46
|
+
for predicate in @_predicates
|
47
|
+
return predicate if predicate.value is $(@element).data('current-predicate')
|
48
|
+
|
49
|
+
###############################################################################
|
50
|
+
|
1
51
|
$ ->
|
52
|
+
for element in $("[data-#{ PredicateSelector.element_for_attribute().name }='#{ PredicateSelector.element_for_attribute().value }']")
|
53
|
+
new PredicateSelector(element)
|
54
|
+
|
2
55
|
$('.filter_form_select2').select2()
|
3
56
|
|
4
57
|
$('.filter_form_date').datepicker
|
5
58
|
dateFormat: 'yy-mm-dd'
|
6
|
-
|
@@ -14,7 +14,7 @@ module FilterForm
|
|
14
14
|
def default_options
|
15
15
|
{
|
16
16
|
required: false,
|
17
|
-
input_html:
|
17
|
+
input_html: additional_input_options.merge(options.delete(:input_html) || {})
|
18
18
|
}
|
19
19
|
end
|
20
20
|
|
@@ -23,7 +23,17 @@ module FilterForm
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def additional_input_options
|
26
|
-
|
26
|
+
result = { name: input_name, data: {} }
|
27
|
+
|
28
|
+
result[:class] = input_class if input_class
|
29
|
+
result[:data][:with] = options[:with] if options[:with]
|
30
|
+
result[:data][:current_predicate] = current_predicate if current_predicate
|
31
|
+
|
32
|
+
result
|
33
|
+
end
|
34
|
+
|
35
|
+
def current_predicate
|
36
|
+
object.base.conditions.first.predicate.name if object.base.conditions.any?
|
27
37
|
end
|
28
38
|
|
29
39
|
def input_class
|
data/lib/filter_form/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: filter_form
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Evgeny Li
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-11-
|
11
|
+
date: 2013-11-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: simple_form
|
@@ -107,6 +107,7 @@ files:
|
|
107
107
|
- Rakefile
|
108
108
|
- filter_form.gemspec
|
109
109
|
- lib/assets/javascripts/filter_form.js.coffee
|
110
|
+
- lib/assets/stylesheets/filter_form.css.sass
|
110
111
|
- lib/filter_form.rb
|
111
112
|
- lib/filter_form/form_helper.rb
|
112
113
|
- lib/filter_form/input_options/base.rb
|