Class: Glimmer::SWT::DateTimeProxy
Constant Summary
Constants inherited
from WidgetProxy
WidgetProxy::DEFAULT_INITIALIZERS, WidgetProxy::JS_KEY_CODE_TO_SWT_KEY_CODE_MAP, WidgetProxy::JS_LOCATION_TO_SWT_KEY_LOCATION_MAP, WidgetProxy::SWT_CURSOR_TO_CSS_CURSOR_MAP
Instance Attribute Summary
Attributes inherited from WidgetProxy
#args, #background, #children, #cursor, #disposed?, #enabled, #focus, #font, #foreground, #menu, #menu_requested, #menu_x, #menu_y, #parent, #path, #rendered
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from WidgetProxy
#add_content_on_render, #add_css_class, #add_css_classes, #add_observer, #apply_property_type_converters, #attach, #build_dom, #can_handle_observation_request?, #clear_css_classes, #content, #content_on_render_blocks, #css_classes, #default_observation_request_to_event_mapping, #dialog_ancestor, #dispose, #dom_element, #effective_observation_request_to_event_mapping, #event_handling_suspended?, #event_listener_proxies, for, #get_data, #handle_javascript_observation_request, #handle_observation_request, #has_style?, #id, #id=, #listener_dom_element, #listener_path, #listeners, #listeners_for, max_id_number_for, max_id_numbers, #method_missing, #name, next_id_number_for, #observation_requests, #parent_dom_element, #parent_path, #parents, #post_dispose_child, #post_initialize_child, #print, #property_type_converters, #reattach, #remove_all_listeners, #remove_css_class, #remove_css_classes, #remove_event_listener_proxies, #render, reset_max_id_numbers!, #resume_event_handling, #selector, #set_attribute, #set_data, #set_focus, #shell, #skip_content_on_render_blocks?, #style_element, #suspend_event_handling, #swt_data, #swt_widget, underscored_widget_name, widget_class, widget_exists?, widget_handling_listener, #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
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Glimmer::SWT::WidgetProxy
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
71
72
73
|
# File 'lib/glimmer/swt/date_time_proxy.rb', line 71
def calendar?
args.to_a.include?(:calendar)
end
|
#date? ⇒ Boolean
59
60
61
|
# File 'lib/glimmer/swt/date_time_proxy.rb', line 59
def date?
args.to_a.include?(:date)
end
|
#date_time ⇒ Object
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
|
# File 'lib/glimmer/swt/date_time_proxy.rb', line 75
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
95
96
97
98
99
100
101
102
103
104
105
106
|
# File 'lib/glimmer/swt/date_time_proxy.rb', line 95
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
154
155
156
157
158
159
160
161
|
# File 'lib/glimmer/swt/date_time_proxy.rb', line 154
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
67
68
69
|
# File 'lib/glimmer/swt/date_time_proxy.rb', line 67
def drop_down?
args.to_a.include?(:drop_down)
end
|
#element ⇒ Object
150
151
152
|
# File 'lib/glimmer/swt/date_time_proxy.rb', line 150
def element
calendar? ? 'div' : 'input'
end
|
#observation_request_to_event_mapping ⇒ Object
TODO add date, time, year, month, day, hours, minutes, seconds attribute methods
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
|
# File 'lib/glimmer/swt/date_time_proxy.rb', line 110
def observation_request_to_event_mapping
{
'on_widget_selected' => [
{
event: 'change',
event_handler: -> (event_listener) {
-> (event) {
if calendar? || date? || (time? && @timepicker_done)
@timepicker_done = false if time?
event_listener.call(event)
end
}
}
},
],
'on_focus_lost' => [
{
event: 'blur',
event_handler: -> (event_listener) {
-> (event) {
if time? && @timepicker_done
@timepicker_done = false if time?
event_listener.call(event)
end
}
}
},
],
}
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
52
53
54
55
56
57
|
# 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',
showNowButton: true,
showCloseButton: true,
button: "##{time_button_id}",
onClose: proc do |v|
@timepicker_done = true
dom_element.trigger('change')
end,
})
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
63
64
65
|
# File 'lib/glimmer/swt/date_time_proxy.rb', line 63
def time?
args.to_a.include?(:time)
end
|
146
147
148
|
# File 'lib/glimmer/swt/date_time_proxy.rb', line 146
def time_button_class
"#{name}-time-button"
end
|
142
143
144
|
# File 'lib/glimmer/swt/date_time_proxy.rb', line 142
def time_button_id
"#{id}-time-button"
end
|