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: dc130994d3c55ed5c6f1c4b2688cd4813ba6af91
4
- data.tar.gz: 487b03ce0bb806abf0dbd6f4a3f0a83e2673dac8
3
+ metadata.gz: ec225cccac2f53560a86cf1547c0cda96bb1eb02
4
+ data.tar.gz: 88eec85cf485d5d6dea24a750c76adf5b76ac438
5
5
  SHA512:
6
- metadata.gz: 9b956134196f326345e0656770dfd4940adc3bc8046ff938a7da764282e99a18ecde2b6c0ce0f37cbea4068a64ff86b95a5c48d3e72aef92409deaf75b185501
7
- data.tar.gz: e18ec3457dabad9c5daf5f2fe186f615a52c7e05e1987703f32ebc730c816b77d09ac8e02e1a71d2e3db8ef3623fb2d3c0f705db71899030cac2cc0fc3409f44
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 :title, as: :select, in: :select2 %>
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
-
@@ -0,0 +1,12 @@
1
+ .form-group
2
+ .predicate_selector
3
+ width: 20%
4
+ display: block
5
+ margin-right: 10px
6
+ float: left
7
+
8
+ input[data-with="predicate_selector"]
9
+ width: 60%
10
+
11
+ label
12
+ display: block
@@ -14,7 +14,7 @@ module FilterForm
14
14
  def default_options
15
15
  {
16
16
  required: false,
17
- input_html: { name: input_name }.merge(additional_input_options).merge(options.delete(: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
- input_class ? { class: input_class } : {}
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
@@ -1,3 +1,3 @@
1
1
  module FilterForm
2
- VERSION = '0.3.2'
2
+ VERSION = '0.3.4'
3
3
  end
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.2
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-13 00:00:00.000000000 Z
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