Class: Wee::Brush::SelectListTag
Overview
Constant Summary
collapse
- HTML_TAG =
'select'.freeze
GenericTagBrush::EVENTS
Instance Attribute Summary
Attributes inherited from Wee::Brush
#canvas, #document
Instance Method Summary
collapse
#call, #callback, #callback_method
#callback_on, #get_oid, html_attr, #javascript_on, #oid, #onclick_callback, #onclick_javascript, #ondblclick_callback, #update_component_on, #update_on
Methods inherited from Wee::Brush
#close, nesting?, #setup
Constructor Details
Returns a new instance of SelectListTag.
571
572
573
574
|
# File 'lib/wee/html_brushes.rb', line 571
def initialize(items)
super(HTML_TAG)
@items = items
end
|
Instance Method Details
#__callback ⇒ Object
599
600
601
602
603
604
605
|
# File 'lib/wee/html_brushes.rb', line 599
def __callback
name(@canvas.register_callback(:input, method(:handler)) + "[]")
end
|
#items(items) ⇒ Object
576
577
578
579
|
# File 'lib/wee/html_brushes.rb', line 576
def items(items)
@items = items
self
end
|
#labels(arg = nil, &block) ⇒ Object
587
588
589
590
591
592
593
594
595
|
# File 'lib/wee/html_brushes.rb', line 587
def labels(arg=nil, &block)
raise ArgumentError if arg and block
if block
@labels = proc {|i| block.call(@items[i])}
else
@labels = arg
end
self
end
|
#selected(arg = nil, &block) ⇒ Object
581
582
583
584
585
|
# File 'lib/wee/html_brushes.rb', line 581
def selected(arg=nil, &block)
raise ArgumentError if arg and block
@selected = block || arg
self
end
|
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
|
# File 'lib/wee/html_brushes.rb', line 625
def with
@labels ||= @items.collect {|i| i.to_s}
if @attributes.has_key?(:multiple)
@selected ||= Array.new
meth = @selected.kind_of?(Proc) ? (:call) : (:include?)
else
meth = @selected.kind_of?(Proc) ? (:call) : (:==)
end
super {
@items.each_index do |i|
@canvas.option.value(i).selected(@selected.send(meth, @items[i])).with(@labels[i])
end
}
end
|