recordselect 3.10.8 → 4.0.0
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 +37 -1
- data/app/assets/javascripts/record_select.js +656 -0
- data/config/locales/en.yml +2 -2
- data/lib/record_select/config.rb +0 -12
- data/lib/record_select/engine.rb +1 -1
- data/lib/record_select/helpers/record_select_helper.rb +40 -25
- data/lib/record_select/version.rb +3 -3
- metadata +4 -6
- data/app/assets/javascripts/jquery/record_select.js +0 -632
- data/app/assets/javascripts/prototype/record_select.js +0 -429
- data/app/assets/javascripts/record_select.js.erb +0 -6
@@ -4,6 +4,10 @@ module RecordSelectHelper
|
|
4
4
|
def permit_rs_browse_params
|
5
5
|
end
|
6
6
|
|
7
|
+
def record_select_js(type:, id:, url:, options:)
|
8
|
+
javascript_tag("new RecordSelect.#{type}(#{id.to_json}, #{url.to_json}, #{options.to_json});")
|
9
|
+
end
|
10
|
+
|
7
11
|
# Adds a link on the page that toggles a RecordSelect widget from the given controller.
|
8
12
|
#
|
9
13
|
# *Options*
|
@@ -22,10 +26,12 @@ module RecordSelectHelper
|
|
22
26
|
record_select_options = {id: record_select_id(controller.controller_path), onselect: options[:onselect] || ''}
|
23
27
|
record_select_options.merge! options[:rs] if options[:rs]
|
24
28
|
|
29
|
+
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 request.xhr?
|
25
31
|
html = link_to(name, '#', options[:html])
|
26
|
-
html <<
|
32
|
+
html << record_select_js(**rs_data) if request.xhr?
|
27
33
|
|
28
|
-
|
34
|
+
html
|
29
35
|
end
|
30
36
|
|
31
37
|
# Adds a RecordSelect-based form field. The field submits the record's id using a hidden input.
|
@@ -58,14 +64,18 @@ module RecordSelectHelper
|
|
58
64
|
record_select_options[:label] = label_for_field(current, controller)
|
59
65
|
clear_button_class << ' enabled'
|
60
66
|
end
|
61
|
-
record_select_options.merge! options
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
url = url_for({:
|
66
|
-
|
67
|
-
|
68
|
-
|
67
|
+
record_select_options.merge! options.delete(:rs) if options[:rs]
|
68
|
+
|
69
|
+
clear_button = options.delete(:clear_button)
|
70
|
+
options.merge!(autocomplete: 'off', onfocus: "this.focused=true", onblur: "this.focused=false")
|
71
|
+
url = url_for({action: :browse, controller: controller.controller_path}.merge(params))
|
72
|
+
rs_data = {type: 'Single', id: options[:id], url: url, options: record_select_options}
|
73
|
+
options[:data] = rs_data.transform_keys { |k| "rs_#{k}" } unless request.xhr?
|
74
|
+
html = text_field_tag(name, nil, options)
|
75
|
+
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 request.xhr?
|
77
|
+
|
78
|
+
html
|
69
79
|
end
|
70
80
|
|
71
81
|
# Adds a RecordSelect-based form field. The field is autocompleted.
|
@@ -92,13 +102,16 @@ module RecordSelectHelper
|
|
92
102
|
if current
|
93
103
|
record_select_options[:label] ||= label_for_field(current, controller)
|
94
104
|
end
|
95
|
-
record_select_options.merge! options
|
105
|
+
record_select_options.merge! options.delete(:rs) if options[:rs]
|
96
106
|
|
97
|
-
|
98
|
-
url = url_for({:
|
99
|
-
|
107
|
+
options.merge!(autocomplete: 'off', onfocus: "this.focused=true", onblur: "this.focused=false")
|
108
|
+
url = url_for({action: :browse, controller: controller.controller_path}.merge(params))
|
109
|
+
rs_data = {type: 'Autocomplete', id: options[:id], url: url, options: record_select_options}
|
110
|
+
options[:data] = rs_data.transform_keys { |k| "rs_#{k}" } unless request.xhr?
|
111
|
+
html = text_field_tag(name, nil, options)
|
112
|
+
html << record_select_js(**rs_data) if request.xhr?
|
100
113
|
|
101
|
-
|
114
|
+
html
|
102
115
|
end
|
103
116
|
|
104
117
|
# Adds a RecordSelect-based form field for multiple selections. The values submit using a list of hidden inputs.
|
@@ -124,16 +137,18 @@ module RecordSelectHelper
|
|
124
137
|
params = options.delete(:params)
|
125
138
|
record_select_options = {id: record_select_id(controller.controller_path)}
|
126
139
|
record_select_options[:current] = current.inject([]) { |memo, record| memo.push({:id => record.id, :label => label_for_field(record, controller)}) }
|
127
|
-
record_select_options.merge! options
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
html <<
|
135
|
-
|
136
|
-
|
140
|
+
record_select_options.merge! options.delete(:rs) if options[:rs]
|
141
|
+
|
142
|
+
options.merge!(autocomplete: 'off', onfocus: "this.focused=true", onblur: "this.focused=false")
|
143
|
+
url = url_for({action: :browse, controller: controller.controller_path}.merge(params))
|
144
|
+
rs_data = {type: 'Multiple', id: options[:id], url: url, options: record_select_options}
|
145
|
+
options[:data] = rs_data.transform_keys { |k| "rs_#{k}" } unless request.xhr?
|
146
|
+
html = text_field_tag("#{name}[]", nil, options)
|
147
|
+
html << hidden_field_tag("#{name}[]", '', id: nil)
|
148
|
+
html << content_tag(:ul, '', class: 'record-select-list')
|
149
|
+
html << record_select_js(**rs_data) if request.xhr?
|
150
|
+
|
151
|
+
html
|
137
152
|
end
|
138
153
|
|
139
154
|
# A helper to render RecordSelect partials
|
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
|
+
version: 4.0.0
|
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: 2024-04-
|
13
|
+
date: 2024-04-22 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|
@@ -55,9 +55,7 @@ files:
|
|
55
55
|
- app/assets/images/record_select/cross.gif
|
56
56
|
- app/assets/images/record_select/next.gif
|
57
57
|
- app/assets/images/record_select/previous.gif
|
58
|
-
- app/assets/javascripts/
|
59
|
-
- app/assets/javascripts/prototype/record_select.js
|
60
|
-
- app/assets/javascripts/record_select.js.erb
|
58
|
+
- app/assets/javascripts/record_select.js
|
61
59
|
- app/assets/stylesheets/record_select.css.scss
|
62
60
|
- app/views/record_select/_browse.html.erb
|
63
61
|
- app/views/record_select/_highlight.js.erb
|
@@ -99,7 +97,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
99
97
|
- !ruby/object:Gem::Version
|
100
98
|
version: '0'
|
101
99
|
requirements: []
|
102
|
-
rubygems_version: 3.5.
|
100
|
+
rubygems_version: 3.5.6
|
103
101
|
signing_key:
|
104
102
|
specification_version: 4
|
105
103
|
summary: RecordSelect widget as a replacement for massive drop down lists
|