recordselect 3.0.5 → 3.1.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.
File without changes
File without changes
File without changes
@@ -191,9 +191,6 @@ RecordSelect.Abstract = Class.extend({
191
191
  this.url = url;
192
192
  this.options = options;
193
193
  this.container;
194
- if (this.options.onchange && typeof(this.options.onchange) != 'function') {
195
- this.options.onchange = eval(this.options.onchange);
196
- }
197
194
 
198
195
  if (RecordSelect.document_loaded) {
199
196
  this.onload();
@@ -61,9 +61,6 @@ 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
- }
67
64
 
68
65
  if (RecordSelect.document_loaded) this.onload();
69
66
  else Event.observe(window, 'load', this.onload.bind(this));
@@ -0,0 +1,5 @@
1
+ <% if RecordSelect::Config.js_framework == :jquery %>
2
+ <% require_asset "jquery/record_select" %>
3
+ <% else %>
4
+ <% require_asset "prototype/record_select" %>
5
+ <% end %>
data/lib/record_select.rb CHANGED
@@ -1,7 +1,6 @@
1
1
  module RecordSelect
2
2
  def self.included(base)
3
3
  base.send :extend, ClassMethods
4
- #base.append_view_path "#{File.dirname(__FILE__)}/../app/views" if defined?(RECORD_SELECT_GEM)
5
4
  end
6
5
 
7
6
  module ClassMethods
@@ -26,7 +26,11 @@ module RecordSelect
26
26
  end
27
27
 
28
28
  def self.js_framework
29
- @@js_framework ||= :prototype
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
@@ -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*
@@ -1,8 +1,8 @@
1
1
  module RecordSelect
2
2
  module Version
3
3
  MAJOR = 3
4
- MINOR = 0
5
- PATCH = 5
4
+ MINOR = 1
5
+ PATCH = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, PATCH].compact.join('.')
8
8
  end
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'
@@ -13,11 +12,3 @@ require 'record_select/engine' unless defined? RECORD_SELECT_PLUGIN
13
12
  ActionController::Base.send(:include, RecordSelect)
14
13
  ActionView::Base.send(:include, RecordSelectHelper)
15
14
  ActionView::Helpers::FormBuilder.send(:include, RecordSelect::FormBuilder)
16
-
17
- Rails::Application.initializer("recordselect.install_assets") do
18
- begin
19
- RecordSelectAssets.copy_to_public
20
- rescue
21
- raise $! unless Rails.env == 'production'
22
- end
23
- end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: recordselect
3
3
  version: !ruby/object:Gem::Version
4
- hash: 13
4
+ hash: 3
5
5
  prerelease:
6
6
  segments:
7
7
  - 3
8
+ - 1
8
9
  - 0
9
- - 5
10
- version: 3.0.5
10
+ version: 3.1.0
11
11
  platform: ruby
12
12
  authors:
13
13
  - Sergio Cambra
@@ -17,10 +17,9 @@ autorequire:
17
17
  bindir: bin
18
18
  cert_chain: []
19
19
 
20
- date: 2013-05-02 00:00:00 Z
20
+ date: 2011-09-15 00:00:00 Z
21
21
  dependencies:
22
22
  - !ruby/object:Gem::Dependency
23
- type: :development
24
23
  requirement: &id001 !ruby/object:Gem::Requirement
25
24
  none: false
26
25
  requirements:
@@ -30,11 +29,11 @@ dependencies:
30
29
  segments:
31
30
  - 0
32
31
  version: "0"
32
+ type: :development
33
+ name: shoulda
33
34
  version_requirements: *id001
34
35
  prerelease: false
35
- name: shoulda
36
36
  - !ruby/object:Gem::Dependency
37
- type: :development
38
37
  requirement: &id002 !ruby/object:Gem::Requirement
39
38
  none: false
40
39
  requirements:
@@ -46,11 +45,11 @@ dependencies:
46
45
  - 0
47
46
  - 0
48
47
  version: 1.0.0
48
+ type: :development
49
+ name: bundler
49
50
  version_requirements: *id002
50
51
  prerelease: false
51
- name: bundler
52
52
  - !ruby/object:Gem::Dependency
53
- type: :development
54
53
  requirement: &id003 !ruby/object:Gem::Requirement
55
54
  none: false
56
55
  requirements:
@@ -60,25 +59,26 @@ dependencies:
60
59
  segments:
61
60
  - 0
62
61
  version: "0"
62
+ type: :development
63
+ name: rcov
63
64
  version_requirements: *id003
64
65
  prerelease: false
65
- name: rcov
66
66
  - !ruby/object:Gem::Dependency
67
- type: :runtime
68
67
  requirement: &id004 !ruby/object:Gem::Requirement
69
68
  none: false
70
69
  requirements:
71
70
  - - ~>
72
71
  - !ruby/object:Gem::Version
73
- hash: 7
72
+ hash: 3
74
73
  segments:
75
74
  - 3
75
+ - 1
76
76
  - 0
77
- - 0
78
- version: 3.0.0
77
+ version: 3.1.0
78
+ type: :runtime
79
+ name: rails
79
80
  version_requirements: *id004
80
81
  prerelease: false
81
- name: rails
82
82
  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
83
  email: activescaffold@googlegroups.com
84
84
  executables: []
@@ -88,19 +88,17 @@ extensions: []
88
88
  extra_rdoc_files:
89
89
  - README
90
90
  files:
91
- - assets/images/cross.gif
92
- - assets/images/next.gif
93
- - assets/images/previous.gif
94
- - assets/javascripts/jquery/record_select.js
95
- - assets/javascripts/prototype/record_select.js
96
- - assets/stylesheets/record_select.css
97
91
  - app/views/record_select/_list.html.erb
98
92
  - app/views/record_select/_search.html.erb
99
93
  - app/views/record_select/browse.js.rjs
100
94
  - app/views/record_select/_browse.html.erb
101
- - app/views/record_select/_list.html.erb~
102
- - app/assets/javascripts/jquery/record_select.js~
103
- - app/assets/javascripts/prototype/record_select.js~
95
+ - app/assets/images/cross.gif
96
+ - app/assets/images/next.gif
97
+ - app/assets/images/previous.gif
98
+ - app/assets/javascripts/jquery/record_select.js
99
+ - app/assets/javascripts/prototype/record_select.js
100
+ - app/assets/javascripts/record_select.js.erb
101
+ - app/assets/stylesheets/record_select.css
104
102
  - lib/record_select.rb
105
103
  - lib/recordselect.rb
106
104
  - lib/record_select/actions.rb
@@ -110,13 +108,9 @@ files:
110
108
  - lib/record_select/extensions/active_record.rb
111
109
  - lib/record_select/extensions/localization.rb
112
110
  - lib/record_select/extensions/routing_mapper.rb
113
- - lib/record_select/extensions/localization.rb~
114
111
  - lib/record_select/helpers/record_select_helper.rb
115
- - lib/record_select/helpers/record_select_helper.rb~
116
112
  - lib/record_select/version.rb
117
113
  - lib/record_select/engine.rb
118
- - lib/record_select/version.rb~
119
- - lib/record_select_assets.rb
120
114
  - MIT-LICENSE
121
115
  - CHANGELOG
122
116
  - README
@@ -150,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
150
144
  requirements: []
151
145
 
152
146
  rubyforge_project:
153
- rubygems_version: 1.8.23
147
+ rubygems_version: 1.8.10
154
148
  signing_key:
155
149
  specification_version: 3
156
150
  summary: RecordSelect widget as a replacement for massive drop down lists
@@ -1,543 +0,0 @@
1
- if (typeof(Class) === 'undefined') {
2
- /* Simple Inheritance
3
- http://ejohn.org/blog/simple-javascript-inheritance/
4
- */
5
- (function(){
6
- var initializing = false, fnTest = /xyz/.test(function(){xyz;}) ? /\b_super\b/ : /.*/;
7
-
8
- // The base Class implementation (does nothing)
9
- this.Class = function(){};
10
-
11
- // Create a new Class that inherits from this class
12
- Class.extend = function(prop) {
13
- var _super = this.prototype;
14
-
15
- // Instantiate a base class (but only create the instance,
16
- // don't run the init constructor)
17
- initializing = true;
18
- var prototype = new this();
19
- initializing = false;
20
-
21
- // Copy the properties over onto the new prototype
22
- for (var name in prop) {
23
- // Check if we're overwriting an existing function
24
- prototype[name] = typeof prop[name] == "function" &&
25
- typeof _super[name] == "function" && fnTest.test(prop[name]) ?
26
- (function(name, fn){
27
- return function() {
28
- var tmp = this._super;
29
-
30
- // Add a new ._super() method that is the same method
31
- // but on the super-class
32
- this._super = _super[name];
33
-
34
- // The method only need to be bound temporarily, so we
35
- // remove it when we're done executing
36
- var ret = fn.apply(this, arguments);
37
- this._super = tmp;
38
-
39
- return ret;
40
- };
41
- })(name, prop[name]) :
42
- prop[name];
43
- }
44
-
45
- // The dummy class constructor
46
- function Class() {
47
- // All construction is actually done in the init method
48
- if ( !initializing && this.init )
49
- this.init.apply(this, arguments);
50
- }
51
-
52
- // Populate our constructed prototype object
53
- Class.prototype = prototype;
54
-
55
- // Enforce the constructor to be what we expect
56
- Class.constructor = Class;
57
-
58
- // And make this class extendable
59
- Class.extend = arguments.callee;
60
-
61
- return Class;
62
- };
63
- })();
64
- };
65
-
66
- /*
67
- jQuery delayed observer
68
- (c) 2007 - Maxime Haineault (max@centdessin.com)
69
-
70
- Special thanks to Stephen Goguen & Tane Piper.
71
-
72
- Slight modifications by Elliot Winkler
73
- */
74
-
75
- if (typeof(jQuery.fn.delayedObserver) === 'undefined') {
76
- (function() {
77
- var delayedObserverStack = [];
78
- var observed;
79
-
80
- function delayedObserverCallback(stackPos) {
81
- observed = delayedObserverStack[stackPos];
82
- if (observed.timer) clearTimeout(observed.timer);
83
-
84
- observed.timer = setTimeout(function(){
85
- observed.timer = null;
86
- observed.callback(observed.obj.val(), observed.obj);
87
- }, observed.delay * 1000);
88
-
89
- observed.oldVal = observed.obj.val();
90
- }
91
-
92
- // going by
93
- // <http://www.cambiaresearch.com/c4/702b8cd1-e5b0-42e6-83ac-25f0306e3e25/Javascript-Char-Codes-Key-Codes.aspx>
94
- // I think these codes only work when using keyup or keydown
95
- function isNonPrintableKey(event) {
96
- var code = event.keyCode;
97
- return (
98
- event.metaKey ||
99
- (code >= 9 || code <= 16) || (code >= 27 && code <= 40) || (code >= 91 && code <= 93) || (code >= 112 && code <= 145)
100
- );
101
- }
102
-
103
- jQuery.fn.extend({
104
- delayedObserver:function(delay, callback){
105
- $this = jQuery(this);
106
-
107
- delayedObserverStack.push({
108
- obj: $this, timer: null, delay: delay,
109
- oldVal: $this.val(), callback: callback
110
- });
111
-
112
- stackPos = delayedObserverStack.length-1;
113
-
114
- $this.keyup(function(event) {
115
- if (isNonPrintableKey(event)) return;
116
- observed = delayedObserverStack[stackPos];
117
- if (observed.obj.val() == observed.obj.oldVal) return;
118
- else delayedObserverCallback(stackPos);
119
- });
120
- }
121
- });
122
- })();
123
- };
124
-
125
- jQuery(document).ready(function() {
126
- RecordSelect.document_loaded = true;
127
- jQuery('div.record-select * li.record a').live('ajax:before', function(event) {
128
- var link = jQuery(this);
129
- if (link) {
130
- if (RecordSelect.notify(link) == false) {
131
- return false;
132
- } else {
133
- link.toggleClass("selected");
134
- }
135
- }
136
- return true;
137
- });
138
- });
139
-
140
- /**
141
- Form.Element.AfterActivity = function(element, callback, delay) {
142
- element = jQuery(element);
143
- if (!delay) delay = 0.25;
144
- new Form.Element.Observer(element, delay, function(element, value) {
145
- // TODO: display loading indicator
146
- if (element.activity_timer) clearTimeout(element.activity_timer);
147
- element.activity_timer = setTimeout(function() {
148
- callback(element.value);
149
- }, delay * 1000 + 50);
150
- });
151
- }
152
- */
153
-
154
- var RecordSelect = new Object();
155
- RecordSelect.document_loaded = false;
156
-
157
- RecordSelect.notify = function(item) {
158
- var e = item.closest('.record-select-handler');
159
- var onselect = e.get(0).onselect || e.attr('onselect');
160
- if (typeof onselect != 'function') onselect = eval(onselect);
161
- if (onselect)
162
- {
163
- try {
164
- var label = jQuery.trim(item.find('label').first().text());
165
- if (!label) label = item.text();
166
- onselect(item.parent().attr('id').substr(2), label, e);
167
- } catch(e) {
168
- alert(e);
169
- }
170
- return false;
171
- }
172
- else return true;
173
- }
174
-
175
- RecordSelect.render_page = function(record_select_id, page) {
176
- jQuery('#' + record_select_id + ' ol').first().replaceWith(page);
177
- };
178
-
179
- RecordSelect.Abstract = Class.extend({
180
- /**
181
- * obj - the id or element that will anchor the recordselect to the page
182
- * url - the url to run the recordselect
183
- * options - ??? (check concrete classes)
184
- */
185
- init: function(obj, url, options) {
186
- if (typeof(obj) == 'string') obj = '#' + obj;
187
- this.obj = jQuery(obj);
188
- this.url = url;
189
- this.options = options;
190
- this.container;
191
- if (this.options.onchange && typeof this.options.onchange != 'function') {
192
- this.options.onchange = eval(this.options.onchange);
193
- }
194
-
195
- if (RecordSelect.document_loaded) {
196
- this.onload();
197
- } else {
198
- var _this = this; jQuery(document).ready(function() { _this.onload(); })
199
- }
200
- },
201
-
202
- /**
203
- * Finish the setup - IE doesn't like doing certain things before the page loads
204
- * --override--
205
- */
206
- onload: function() {},
207
-
208
- /**
209
- * the onselect event handler - when someone clicks on a record
210
- * --override--
211
- */
212
- onselect: function(id, value) {
213
- alert(id + ': ' + value);
214
- },
215
-
216
- /**
217
- * opens the recordselect
218
- */
219
- open: function() {
220
- if (this.is_open()) return;
221
- var _this = this;
222
- jQuery.ajax({
223
- url: this.url,
224
- //type: "POST",
225
- //data: options['params'],
226
- //dataType: options.ajax_data_type,
227
- success: function(data){
228
- _this.container.html(data);
229
- _this.show();
230
- jQuery(document.body).mousedown(jQuery.proxy(_this, "onbodyclick"));
231
- }
232
- });
233
- },
234
-
235
- /**
236
- * positions and reveals the recordselect
237
- */
238
- show: function() {
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() > jQuery(window).height())
243
- this.container.css('bottom', jQuery(window).height() - offset.top);
244
- else this.container.css('top', top);
245
-
246
- if (this._use_iframe_mask()) {
247
- this.container.after('<iframe src="javascript:false;" class="record-select-mask" />');
248
- var mask = this.container.next('iframe');
249
- mask.css('left', this.container.css('left'))
250
- .css('top', this.container.css('top'));
251
- }
252
-
253
- if (this._use_iframe_mask()) {
254
- var dimensions = this.container.children().first();
255
- mask.css('width', dimensions.css('width'))
256
- .css('height', dimensions.css('height'));
257
- }
258
- },
259
-
260
- /**
261
- * closes the recordselect by emptying the container
262
- */
263
- close: function() {
264
- if (this._use_iframe_mask()) {
265
- this.container.next('iframe').remove();
266
- }
267
-
268
- this.container.hide();
269
- // hopefully by using remove() instead of innerHTML we won't leak memory
270
- this.container.children().remove();
271
- },
272
-
273
- /**
274
- * returns true/false for whether the recordselect is open
275
- */
276
- is_open: function() {
277
- return (!(jQuery.trim(this.container.html()).length == 0))
278
- },
279
-
280
- /**
281
- * when the user clicks outside the dropdown
282
- */
283
- onbodyclick: function(event) {
284
- if (!this.is_open()) return;
285
- if (this.container.has(jQuery(event.target)).length > 0) {
286
- return;
287
- } else if (!this.obj.is(event.target)) {
288
- this.close();
289
- }
290
- },
291
-
292
- /**
293
- * creates and initializes (and returns) the recordselect container
294
- */
295
- create_container: function() {
296
- var e = jQuery("<div />", {'class': "record-select-container record-select-handler"});
297
- e.css('display', 'none')
298
- jQuery(document.body).append(e);
299
- e.get(0).onselect = jQuery.proxy(this, "onselect")
300
- return e;
301
- },
302
-
303
- onkeyup: function(event) {
304
- if (!this.is_open()) return;
305
- this.container.find('.text-input').val(this.obj.val()).trigger(event);
306
- },
307
-
308
- /**
309
- * all the behavior to respond to a text field as a search box
310
- */
311
- _respond_to_text_field: function(text_field) {
312
- // attach the events to start this party
313
- text_field.focus(jQuery.proxy(this, 'open'));
314
-
315
- // the autosearch event - needs to happen slightly late (keyup is later than keypress)
316
- text_field.keyup(jQuery.proxy(this, 'onkeyup'));
317
-
318
- // keyboard navigation, if available
319
- if (this.onkeydown) {
320
- text_field.keydown(jQuery.proxy(this, "onkeydown"));
321
- }
322
- },
323
-
324
- _use_iframe_mask: function() {
325
- return this.container.insertAdjacentHTML ? true : false;
326
- }
327
- });
328
-
329
-
330
-
331
- /**
332
- * Adds keyboard navigation to RecordSelect objects
333
- */
334
- jQuery.extend(RecordSelect.Abstract.prototype, {
335
- current: null,
336
-
337
- /**
338
- * keyboard navigation - where to intercept the keys is up to the concrete class
339
- */
340
- onkeydown: function(ev) {
341
- var elem;
342
- switch (ev.keyCode) {
343
- case 38: //Event.KEY_UP
344
- if (this.current && this.current.closest('html').length) elem = this.current.prev();
345
- if (!elem) elem = this.container.find('ol li.record').last();
346
- this.highlight(elem);
347
- break;
348
- case 40: //Event.KEY_DOWN
349
- if (this.current && this.current.closest('html').length) elem = this.current.next();
350
- if (!elem) elem = this.container.find('ol li.record').first();
351
- this.highlight(elem);
352
- break;
353
- case 13: // Event.KEY_RETURN
354
- if (this.current) this.current.find('a').click();
355
- break;
356
- case 39: // Event.KEY_RIGHT
357
- elem = this.container.find('li.pagination.next');
358
- if (elem) elem.find('a').click();
359
- break;
360
- case 37: // Event.KEY_LEFT
361
- elem = this.container.find('li.pagination.previous');
362
- if (elem) elem.find('a').click();
363
- break;
364
- case 27: // Event.KEY_ESC
365
- this.close();
366
- break;
367
- default:
368
- return true;
369
- }
370
- ev.preventDefault(); // so "enter" doesn't submit the form, among other things(?)
371
- },
372
-
373
- /**
374
- * moves the highlight to a new object
375
- */
376
- highlight: function(obj) {
377
- if (this.current) this.current.removeClass('current');
378
- this.current = jQuery(obj);
379
- obj.addClass('current');
380
- }
381
- });
382
-
383
- /**
384
- * Used by link_to_record_select
385
- * The options hash should contain a onselect: key, with a javascript function as value
386
- */
387
- RecordSelect.Dialog = RecordSelect.Abstract.extend({
388
- onload: function() {
389
- this.container = this.create_container();
390
- this.obj.click(jQuery.proxy(this, "toggle"));
391
- if (this.onkeypress) this.obj.keypress(jQuery.proxy(this, 'onkeypress'));
392
- },
393
-
394
- onselect: function(id, value) {
395
- if (this.options.onselect(id, value) != false) this.close();
396
- },
397
-
398
- toggle: function() {
399
- if (this.is_open()) this.close();
400
- else this.open();
401
- }
402
- });
403
-
404
- /**
405
- * Used by record_select_field helper
406
- * The options hash may contain id: and label: keys, designating the current value
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.
409
- */
410
- RecordSelect.Single = RecordSelect.Abstract.extend({
411
- onload: function() {
412
- // initialize the container
413
- this.container = this.create_container();
414
- this.container.addClass('record-select-autocomplete');
415
-
416
- // create the hidden input
417
- this.obj.after('<input type="hidden" name="" value="" />');
418
- this.hidden_input = this.obj.next();
419
-
420
- // transfer the input name from the text input to the hidden input
421
- this.hidden_input.attr('name', this.obj.attr('name'));
422
- this.obj.attr('name', this.options.field_name || '');
423
-
424
- // initialize the values
425
- if (this.options.label) this.set(this.options.id, this.options.label);
426
-
427
- this._respond_to_text_field(this.obj);
428
- if (this.obj.focused) this.open(); // if it was focused before we could attach observers
429
- },
430
-
431
- close: function() {
432
- // if they close the dialog with the text field empty, then delete the id value
433
- if (this.obj.val() == '') this.set('', '');
434
-
435
- RecordSelect.Abstract.prototype.close.call(this);
436
- },
437
-
438
- onselect: function(id, value) {
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]);
442
- this.close();
443
- },
444
-
445
- /**
446
- * sets the id/label
447
- */
448
- set: function(id, label) {
449
- // unescaped html missing for label
450
- this.obj.val(label);
451
- this.hidden_input.val(id);
452
- }
453
- });
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
-
496
- /**
497
- * Used by record_multi_select_field helper.
498
- * Options:
499
- * list - the id (or object) of the <ul> to contain the <li>s of selected entries
500
- * current - an array of id:/label: keys designating the currently selected entries
501
- */
502
- RecordSelect.Multiple = RecordSelect.Abstract.extend({
503
- onload: function() {
504
- // initialize the container
505
- this.container = this.create_container();
506
- this.container.addClass('record-select-autocomplete');
507
-
508
- // decide where the <li> entries should be placed
509
- if (this.options.list) this.list_container = jQuery(this.options.list);
510
- else this.list_container = this.obj.next('ul');
511
-
512
- // take the input name from the text input, and store it for this.add()
513
- this.input_name = this.obj.attr('name');
514
- this.obj.attr('name', '');
515
-
516
- // initialize the list
517
- for(var i = 0, length = this.options.current.length; i < length; i++) {
518
- this.add(this.options.current[i].id, this.options.current[i].label);
519
- }
520
-
521
- this._respond_to_text_field(this.obj);
522
- if (this.obj.focused) this.open(); // if it was focused before we could attach observers
523
- },
524
-
525
- onselect: function(id, value) {
526
- this.add(id, value);
527
- },
528
-
529
- /**
530
- * Adds a record to the selected list
531
- */
532
- add: function(id, label) {
533
- // return silently if this value has already been selected
534
- if (this.list_container.has('input[value=' + id + ']').length > 0) return;
535
-
536
- var entry = '<li>'
537
- + '<a href="#" onclick="jQuery(this).parent().remove(); return false;" class="remove">remove</a>'
538
- + '<input type="hidden" name="' + this.input_name + '" value="' + id + '" />'
539
- + '<label>' + label + '</label>'
540
- + '</li>';
541
- this.list_container.prepend(entry)
542
- }
543
- });