Class: Wee::Brush::SelectListTag
Defined Under Namespace
Classes: SelectListCallback
Instance Attribute Summary
Attributes inherited from Wee::Brush
#canvas, #parent
Instance Method Summary
collapse
#__action_callback, #__actionurl_callback, #__actionurl_named_callback, #__input_callback, #css_class, #css_class_for, #method_missing, #onclick_callback, #onclick_update
Methods inherited from Wee::Brush
#close
Constructor Details
Returns a new instance of SelectListTag.
335
336
337
338
|
# File 'lib/wee/renderer/html/brushes.rb', line 335
def initialize(items)
super('select')
@items = items
end
|
Instance Method Details
#callback(symbol = nil, *args, &block) ⇒ Object
362
363
364
365
|
# File 'lib/wee/renderer/html/brushes.rb', line 362
def callback(symbol=nil, *args, &block)
@callback = to_callback(symbol, args, block)
self
end
|
#items(arg) ⇒ Object
340
341
342
343
|
# File 'lib/wee/renderer/html/brushes.rb', line 340
def items(arg)
@items = arg
self
end
|
#labels(arg = nil, &block) ⇒ Object
351
352
353
354
355
356
357
358
359
360
|
# File 'lib/wee/renderer/html/brushes.rb', line 351
def labels(arg=nil, &block)
raise if arg and block
if block
@labels = proc{|i| block.call(@items[i])}
else
@labels = arg
end
self
end
|
#selected(arg = nil, &block) ⇒ Object
345
346
347
348
349
|
# File 'lib/wee/renderer/html/brushes.rb', line 345
def selected(arg=nil, &block)
raise if arg and block
@selected = arg || block
self
end
|
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
|
# File 'lib/wee/renderer/html/brushes.rb', line 385
def with
@labels ||= @items.collect { |i| i.to_s }
is_multiple = @attributes.has_key?('multiple')
if @callback
__input_callback(SelectListCallback.new(@callback, @items, is_multiple))
end
super do
meth =
if is_multiple
@selected ||= Array.new
@selected.kind_of?(Proc) ? (:call) : (:include?)
else
@selected.kind_of?(Proc) ? (:call) : (:==)
end
@items.each_index {|i|
@canvas.option.value(i).selected(@selected.send(meth, @items[i])).with(@labels[i])
}
end
end
|