4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
|
# File 'lib/niles/helpers/forms.rb', line 4
def date_time_select(name, options = {})
options = {
:years => 1976..2012,
:months => 1..12,
:days => 1..31,
:month_formatter => ->(i) { translate("date.month_names")[i] },
:day_formatter => ->(i) { "#{i}." },
:value => Time.now
}.merge(options)
year_select = html_tag(:select, name: "#{name}[year]") do
options[:years].map do |year|
html_tag(:option, value: year, selected: year == options[:value].try(:year)) { year }
end.join
end
month_select = html_tag(:select, name: "#{name}[month]") do
options[:months].map do |month|
html_tag(:option, value: month, selected: month == options[:value].try(:month)) { options[:month_formatter].call(month) }
end.join
end
day_select = html_tag(:select, name: "#{name}[day]") do
options[:days].map do |day|
html_tag(:option, value: day, selected: day == options[:value].try(:day)) { options[:day_formatter].call(day) }
end.join
end
hour_select = html_tag(:select, name: "#{name}[hour]") do
(0..23).map do |hour|
html_tag(:option, value: hour, selected: hour == options[:value].try(:hour)) { sprintf "%02d", hour }
end.join
end
minute_select = html_tag(:select, name: "#{name}[minute]") do
(0..59).map do |minute|
html_tag(:option, value: minute, selected: minute == options[:value].try(:minute)) { sprintf "%02d", minute }
end.join
end
"#{day_select} #{month_select} #{year_select} - #{hour_select} : #{minute_select} Uhr"
end
|