Class: Glimmer::SWT::DateTimeProxy
Constant Summary
Constants inherited
from WidgetProxy
WidgetProxy::DEFAULT_INITIALIZERS
Instance Attribute Summary
Attributes inherited from WidgetProxy
#args, #background, #children, #enabled, #focus, #font, #foreground, #parent, #path
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from WidgetProxy
#add_css_class, #add_css_classes, #add_observer, #apply_property_type_converters, #build_dom, #can_handle_observation_request?, #clear_css_classes, #content, #css_classes, #dispose, #dom_element, for, #handle_observation_request, #has_style?, #id, #id=, #listener_dom_element, #listener_path, max_id_number_for, max_id_numbers, #name, next_id_number_for, #parent_dom_element, #parent_path, #post_initialize_child, #property_type_converters, #remove_css_class, #remove_css_classes, #render, reset_max_id_numbers!, #selector, #set_attribute, #set_focus, #style_element, underscored_widget_name, widget_class, widget_exists?, #widget_property_listener_installers
#attribute_getter, #attribute_setter, #get_attribute, #set_attribute
Constructor Details
#initialize(parent, args, block) ⇒ DateTimeProxy
Returns a new instance of DateTimeProxy.
22
23
24
25
|
# File 'lib/glimmer/swt/date_time_proxy.rb', line 22
def initialize(parent, args, block)
super(parent, args, block)
post_add_content if block.nil?
end
|
Class Method Details
.create(keyword, parent, args, block) ⇒ Object
7
8
9
10
11
12
13
14
15
16
17
18
19
|
# File 'lib/glimmer/swt/date_time_proxy.rb', line 7
def create(keyword, parent, args, block)
case keyword
when 'date'
args += [:date]
when 'date_drop_down'
args += [:date, :drop_down]
when 'time'
args += [:time]
when 'calendar'
args += [:calendar]
end
new(parent, args, block)
end
|
Instance Method Details
#calendar? ⇒ Boolean
65
66
67
|
# File 'lib/glimmer/swt/date_time_proxy.rb', line 65
def calendar?
args.to_a.include?(:calendar)
end
|
#date? ⇒ Boolean
53
54
55
|
# File 'lib/glimmer/swt/date_time_proxy.rb', line 53
def date?
args.to_a.include?(:date)
end
|
#date_time ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
|
# File 'lib/glimmer/swt/date_time_proxy.rb', line 69
def date_time
if @added_content
default_date = DateTime.new if @date_time.nil?
default_year = @date_time&.year || default_date.year
default_month = @date_time&.month || default_date.month
default_day = @date_time&.day || default_date.day
default_hour = @date_time&.hour || default_date.hour
default_min = @date_time&.min || default_date.min
default_sec = @date_time&.sec || default_date.sec
if time?
@date_time = DateTime.new(default_year, default_month, default_day, dom_element.timepicker('getHour').to_i, dom_element.timepicker('getMinute').to_i, default_sec)
else
@date_time = DateTime.new(dom_element.datepicker('getDate')&.year.to_i, dom_element.datepicker('getDate')&.month.to_i, dom_element.datepicker('getDate')&.day.to_i, default_hour, default_min, default_sec)
end
@date_time = @date_time&.to_datetime
else
@initial_date_time
end
end
|
#date_time=(value) ⇒ Object
89
90
91
92
93
94
95
96
97
98
99
100
|
# File 'lib/glimmer/swt/date_time_proxy.rb', line 89
def date_time=(value)
if @added_content
@date_time = value&.to_datetime || DateTime.new
if time?
dom_element.timepicker('setTime', "#{@date_time.hour}:#{@date_time.min}")
else
dom_element.datepicker('setDate', @date_time.to_time)
end
else
@initial_date_time = value
end
end
|
#dom ⇒ Object
126
127
128
129
130
131
132
133
|
# File 'lib/glimmer/swt/date_time_proxy.rb', line 126
def dom
@dom ||= html {
span {
send(element, type: 'text', id: id, class: name)
button(id: time_button_id, class: time_button_class, style: "border: none; background: url(assets/glimmer/images/ui-icons_222222_256x240.png) -80px, -96px; width: 16px; height: 16px;") if time?
}
}.to_s
end
|
#drop_down? ⇒ Boolean
61
62
63
|
# File 'lib/glimmer/swt/date_time_proxy.rb', line 61
def drop_down?
args.to_a.include?(:drop_down)
end
|
#element ⇒ Object
122
123
124
|
# File 'lib/glimmer/swt/date_time_proxy.rb', line 122
def element
calendar? ? 'div' : 'input'
end
|
#observation_request_to_event_mapping ⇒ Object
TODO add date, time, year, month, day, hours, minutes, seconds attribute methods
104
105
106
107
108
109
110
111
112
|
# File 'lib/glimmer/swt/date_time_proxy.rb', line 104
def observation_request_to_event_mapping
{
'on_widget_selected' => [
{
event: 'change'
},
],
}
end
|
#post_add_content ⇒ Object
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'lib/glimmer/swt/date_time_proxy.rb', line 27
def post_add_content
if time?
dom_element.timepicker({
showPeriod: true,
showLeadingZero: true,
showOn: 'both',
button: "##{time_button_id}",
})
else
options = {}
if drop_down?
options = {
showOn: 'both',
buttonImage: 'assets/glimmer/images/calendar.gif',
buttonImageOnly: true,
buttonText: 'Select date'
}
end
dom_element.datepicker(options)
end
date_time_value = self.date_time
@added_content = true
self.date_time = date_time_value
end
|
#time? ⇒ Boolean
57
58
59
|
# File 'lib/glimmer/swt/date_time_proxy.rb', line 57
def time?
args.to_a.include?(:time)
end
|
118
119
120
|
# File 'lib/glimmer/swt/date_time_proxy.rb', line 118
def time_button_class
"#{name}-time-button"
end
|
114
115
116
|
# File 'lib/glimmer/swt/date_time_proxy.rb', line 114
def time_button_id
"#{id}-time-button"
end
|