recordselect 4.0.1 → 4.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README +0 -4
- data/app/assets/javascripts/record_select.js +3 -2
- data/lib/record_select/actions.rb +10 -6
- data/lib/record_select/conditions.rb +0 -2
- data/lib/record_select/config.rb +4 -4
- data/lib/record_select/helpers/record_select_helper.rb +12 -8
- data/lib/record_select/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 989e8ccab3b2a8123cba1e96bc4afae3038ff5091cf7c35c883435ce12ecea82
|
4
|
+
data.tar.gz: 96a8a2072f8e3dce451abade379580ae53ac8077c5aa1d4e681b955cae6a36fb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 21dddd73eb6dec6530ba21899f94a5e690e81fb5bd13669e4deb1ee7e81b355db0ba5f66a9444d06a9f749ac8ab43dca556edb4f1ea6c1f27e27d332cb4e6c7e
|
7
|
+
data.tar.gz: b694520b3b5b295e57a9c274f2e4c13924df79bc0d1b8164e35a6689be8f63a14ecee3981941a92f248aae3de8b08b5b6c4114e7e665de1487ef9cad8862d15a
|
data/README
CHANGED
@@ -45,7 +45,3 @@ Either using assets pipeline or importmap, it will be loaded when requiring or i
|
|
45
45
|
|
46
46
|
= DEPENDENCIES
|
47
47
|
This depends on the excellent Paginator gem by Bruce Williams. This simple gem is available at paginator.rubyforge.org.
|
48
|
-
|
49
|
-
It should autoselect js framework, but you can select :jquery or :prototype framework with config/initializer file:
|
50
|
-
RecordSelect::Config.js_framework = :jquery
|
51
|
-
RecordSelect::Config.js_framework = :prototype
|
@@ -163,8 +163,9 @@
|
|
163
163
|
RecordSelect.document_loaded = false;
|
164
164
|
|
165
165
|
RecordSelect.from_attributes = function(item) {
|
166
|
+
if (item.prop('disabled')) return;
|
166
167
|
var rs_class = RecordSelect[item.data('rs-type')];
|
167
|
-
new rs_class(item.data('rs-id'), item.data('rs-url'), item.data('rs-options'));
|
168
|
+
new rs_class(item.data('rs-id') || item, item.data('rs-url'), item.data('rs-options'));
|
168
169
|
}
|
169
170
|
|
170
171
|
RecordSelect.select_item = function(item) {
|
@@ -337,7 +338,7 @@
|
|
337
338
|
* returns true/false for whether the recordselect is open
|
338
339
|
*/
|
339
340
|
is_open: function() {
|
340
|
-
return
|
341
|
+
return this.container.children().length != 0;
|
341
342
|
},
|
342
343
|
|
343
344
|
/**
|
@@ -3,12 +3,7 @@ module RecordSelect
|
|
3
3
|
# :method => :get
|
4
4
|
# params => [:page, :search]
|
5
5
|
def browse
|
6
|
-
|
7
|
-
user_includes = record_select_includes
|
8
|
-
query = conditions.inject(record_select_model.includes(user_includes)) do |query, cond|
|
9
|
-
query.where(cond)
|
10
|
-
end
|
11
|
-
query = query.references(user_includes) if Rails::VERSION::MAJOR >= 4 && user_includes.present?
|
6
|
+
query = record_select_query
|
12
7
|
@count = query.count if record_select_config.pagination?
|
13
8
|
@count = @count.length if @count.is_a? Hash
|
14
9
|
pager = ::Paginator.new(@count, record_select_config.per_page) do |offset, per_page|
|
@@ -67,6 +62,15 @@ module RecordSelect
|
|
67
62
|
|
68
63
|
private
|
69
64
|
|
65
|
+
def record_select_query
|
66
|
+
query = record_select_model
|
67
|
+
user_includes = record_select_includes
|
68
|
+
query = query.includes(user_includes).references(user_includes) if user_includes.present?
|
69
|
+
query = query.joins(record_select_config.joins).distinct if record_select_config.joins.present?
|
70
|
+
query = query.left_joins(record_select_config.left_joins) if record_select_config.left_joins.present?
|
71
|
+
record_select_conditions.inject(query) { |query, cond| query.where(cond) }
|
72
|
+
end
|
73
|
+
|
70
74
|
def record_select_views_path
|
71
75
|
"record_select"
|
72
76
|
end
|
@@ -7,8 +7,6 @@ module RecordSelect
|
|
7
7
|
# * intelligent url params (e.g. params[:first_name] if first_name is a model column)
|
8
8
|
# * specific conditions supplied by the developer
|
9
9
|
def record_select_conditions
|
10
|
-
conditions = []
|
11
|
-
|
12
10
|
[
|
13
11
|
record_select_conditions_from_search,
|
14
12
|
*record_select_conditions_from_params,
|
data/lib/record_select/config.rb
CHANGED
@@ -9,11 +9,15 @@ module RecordSelect
|
|
9
9
|
@order_by = options[:order_by]
|
10
10
|
@full_text_search = options[:full_text_search]
|
11
11
|
@label = options[:label]
|
12
|
+
@joins = options[:joins]
|
13
|
+
@left_joins = options[:left_joins]
|
12
14
|
@include = options[:include]
|
13
15
|
@pagination = options.include?(:pagination) ? options[:pagination] : true
|
14
16
|
@toggle_search_mode = options[:toggle_search_mode]
|
15
17
|
end
|
16
18
|
|
19
|
+
attr_reader :include, :joins, :left_joins
|
20
|
+
|
17
21
|
def pagination?
|
18
22
|
@pagination
|
19
23
|
end
|
@@ -52,10 +56,6 @@ module RecordSelect
|
|
52
56
|
@toggle_search_mode ? true : false
|
53
57
|
end
|
54
58
|
|
55
|
-
def include
|
56
|
-
@include
|
57
|
-
end
|
58
|
-
|
59
59
|
# If a proc, must accept the record as an argument and return a descriptive string.
|
60
60
|
#
|
61
61
|
# If a symbol or string, must name a partial that renders a representation of the
|
@@ -21,15 +21,16 @@ module RecordSelectHelper
|
|
21
21
|
options[:onselect] = "(function(id, label) {#{options[:onselect]}})" if options[:onselect]
|
22
22
|
options[:html] ||= {}
|
23
23
|
options[:html][:id] ||= "rs_#{rand(9999)}"
|
24
|
+
js = options.include?(:js) ? options[:js] : request.xhr?
|
24
25
|
|
25
26
|
controller = assert_controller_responds(options[:params][:controller])
|
26
27
|
record_select_options = {id: record_select_id(controller.controller_path), onselect: options[:onselect] || ''}
|
27
28
|
record_select_options.merge! options[:rs] if options[:rs]
|
28
29
|
|
29
30
|
rs_data = {type: 'Dialog', id: options[:html][:id], url: url_for(options[:params]), options: record_select_options}
|
30
|
-
options[:html][:data] = rs_data.transform_keys { |k| "rs_#{k}" } unless
|
31
|
+
options[:html][:data] = rs_data.transform_keys { |k| "rs_#{k}" } unless js
|
31
32
|
html = link_to(name, '#', options[:html])
|
32
|
-
html << record_select_js(**rs_data) if
|
33
|
+
html << record_select_js(**rs_data) if js
|
33
34
|
|
34
35
|
html
|
35
36
|
end
|
@@ -53,6 +54,7 @@ module RecordSelectHelper
|
|
53
54
|
options[:class] ||= ''
|
54
55
|
options[:class] << ' recordselect'
|
55
56
|
options[:clear_button] = true unless options.include? :clear_button
|
57
|
+
js = options.include?(:js) ? options.delete(:js) : request.xhr?
|
56
58
|
|
57
59
|
controller = assert_controller_responds(options.delete(:controller))
|
58
60
|
params = options.delete(:params)
|
@@ -70,10 +72,10 @@ module RecordSelectHelper
|
|
70
72
|
options.merge!(autocomplete: 'off', onfocus: "this.focused=true", onblur: "this.focused=false")
|
71
73
|
url = url_for({action: :browse, controller: controller.controller_path}.merge(params))
|
72
74
|
rs_data = {type: 'Single', id: options[:id], url: url, options: record_select_options}
|
73
|
-
options[:data] = rs_data.transform_keys { |k| "rs_#{k}" } unless
|
75
|
+
options[:data] = rs_data.transform_keys { |k| "rs_#{k}" } unless js
|
74
76
|
html = text_field_tag(name, nil, options)
|
75
77
|
html << button_tag('x', type: :button, class: clear_button_class, aria_label: 'Clear input', title: 'Clear input') if clear_button
|
76
|
-
html << record_select_js(**rs_data) if
|
78
|
+
html << record_select_js(**rs_data) if js
|
77
79
|
|
78
80
|
html
|
79
81
|
end
|
@@ -95,6 +97,7 @@ module RecordSelectHelper
|
|
95
97
|
options[:id] ||= name.gsub(/[\[\]]/, '_')
|
96
98
|
options[:class] ||= ''
|
97
99
|
options[:class] << ' recordselect'
|
100
|
+
js = options.include?(:js) ? options.delete(:js) : request.xhr?
|
98
101
|
|
99
102
|
controller = assert_controller_responds(options.delete(:controller))
|
100
103
|
params = options.delete(:params)
|
@@ -107,9 +110,9 @@ module RecordSelectHelper
|
|
107
110
|
options.merge!(autocomplete: 'off', onfocus: "this.focused=true", onblur: "this.focused=false")
|
108
111
|
url = url_for({action: :browse, controller: controller.controller_path}.merge(params))
|
109
112
|
rs_data = {type: 'Autocomplete', id: options[:id], url: url, options: record_select_options}
|
110
|
-
options[:data] = rs_data.transform_keys { |k| "rs_#{k}" } unless
|
113
|
+
options[:data] = rs_data.transform_keys { |k| "rs_#{k}" } unless js
|
111
114
|
html = text_field_tag(name, nil, options)
|
112
|
-
html << record_select_js(**rs_data) if
|
115
|
+
html << record_select_js(**rs_data) if js
|
113
116
|
|
114
117
|
html
|
115
118
|
end
|
@@ -132,6 +135,7 @@ module RecordSelectHelper
|
|
132
135
|
options[:class] ||= ''
|
133
136
|
options[:class] << ' recordselect'
|
134
137
|
options.delete(:name)
|
138
|
+
js = options.include?(:js) ? options.delete(:js) : request.xhr?
|
135
139
|
|
136
140
|
controller = assert_controller_responds(options.delete(:controller))
|
137
141
|
params = options.delete(:params)
|
@@ -142,11 +146,11 @@ module RecordSelectHelper
|
|
142
146
|
options.merge!(autocomplete: 'off', onfocus: "this.focused=true", onblur: "this.focused=false")
|
143
147
|
url = url_for({action: :browse, controller: controller.controller_path}.merge(params))
|
144
148
|
rs_data = {type: 'Multiple', id: options[:id], url: url, options: record_select_options}
|
145
|
-
options[:data] = rs_data.transform_keys { |k| "rs_#{k}" } unless
|
149
|
+
options[:data] = rs_data.transform_keys { |k| "rs_#{k}" } unless js
|
146
150
|
html = text_field_tag("#{name}[]", nil, options)
|
147
151
|
html << hidden_field_tag("#{name}[]", '', id: nil)
|
148
152
|
html << content_tag(:ul, '', class: 'record-select-list')
|
149
|
-
html << record_select_js(**rs_data) if
|
153
|
+
html << record_select_js(**rs_data) if js
|
150
154
|
|
151
155
|
html
|
152
156
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: recordselect
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.
|
4
|
+
version: 4.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sergio Cambra
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2025-01-23 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|
@@ -97,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
97
97
|
- !ruby/object:Gem::Version
|
98
98
|
version: '0'
|
99
99
|
requirements: []
|
100
|
-
rubygems_version: 3.5.
|
100
|
+
rubygems_version: 3.5.11
|
101
101
|
signing_key:
|
102
102
|
specification_version: 4
|
103
103
|
summary: RecordSelect widget as a replacement for massive drop down lists
|