recordselect 3.4.8 → 3.4.9
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bdc6d3a809b14a7a210f726104af134745758365
|
4
|
+
data.tar.gz: c6a6c0d7eb34946e0833bca299144cc1ca7b0401
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b827899803ea63753c798f32c7d0cc0b6ef404cb195ed40e389e8a81adf08288df955875820276e8970e3546ac88160692f10b86a041558a8a63389433dd1e9f
|
7
|
+
data.tar.gz: 8a203cce44027975b163aa03af8e53bfeb4ca6c4e2514fa606b20ea971ac8dd3a90c84bca8ac800f443cd249b7cac664db1b89575353fd8125775d1b59e95a7c
|
@@ -110,6 +110,18 @@ jQuery(document).ready(function() {
|
|
110
110
|
}
|
111
111
|
return true;
|
112
112
|
});
|
113
|
+
jQuery(document).on('ajax:beforeSend', '.record-select-container', function(event, xhr) {
|
114
|
+
var rs = jQuery(this).data('recordselect'), cur = rs.current_xhr;
|
115
|
+
rs.current_xhr = xhr;
|
116
|
+
if (cur) cur.abort();
|
117
|
+
});
|
118
|
+
jQuery(document).on('ajax:complete', '.record-select-container', function(event, xhr, status) {
|
119
|
+
var rs = jQuery(this).data('recordselect');
|
120
|
+
if (status != 'abort' || rs.current_xhr == xhr) {
|
121
|
+
if (rs.is_open()) rs.show();
|
122
|
+
rs.current_xhr = null;
|
123
|
+
}
|
124
|
+
});
|
113
125
|
});
|
114
126
|
|
115
127
|
var RecordSelect = new Object();
|
@@ -129,10 +141,17 @@ RecordSelect.select_item = function(item) {
|
|
129
141
|
}
|
130
142
|
|
131
143
|
RecordSelect.observe = function(id) {
|
132
|
-
var form = jQuery("#" + id);
|
144
|
+
var form = jQuery("#" + id), min_length = 0;
|
145
|
+
var rs = form.closest('.record-select-container').data('recordselect');
|
146
|
+
if (rs) min_length = rs.min_length;
|
133
147
|
form.find('input.text-input').delayedObserver(function() {
|
134
148
|
if (form.closest('body').length) form.trigger("submit");
|
135
|
-
}, 0.35
|
149
|
+
}, 0.35, {
|
150
|
+
condition: function() {
|
151
|
+
var item = jQuery(this);
|
152
|
+
return item.data('oldval') == item.val() || item.val().length < min_length;
|
153
|
+
}
|
154
|
+
});
|
136
155
|
}
|
137
156
|
|
138
157
|
RecordSelect.render_page = function(record_select_id, page) {
|
@@ -151,6 +170,7 @@ RecordSelect.Abstract = Class.extend({
|
|
151
170
|
this.url = url;
|
152
171
|
this.options = options;
|
153
172
|
this.container;
|
173
|
+
this.min_length = options.min_length || 0;
|
154
174
|
if (this.options.onchange && typeof this.options.onchange != 'function') {
|
155
175
|
this.options.onchange = eval(this.options.onchange);
|
156
176
|
}
|
@@ -185,22 +205,24 @@ RecordSelect.Abstract = Class.extend({
|
|
185
205
|
jQuery.rails.fire(_this.obj, 'recordselect:before');
|
186
206
|
_this.container.html('');
|
187
207
|
_this.container.show();
|
188
|
-
var params = _this.obj.data('params');
|
189
|
-
|
208
|
+
var params = _this.obj.data('params'), text = _this.obj.val();
|
209
|
+
|
210
|
+
var search_params = jQuery.param({search: text});
|
190
211
|
params = params ? [params, search_params].join("&") : search_params;
|
191
|
-
jQuery.ajax({
|
212
|
+
this.current_xhr = jQuery.ajax({
|
192
213
|
url: this.url,
|
193
214
|
//type: "POST",
|
194
215
|
data: params,
|
195
216
|
//dataType: options.ajax_data_type,
|
196
|
-
success: function(data){
|
217
|
+
success: function(data, status){
|
218
|
+
if (status != 'abort') _this.current_xhr = null;
|
197
219
|
_this.container.html(data);
|
198
220
|
if (!_this.container.is(':visible')) _this.close();
|
199
221
|
else {
|
200
222
|
_this.container.find('.text-input').val(_this.obj.val());
|
201
223
|
RecordSelect.observe(_this.container.find('form').attr('id'));
|
202
224
|
_this.container.hide(); // needed to get right document height to position first time
|
203
|
-
_this.show();
|
225
|
+
if (text.length >= this.min_length) _this.show();
|
204
226
|
jQuery(document.body).mousedown(jQuery.proxy(_this, "onbodyclick"));
|
205
227
|
}
|
206
228
|
}
|
@@ -4,6 +4,8 @@ module RecordSelectHelper
|
|
4
4
|
# *Options*
|
5
5
|
# +onselect+:: JavaScript code to handle selections client-side. This code has access to two variables: id, label. If the code returns false, the dialog will *not* close automatically.
|
6
6
|
# +params+:: Extra URL parameters. If any parameter is a column name, the parameter will be used as a search term to filter the result set.
|
7
|
+
# +html+:: Options for A tag
|
8
|
+
# +rs+:: Options for RecordSelect constructor
|
7
9
|
def link_to_record_select(name, controller, options = {})
|
8
10
|
options[:params] ||= {}
|
9
11
|
options[:params].merge!(:controller => controller, :action => :browse)
|
@@ -12,9 +14,11 @@ module RecordSelectHelper
|
|
12
14
|
options[:html][:id] ||= "rs_#{rand(9999)}"
|
13
15
|
|
14
16
|
assert_controller_responds(options[:params][:controller])
|
17
|
+
record_select_options = {:onselect => options[:onselect] || ''}
|
18
|
+
record_select_options.merge! options[:rs] if options[:rs]
|
15
19
|
|
16
20
|
html = link_to(name, '#', options[:html])
|
17
|
-
html << javascript_tag("new RecordSelect.Dialog(#{options[:html][:id].to_json}, #{url_for(options[:params]).to_json},
|
21
|
+
html << javascript_tag("new RecordSelect.Dialog(#{options[:html][:id].to_json}, #{url_for(options[:params]).to_json}, #{record_select_options.to_json});")
|
18
22
|
|
19
23
|
return html
|
20
24
|
end
|
@@ -30,6 +34,7 @@ module RecordSelectHelper
|
|
30
34
|
# +params+:: A hash of extra URL parameters
|
31
35
|
# +id+:: The id to use for the input. Defaults based on the input's name.
|
32
36
|
# +field_name+:: The name to use for the text input. Defaults to '', so field is not submitted.
|
37
|
+
# +rs+:: Options for RecordSelect constructor
|
33
38
|
def record_select_field(name, current, options = {})
|
34
39
|
options[:controller] ||= current.class.to_s.pluralize.underscore
|
35
40
|
options[:params] ||= {}
|
@@ -45,6 +50,7 @@ module RecordSelectHelper
|
|
45
50
|
record_select_options[:id] = current.id
|
46
51
|
record_select_options[:label] = label_for_field(current, controller)
|
47
52
|
end
|
53
|
+
record_select_options.merge! options[:rs] if options[:rs]
|
48
54
|
|
49
55
|
html = text_field_tag(name, nil, options.merge(:autocomplete => 'off', :onfocus => "this.focused=true", :onblur => "this.focused=false"))
|
50
56
|
url = url_for({:action => :browse, :controller => controller.controller_path}.merge(params))
|
@@ -63,6 +69,7 @@ module RecordSelectHelper
|
|
63
69
|
# +controller+:: The controller configured to provide the result set. Optional if you have standard resource controllers (e.g. UsersController for the User model), in which case the controller will be inferred from the class of +current+ (the second argument)
|
64
70
|
# +params+:: A hash of extra URL parameters
|
65
71
|
# +id+:: The id to use for the input. Defaults based on the input's name.
|
72
|
+
# +rs+:: Options for RecordSelect constructor
|
66
73
|
def record_select_autocomplete(name, current, options = {})
|
67
74
|
options[:controller] ||= current.class.to_s.pluralize.underscore
|
68
75
|
options[:params] ||= {}
|
@@ -76,6 +83,7 @@ module RecordSelectHelper
|
|
76
83
|
if current
|
77
84
|
record_select_options[:label] ||= label_for_field(current, controller)
|
78
85
|
end
|
86
|
+
record_select_options.merge! options[:rs] if options[:rs]
|
79
87
|
|
80
88
|
html = text_field_tag(name, nil, options.merge(:autocomplete => 'off', :onfocus => "this.focused=true", :onblur => "this.focused=false"))
|
81
89
|
url = url_for({:action => :browse, :controller => controller.controller_path}.merge(params))
|
@@ -94,6 +102,7 @@ module RecordSelectHelper
|
|
94
102
|
# +controller+:: The controller configured to provide the result set.
|
95
103
|
# +params+:: A hash of extra URL parameters
|
96
104
|
# +id+:: The id to use for the input. Defaults based on the input's name.
|
105
|
+
# +rs+:: Options for RecordSelect constructor
|
97
106
|
def record_multi_select_field(name, current, options = {})
|
98
107
|
options[:controller] ||= current.first.class.to_s.pluralize.underscore
|
99
108
|
options[:params] ||= {}
|
@@ -106,6 +115,7 @@ module RecordSelectHelper
|
|
106
115
|
params = options.delete(:params)
|
107
116
|
record_select_options = {}
|
108
117
|
record_select_options[:current] = current.inject([]) { |memo, record| memo.push({:id => record.id, :label => label_for_field(record, controller)}) }
|
118
|
+
record_select_options.merge! options[:rs] if options[:rs]
|
109
119
|
|
110
120
|
html = text_field_tag("#{name}[]", nil, options.merge(:autocomplete => 'off', :onfocus => "this.focused=true", :onblur => "this.focused=false"))
|
111
121
|
html << hidden_field_tag("#{name}[]", '', :id => nil)
|
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: 3.4.
|
4
|
+
version: 3.4.9
|
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: 2015-
|
13
|
+
date: 2015-11-26 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: shoulda
|
@@ -113,7 +113,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
113
113
|
version: '0'
|
114
114
|
requirements: []
|
115
115
|
rubyforge_project:
|
116
|
-
rubygems_version: 2.4.
|
116
|
+
rubygems_version: 2.4.4
|
117
117
|
signing_key:
|
118
118
|
specification_version: 4
|
119
119
|
summary: RecordSelect widget as a replacement for massive drop down lists
|