Class: Lore::GUI::Text

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

Overview

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

Direct Known Subclasses

Password

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) ⇒ Text

{{{



124
125
126
127
128
# File 'lib/lore/gui/form_element.rb', line 124

def initialize(_table, _attrib_name, _attrib_label, _attrib_range=nil, _attrib_value=nil)
  setup(_table, _attrib_name, _attrib_label, _attrib_range, _attrib_value)
  @template_file = 'text.rhtml'
  @readonly_template_file = 'text_readonly.rhtml'
end

Instance Method Details

#set_length(length) ⇒ Object



130
131
132
# File 'lib/lore/gui/form_element.rb', line 130

def set_length(length)
  @length = length
end

#stringObject



134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
# File 'lib/lore/gui/form_element.rb', line 134

def string
  # to avoid value=""
  if @attribute_value == '' then @attribute_value = nil end

  if @mode == :mutable then
    template = @template.new(@template_file)

    if @attribute_table.to_s == '' then
      name = @attribute_name 
    else
      name = @attribute_table + '.' + @attribute_name
    end
    if @length.nil? then
      data = {
        :id        => @attribute_id, 
        :class     => @style_class.to_s, 
        :name      => name, 
        :value     => @attribute_value, 
        :style     => @style, 
        :onfocus   => onfocus("#{@attribute_table.to_s.gsub('.','_')}__#{@attribute_name.to_s}"),
        :onblur    => onblur("#{@attribute_table.to_s.gsub('.','_')}__#{@attribute_name.to_s}")
      }
    else
      data = {
        :id        => @attribute_id, 
        :class     => @style_class.to_s, 
        :name      => name, 
        :maxlength => @length, 
        :value     => @attribute_value, 
        :style     => @style, 
        :onfocus   => onfocus("#{@attribute_table.to_s.gsub('.','_')}__#{@attribute_name.to_s}"),
        :onblur    => onblur("#{@attribute_table.to_s.gsub('.','_')}__#{@attribute_name.to_s}")
      }
    end

  elsif @mode == :readonly then
    template = @template.new(@readonly_template_file)
    data = { :value => @attribute_value }
  end
  template.set_data(:attributes => data)
  template.string()
end