Class: Lore::GUI::Select

Inherits:
Form_Element show all
Defined in:
lib/lore/gui/form_element.rb

Overview

Form select box element (<input type=“select” …><option …>). Subclass of Form_Element.

Instance Attribute Summary collapse

Attributes inherited from Form_Element

#attribute_label, #attribute_name, #attribute_range, #attribute_table, #attribute_value, #mode, #on_click, #style, #style_class, #template, #template_file

Instance Method Summary collapse

Methods inherited from Form_Element

for, #label, #onblur, #onfocus, #print, #set_attribute_style, #set_attribute_value, #set_mode, #setup

Constructor Details

#initialize(_table, _attrib_name, _attrib_label, _attrib_range = nil, _attrib_value = nil, sublabels = nil) ⇒ Select

Returns a new instance of Select.



511
512
513
514
# File 'lib/lore/gui/form_element.rb', line 511

def initialize(_table, _attrib_name, _attrib_label, _attrib_range=nil, _attrib_value=nil, sublabels=nil)
  setup(_table, _attrib_name, _attrib_label, _attrib_range, _attrib_value)
  @labels = sublabels
end

Instance Attribute Details

#attribute_idObject

{{{



509
510
511
# File 'lib/lore/gui/form_element.rb', line 509

def attribute_id
  @attribute_id
end

#idObject

{{{



509
510
511
# File 'lib/lore/gui/form_element.rb', line 509

def id
  @id
end

#on_blurObject

{{{



509
510
511
# File 'lib/lore/gui/form_element.rb', line 509

def on_blur
  @on_blur
end

#on_changeObject

{{{



509
510
511
# File 'lib/lore/gui/form_element.rb', line 509

def on_change
  @on_change
end

#on_focusObject

{{{



509
510
511
# File 'lib/lore/gui/form_element.rb', line 509

def on_focus
  @on_focus
end

Instance Method Details

#stringObject

def



516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
# File 'lib/lore/gui/form_element.rb', line 516

def string

  if !@labels.instance_of? Array 
    then @labels = @attribute_range 
  end
  
  if @mode == :readonly then
    
    template = @template.new('text_readonly.rhtml')
    index = @attribute_range.index(@attribute_value.to_s)
    if index.nil? then index = @attribute_range.index(@attribute_value.to_i) end

    label = @labels[index.to_i]
    data = { :attributes => { :value => label }}
    
  elsif @mode == :mutable or @mode == nil then

    @on_focus = onfocus("#{@attribute_table.to_s.gsub('.','_')}__#{@attribute_name.to_s}")
    @on_blur  = onblur("#{@attribute_table.to_s.gsub('.','_')}__#{@attribute_name.to_s}")

    template = @template.new('select.rhtml')
    data = {
      :attributes =>  { 
#           :id        => @id.to_s, 
        :id        => @attribute_id, 
        :class     => @style_class.to_s, 
        :style   => @style, 
        :name      => @attribute_name, 
        :onfocus   => @on_focus.to_s, 
        :onChange  => @on_change.to_s, 
        :onblur    => @on_blur.to_s, 
        :value     => @attribute_value
      },
      :range => @attribute_range, 
      :labels => @labels, 
      :value => @attribute_value
    }
  end
  template.set_data(data)
  template.string()
  
end