recordselect_vho 3.0.206 → 3.1.100
Sign up to get free protection for your applications and to get access to all the features.
- data/{assets/images → app/assets/images/record_select}/cross.gif +0 -0
- data/{assets/images → app/assets/images/record_select}/next.gif +0 -0
- data/{assets/images → app/assets/images/record_select}/previous.gif +0 -0
- data/{assets → app/assets}/javascripts/jquery/record_select.js +60 -16
- data/{assets → app/assets}/javascripts/prototype/record_select.js +49 -3
- data/app/assets/javascripts/recordselect.js.erb +5 -0
- data/{assets/stylesheets/record_select.css → app/assets/stylesheets/recordselect.css.erb} +2 -2
- data/app/views/record_select/_list.html.erb +5 -5
- data/app/views/record_select/browse.js.erb +1 -0
- data/lib/record_select/actions.rb +9 -3
- data/lib/record_select/conditions.rb +5 -0
- data/lib/record_select/config.rb +6 -2
- data/lib/record_select/engine.rb +4 -0
- data/lib/record_select/extensions/localization.rb +7 -2
- data/lib/record_select/helpers/record_select_helper.rb +57 -26
- data/lib/record_select/version.rb +2 -2
- data/lib/record_select.rb +0 -1
- data/lib/recordselect.rb +1 -9
- metadata +28 -31
- data/app/views/record_select/browse.js.rjs +0 -1
- data/lib/record_select_assets.rb +0 -28
File without changes
|
File without changes
|
File without changes
|
@@ -79,7 +79,7 @@ if (typeof(jQuery.fn.delayedObserver) === 'undefined') {
|
|
79
79
|
|
80
80
|
function delayedObserverCallback(stackPos) {
|
81
81
|
observed = delayedObserverStack[stackPos];
|
82
|
-
if (observed.timer)
|
82
|
+
if (observed.timer) clearTimeout(observed.timer);
|
83
83
|
|
84
84
|
observed.timer = setTimeout(function(){
|
85
85
|
observed.timer = null;
|
@@ -124,7 +124,7 @@ if (typeof(jQuery.fn.delayedObserver) === 'undefined') {
|
|
124
124
|
|
125
125
|
$(document).ready(function() {
|
126
126
|
RecordSelect.document_loaded = true;
|
127
|
-
$(
|
127
|
+
$('div.record-select * li.record a').live('ajax:before', function(event) {
|
128
128
|
var link = $(this);
|
129
129
|
if (link) {
|
130
130
|
if (RecordSelect.notify(link) == false) {
|
@@ -161,11 +161,8 @@ RecordSelect.notify = function(item) {
|
|
161
161
|
if (onselect)
|
162
162
|
{
|
163
163
|
try {
|
164
|
-
|
165
|
-
|
166
|
-
if (label.length == 0) {
|
167
|
-
label = item.html();
|
168
|
-
}
|
164
|
+
var label = $.trim(item.find('label').first().text());
|
165
|
+
if (!label) label = item.text();
|
169
166
|
onselect(item.parent().attr('id').substr(2), label, e);
|
170
167
|
} catch(e) {
|
171
168
|
alert(e);
|
@@ -191,6 +188,9 @@ RecordSelect.Abstract = Class.extend({
|
|
191
188
|
this.url = url;
|
192
189
|
this.options = options;
|
193
190
|
this.container;
|
191
|
+
if (this.options.onchange && typeof this.options.onchange != 'function') {
|
192
|
+
this.options.onchange = eval(this.options.onchange);
|
193
|
+
}
|
194
194
|
|
195
195
|
if (RecordSelect.document_loaded) {
|
196
196
|
this.onload();
|
@@ -236,9 +236,12 @@ RecordSelect.Abstract = Class.extend({
|
|
236
236
|
* positions and reveals the recordselect
|
237
237
|
*/
|
238
238
|
show: function() {
|
239
|
-
var offset = this.obj.offset();
|
240
|
-
this.container.
|
241
|
-
|
239
|
+
var offset = this.obj.offset(), top = this.obj.height() + offset.top;
|
240
|
+
this.container.show();
|
241
|
+
this.container.css('left', offset.left);
|
242
|
+
if (top + this.container.height() > $(document).height())
|
243
|
+
this.container.css('top', offset.top - this.container.height());
|
244
|
+
else this.container.css('top', top);
|
242
245
|
|
243
246
|
if (this._use_iframe_mask()) {
|
244
247
|
this.container.after('<iframe src="javascript:false;" class="record-select-mask" />');
|
@@ -247,8 +250,6 @@ RecordSelect.Abstract = Class.extend({
|
|
247
250
|
.css('top', this.container.css('top'));
|
248
251
|
}
|
249
252
|
|
250
|
-
this.container.show();
|
251
|
-
|
252
253
|
if (this._use_iframe_mask()) {
|
253
254
|
var dimensions = this.container.children().first();
|
254
255
|
mask.css('width', dimensions.css('width'))
|
@@ -283,7 +284,7 @@ RecordSelect.Abstract = Class.extend({
|
|
283
284
|
if (!this.is_open()) return;
|
284
285
|
if (this.container.has($(event.target)).length > 0) {
|
285
286
|
return;
|
286
|
-
} else {
|
287
|
+
} else if (!this.obj.is(event.target)) {
|
287
288
|
this.close();
|
288
289
|
}
|
289
290
|
},
|
@@ -403,7 +404,8 @@ RecordSelect.Dialog = RecordSelect.Abstract.extend({
|
|
403
404
|
/**
|
404
405
|
* Used by record_select_field helper
|
405
406
|
* The options hash may contain id: and label: keys, designating the current value
|
406
|
-
* The options hash may also include an onchange: key, where the value is a javascript function (or eval-able string) for an callback routine
|
407
|
+
* The options hash may also include an onchange: key, where the value is a javascript function (or eval-able string) for an callback routine
|
408
|
+
* and field_name: key, where value will be set as name of the input field.
|
407
409
|
*/
|
408
410
|
RecordSelect.Single = RecordSelect.Abstract.extend({
|
409
411
|
onload: function() {
|
@@ -417,7 +419,7 @@ RecordSelect.Single = RecordSelect.Abstract.extend({
|
|
417
419
|
|
418
420
|
// transfer the input name from the text input to the hidden input
|
419
421
|
this.hidden_input.attr('name', this.obj.attr('name'));
|
420
|
-
this.obj.attr('name', '');
|
422
|
+
this.obj.attr('name', this.options.field_name || '');
|
421
423
|
|
422
424
|
// initialize the values
|
423
425
|
this.set(this.options.id, this.options.label);
|
@@ -434,8 +436,9 @@ RecordSelect.Single = RecordSelect.Abstract.extend({
|
|
434
436
|
},
|
435
437
|
|
436
438
|
onselect: function(id, value) {
|
437
|
-
if (this.options.onchange) this.options.onchange(id, value);
|
438
439
|
this.set(id, value);
|
440
|
+
if (this.options.onchange) this.options.onchange.call(this, id, value);
|
441
|
+
this.obj.trigger("recordselect:change", [id, value]);
|
439
442
|
this.close();
|
440
443
|
},
|
441
444
|
|
@@ -449,6 +452,47 @@ RecordSelect.Single = RecordSelect.Abstract.extend({
|
|
449
452
|
}
|
450
453
|
});
|
451
454
|
|
455
|
+
/**
|
456
|
+
* Used by record_select_autocomplete helper
|
457
|
+
* The options hash may contain label: key, designating the current value
|
458
|
+
* The options hash may also include an onchange: key, where the value is a javascript function (or eval-able string) for an callback routine.
|
459
|
+
*/
|
460
|
+
RecordSelect.Autocomplete = RecordSelect.Abstract.extend({
|
461
|
+
onload: function() {
|
462
|
+
// initialize the container
|
463
|
+
this.container = this.create_container();
|
464
|
+
this.container.addClass('record-select-autocomplete');
|
465
|
+
|
466
|
+
// initialize the values
|
467
|
+
this.set(this.options.label);
|
468
|
+
|
469
|
+
this._respond_to_text_field(this.obj);
|
470
|
+
if (this.obj.focused) this.open(); // if it was focused before we could attach observers
|
471
|
+
},
|
472
|
+
|
473
|
+
close: function() {
|
474
|
+
// if they close the dialog with the text field empty, then delete the id value
|
475
|
+
if (this.obj.val() == '') this.set('');
|
476
|
+
|
477
|
+
RecordSelect.Abstract.prototype.close.call(this);
|
478
|
+
},
|
479
|
+
|
480
|
+
onselect: function(id, value) {
|
481
|
+
this.set(value);
|
482
|
+
if (this.options.onchange) this.options.onchange.call(this, id, value);
|
483
|
+
this.obj.trigger("recordselect:change", [id, value]);
|
484
|
+
this.close();
|
485
|
+
},
|
486
|
+
|
487
|
+
/**
|
488
|
+
* sets the id/label
|
489
|
+
*/
|
490
|
+
set: function(label) {
|
491
|
+
// unescaped html missing for label
|
492
|
+
this.obj.val(label);
|
493
|
+
}
|
494
|
+
});
|
495
|
+
|
452
496
|
/**
|
453
497
|
* Used by record_multi_select_field helper.
|
454
498
|
* Options:
|
@@ -61,6 +61,9 @@ Object.extend(RecordSelect.Abstract.prototype, {
|
|
61
61
|
this.url = url;
|
62
62
|
this.options = options;
|
63
63
|
this.container;
|
64
|
+
if (this.options.onchange && typeof this.options.onchange != 'function') {
|
65
|
+
this.options.onchange = eval(this.options.onchange);
|
66
|
+
}
|
64
67
|
|
65
68
|
if (RecordSelect.document_loaded) this.onload();
|
66
69
|
else Event.observe(window, 'load', this.onload.bind(this));
|
@@ -269,7 +272,8 @@ RecordSelect.Dialog.prototype = Object.extend(new RecordSelect.Abstract(), {
|
|
269
272
|
/**
|
270
273
|
* Used by record_select_field helper
|
271
274
|
* The options hash may contain id: and label: keys, designating the current value
|
272
|
-
* The options hash may also include an onchange: key, where the value is a javascript function (or eval-able string) for an callback routine
|
275
|
+
* The options hash may also include an onchange: key, where the value is a javascript function (or eval-able string) for an callback routine
|
276
|
+
* and field_name: key, where value will be set as name of the input field.
|
273
277
|
*/
|
274
278
|
RecordSelect.Single = Class.create();
|
275
279
|
RecordSelect.Single.prototype = Object.extend(new RecordSelect.Abstract(), {
|
@@ -284,7 +288,7 @@ RecordSelect.Single.prototype = Object.extend(new RecordSelect.Abstract(), {
|
|
284
288
|
|
285
289
|
// transfer the input name from the text input to the hidden input
|
286
290
|
this.hidden_input.name = this.obj.name;
|
287
|
-
this.obj.name = '';
|
291
|
+
this.obj.name = this.options.field_name || '';
|
288
292
|
|
289
293
|
// initialize the values
|
290
294
|
this.set(this.options.id, this.options.label);
|
@@ -301,8 +305,9 @@ RecordSelect.Single.prototype = Object.extend(new RecordSelect.Abstract(), {
|
|
301
305
|
},
|
302
306
|
|
303
307
|
onselect: function(id, value) {
|
304
|
-
if (this.options.onchange) this.options.onchange(id, value);
|
305
308
|
this.set(id, value);
|
309
|
+
if (this.options.onchange) this.options.onchange.call(this, id, value);
|
310
|
+
this.obj.fire('recordselect:change', {"id": id, "label": value});
|
306
311
|
this.close();
|
307
312
|
},
|
308
313
|
|
@@ -315,6 +320,47 @@ RecordSelect.Single.prototype = Object.extend(new RecordSelect.Abstract(), {
|
|
315
320
|
}
|
316
321
|
});
|
317
322
|
|
323
|
+
/**
|
324
|
+
* Used by record_select_autocomplete helper
|
325
|
+
* The options hash may contain label: key, designating the current value
|
326
|
+
* The options hash may also include an onchange: key, where the value is a javascript function (or eval-able string) for an callback routine.
|
327
|
+
*/
|
328
|
+
RecordSelect.Autocomplete = Class.create();
|
329
|
+
RecordSelect.Autocomplete.prototype = Object.extend(new RecordSelect.Abstract(), {
|
330
|
+
onload: function() {
|
331
|
+
// initialize the container
|
332
|
+
this.container = this.create_container();
|
333
|
+
this.container.addClassName('record-select-autocomplete');
|
334
|
+
|
335
|
+
// initialize the values
|
336
|
+
this.set(this.options.label);
|
337
|
+
|
338
|
+
this._respond_to_text_field(this.obj);
|
339
|
+
if (this.obj.focused) this.open(); // if it was focused before we could attach observers
|
340
|
+
},
|
341
|
+
|
342
|
+
close: function() {
|
343
|
+
// if they close the dialog with the text field empty, then delete the id value
|
344
|
+
if (this.obj.value == '') this.set('', '');
|
345
|
+
|
346
|
+
RecordSelect.Abstract.prototype.close.call(this);
|
347
|
+
},
|
348
|
+
|
349
|
+
onselect: function(id, value) {
|
350
|
+
this.set(value);
|
351
|
+
if (this.options.onchange) this.options.onchange.call(this, id, value);
|
352
|
+
this.obj.fire('recordselect:change', {"id": id, "label": value});
|
353
|
+
this.close();
|
354
|
+
},
|
355
|
+
|
356
|
+
/**
|
357
|
+
* sets the id/label
|
358
|
+
*/
|
359
|
+
set: function(label) {
|
360
|
+
this.obj.value = label.unescapeHTML();
|
361
|
+
}
|
362
|
+
});
|
363
|
+
|
318
364
|
/**
|
319
365
|
* Used by record_multi_select_field helper.
|
320
366
|
* Options:
|
@@ -126,8 +126,8 @@ iframe.record-select-mask {
|
|
126
126
|
width: 0px;
|
127
127
|
height: 16px;
|
128
128
|
padding-left: 16px;
|
129
|
-
background: url('
|
129
|
+
background: url(<%= image_path 'record_select/cross.gif' %>) no-repeat 0 0;
|
130
130
|
overflow: hidden;
|
131
131
|
float: left;
|
132
132
|
margin-right: 5px;
|
133
|
-
}
|
133
|
+
}
|
@@ -6,12 +6,12 @@ prev_url = url_for(pagination_url_params.merge(:page => page.prev.number, :escap
|
|
6
6
|
next_url = url_for(pagination_url_params.merge(:page => page.next.number, :escape => false)) if page.next?
|
7
7
|
-%>
|
8
8
|
<ol>
|
9
|
-
<li class="found"><%= rs_(
|
10
|
-
record_select_config.model.
|
9
|
+
<li class="found"><%= rs_(:records_found, :count => page.pager.count,
|
10
|
+
:model => record_select_config.model.model_name.human(:count => page.pager.count).downcase) %></li>
|
11
11
|
<% if page.prev? -%>
|
12
12
|
<li class="pagination previous">
|
13
|
-
<%= link_to image_tag('record_select/previous.gif', :alt => rs_(
|
14
|
-
page.pager.per_page),
|
13
|
+
<%= link_to image_tag('record_select/previous.gif', :alt => rs_(:previous)) + " " + rs_(:previous_items,
|
14
|
+
:count => page.pager.per_page),
|
15
15
|
{:url => prev_url},
|
16
16
|
{:href => prev_url, :method => :get, :remote => true} %>
|
17
17
|
</li>
|
@@ -23,7 +23,7 @@ page.pager.per_page),
|
|
23
23
|
<% end -%>
|
24
24
|
<% if page.next? -%>
|
25
25
|
<li class="pagination next">
|
26
|
-
<%= link_to (rs_(
|
26
|
+
<%= link_to (rs_(:next_items, :count => page.pager.per_page) + " " + image_tag('record_select/next.gif', :alt => rs_(:next))).html_safe,
|
27
27
|
{:url => next_url},
|
28
28
|
{:href => next_url, :method => :get, :remote => true} %>
|
29
29
|
</li>
|
@@ -0,0 +1 @@
|
|
1
|
+
RecordSelect.render_page('<%= record_select_id %>', '<%= escape_javascript(render_record_select(:partial => 'list', :locals => {:page => @page})) %>');
|
@@ -4,10 +4,12 @@ module RecordSelect
|
|
4
4
|
# params => [:page, :search]
|
5
5
|
def browse
|
6
6
|
conditions = record_select_conditions
|
7
|
-
klass =
|
7
|
+
klass = record_select_model
|
8
8
|
@count = klass.count(:conditions => conditions, :include => record_select_includes)
|
9
|
+
@count = @count.length if @count.is_a? ActiveSupport::OrderedHash
|
9
10
|
pager = ::Paginator.new(@count, record_select_config.per_page) do |offset, per_page|
|
10
11
|
klass.find(:all, :offset => offset,
|
12
|
+
:select => record_select_select||"*",
|
11
13
|
:include => [record_select_includes, record_select_config.include].flatten.compact,
|
12
14
|
:limit => per_page,
|
13
15
|
:conditions => conditions,
|
@@ -19,7 +21,7 @@ module RecordSelect
|
|
19
21
|
wants.html { render_record_select :partial => 'browse'}
|
20
22
|
wants.js {
|
21
23
|
if params[:update]
|
22
|
-
render_record_select :template => 'browse', :
|
24
|
+
render_record_select :template => 'browse.js', :layout => false
|
23
25
|
else
|
24
26
|
render_record_select :partial => 'browse'
|
25
27
|
end
|
@@ -33,7 +35,7 @@ module RecordSelect
|
|
33
35
|
# :method => :post
|
34
36
|
# params => [:id]
|
35
37
|
def select
|
36
|
-
klass =
|
38
|
+
klass = record_select_model
|
37
39
|
record = klass.find(params[:id])
|
38
40
|
if record_select_config.notify.is_a? Proc
|
39
41
|
record_select_config.notify.call(record)
|
@@ -64,4 +66,8 @@ module RecordSelect
|
|
64
66
|
"record_select"
|
65
67
|
end
|
66
68
|
end
|
69
|
+
|
70
|
+
def record_select_model
|
71
|
+
record_select_config.model
|
72
|
+
end
|
67
73
|
end
|
@@ -28,6 +28,11 @@ module RecordSelect
|
|
28
28
|
@like_operator ||= ::ActiveRecord::Base.connection.adapter_name == "PostgreSQL" ? "ILIKE" : "LIKE"
|
29
29
|
end
|
30
30
|
|
31
|
+
# define special list of selected fields,
|
32
|
+
# mainly to define extra fields that can be used for
|
33
|
+
# specialized sorting.
|
34
|
+
def record_select_select; end
|
35
|
+
|
31
36
|
# generate conditions from params[:search]
|
32
37
|
# override this if you want to customize the search routine
|
33
38
|
def record_select_conditions_from_search
|
data/lib/record_select/config.rb
CHANGED
@@ -26,7 +26,11 @@ module RecordSelect
|
|
26
26
|
end
|
27
27
|
|
28
28
|
def self.js_framework
|
29
|
-
@@js_framework ||=
|
29
|
+
@@js_framework ||= if defined? Jquery
|
30
|
+
:jquery
|
31
|
+
elsif defined? PrototypeRails
|
32
|
+
:prototype
|
33
|
+
end
|
30
34
|
end
|
31
35
|
|
32
36
|
# The model object we're browsing
|
@@ -96,4 +100,4 @@ module RecordSelect
|
|
96
100
|
@klass
|
97
101
|
end
|
98
102
|
end
|
99
|
-
end
|
103
|
+
end
|
@@ -2,7 +2,12 @@
|
|
2
2
|
# to localize RS, you need to override this method and route it to your
|
3
3
|
# own system.
|
4
4
|
class Object
|
5
|
-
def rs_(
|
6
|
-
|
5
|
+
def rs_(key, options = {})
|
6
|
+
unless key.blank?
|
7
|
+
text = I18n.translate "#{key}", {:scope => [:record_select], :default => key.is_a?(String) ? key : key.to_s.titleize}.merge(options)
|
8
|
+
# text = nil if text.include?('translation missing:')
|
9
|
+
end
|
10
|
+
text ||= key
|
11
|
+
text
|
7
12
|
end
|
8
13
|
end
|
@@ -1,13 +1,4 @@
|
|
1
1
|
module RecordSelectHelper
|
2
|
-
# Print this from your layout to include everything necessary for RecordSelect to work.
|
3
|
-
# Well, not everything. You need Prototype too.
|
4
|
-
def record_select_includes
|
5
|
-
includes = ''
|
6
|
-
includes << stylesheet_link_tag('record_select/record_select')
|
7
|
-
includes << javascript_include_tag('record_select/record_select')
|
8
|
-
includes.html_safe
|
9
|
-
end
|
10
|
-
|
11
2
|
# Adds a link on the page that toggles a RecordSelect widget from the given controller.
|
12
3
|
#
|
13
4
|
# *Options*
|
@@ -38,24 +29,61 @@ module RecordSelectHelper
|
|
38
29
|
# +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)
|
39
30
|
# +params+:: A hash of extra URL parameters
|
40
31
|
# +id+:: The id to use for the input. Defaults based on the input's name.
|
41
|
-
# +
|
32
|
+
# +field_name+:: The name to use for the text input. Defaults to '', so field is not submitted.
|
42
33
|
def record_select_field(name, current, options = {})
|
43
34
|
options[:controller] ||= current.class.to_s.pluralize.underscore
|
44
35
|
options[:params] ||= {}
|
45
36
|
options[:id] ||= name.gsub(/[\[\]]/, '_')
|
37
|
+
options[:class] ||= ''
|
38
|
+
options[:class] << ' recordselect'
|
46
39
|
|
47
|
-
|
40
|
+
ActiveSupport::Deprecation.warn 'onchange option is deprecated. Bind recordselect:change event instead.' if options[:onchange]
|
48
41
|
|
49
|
-
|
42
|
+
controller = assert_controller_responds(options.delete(:controller))
|
43
|
+
params = options.delete(:params)
|
44
|
+
record_select_options = {}
|
45
|
+
record_select_options[:field_name] = options.delete(:field_name) if options[:field_name]
|
50
46
|
if current and not current.new_record?
|
51
|
-
id = current.id
|
52
|
-
label = label_for_field(current, controller)
|
47
|
+
record_select_options[:id] = current.id
|
48
|
+
record_select_options[:label] = label_for_field(current, controller)
|
53
49
|
end
|
54
50
|
|
55
|
-
|
51
|
+
html = text_field_tag(name, nil, options.merge(:autocomplete => 'off', :onfocus => "this.focused=true", :onblur => "this.focused=false"))
|
52
|
+
url = url_for({:action => :browse, :controller => controller.controller_path, :escape => false}.merge(params))
|
53
|
+
html << javascript_tag("new RecordSelect.Single(#{options[:id].to_json}, #{url.to_json}, #{record_select_options.to_json});")
|
54
|
+
|
55
|
+
return html
|
56
|
+
end
|
57
|
+
|
58
|
+
# Adds a RecordSelect-based form field. The field is autocompleted.
|
59
|
+
#
|
60
|
+
# *Arguments*
|
61
|
+
# +name+:: the input name that will be used to submit the selected value.
|
62
|
+
# +current+:: the current object. provide a new record if there're none currently selected and you have not passed the optional :controller argument.
|
63
|
+
#
|
64
|
+
# *Options*
|
65
|
+
# +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)
|
66
|
+
# +params+:: A hash of extra URL parameters
|
67
|
+
# +id+:: The id to use for the input. Defaults based on the input's name.
|
68
|
+
def record_select_autocomplete(name, current, options = {})
|
69
|
+
options[:controller] ||= current.class.to_s.pluralize.underscore
|
70
|
+
options[:params] ||= {}
|
71
|
+
options[:id] ||= name.gsub(/[\[\]]/, '_')
|
72
|
+
options[:class] ||= ''
|
73
|
+
options[:class] << ' recordselect'
|
74
|
+
|
75
|
+
ActiveSupport::Deprecation.warn 'onchange option is deprecated. Bind recordselect:change event instead.' if options[:onchange]
|
76
|
+
|
77
|
+
controller = assert_controller_responds(options.delete(:controller))
|
78
|
+
params = options.delete(:params)
|
79
|
+
record_select_options = {}
|
80
|
+
if current and not current.new_record?
|
81
|
+
record_select_options[:label] = label_for_field(current, controller)
|
82
|
+
end
|
56
83
|
|
57
|
-
html = text_field_tag(name, nil, :autocomplete => 'off', :
|
58
|
-
|
84
|
+
html = text_field_tag(name, nil, options.merge(:autocomplete => 'off', :onfocus => "this.focused=true", :onblur => "this.focused=false"))
|
85
|
+
url = url_for({:action => :browse, :controller => controller.controller_path, :escape => false}.merge(params))
|
86
|
+
html << javascript_tag("new RecordSelect.Autocomplete(#{options[:id].to_json}, #{url.to_json}, #{record_select_options.to_json});")
|
59
87
|
|
60
88
|
return html
|
61
89
|
end
|
@@ -91,19 +119,22 @@ module RecordSelectHelper
|
|
91
119
|
options[:controller] ||= current.first.class.to_s.pluralize.underscore
|
92
120
|
options[:params] ||= {}
|
93
121
|
options[:id] ||= name.gsub(/[\[\]]/, '_')
|
122
|
+
options[:class] ||= ''
|
123
|
+
options[:class] << ' recordselect'
|
124
|
+
options.delete(:name)
|
94
125
|
|
95
|
-
controller = assert_controller_responds(options
|
126
|
+
controller = assert_controller_responds(options.delete(:controller))
|
127
|
+
params = options.delete(:params)
|
128
|
+
record_select_options = {}
|
129
|
+
record_select_options[:current] = current.inject([]) { |memo, record| memo.push({:id => record.id, :label => label_for_field(record, controller)}) }
|
130
|
+
|
131
|
+
html = text_field_tag("#{name}[]", nil, options.merge(:autocomplete => 'off', :onfocus => "this.focused=true", :onblur => "this.focused=false"))
|
132
|
+
html << content_tag('ul', '', :class => 'record-select-list');
|
96
133
|
|
97
134
|
# js identifier so we can talk to it.
|
98
135
|
widget = "rs_%s" % name.gsub(/[\[\]]/, '_').chomp('_')
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
url = url_for({:action => :browse, :controller => options[:controller], :escape => false}.merge(options[:params]))
|
103
|
-
|
104
|
-
html = text_field_tag("#{name}[]", nil, :autocomplete => 'off', :id => options[:id], :class => options[:class], :onfocus => "this.focused=true", :onblur => "this.focused=false")
|
105
|
-
html << content_tag('ul', '', :class => 'record-select-list');
|
106
|
-
html << javascript_tag("#{widget} = new RecordSelect.Multiple(#{options[:id].to_json}, #{url.to_json}, {current: #{current.to_json}});")
|
136
|
+
url = url_for({:action => :browse, :controller => controller.controller_path, :escape => false}.merge(params))
|
137
|
+
html << javascript_tag("#{widget} = new RecordSelect.Multiple(#{options[:id].to_json}, #{url.to_json}, #{record_select_options.to_json});")
|
107
138
|
|
108
139
|
return html
|
109
140
|
end
|
data/lib/record_select.rb
CHANGED
data/lib/recordselect.rb
CHANGED
@@ -1,4 +1,3 @@
|
|
1
|
-
require 'record_select_assets'
|
2
1
|
require 'record_select'
|
3
2
|
require 'record_select/extensions/localization'
|
4
3
|
require 'record_select/extensions/active_record'
|
@@ -8,15 +7,8 @@ require 'record_select/conditions'
|
|
8
7
|
require 'record_select/config'
|
9
8
|
require 'record_select/form_builder'
|
10
9
|
require 'record_select/helpers/record_select_helper'
|
10
|
+
require 'record_select/engine' unless defined? RECORD_SELECT_PLUGIN
|
11
11
|
|
12
12
|
ActionController::Base.send(:include, RecordSelect)
|
13
13
|
ActionView::Base.send(:include, RecordSelectHelper)
|
14
14
|
ActionView::Helpers::FormBuilder.send(:include, RecordSelect::FormBuilder)
|
15
|
-
|
16
|
-
Rails::Application.initializer("recordselect.install_assets") do
|
17
|
-
begin
|
18
|
-
RecordSelectAssets.copy_to_public
|
19
|
-
rescue
|
20
|
-
raise $! unless Rails.env == 'production'
|
21
|
-
end
|
22
|
-
end if defined?(RECORD_SELECT_GEM)
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: recordselect_vho
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
prerelease:
|
4
|
+
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 3
|
8
|
-
-
|
9
|
-
-
|
10
|
-
version: 3.
|
7
|
+
- 1
|
8
|
+
- 100
|
9
|
+
version: 3.1.100
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Sergio Cambra
|
@@ -17,68 +16,65 @@ autorequire:
|
|
17
16
|
bindir: bin
|
18
17
|
cert_chain: []
|
19
18
|
|
20
|
-
date:
|
19
|
+
date: 2012-01-10 00:00:00 +01:00
|
20
|
+
default_executable:
|
21
21
|
dependencies:
|
22
22
|
- !ruby/object:Gem::Dependency
|
23
|
+
name: shoulda
|
23
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
24
25
|
none: false
|
25
26
|
requirements:
|
26
27
|
- - ">="
|
27
28
|
- !ruby/object:Gem::Version
|
28
|
-
hash: 3
|
29
29
|
segments:
|
30
30
|
- 0
|
31
31
|
version: "0"
|
32
32
|
type: :development
|
33
|
-
name: shoulda
|
34
|
-
version_requirements: *id001
|
35
33
|
prerelease: false
|
34
|
+
version_requirements: *id001
|
36
35
|
- !ruby/object:Gem::Dependency
|
36
|
+
name: bundler
|
37
37
|
requirement: &id002 !ruby/object:Gem::Requirement
|
38
38
|
none: false
|
39
39
|
requirements:
|
40
40
|
- - ~>
|
41
41
|
- !ruby/object:Gem::Version
|
42
|
-
hash: 23
|
43
42
|
segments:
|
44
43
|
- 1
|
45
44
|
- 0
|
46
45
|
- 0
|
47
46
|
version: 1.0.0
|
48
47
|
type: :development
|
49
|
-
name: bundler
|
50
|
-
version_requirements: *id002
|
51
48
|
prerelease: false
|
49
|
+
version_requirements: *id002
|
52
50
|
- !ruby/object:Gem::Dependency
|
51
|
+
name: rcov
|
53
52
|
requirement: &id003 !ruby/object:Gem::Requirement
|
54
53
|
none: false
|
55
54
|
requirements:
|
56
55
|
- - ">="
|
57
56
|
- !ruby/object:Gem::Version
|
58
|
-
hash: 3
|
59
57
|
segments:
|
60
58
|
- 0
|
61
59
|
version: "0"
|
62
60
|
type: :development
|
63
|
-
name: rcov
|
64
|
-
version_requirements: *id003
|
65
61
|
prerelease: false
|
62
|
+
version_requirements: *id003
|
66
63
|
- !ruby/object:Gem::Dependency
|
64
|
+
name: rails
|
67
65
|
requirement: &id004 !ruby/object:Gem::Requirement
|
68
66
|
none: false
|
69
67
|
requirements:
|
70
68
|
- - ">="
|
71
69
|
- !ruby/object:Gem::Version
|
72
|
-
hash: 7
|
73
70
|
segments:
|
74
71
|
- 3
|
72
|
+
- 1
|
75
73
|
- 0
|
76
|
-
|
77
|
-
version: 3.0.0
|
74
|
+
version: 3.1.0
|
78
75
|
type: :runtime
|
79
|
-
name: rails
|
80
|
-
version_requirements: *id004
|
81
76
|
prerelease: false
|
77
|
+
version_requirements: *id004
|
82
78
|
description: RecordSelect is a Rails widget to help you pick one record out of many. I designed it as a more usable and performant alternative to generating a massive dropdown list
|
83
79
|
email: activescaffold@googlegroups.com
|
84
80
|
executables: []
|
@@ -89,9 +85,16 @@ extra_rdoc_files:
|
|
89
85
|
- README
|
90
86
|
files:
|
91
87
|
- app/views/record_select/_list.html.erb
|
92
|
-
- app/views/record_select/browse.js.rjs
|
93
88
|
- app/views/record_select/_search.html.erb
|
89
|
+
- app/views/record_select/browse.js.erb
|
94
90
|
- app/views/record_select/_browse.html.erb
|
91
|
+
- app/assets/javascripts/recordselect.js.erb
|
92
|
+
- app/assets/javascripts/prototype/record_select.js
|
93
|
+
- app/assets/javascripts/jquery/record_select.js
|
94
|
+
- app/assets/stylesheets/recordselect.css.erb
|
95
|
+
- app/assets/images/record_select/next.gif
|
96
|
+
- app/assets/images/record_select/previous.gif
|
97
|
+
- app/assets/images/record_select/cross.gif
|
95
98
|
- lib/recordselect_vho.rb
|
96
99
|
- lib/recordselect.rb
|
97
100
|
- lib/record_select/version.rb
|
@@ -103,18 +106,13 @@ files:
|
|
103
106
|
- lib/record_select/actions.rb
|
104
107
|
- lib/record_select/conditions.rb
|
105
108
|
- lib/record_select/form_builder.rb
|
106
|
-
- lib/
|
109
|
+
- lib/record_select/engine.rb
|
107
110
|
- lib/record_select.rb
|
108
|
-
- assets/javascripts/prototype/record_select.js
|
109
|
-
- assets/javascripts/jquery/record_select.js
|
110
|
-
- assets/stylesheets/record_select.css
|
111
|
-
- assets/images/next.gif
|
112
|
-
- assets/images/previous.gif
|
113
|
-
- assets/images/cross.gif
|
114
111
|
- MIT-LICENSE
|
115
112
|
- CHANGELOG
|
116
113
|
- README
|
117
114
|
- test/recordselect_test.rb
|
115
|
+
has_rdoc: true
|
118
116
|
homepage: http://github.com/vhochstein/recordselect
|
119
117
|
licenses:
|
120
118
|
- MIT
|
@@ -128,7 +126,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
128
126
|
requirements:
|
129
127
|
- - ">="
|
130
128
|
- !ruby/object:Gem::Version
|
131
|
-
hash:
|
129
|
+
hash: -2910815514046126153
|
132
130
|
segments:
|
133
131
|
- 0
|
134
132
|
version: "0"
|
@@ -137,14 +135,13 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
137
135
|
requirements:
|
138
136
|
- - ">="
|
139
137
|
- !ruby/object:Gem::Version
|
140
|
-
hash: 3
|
141
138
|
segments:
|
142
139
|
- 0
|
143
140
|
version: "0"
|
144
141
|
requirements: []
|
145
142
|
|
146
143
|
rubyforge_project:
|
147
|
-
rubygems_version: 1.
|
144
|
+
rubygems_version: 1.3.7
|
148
145
|
signing_key:
|
149
146
|
specification_version: 3
|
150
147
|
summary: RecordSelect widget as a replacement for massive drop down lists
|
@@ -1 +0,0 @@
|
|
1
|
-
page.call 'RecordSelect.render_page', record_select_id, render_record_select(:partial => 'list', :locals => {:page => @page})
|
data/lib/record_select_assets.rb
DELETED
@@ -1,28 +0,0 @@
|
|
1
|
-
class RecordSelectAssets
|
2
|
-
|
3
|
-
def self.copy_to_public(options = {})
|
4
|
-
if defined? ActiveScaffold
|
5
|
-
RecordSelect::Config.js_framework = ActiveScaffold.js_framework
|
6
|
-
else
|
7
|
-
RecordSelect::Config.js_framework = :jquery
|
8
|
-
end
|
9
|
-
unless defined?(RECORD_SELECT_INSTALL_ASSETS) && RECORD_SELECT_INSTALL_ASSETS == false
|
10
|
-
['stylesheets', 'images', 'javascripts'].each do |asset_type|
|
11
|
-
if asset_type == 'javascripts'
|
12
|
-
local_dir = File.join(File.dirname(__FILE__), '..', 'assets', asset_type, RecordSelect::Config.js_framework.to_s)
|
13
|
-
else
|
14
|
-
local_dir = File.join(File.dirname(__FILE__), '..', 'assets', asset_type)
|
15
|
-
end
|
16
|
-
public_dir = File.join(Rails.root, 'public', asset_type, 'record_select')
|
17
|
-
FileUtils.mkdir public_dir unless File.exists? public_dir
|
18
|
-
Dir.entries(local_dir).each do |file|
|
19
|
-
next if file =~ /^\./
|
20
|
-
FileUtils.cp File.join(local_dir, file), public_dir
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
protected
|
27
|
-
|
28
|
-
end
|