combined_time_select 0.0.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +31 -5
- data/lib/combined_time_select.rb +6 -7
- data/lib/combined_time_select/version.rb +1 -1
- metadata +12 -7
data/README.md
CHANGED
@@ -1,9 +1,22 @@
|
|
1
1
|
Combined Time Select
|
2
2
|
====================
|
3
3
|
|
4
|
+
Written by [Chris Oliver](http://excid3.com) [@excid3](https://twitter.com/excid3).
|
5
|
+
|
4
6
|
This is a small gem for creating Google Calendar style 12 hour AM/PM
|
5
7
|
time_select fields for Rails 3. It's based off of [simple_time_select](https://github.com/tamoyal/simple_time_select) by tamoyal.
|
6
8
|
|
9
|
+
![combined_time_select](http://f.cl.ly/items/1945331M3W1h0f1K3I2v/Screen%20Shot%202011-12-23%20at%2012.08.37%20AM.png)
|
10
|
+
|
11
|
+
![combined_time_select](http://f.cl.ly/items/0H1x3a0S3m3E1U020s2m/Screen%20Shot%202011-12-23%20at%2012.09.00%20AM.png)
|
12
|
+
|
13
|
+
Installation
|
14
|
+
------------
|
15
|
+
|
16
|
+
Just add this into your Gemfile followed by a bundle install:
|
17
|
+
|
18
|
+
gem "combined_time_select", "~> 1.0.0"
|
19
|
+
|
7
20
|
Usage
|
8
21
|
-----
|
9
22
|
|
@@ -22,10 +35,13 @@ In the view you can do the following:
|
|
22
35
|
:minute_interval => 15,
|
23
36
|
:time_separator => "",
|
24
37
|
:start_hour => 10,
|
25
|
-
:
|
38
|
+
:start_minute => 30,
|
39
|
+
:end_hour => 14,
|
40
|
+
:end_minute => 30
|
41
|
+
%>
|
26
42
|
|
27
|
-
This will create a combined time select starting at 10 AM and going till
|
28
|
-
2 PM with 15 minute intervals with a default of 11:30 AM. This will set the
|
43
|
+
This will create a combined time select starting at 10:30 AM and going till
|
44
|
+
2:30 PM with 15 minute intervals with a default of 11:30 AM. This will set the
|
29
45
|
value for the start_time attribute on the object this form was created
|
30
46
|
for.
|
31
47
|
|
@@ -39,6 +55,14 @@ before you initialize the new model:
|
|
39
55
|
@event = Event.new params[:event]
|
40
56
|
end
|
41
57
|
|
58
|
+
def update
|
59
|
+
params[:event].parse_time_select! :start_time
|
60
|
+
@event = Event.find(params[:event])
|
61
|
+
if @event.update_attributes params[:event]
|
62
|
+
...
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
42
66
|
And voila! You're all set.
|
43
67
|
|
44
68
|
Behind The Scenes
|
@@ -56,5 +80,7 @@ parse_time_select!(attribute) looks like this:
|
|
56
80
|
|
57
81
|
{"utf8"=>"✓", "event"=>{"start_time"=>Fri, 23 Dec 2011 10:00:00 UTC +00:00}, "commit"=>"Save changes"}
|
58
82
|
|
59
|
-
This allows you to also seamlessly use a date_select field
|
60
|
-
combined_time_select.
|
83
|
+
This allows you to also seamlessly use a date_select field in
|
84
|
+
combination with combined_time_select.
|
85
|
+
|
86
|
+
|
data/lib/combined_time_select.rb
CHANGED
@@ -29,23 +29,22 @@ module ActionView::Helpers
|
|
29
29
|
@options[:time_separator] = ""
|
30
30
|
|
31
31
|
# Default is 15 minute intervals
|
32
|
-
minute_interval = 15
|
33
|
-
if @options[:minute_interval]
|
34
|
-
minute_interval = @options[:minute_interval]
|
35
|
-
end
|
32
|
+
minute_interval = @options.fetch(:minute_interval, 15)
|
36
33
|
|
37
34
|
start_minute = 0
|
35
|
+
end_minute = 1439
|
36
|
+
|
38
37
|
# @options[:start_hour] should be specified in military
|
39
38
|
# i.e. 0-23
|
40
39
|
if @options[:start_hour]
|
41
|
-
start_minute =
|
40
|
+
start_minute = @options[:start_hour] * 60
|
41
|
+
start_minute += @options.fetch(:start_minute, 0)
|
42
42
|
end
|
43
43
|
|
44
|
-
end_minute = 1439
|
45
44
|
# @options[:end_hour] should be specified in military
|
46
45
|
# i.e. 0-23
|
47
46
|
if @options[:end_hour]
|
48
|
-
end_minute = (
|
47
|
+
end_minute = (@options[:end_hour] * 60) + @options.fetch(:end_minute, 59)
|
49
48
|
end
|
50
49
|
|
51
50
|
if @options[:use_hidden] || @options[:discard_minute]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: combined_time_select
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 1.0.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2012-12-22 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
16
|
-
requirement:
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,7 +21,12 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements:
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
25
30
|
description: Generates a time_select field like Google calendar.
|
26
31
|
email:
|
27
32
|
- excid3@gmail.com
|
@@ -52,7 +57,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
52
57
|
version: '0'
|
53
58
|
segments:
|
54
59
|
- 0
|
55
|
-
hash:
|
60
|
+
hash: 4311608183375538091
|
56
61
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
57
62
|
none: false
|
58
63
|
requirements:
|
@@ -61,10 +66,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
61
66
|
version: '0'
|
62
67
|
segments:
|
63
68
|
- 0
|
64
|
-
hash:
|
69
|
+
hash: 4311608183375538091
|
65
70
|
requirements: []
|
66
71
|
rubyforge_project: combined_time_select
|
67
|
-
rubygems_version: 1.8.
|
72
|
+
rubygems_version: 1.8.24
|
68
73
|
signing_key:
|
69
74
|
specification_version: 3
|
70
75
|
summary: A Rails time_select like Google Calendar with combined hour and minute time_select
|