Class: Wee::Brush::SelectListTag
Overview
Constant Summary
collapse
- HTML_TAG =
'select'.freeze
Instance Attribute Summary
Attributes inherited from Wee::Brush
#canvas, #document
Instance Method Summary
collapse
#call, #callback, #callback_method
#get_oid, html_attr, #oid, #onclick_callback, #onclick_javascript, #onclick_update_callback, #onclick_update_self_callback, #ondblclick_callback
Methods inherited from Wee::Brush
#close, nesting?, #setup
Constructor Details
Returns a new instance of SelectListTag.
524
525
526
527
|
# File 'lib/wee/html_brushes.rb', line 524
def initialize(items)
super(HTML_TAG)
@items = items
end
|
Instance Method Details
#__callback ⇒ Object
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
|
# File 'lib/wee/html_brushes.rb', line 552
def __callback
name(@canvas.register_callback(:input, proc {|input|
input = [input] unless input.kind_of?(Array)
choosen = input.map {|idx| get_item(idx) }
if @attributes.has_key?(:multiple)
@callback.call(choosen)
elsif choosen.size > 1
raise "more than one element was choosen from a not-multiple SelectListTag"
else
@callback.call(choosen.first)
end
}))
end
|
#items(items) ⇒ Object
529
530
531
532
|
# File 'lib/wee/html_brushes.rb', line 529
def items(items)
@items = items
self
end
|
#labels(arg = nil, &block) ⇒ Object
540
541
542
543
544
545
546
547
548
|
# File 'lib/wee/html_brushes.rb', line 540
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
534
535
536
537
538
|
# File 'lib/wee/html_brushes.rb', line 534
def selected(arg=nil, &block)
raise ArgumentError if arg and block
@selected = block || arg
self
end
|
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
|
# File 'lib/wee/html_brushes.rb', line 579
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
|