Class: Lore::GUI::Date

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

Overview

Form date element (three select boxes for year/month/day). Subclass of Form_Element.

Constant Summary collapse

@@date_field_counter =

{{{

1

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

Returns a new instance of Date.



280
281
282
# File 'lib/lore/gui/form_element.rb', line 280

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

Instance Method Details

#stringObject



284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
# File 'lib/lore/gui/form_element.rb', line 284

def string

  @@date_field_counter += 1
  idx = @@date_field_counter.to_s
  if @mode == :mutable then
  return '<input class="lore_date" type="text" name="'+@attribute_name+'" value="'+@attribute_value.to_s+'" id="date_field_'+idx+'" /> 
          <input class="lore_button_varwidth" type="button" value="..." id="date_trigger_'+idx+'" onclick="open_calendar(\'date_field_'+idx+'\',\'date_trigger_'+idx+'\');" />'
  else 
    return '<nobr>' << @attribute_value.to_s.gsub(' ','.') + '</nobr>'
  end

  if @attribute_range.nil? then 
    @attribute_range = (2005..2008).to_a
  else 
    @attribute_range = @attribute_range.to_a
  end
  
  select_year = Select.new(  @attribute_table, 
                 @attribute_name+'--year', 
                 nil, 
                 ['']+@attribute_range, 
                 @attribute_value.to_s[0..3])
  select_month = Select.new(  @attribute_table, 
                 @attribute_name+'--month', 
                 nil, 
                 ['']+('01'..'12').to_a, 
                 @attribute_value.to_s[5..6])
  select_day = Select.new(  @attribute_table, 
                 @attribute_name+'--day', 
                 nil, 
                 ['']+('01'..'31').to_a, 
                 @attribute_value.to_s[8..9])

  select_year.set_attribute_value(@attribute_value.to_s[0..3])
  select_month.set_attribute_value(@attribute_value.to_s[5..6])
  select_day.set_attribute_value(@attribute_value.to_s[8..9])

  select_year.set_mode(@mode)
  select_month.set_mode(@mode)
  select_day.set_mode(@mode)

  return select_day.string+select_month.string+select_year.string
end