Class: Lore::GUI::Form_Element

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

Overview

Form element that can be handled by Cuba::GUI::Form.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#attribute_idObject

{{{



11
12
13
# File 'lib/lore/gui/form_element.rb', line 11

def attribute_id
  @attribute_id
end

#attribute_labelObject

{{{



11
12
13
# File 'lib/lore/gui/form_element.rb', line 11

def attribute_label
  @attribute_label
end

#attribute_nameObject

{{{



11
12
13
# File 'lib/lore/gui/form_element.rb', line 11

def attribute_name
  @attribute_name
end

#attribute_rangeObject

{{{



11
12
13
# File 'lib/lore/gui/form_element.rb', line 11

def attribute_range
  @attribute_range
end

#attribute_tableObject

{{{



11
12
13
# File 'lib/lore/gui/form_element.rb', line 11

def attribute_table
  @attribute_table
end

#attribute_valueObject

{{{



11
12
13
# File 'lib/lore/gui/form_element.rb', line 11

def attribute_value
  @attribute_value
end

#idObject

{{{



11
12
13
# File 'lib/lore/gui/form_element.rb', line 11

def id
  @id
end

#modeObject

{{{



11
12
13
# File 'lib/lore/gui/form_element.rb', line 11

def mode
  @mode
end

#on_changeObject

{{{



11
12
13
# File 'lib/lore/gui/form_element.rb', line 11

def on_change
  @on_change
end

#on_clickObject

{{{



11
12
13
# File 'lib/lore/gui/form_element.rb', line 11

def on_click
  @on_click
end

#styleObject

{{{



11
12
13
# File 'lib/lore/gui/form_element.rb', line 11

def style
  @style
end

#style_classObject

{{{



11
12
13
# File 'lib/lore/gui/form_element.rb', line 11

def style_class
  @style_class
end

#templateObject

{{{



11
12
13
# File 'lib/lore/gui/form_element.rb', line 11

def template
  @template
end

#template_fileObject

{{{



11
12
13
# File 'lib/lore/gui/form_element.rb', line 11

def template_file
  @template_file
end

Class Method Details

.for(clause, label, value = '', range = nil) ⇒ Object



13
14
15
16
17
18
19
20
# File 'lib/lore/gui/form_element.rb', line 13

def self.for(clause, label, value='', range=nil)
  attrib = clause.to_s.split('.')
  if attrib.length == 3 then
    new(attrib[0..1].join('.'), attrib[2], label, range, value)
  else
    new(nil, clause.to_s, label, range, value)
  end
end

Instance Method Details

#labelObject

Returns attribute label as string.



75
76
77
# File 'lib/lore/gui/form_element.rb', line 75

def label
  if @attribute_label.nil? then '' else @attribute_label end
end

#onblur(attribute_id) ⇒ Object



94
95
96
97
98
99
100
101
102
# File 'lib/lore/gui/form_element.rb', line 94

def onblur(attribute_id)
  begin
    context_help = "Element.removeClassName('#{attribute_id.gsub('.','_')}_wrap', 'focussed' ); Element.removeClassName('#{attribute_id.gsub('.','_')}', 'focussed' );"
  rescue ::Exception => e
    context_help = ''
  end

  return context_help
end

#onfocus(attribute_id) ⇒ Object



84
85
86
87
88
89
90
91
92
# File 'lib/lore/gui/form_element.rb', line 84

def onfocus(attribute_id)
  begin
    context_help = "Element.addClassName('#{attribute_id.gsub('.','_')}_wrap', 'focussed' ); Element.addClassName('#{attribute_id.gsub('.','_')}', 'focussed' );"
  rescue ::Exception => e
    context_help = ''
  end

  return context_help
end

Prints string()



80
81
82
# File 'lib/lore/gui/form_element.rb', line 80

def print
  puts string()
end

#set_attribute_style(style) ⇒ Object

Set style class for element.



58
59
60
# File 'lib/lore/gui/form_element.rb', line 58

def set_attribute_style(style)
  @style = style
end

#set_attribute_value(val) ⇒ Object

Set value for this element.



53
54
55
# File 'lib/lore/gui/form_element.rb', line 53

def set_attribute_value(val)
  @attribute_value = val
end

#set_mode(mode = :mutable) ⇒ Object

Set mode for this element. Modes are :mutable and :readonly.



64
65
66
# File 'lib/lore/gui/form_element.rb', line 64

def set_mode(mode=:mutable)
  @mode = mode
end

#setup(_attrib_table, _attrib_name, _attrib_label, _attrib_range = nil, _attrib_value = '') ⇒ Object

Expects table name and attribute this element is referring to, as well as label to be used for it. _attrib_range is an array of option values, e.g. needed for select boxes or radio groups, _attrib_value is the elements current value if existing.



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/lore/gui/form_element.rb', line 26

def setup(_attrib_table, _attrib_name, _attrib_label, 
          _attrib_range=nil, _attrib_value='')

  @attribute_table   = _attrib_table
  @attribute_label   = _attrib_label
  @attribute_name    = _attrib_name.to_s
  @attribute_range   = _attrib_range
  @attribute_value   = _attrib_value
  @attribute_id      = _attrib_table.to_s.gsub('.','_') + '__' << _attrib_name.to_s
  @mode              = :mutable
  @template          = ERB_Template
  @template_file     = nil

  @style             = ''
  @style_class       = :lore
  
  @id                = ''
  @on_click          = '' 
  @on_change         = '' 

  if @attribute_range.instance_of? Range then 
    @attribute_range = @attribute_range.to_a
  end
  
end

#stringObject

Returns this element as html string. To be overloaded by subclasses.



70
71
72
# File 'lib/lore/gui/form_element.rb', line 70

def string
  ''
end