Class: Aurita::GUI::Datetime_Field

Inherits:
Date_Field show all
Defined in:
lib/aurita-gui/form/datetime_field.rb

Instance Attribute Summary collapse

Attributes inherited from Date_Field

#date_format, #day, #day_element, #month, #month_element, #year, #year_element, #years

Attributes inherited from Form_Field

#data_type, #form, #hidden, #hint, #invalid, #label, #required, #type

Attributes inherited from Element

#attrib, #force_closing_tag, #gui_element_id, #parent, #tag

Instance Method Summary collapse

Methods inherited from Form_Field

#disable!, #disabled=, #editable!, #enable!, #hidden?, #hide!, #invalid!, #invalid?, #optional!, #readonly!, #readonly=, #readonly?, #readonly_element, #required!, #required?, #show!, #to_hidden_field, #to_s

Methods inherited from Element

#+, #<<, #[], #[]=, #add_class, #aurita_gui_element, #clear_floating, #css_classes, #find_by_dom_id, #get_content, #has_content?, #id, #id=, #inspect, #js_init_code, #length, #method_missing, #recurse, #remove_class, #set_content, #string, #swap, #to_ary, #touch, #touched?, #type=, #untouch

Methods included from Marshal_Helper_Class_Methods

#marshal_load

Methods included from Marshal_Helper

#marshal_dump

Constructor Details

#initialize(params, &block) ⇒ Datetime_Field

Returns a new instance of Datetime_Field.



11
12
13
14
15
16
17
18
19
20
# File 'lib/aurita-gui/form/datetime_field.rb', line 11

def initialize(params, &block)
  @time_format   = params[:time_format]
  @time_format ||= 'hms'

  params.delete(:time_format)
  params.delete(:hour)
  params.delete(:minute)
  params.delete(:second)
  super(params, &block)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Aurita::GUI::Element

Instance Attribute Details

#hourObject

Returns the value of attribute hour.



9
10
11
# File 'lib/aurita-gui/form/datetime_field.rb', line 9

def hour
  @hour
end

#hour_elementObject

Returns the value of attribute hour_element.



9
10
11
# File 'lib/aurita-gui/form/datetime_field.rb', line 9

def hour_element
  @hour_element
end

#minuteObject

Returns the value of attribute minute.



9
10
11
# File 'lib/aurita-gui/form/datetime_field.rb', line 9

def minute
  @minute
end

#minute_elementObject

Returns the value of attribute minute_element.



9
10
11
# File 'lib/aurita-gui/form/datetime_field.rb', line 9

def minute_element
  @minute_element
end

#secondObject

Returns the value of attribute second.



9
10
11
# File 'lib/aurita-gui/form/datetime_field.rb', line 9

def second
  @second
end

#second_elementObject

Returns the value of attribute second_element.



9
10
11
# File 'lib/aurita-gui/form/datetime_field.rb', line 9

def second_element
  @second_element
end

#time_formatObject

Returns the value of attribute time_format.



9
10
11
# File 'lib/aurita-gui/form/datetime_field.rb', line 9

def time_format
  @time_format
end

Instance Method Details

#elementObject



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/aurita-gui/form/datetime_field.rb', line 47

def element
  select_fields = []
  @date_format.scan(/./).each { |c|
    case c
    when 'y' then
      select_fields << year_element() 
    when 'm' then
      select_fields << month_element() 
    when 'd' then
      select_fields << day_element() 
    end
  }
  @time_format.scan(/./).each { |c|
    case c
    when 'h' then
      select_fields << hour_element() 
    when 'm' then
      select_fields << minute_element() 
    when 's' then
      select_fields << second_element() 
    end
  }
  HTML.div(@attrib) { 
    select_fields
  }
end

#valueObject



95
96
97
# File 'lib/aurita-gui/form/datetime_field.rb', line 95

def value
  super().update(:second => @second, :minute => @minute, :hour => @hour)
end

#value=(date) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/aurita-gui/form/datetime_field.rb', line 74

def value=(date)
  case date 
  when Hash then
    @value = date
  when Datetime then
    @value = { :hour   => date.hour, 
               :minute => date.month, 
               :second => date.second }
  when Date then
    @value = { :hour   => date.hour, 
               :minute => date.minute, 
               :second => date.second }
  when String then
#       date = Datetime.strptime(date)
#       @value = { :hour   => date.hour, 
#                  :minute => date.minute, 
#                  :second => date.second }
  else
  end
end