just-datetime-picker 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.rdoc
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
= Introduction
|
2
2
|
|
3
|
-
This is a simple gem for {Active Admin}[http://www.activeadmin.
|
3
|
+
This is a simple gem for {Active Admin}[http://www.activeadmin.info] that just
|
4
4
|
adds support for Date/Time picker.
|
5
5
|
|
6
6
|
It supports both ActiveRecord for relational databases and {Mongoid}[http://www.mongoid.org]
|
@@ -12,9 +12,11 @@ Screenshot[https://raw.github.com/saepia/just-datetime-picker/master/doc/just-da
|
|
12
12
|
|
13
13
|
== Code samples
|
14
14
|
|
15
|
-
Here comes a quick code sample. Sorry, currently no docs.
|
15
|
+
Here comes a quick code sample. Sorry, currently no detailed docs.
|
16
16
|
|
17
|
-
That should create nice date/time picker for User#born_at.
|
17
|
+
That should create nice date/time picker for User#born_at. Associated column in the DB should be nullable.
|
18
|
+
|
19
|
+
To delete previously stored date/time just make all fields blank (date, hour and minute).
|
18
20
|
|
19
21
|
=== Migration (if you use ActiveRecord)
|
20
22
|
|
@@ -96,13 +98,15 @@ Once you have the source, you can unpack it and use from wherever you downloaded
|
|
96
98
|
|
97
99
|
=== CSS
|
98
100
|
|
99
|
-
If you use Rails >= 3.1 just add this line to active_admin.css.scss
|
101
|
+
If you use Rails >= 3.1 AND ActiveAdmin >= 0.5.0 just add this line to active_admin.css.scss
|
100
102
|
|
101
103
|
@import "just_datetime_picker/base";
|
102
104
|
|
103
105
|
Otherwise, just manually append the code from {this file}[https://raw.github.com/saepia/just-datetime-picker/master/app/assets/stylesheets/just_datetime_picker/base.css]
|
104
106
|
to your CSS stylesheet.
|
105
107
|
|
108
|
+
In ActiveAdmin 0.4.x you must strip body.active_admin from CSS declarations.
|
109
|
+
|
106
110
|
=== JavaScript
|
107
111
|
|
108
112
|
If you use nested set and dynamically create date or date/time pickers,
|
@@ -121,10 +125,10 @@ to your JS script.
|
|
121
125
|
|
122
126
|
Code was tested with:
|
123
127
|
|
124
|
-
* ruby[http://www.ruby-lang.org] 1.9.3-p194 [ amd64 ] under RVM[http://www.rvm.io],
|
125
|
-
* ActiveAdmin[http://www.activeadmin.info] 0.4.4 and 0.5.
|
128
|
+
* ruby[http://www.ruby-lang.org] 1.9.3-p194 [ amd64 ] and 1.9.3p286 [ i386 ] under RVM[http://www.rvm.io],
|
129
|
+
* ActiveAdmin[http://www.activeadmin.info] 0.4.4, 0.5.0 and 0.5.1,
|
126
130
|
* formtastic[https://github.com/justinfrench/formtastic] 2.2.1,
|
127
|
-
* {Ruby on Rails}[http://www.rubyonrails.org] 3.2.8.
|
131
|
+
* {Ruby on Rails}[http://www.rubyonrails.org] 3.2.8, 3.2.11.
|
128
132
|
|
129
133
|
== License
|
130
134
|
|
@@ -137,6 +141,11 @@ This code is licensed under GPLv3[http://www.gnu.org/licenses/gpl.html].
|
|
137
141
|
|
138
142
|
== ChangeLog
|
139
143
|
|
144
|
+
=== 0.0.6 (February 23, 2013)
|
145
|
+
|
146
|
+
* Fixed nested form workaround - do not use obsolete jQuery live() syntax ({Marcin Lewandowski}[https://github.com/saepia])
|
147
|
+
* Allow to set date time to null value (thanks to {yaoquan}[https://github.com/yaoquan] for pointing this out)
|
148
|
+
|
140
149
|
=== 0.0.5 (September 28, 2012)
|
141
150
|
|
142
151
|
* Changed dependency of ActiveAdmin 0.5.0 to 0.4.4 ({Marcin Lewandowski}[https://github.com/saepia])
|
@@ -1,4 +1,11 @@
|
|
1
|
-
|
1
|
+
// Workaround that enables date picker for fields in nested forms.
|
2
|
+
// By default ActiveAdmin enables date picker once, after the page
|
3
|
+
// has been loaded, so all datepicker fields created afterwards
|
4
|
+
// are dead by default.
|
5
|
+
//
|
6
|
+
// We attach to a.button to catch a moment where user can potentially
|
7
|
+
// add new field like this in a nested form.
|
8
|
+
$(document).on('click', 'body.active_admin a.button', function() {
|
2
9
|
$('input.datepicker:not(.hasDatepicker)').datepicker();
|
3
10
|
});
|
4
11
|
|
@@ -11,7 +11,7 @@ Gem::Specification.new do |gem|
|
|
11
11
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
12
12
|
gem.name = "just-datetime-picker"
|
13
13
|
gem.require_paths = ["lib"]
|
14
|
-
gem.version = '0.0.
|
14
|
+
gem.version = '0.0.6'
|
15
15
|
gem.add_dependency 'formtastic', '>= 2.0.0'
|
16
16
|
gem.add_dependency 'activeadmin', '>= 0.4.4'
|
17
17
|
end
|
@@ -69,33 +69,53 @@ module Just
|
|
69
69
|
end
|
70
70
|
|
71
71
|
define_method "#{field_name}_date=" do |v|
|
72
|
-
|
72
|
+
if v.to_s.empty?
|
73
|
+
instance_variable_set("@#{field_name}_date", nil)
|
74
|
+
else
|
75
|
+
instance_variable_set("@#{field_name}_date", v)
|
76
|
+
end
|
73
77
|
|
74
|
-
instance_variable_set("@#{field_name}_date", v)
|
75
78
|
just_combine_datetime field_name
|
76
79
|
end
|
77
80
|
|
78
81
|
define_method "#{field_name}_time_hour=" do |v|
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
+
if v.to_s.empty?
|
83
|
+
instance_variable_set("@#{field_name}_time_hour", nil)
|
84
|
+
else
|
85
|
+
instance_variable_set("@#{field_name}_time_hour", v.to_i)
|
86
|
+
end
|
87
|
+
|
82
88
|
just_combine_datetime field_name
|
83
89
|
end
|
84
90
|
|
85
91
|
define_method "#{field_name}_time_minute=" do |v|
|
86
|
-
|
87
|
-
|
88
|
-
|
92
|
+
if v.to_s.empty?
|
93
|
+
instance_variable_set("@#{field_name}_time_minute", nil)
|
94
|
+
else
|
95
|
+
instance_variable_set("@#{field_name}_time_minute", v.to_i)
|
96
|
+
end
|
97
|
+
|
89
98
|
just_combine_datetime field_name
|
90
99
|
end
|
91
100
|
|
92
|
-
|
93
101
|
if options.has_key? :add_to_attr_accessible and options[:add_to_attr_accessible] == true
|
94
102
|
attr_accessible "#{field_name}_date".to_sym, "#{field_name}_time_hour".to_sym, "#{field_name}_time_minute".to_sym
|
95
103
|
end
|
96
104
|
end # just_define_datetime_picker
|
97
105
|
|
98
106
|
protected
|
107
|
+
|
108
|
+
# Combines values passed to individual fields (date, hour and minutes) into syntax acceptable by DB.
|
109
|
+
#
|
110
|
+
# It performs validation by trying to parse combined time. In case of error it just logs warning.
|
111
|
+
# In such case, stored date/time remains unchanged.
|
112
|
+
#
|
113
|
+
# It performs and tries to store the value only if all components (date, hour and minutes) are set.
|
114
|
+
# Otherwise it checks the opposite - if maybe all values are nil, and then sets NULL in the DB if
|
115
|
+
# this condition is true.
|
116
|
+
#
|
117
|
+
# * *Arguments* :
|
118
|
+
# - +field_name+ -> attribute that is used to represent +Just Date/Time Picker+ storage
|
99
119
|
def just_combine_datetime(field_name)
|
100
120
|
if not instance_variable_get("@#{field_name}_date").nil? and not instance_variable_get("@#{field_name}_time_hour").nil? and not instance_variable_get("@#{field_name}_time_minute").nil?
|
101
121
|
|
@@ -106,11 +126,11 @@ module Just
|
|
106
126
|
rescue ArgumentError
|
107
127
|
logger.warn "Just error while trying to set #{field_name} attribute: \"#{combined}\" is not valid date/time"
|
108
128
|
end
|
129
|
+
|
130
|
+
elsif instance_variable_get("@#{field_name}_date").nil? and instance_variable_get("@#{field_name}_time_hour").nil? and instance_variable_get("@#{field_name}_time_minute").nil?
|
131
|
+
self.send("#{field_name}=", nil)
|
109
132
|
end
|
110
|
-
|
111
|
-
end
|
112
|
-
|
113
|
-
|
133
|
+
end
|
114
134
|
end # included
|
115
135
|
|
116
136
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: just-datetime-picker
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2013-02-23 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: formtastic
|