auto_select2 0.5.3 → 0.5.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/auto_select2/engine.rb +2 -1
- data/lib/auto_select2/helpers/select2_helpers.rb +7 -0
- data/lib/auto_select2/select2_search_adapter/base.rb +19 -4
- data/lib/auto_select2/select2_search_adapter/default.rb +17 -4
- data/lib/auto_select2/version.rb +1 -1
- data/lib/generators/auto_select2/search_adapter_generator.rb +8 -0
- data/lib/generators/auto_select2/templates/search_adapter.rb.erb +1 -0
- data/vendor/assets/javascripts/auto_select2/ajax_select2.js.coffee +3 -3
- data/vendor/assets/javascripts/auto_select2/custom_select2.coffee +14 -0
- data/vendor/assets/javascripts/auto_select2/data_select2.js.coffee +3 -3
- data/vendor/assets/javascripts/auto_select2/static_select2.js.coffee +3 -3
- metadata +20 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4f1c055e2012182da247df66908f6fdf0e6f951a
|
4
|
+
data.tar.gz: f44e5ae3cce3f1a19d5b522ad25b738552e03df2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 022f35da345225b0559ccfbc85490df14f858fa76a20690e044fd7d3090f6b6d66b0a180134856f807711f25656a105c482d1f30287160b05d4d7d2ba4d75a25
|
7
|
+
data.tar.gz: 115d3fd414588db14f967cb5395206c68cca1b163efda0454780918ac5e43c4fc8e26fd5e2a1250e2abec5c12e4daae80e6bcac249945bc365aa9eb515bb3d9b
|
data/lib/auto_select2/engine.rb
CHANGED
@@ -15,6 +15,13 @@ module AutoSelect2
|
|
15
15
|
end
|
16
16
|
end
|
17
17
|
|
18
|
+
def custom_select2_init_header_tags
|
19
|
+
unless @select2_custom_script_included
|
20
|
+
@select2_custom_script_included = true
|
21
|
+
javascript_include_tag('auto_select2/custom_select2')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
18
25
|
def static_select2_init_header_tags
|
19
26
|
unless @select2_static_script_included
|
20
27
|
@select2_static_script_included = true
|
@@ -19,7 +19,11 @@ module AutoSelect2
|
|
19
19
|
|
20
20
|
def default_finder(searched_class, term, options)
|
21
21
|
columns = options[:column].present? ? options[:column] : 'name'
|
22
|
-
conditions =
|
22
|
+
conditions =
|
23
|
+
default_search_conditions(term,
|
24
|
+
options[:basic_conditions],
|
25
|
+
columns,
|
26
|
+
options.slice(:case_sensitive))
|
23
27
|
if term.nil?
|
24
28
|
[ searched_class.where(options[:basic_conditions]) ]
|
25
29
|
else
|
@@ -35,14 +39,18 @@ module AutoSelect2
|
|
35
39
|
end
|
36
40
|
|
37
41
|
def default_count(searched_class, term, options = {})
|
38
|
-
conditions =
|
42
|
+
conditions =
|
43
|
+
default_search_conditions(term,
|
44
|
+
options[:basic_conditions],
|
45
|
+
options[:column] || 'name',
|
46
|
+
options.slice(:case_sensitive))
|
39
47
|
query = searched_class.where(conditions)
|
40
48
|
query = query.select(options[:select]) if options[:select].present?
|
41
49
|
query = options[:uniq] ? query.uniq : query
|
42
50
|
query.count
|
43
51
|
end
|
44
52
|
|
45
|
-
def default_search_conditions(term, basic_conditions, columns)
|
53
|
+
def default_search_conditions(term, basic_conditions, columns, options = {})
|
46
54
|
term_filter = ''
|
47
55
|
conditions = []
|
48
56
|
unless columns.is_a?(Array)
|
@@ -50,13 +58,20 @@ module AutoSelect2
|
|
50
58
|
end
|
51
59
|
unless term.nil?
|
52
60
|
words = term.split(' ')
|
61
|
+
# @ todo: needs to create arrays with conditions for words and columns and concatenate them in a properly way
|
53
62
|
words.each_with_index do |word, index|
|
54
63
|
term_filter += ' AND ' if index > 0
|
64
|
+
term_filter += '( ' if columns.any?
|
55
65
|
columns.each_with_index do |column, idx|
|
56
66
|
term_filter += ' OR ' if idx > 0
|
57
|
-
|
67
|
+
if options[:case_sensitive]
|
68
|
+
term_filter += "#{column} LIKE ?"
|
69
|
+
else
|
70
|
+
term_filter += "LOWER(#{column}) LIKE LOWER(?)"
|
71
|
+
end
|
58
72
|
conditions << "%#{word}%"
|
59
73
|
end
|
74
|
+
term_filter += ' )' if columns.any?
|
60
75
|
end
|
61
76
|
term_filter = term_filter.empty? ? nil : "(#{term_filter})"
|
62
77
|
basic_conditions_part = basic_conditions.present? ? "(#{basic_conditions }) " : nil
|
@@ -3,12 +3,21 @@ module AutoSelect2
|
|
3
3
|
class Default < Base
|
4
4
|
class << self
|
5
5
|
def search_default(term, page, options)
|
6
|
-
if
|
6
|
+
if !@searchable_class || @id_column.blank? || @text_columns.blank?
|
7
7
|
raise_not_implemented
|
8
8
|
end
|
9
9
|
if options[:init].nil?
|
10
|
-
default_values =
|
11
|
-
|
10
|
+
default_values =
|
11
|
+
default_finder(@searchable_class,
|
12
|
+
term,
|
13
|
+
page: page,
|
14
|
+
column: @text_columns,
|
15
|
+
case_sensitive: @case_sensitive.nil? ? options[:case_sensitive] : @case_sensitive)
|
16
|
+
total_count =
|
17
|
+
default_count(@searchable_class,
|
18
|
+
term,
|
19
|
+
column: @text_columns,
|
20
|
+
case_sensitive: @case_sensitive.nil? ? options[:case_sensitive] : @case_sensitive)
|
12
21
|
{
|
13
22
|
items: default_values.map do |default_value|
|
14
23
|
get_select2_hash(
|
@@ -18,7 +27,7 @@ module AutoSelect2
|
|
18
27
|
@text_columns
|
19
28
|
)
|
20
29
|
end,
|
21
|
-
total:
|
30
|
+
total: total_count
|
22
31
|
}
|
23
32
|
else
|
24
33
|
options[:id_column] = @id_column
|
@@ -49,6 +58,10 @@ module AutoSelect2
|
|
49
58
|
@select2_hash_method = method_sym
|
50
59
|
end
|
51
60
|
|
61
|
+
def case_sensitive(casi)
|
62
|
+
@case_sensitive = casi
|
63
|
+
end
|
64
|
+
|
52
65
|
def raise_not_implemented
|
53
66
|
raise NotImplementedError,
|
54
67
|
'You need to implement your own SearchAdapter. Use: `rails generate auto_select2:search_adapter`'
|
data/lib/auto_select2/version.rb
CHANGED
@@ -22,6 +22,10 @@ module AutoSelect2
|
|
22
22
|
type: :string,
|
23
23
|
desc: 'Instance method of model for converting into Hash for transporting into select2',
|
24
24
|
banner: 'to_select2'
|
25
|
+
class_option :case_sensitive,
|
26
|
+
type: :boolean,
|
27
|
+
desc: 'Is adapter request case sensitive or not',
|
28
|
+
banner: 'case_sensitive'
|
25
29
|
|
26
30
|
desc 'Creates SearchAdapter classes for your models'
|
27
31
|
def create_search_adapter
|
@@ -48,6 +52,10 @@ module AutoSelect2
|
|
48
52
|
def hash_method
|
49
53
|
options[:hash_method]
|
50
54
|
end
|
55
|
+
|
56
|
+
def case_sensitive
|
57
|
+
options[:case_sensitive]
|
58
|
+
end
|
51
59
|
end
|
52
60
|
end
|
53
61
|
end
|
@@ -3,4 +3,5 @@ class <%= name.classify %>SearchAdapter < AutoSelect2::Select2SearchAdapter::Def
|
|
3
3
|
id_column :<%= id_column %>
|
4
4
|
text_columns <%= text_columns.join(', ') %>
|
5
5
|
<% if hash_method.present? %>hash_method :<%= hash_method %><% end %>
|
6
|
+
<% if case_sensitive.present? %>case_sensitive <%= case_sensitive %><% end %>
|
6
7
|
end
|
@@ -126,12 +126,12 @@ jQuery ($) ->
|
|
126
126
|
return
|
127
127
|
initAutoAjaxSelect2()
|
128
128
|
|
129
|
-
$
|
130
|
-
$
|
129
|
+
$document = $(document)
|
130
|
+
$document.on 'ajaxSuccess', ->
|
131
131
|
initAutoAjaxSelect2()
|
132
132
|
return
|
133
133
|
|
134
|
-
$
|
134
|
+
$document.on 'cocoon:after-insert', ->
|
135
135
|
initAutoAjaxSelect2()
|
136
136
|
return
|
137
137
|
return
|
@@ -0,0 +1,14 @@
|
|
1
|
+
jQuery ($) ->
|
2
|
+
window.initAutoCustomSelect2 = ->
|
3
|
+
$('input.auto-custom-select2').not('.select2-offscreen').each ->
|
4
|
+
$input = $(this)
|
5
|
+
|
6
|
+
s2Options = $input.data("s2-options")
|
7
|
+
if s2Options != undefined
|
8
|
+
$input.select2(s2Options)
|
9
|
+
return
|
10
|
+
return
|
11
|
+
|
12
|
+
initAutoCustomSelect2()
|
13
|
+
|
14
|
+
return
|
@@ -18,12 +18,12 @@ jQuery ($) ->
|
|
18
18
|
initAutoDataSelect2()
|
19
19
|
|
20
20
|
|
21
|
-
$
|
22
|
-
$
|
21
|
+
$document = $(document)
|
22
|
+
$document.on 'ajaxSuccess', ->
|
23
23
|
initAutoDataSelect2()
|
24
24
|
return
|
25
25
|
|
26
|
-
$
|
26
|
+
$document.on 'cocoon:after-insert', ->
|
27
27
|
initAutoDataSelect2()
|
28
28
|
return
|
29
29
|
return
|
@@ -19,12 +19,12 @@ jQuery ($) ->
|
|
19
19
|
return
|
20
20
|
initAutoStaticSelect2()
|
21
21
|
|
22
|
-
$
|
23
|
-
$
|
22
|
+
$document = $(document)
|
23
|
+
$document.on 'ajaxSuccess', ->
|
24
24
|
initAutoStaticSelect2()
|
25
25
|
return
|
26
26
|
|
27
|
-
$
|
27
|
+
$document.on 'cocoon:after-insert', ->
|
28
28
|
initAutoStaticSelect2()
|
29
29
|
return
|
30
30
|
return
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: auto_select2
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dmitriy Lisichkin
|
@@ -9,90 +9,90 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2016-
|
12
|
+
date: 2016-09-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: railties
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- -
|
18
|
+
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
20
|
version: '3.1'
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
|
-
- -
|
25
|
+
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
27
|
version: '3.1'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: select2-rails
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
|
-
- -
|
32
|
+
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
34
|
version: '0'
|
35
35
|
type: :runtime
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
|
-
- -
|
39
|
+
- - ">="
|
40
40
|
- !ruby/object:Gem::Version
|
41
41
|
version: '0'
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: coffee-rails
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
45
45
|
requirements:
|
46
|
-
- -
|
46
|
+
- - ">="
|
47
47
|
- !ruby/object:Gem::Version
|
48
48
|
version: '0'
|
49
49
|
type: :runtime
|
50
50
|
prerelease: false
|
51
51
|
version_requirements: !ruby/object:Gem::Requirement
|
52
52
|
requirements:
|
53
|
-
- -
|
53
|
+
- - ">="
|
54
54
|
- !ruby/object:Gem::Version
|
55
55
|
version: '0'
|
56
56
|
- !ruby/object:Gem::Dependency
|
57
57
|
name: bundler
|
58
58
|
requirement: !ruby/object:Gem::Requirement
|
59
59
|
requirements:
|
60
|
-
- - ~>
|
60
|
+
- - "~>"
|
61
61
|
- !ruby/object:Gem::Version
|
62
62
|
version: '1.5'
|
63
63
|
type: :development
|
64
64
|
prerelease: false
|
65
65
|
version_requirements: !ruby/object:Gem::Requirement
|
66
66
|
requirements:
|
67
|
-
- - ~>
|
67
|
+
- - "~>"
|
68
68
|
- !ruby/object:Gem::Version
|
69
69
|
version: '1.5'
|
70
70
|
- !ruby/object:Gem::Dependency
|
71
71
|
name: rake
|
72
72
|
requirement: !ruby/object:Gem::Requirement
|
73
73
|
requirements:
|
74
|
-
- -
|
74
|
+
- - ">="
|
75
75
|
- !ruby/object:Gem::Version
|
76
76
|
version: '0'
|
77
77
|
type: :development
|
78
78
|
prerelease: false
|
79
79
|
version_requirements: !ruby/object:Gem::Requirement
|
80
80
|
requirements:
|
81
|
-
- -
|
81
|
+
- - ">="
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '0'
|
84
84
|
- !ruby/object:Gem::Dependency
|
85
85
|
name: rails
|
86
86
|
requirement: !ruby/object:Gem::Requirement
|
87
87
|
requirements:
|
88
|
-
- - ~>
|
88
|
+
- - "~>"
|
89
89
|
- !ruby/object:Gem::Version
|
90
90
|
version: 3.2.12
|
91
91
|
type: :development
|
92
92
|
prerelease: false
|
93
93
|
version_requirements: !ruby/object:Gem::Requirement
|
94
94
|
requirements:
|
95
|
-
- - ~>
|
95
|
+
- - "~>"
|
96
96
|
- !ruby/object:Gem::Version
|
97
97
|
version: 3.2.12
|
98
98
|
description: |2
|
@@ -106,8 +106,8 @@ executables: []
|
|
106
106
|
extensions: []
|
107
107
|
extra_rdoc_files: []
|
108
108
|
files:
|
109
|
-
- .gitignore
|
110
|
-
- .gitmodules
|
109
|
+
- ".gitignore"
|
110
|
+
- ".gitmodules"
|
111
111
|
- Gemfile
|
112
112
|
- LICENSE.txt
|
113
113
|
- README.md
|
@@ -126,6 +126,7 @@ files:
|
|
126
126
|
- lib/generators/auto_select2/search_adapter_generator.rb
|
127
127
|
- lib/generators/auto_select2/templates/search_adapter.rb.erb
|
128
128
|
- vendor/assets/javascripts/auto_select2/ajax_select2.js.coffee
|
129
|
+
- vendor/assets/javascripts/auto_select2/custom_select2.coffee
|
129
130
|
- vendor/assets/javascripts/auto_select2/data_select2.js.coffee
|
130
131
|
- vendor/assets/javascripts/auto_select2/multi_ajax_select2_value_parser.js.coffee
|
131
132
|
- vendor/assets/javascripts/auto_select2/static_select2.js.coffee
|
@@ -139,17 +140,17 @@ require_paths:
|
|
139
140
|
- lib
|
140
141
|
required_ruby_version: !ruby/object:Gem::Requirement
|
141
142
|
requirements:
|
142
|
-
- -
|
143
|
+
- - ">="
|
143
144
|
- !ruby/object:Gem::Version
|
144
145
|
version: '0'
|
145
146
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
146
147
|
requirements:
|
147
|
-
- -
|
148
|
+
- - ">="
|
148
149
|
- !ruby/object:Gem::Version
|
149
150
|
version: '0'
|
150
151
|
requirements: []
|
151
152
|
rubyforge_project:
|
152
|
-
rubygems_version: 2.
|
153
|
+
rubygems_version: 2.5.1
|
153
154
|
signing_key:
|
154
155
|
specification_version: 4
|
155
156
|
summary: Base methods for wrapping a Select2 and easy initialize it.
|