filter_form 0.3.6 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +32 -10
- data/lib/assets/javascripts/filter_form.js.coffee +15 -19
- data/lib/filter_form/input_options/base.rb +3 -3
- data/lib/filter_form/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 978b3ad1c97b1aba6b76e8880fa080108b5c9690
|
4
|
+
data.tar.gz: e4b7527a7625e13362064dcc1934203efe1c9ac7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b9092311064803c9b527109ba1e2194c4bb38c2f9870564723d7daad1509a72e8419380a583130a0292343846536795cf4bd44c21cdbe03a0c0ed1269c38bb0c
|
7
|
+
data.tar.gz: 80c5249be7a0d51c7d814b25d2bc6ec833457d5849cfe54d0b8ce5a48bdd3d98ec4af3a040ca083e2607fe929ecb1936cfe0d9655f4916e151a50a679271bdd1
|
data/README.md
CHANGED
@@ -55,16 +55,7 @@ In your view file:
|
|
55
55
|
|
56
56
|
### Customization
|
57
57
|
|
58
|
-
|
59
|
-
|
60
|
-
```erb
|
61
|
-
<%= filter_form_for @q do |f| %>
|
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 %>
|
64
|
-
<%= f.filter_input :year, as: :select, collection: (2000..2013).to_a, predicate: :not_eq %>
|
65
|
-
<%= f.button :submit %>
|
66
|
-
<% end %>
|
67
|
-
```
|
58
|
+
#### Assets
|
68
59
|
|
69
60
|
If you want to use jQuery [Datepicker](http://jqueryui.com/datepicker/) for `date` and `datetime` automatically or [Select2](http://ivaynberg.github.io/select2/), add to your application.js file:
|
70
61
|
|
@@ -85,6 +76,37 @@ And application.css:
|
|
85
76
|
*= require filter_form
|
86
77
|
```
|
87
78
|
|
79
|
+
#### Custom predicate
|
80
|
+
|
81
|
+
```erb
|
82
|
+
<%= filter_form_for @q do |f| %>
|
83
|
+
<%= f.filter_input :year, as: :select, collection: (2000..2013).to_a, predicate: :not_eq %>
|
84
|
+
<%= f.button :submit %>
|
85
|
+
<% end %>
|
86
|
+
```
|
87
|
+
|
88
|
+
#### Select2
|
89
|
+
|
90
|
+
You can wrap your select in `select2`:
|
91
|
+
|
92
|
+
```erb
|
93
|
+
<%= filter_form_for @q do |f| %>
|
94
|
+
<%= f.filter_input :title, as: :select, in: :select2 %>
|
95
|
+
<%= f.button :submit %>
|
96
|
+
<% end %>
|
97
|
+
```
|
98
|
+
|
99
|
+
#### Predicate selector
|
100
|
+
|
101
|
+
You can show predicate selector:
|
102
|
+
|
103
|
+
```erb
|
104
|
+
<%= filter_form_for @q do |f| %>
|
105
|
+
<%= f.filter_input :id, predicate_selector: [['=', 'eq'], ['>', 'gt'], ['<', 'lt']] %>
|
106
|
+
<%= f.button :submit %>
|
107
|
+
<% end %>
|
108
|
+
```
|
109
|
+
|
88
110
|
### Other sources
|
89
111
|
|
90
112
|
For more information about predicates visit [ransack](https://github.com/ernie/ransack).
|
@@ -1,17 +1,13 @@
|
|
1
1
|
class PredicateSelector
|
2
|
+
@CLASS_NAME: 'predicate_selector'
|
3
|
+
|
2
4
|
_select: null
|
3
5
|
|
4
|
-
_predicates:
|
5
|
-
|
6
|
-
{ name: '>', value: 'gt' },
|
7
|
-
{ name: '<', value: 'lt' }
|
8
|
-
]
|
6
|
+
_predicates: ->
|
7
|
+
JSON.parse($(@element).attr(@constructor.element_for_attribute()))
|
9
8
|
|
10
9
|
@element_for_attribute: ->
|
11
|
-
|
12
|
-
|
13
|
-
@class_name: ->
|
14
|
-
'predicate_selector'
|
10
|
+
'data-predicate-selector'
|
15
11
|
|
16
12
|
constructor: (@element) ->
|
17
13
|
@insert_selector()
|
@@ -19,9 +15,9 @@ class PredicateSelector
|
|
19
15
|
@set_current_predicate()
|
20
16
|
|
21
17
|
insert_selector: ->
|
22
|
-
@_select = $("<select for='#{ $(@element).attr('id') }' class='#{ @constructor.
|
23
|
-
for predicate in @_predicates
|
24
|
-
$(@_select).append("<option value='#{ predicate
|
18
|
+
@_select = $("<select for='#{ $(@element).attr('id') }' class='#{ @constructor.CLASS_NAME }'><select>")
|
19
|
+
for predicate in @_predicates()
|
20
|
+
$(@_select).append("<option value='#{ predicate[0] }'>#{ predicate[0] }</option>")
|
25
21
|
$(@_select).insertBefore(@element)
|
26
22
|
|
27
23
|
set_onchange_listener: ->
|
@@ -31,25 +27,25 @@ class PredicateSelector
|
|
31
27
|
self.set_name_to_element(predicate)
|
32
28
|
|
33
29
|
set_name_to_element: (predicate) ->
|
34
|
-
new_name = "q[#{ $(@element).attr('id').replace('q_', '') }_#{ predicate
|
30
|
+
new_name = "q[#{ $(@element).attr('id').replace('q_', '') }_#{ predicate[1] }]"
|
35
31
|
$(@element).attr('name', new_name)
|
36
32
|
|
37
33
|
find_predicate_by_name: (name) ->
|
38
|
-
for predicate in @_predicates
|
39
|
-
return predicate if predicate
|
34
|
+
for predicate in @_predicates()
|
35
|
+
return predicate if predicate[0] is name
|
40
36
|
|
41
37
|
set_current_predicate: ->
|
42
38
|
if @current_predicate()
|
43
|
-
$(@_select).val(@current_predicate()
|
39
|
+
$(@_select).val(@current_predicate()[0]).change()
|
44
40
|
|
45
41
|
current_predicate: ->
|
46
|
-
for predicate in @_predicates
|
47
|
-
return predicate if predicate
|
42
|
+
for predicate in @_predicates()
|
43
|
+
return predicate if predicate[1] is $(@element).data('current-predicate')
|
48
44
|
|
49
45
|
###############################################################################
|
50
46
|
|
51
47
|
$ ->
|
52
|
-
for element in $("[
|
48
|
+
for element in $("[#{ PredicateSelector.element_for_attribute() }]")
|
53
49
|
new PredicateSelector(element)
|
54
50
|
|
55
51
|
$('.filter_form_select2').select2()
|
@@ -25,9 +25,9 @@ module FilterForm
|
|
25
25
|
def additional_input_options
|
26
26
|
result = { name: input_name, data: {} }
|
27
27
|
|
28
|
-
result[:class]
|
29
|
-
result[:data][:
|
30
|
-
result[:data][:current_predicate]
|
28
|
+
result[:class] = input_class if input_class
|
29
|
+
result[:data][:predicate_selector] = options[:predicate_selector] if options[:predicate_selector]
|
30
|
+
result[:data][:current_predicate] = current_predicate if current_predicate
|
31
31
|
|
32
32
|
result
|
33
33
|
end
|
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.
|
4
|
+
version: 0.4.0
|
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-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: simple_form
|