Class: Lore::GUI::Radio

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

Overview

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

Instance Attribute Summary

Attributes inherited from Form_Element

#attribute_id, #attribute_label, #attribute_name, #attribute_range, #attribute_table, #attribute_value, #id, #mode, #on_change, #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) ⇒ Radio

{{{



335
336
337
338
339
340
341
342
343
344
345
346
# File 'lib/lore/gui/form_element.rb', line 335

def initialize(_table, _attrib_name, _attrib_label, _attrib_range=nil, _attrib_value=nil)
  setup(_table, _attrib_name, _attrib_label, _attrib_range, _attrib_value)

  if _attrib_label.instance_of? Array then
    @attribute_label    = _attrib_label[0]
    @attribute_sublabel = _attrib_label[1]
  else
    @attribute_label    = _attrib_label.to_s
    @attribute_sublabel = nil
  end

end

Instance Method Details

#stringObject

def



348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
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
411
412
# File 'lib/lore/gui/form_element.rb', line 348

def string

  if @mode == :mutable then 
    
    template = @template.new('radio.rhtml')
    radios = ''
    radio_index = 0
    
    if @attribute_label.nil? or @attribute_label == '' then 
      label = '' 
    end
    
    if @attribute_value.nil? or @attribute_value == '' then 
      @attribute_value = @attribute_range[0] 
    end

    throw 'attribute range must not be nil for Cuba::GUI::Radio instance. ' if @attribute_range.nil?
    
    @attribute_range.each { |value|
    
      if !@attribute_sublabel.nil? and
         !@attribute_sublabel[value].nil? then
        label = @attribute_sublabel[value]
      else 
        label = value
      end
      label = Lang[label.intern]
      
      data = {
        :id      => @attribute_id, 
        :class   => @style_class.to_s + '_radio',  
        :name    => @attribute_table+'.'+@attribute_name, 
        :onfocus => onfocus("#{@attribute_table.gsub('.','_')}__#{@attribute_name}"), 
        :onblur  => onblur("#{@attribute_table.gsub('.','_')}__#{@attribute_name}"), 
        :value   => value,
        :label   => label
      }
      data[:checked] = 'checked' if value == @attribute_value

      template.set_data(:attributes => data)
      radios += template.string.gsub("\n",'')
      radio_index += 1
    }
    
  elsif @mode == :readonly then
    
    template = @template.new('text_readonly.rhtml')
    if !@attribute_sublabel.nil? and
       !@attribute_sublabel[@attribute_value].nil? then
      label = @attribute_sublabel[@attribute_value]
    else 
      label = @attribute_value
    end
    label = Lang[label.intern]
    data = {:value => label}
    template.set_data(:attributes => data)
    radios = template.string

  end
  
  row_template = @template.new('radio_row.rhtml')
  row_template.set_data(:radios => radios)
  row_template.string
    
end