just-datetime-picker 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
18
+ .DS_Store
19
+ *~
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in mongoid_autoinc_id.gemspec
4
+ gemspec
data/LICENSE CHANGED
@@ -1,5 +1,5 @@
1
- GNU AFFERO GENERAL PUBLIC LICENSE
2
- Version 3, 19 November 2007
1
+ GNU GENERAL PUBLIC LICENSE
2
+ Version 3, 29 June 2007
3
3
 
4
4
  Copyright (C) 2007 Free Software Foundation, Inc. <http://fsf.org/>
5
5
  Everyone is permitted to copy and distribute verbatim copies
@@ -7,15 +7,17 @@
7
7
 
8
8
  Preamble
9
9
 
10
- The GNU Affero General Public License is a free, copyleft license for
11
- software and other kinds of works, specifically designed to ensure
12
- cooperation with the community in the case of network server software.
10
+ The GNU General Public License is a free, copyleft license for
11
+ software and other kinds of works.
13
12
 
14
13
  The licenses for most software and other practical works are designed
15
14
  to take away your freedom to share and change the works. By contrast,
16
- our General Public Licenses are intended to guarantee your freedom to
15
+ the GNU General Public License is intended to guarantee your freedom to
17
16
  share and change all versions of a program--to make sure it remains free
18
- software for all its users.
17
+ software for all its users. We, the Free Software Foundation, use the
18
+ GNU General Public License for most of our software; it applies also to
19
+ any other work released this way by its authors. You can apply it to
20
+ your programs, too.
19
21
 
20
22
  When we speak of free software, we are referring to freedom, not
21
23
  price. Our General Public Licenses are designed to make sure that you
@@ -24,34 +26,44 @@ them if you wish), that you receive source code or can get it if you
24
26
  want it, that you can change the software or use pieces of it in new
25
27
  free programs, and that you know you can do these things.
26
28
 
27
- Developers that use our General Public Licenses protect your rights
28
- with two steps: (1) assert copyright on the software, and (2) offer
29
- you this License which gives you legal permission to copy, distribute
30
- and/or modify the software.
31
-
32
- A secondary benefit of defending all users' freedom is that
33
- improvements made in alternate versions of the program, if they
34
- receive widespread use, become available for other developers to
35
- incorporate. Many developers of free software are heartened and
36
- encouraged by the resulting cooperation. However, in the case of
37
- software used on network servers, this result may fail to come about.
38
- The GNU General Public License permits making a modified version and
39
- letting the public access it on a server without ever releasing its
40
- source code to the public.
41
-
42
- The GNU Affero General Public License is designed specifically to
43
- ensure that, in such cases, the modified source code becomes available
44
- to the community. It requires the operator of a network server to
45
- provide the source code of the modified version running there to the
46
- users of that server. Therefore, public use of a modified version, on
47
- a publicly accessible server, gives the public access to the source
48
- code of the modified version.
49
-
50
- An older license, called the Affero General Public License and
51
- published by Affero, was designed to accomplish similar goals. This is
52
- a different license, not a version of the Affero GPL, but Affero has
53
- released a new version of the Affero GPL which permits relicensing under
54
- this license.
29
+ To protect your rights, we need to prevent others from denying you
30
+ these rights or asking you to surrender the rights. Therefore, you have
31
+ certain responsibilities if you distribute copies of the software, or if
32
+ you modify it: responsibilities to respect the freedom of others.
33
+
34
+ For example, if you distribute copies of such a program, whether
35
+ gratis or for a fee, you must pass on to the recipients the same
36
+ freedoms that you received. You must make sure that they, too, receive
37
+ or can get the source code. And you must show them these terms so they
38
+ know their rights.
39
+
40
+ Developers that use the GNU GPL protect your rights with two steps:
41
+ (1) assert copyright on the software, and (2) offer you this License
42
+ giving you legal permission to copy, distribute and/or modify it.
43
+
44
+ For the developers' and authors' protection, the GPL clearly explains
45
+ that there is no warranty for this free software. For both users' and
46
+ authors' sake, the GPL requires that modified versions be marked as
47
+ changed, so that their problems will not be attributed erroneously to
48
+ authors of previous versions.
49
+
50
+ Some devices are designed to deny users access to install or run
51
+ modified versions of the software inside them, although the manufacturer
52
+ can do so. This is fundamentally incompatible with the aim of
53
+ protecting users' freedom to change the software. The systematic
54
+ pattern of such abuse occurs in the area of products for individuals to
55
+ use, which is precisely where it is most unacceptable. Therefore, we
56
+ have designed this version of the GPL to prohibit the practice for those
57
+ products. If such problems arise substantially in other domains, we
58
+ stand ready to extend this provision to those domains in future versions
59
+ of the GPL, as needed to protect the freedom of users.
60
+
61
+ Finally, every program is threatened constantly by software patents.
62
+ States should not allow patents to restrict development and use of
63
+ software on general-purpose computers, but in those that do, we wish to
64
+ avoid the special danger that patents applied to a free program could
65
+ make it effectively proprietary. To prevent this, the GPL assures that
66
+ patents cannot be used to render the program non-free.
55
67
 
56
68
  The precise terms and conditions for copying, distribution and
57
69
  modification follow.
@@ -60,7 +72,7 @@ modification follow.
60
72
 
61
73
  0. Definitions.
62
74
 
63
- "This License" refers to version 3 of the GNU Affero General Public License.
75
+ "This License" refers to version 3 of the GNU General Public License.
64
76
 
65
77
  "Copyright" also means copyright-like laws that apply to other kinds of
66
78
  works, such as semiconductor masks.
@@ -537,45 +549,35 @@ to collect a royalty for further conveying from those to whom you convey
537
549
  the Program, the only way you could satisfy both those terms and this
538
550
  License would be to refrain entirely from conveying the Program.
539
551
 
540
- 13. Remote Network Interaction; Use with the GNU General Public License.
541
-
542
- Notwithstanding any other provision of this License, if you modify the
543
- Program, your modified version must prominently offer all users
544
- interacting with it remotely through a computer network (if your version
545
- supports such interaction) an opportunity to receive the Corresponding
546
- Source of your version by providing access to the Corresponding Source
547
- from a network server at no charge, through some standard or customary
548
- means of facilitating copying of software. This Corresponding Source
549
- shall include the Corresponding Source for any work covered by version 3
550
- of the GNU General Public License that is incorporated pursuant to the
551
- following paragraph.
552
+ 13. Use with the GNU Affero General Public License.
552
553
 
553
554
  Notwithstanding any other provision of this License, you have
554
555
  permission to link or combine any covered work with a work licensed
555
- under version 3 of the GNU General Public License into a single
556
+ under version 3 of the GNU Affero General Public License into a single
556
557
  combined work, and to convey the resulting work. The terms of this
557
558
  License will continue to apply to the part which is the covered work,
558
- but the work with which it is combined will remain governed by version
559
- 3 of the GNU General Public License.
559
+ but the special requirements of the GNU Affero General Public License,
560
+ section 13, concerning interaction through a network will apply to the
561
+ combination as such.
560
562
 
561
563
  14. Revised Versions of this License.
562
564
 
563
565
  The Free Software Foundation may publish revised and/or new versions of
564
- the GNU Affero General Public License from time to time. Such new versions
565
- will be similar in spirit to the present version, but may differ in detail to
566
+ the GNU General Public License from time to time. Such new versions will
567
+ be similar in spirit to the present version, but may differ in detail to
566
568
  address new problems or concerns.
567
569
 
568
570
  Each version is given a distinguishing version number. If the
569
- Program specifies that a certain numbered version of the GNU Affero General
571
+ Program specifies that a certain numbered version of the GNU General
570
572
  Public License "or any later version" applies to it, you have the
571
573
  option of following the terms and conditions either of that numbered
572
574
  version or of any later version published by the Free Software
573
575
  Foundation. If the Program does not specify a version number of the
574
- GNU Affero General Public License, you may choose any version ever published
576
+ GNU General Public License, you may choose any version ever published
575
577
  by the Free Software Foundation.
576
578
 
577
579
  If the Program specifies that a proxy can decide which future
578
- versions of the GNU Affero General Public License can be used, that proxy's
580
+ versions of the GNU General Public License can be used, that proxy's
579
581
  public statement of acceptance of a version permanently authorizes you
580
582
  to choose that version for the Program.
581
583
 
@@ -618,45 +620,3 @@ copy of the Program in return for a fee.
618
620
 
619
621
  END OF TERMS AND CONDITIONS
620
622
 
621
- How to Apply These Terms to Your New Programs
622
-
623
- If you develop a new program, and you want it to be of the greatest
624
- possible use to the public, the best way to achieve this is to make it
625
- free software which everyone can redistribute and change under these terms.
626
-
627
- To do so, attach the following notices to the program. It is safest
628
- to attach them to the start of each source file to most effectively
629
- state the exclusion of warranty; and each file should have at least
630
- the "copyright" line and a pointer to where the full notice is found.
631
-
632
- <one line to give the program's name and a brief idea of what it does.>
633
- Copyright (C) <year> <name of author>
634
-
635
- This program is free software: you can redistribute it and/or modify
636
- it under the terms of the GNU Affero General Public License as published by
637
- the Free Software Foundation, either version 3 of the License, or
638
- (at your option) any later version.
639
-
640
- This program is distributed in the hope that it will be useful,
641
- but WITHOUT ANY WARRANTY; without even the implied warranty of
642
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
643
- GNU Affero General Public License for more details.
644
-
645
- You should have received a copy of the GNU Affero General Public License
646
- along with this program. If not, see <http://www.gnu.org/licenses/>.
647
-
648
- Also add information on how to contact you by electronic and paper mail.
649
-
650
- If your software can interact with users remotely through a computer
651
- network, you should also make sure that it provides a way for users to
652
- get its source. For example, if your program is a web application, its
653
- interface could display a "Source" link that leads users to an archive
654
- of the code. There are many ways you could offer source, and different
655
- solutions will be better for different programs; see section 13 for the
656
- specific requirements.
657
-
658
- You should also get your employer (if you work as a programmer) or school,
659
- if any, to sign a "copyright disclaimer" for the program, if necessary.
660
- For more information on this, and how to apply and follow the GNU AGPL, see
661
- <http://www.gnu.org/licenses/>.
662
-
data/README.rdoc CHANGED
@@ -1,6 +1,10 @@
1
1
  = Introduction
2
2
 
3
- This is a simple gem for Active Admin that just adds support for Date/Time picker.
3
+ This is a simple gem for {Active Admin}[http://www.activeadmin.infp] that just
4
+ adds support for Date/Time picker.
5
+
6
+ It supports both ActiveRecord for relational databases and {Mongoid}[http://www.mongoid.org]
7
+ for {MongoDB}[http://www.mongodb.org] schemaless database.
4
8
 
5
9
  Screenshot[https://raw.github.com/saepia/just-datetime-picker/master/doc/just-datetime-picker.png]
6
10
 
@@ -12,26 +16,38 @@ Here comes a quick code sample. Sorry, currently no docs.
12
16
 
13
17
  That should create nice date/time picker for User#born_at.
14
18
 
15
- === Migration
19
+ === Migration (if you use ActiveRecord)
16
20
 
17
21
  class CreateUsers < ActiveRecord::Migration
18
22
  def change
19
23
  create_table :users do |t|
20
24
  t.datetime :born_at
21
-
25
+
22
26
  t.timestamps
23
27
  end
24
-
28
+
25
29
  end
26
30
  end
27
31
 
28
32
  === Model
29
33
 
34
+ ==== ActiveRecord
35
+
30
36
  class User < ActiveRecord::Base
31
37
  just_define_datetime_picker :born_at, :add_to_attr_accessible => true
32
38
  validates :born_at, :presence => true
33
39
  end
34
40
 
41
+ ==== Mongoid
42
+
43
+ class User
44
+ include Mongoid::Document
45
+ field :born_at, type: DateTime
46
+ just_define_datetime_picker :born_at, :add_to_attr_accessible => true
47
+ end
48
+
49
+ You must place "mongoid" gem BEFORE "just-datetime-picker" gem in your Gemfile!
50
+
35
51
  === ActiveAdmin
36
52
 
37
53
  ActiveAdmin.register User do
@@ -41,9 +57,9 @@ That should create nice date/time picker for User#born_at.
41
57
  end
42
58
 
43
59
  f.buttons
44
- end
60
+ end
45
61
  end
46
-
62
+
47
63
 
48
64
  = Installation
49
65
 
@@ -64,7 +80,7 @@ Then you can install the gem as follows:
64
80
 
65
81
  Add to your Gemfile:
66
82
 
67
- gem "just-datetime-picker", "~> 0.0.1"
83
+ gem "just-datetime-picker"
68
84
 
69
85
  and then type:
70
86
 
@@ -80,37 +96,24 @@ Once you have the source, you can unpack it and use from wherever you downloaded
80
96
 
81
97
  === CSS
82
98
 
83
- You can try to run rails g just:date_time:install to install default CSS,
84
- but I found that method sometimes does not work.
99
+ If you use Rails >= 3.1 just add this line to active_admin.css.scss
85
100
 
86
- In such case, just append the following code to your CSS stylesheet:
101
+ @import "just_datetime_picker/base";
87
102
 
88
- .input.just_datetime_picker input.just-datetime-picker-field {
89
- width: auto !important;
90
- }
91
-
92
- .input.just_datetime_picker input.just-datetime-picker-date {
93
- margin-right: 2ex;
94
- }
95
-
96
- .input.just_datetime_picker input.just-datetime-picker-time-hour {
97
- margin-right: 1ex;
98
- }
99
-
100
- .input.just_datetime_picker input.just-datetime-picker-time-minute {
101
- margin-left: 1ex;
102
- }
103
+ 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
+ to your CSS stylesheet.
103
105
 
104
106
  === JavaScript
105
107
 
106
108
  If you use nested set and dynamically create date or date/time pickers,
107
- they {won't be active by default due to bug in Active Admin}[https://github.com/sferik/rails_admin/issues/1309].
109
+ they {won't be active by default due to bug in Active Admin}[https://github.com/gregbell/active_admin/issues/1651].
108
110
 
109
- You can use following script to overcome that problem:
111
+ To overcome that, if you use Rails >= 3.1 just add this line to active_admin.js
110
112
 
111
- $('a.button').live('click', function() {
112
- $('input.datepicker:not(.hasDatepicker)').datepicker();
113
- });
113
+ //= require just_datetime_picker/nested_form_workaround
114
+
115
+ Otherwise, just manually append the code from {this file}[https://raw.github.com/saepia/just-datetime-picker/master/app/assets/javascripts/just_datetime_picker/nested_form_workaround.js]
116
+ to your JS script.
114
117
 
115
118
  = Additional info
116
119
 
@@ -119,12 +122,32 @@ You can use following script to overcome that problem:
119
122
  Code was tested with:
120
123
 
121
124
  * ruby[http://www.ruby-lang.org] 1.9.3-p194 [ amd64 ] under RVM[http://www.rvm.io],
122
- * ActiveAdmin[http://www.activeadmin.info] 0.5.0,
125
+ * ActiveAdmin[http://www.activeadmin.info] 0.5.0,
123
126
  * formtastic[https://github.com/justinfrench/formtastic] 2.2.1,
124
127
  * {Ruby on Rails}[http://www.rubyonrails.org] 3.2.8.
125
128
 
126
- = ChangeLog
129
+ == License
130
+
131
+ This code is licensed under GPLv3[http://www.gnu.org/licenses/gpl.html].
132
+
133
+ == Authors
134
+
135
+ * {Marcin Lewandowski}[https://github.com/saepia]
136
+ * doabit[https://github.com/doabit]
137
+
138
+ == ChangeLog
139
+
140
+ === 0.0.3 (September 21, 2012)
141
+
142
+ * Added mongoid[http://www.mongoid.org] support (doabit[https://github.com/doabit] & {Marcin Lewandowski}[https://github.com/saepia])
143
+ * Added zh-CN locale (doabit[https://github.com/doabit])
144
+ * Refactored gem building stuff (doabit[https://github.com/doabit] & {Marcin Lewandowski}[https://github.com/saepia])
145
+ * Refactored CSS and JS to use total power of assets pipeline ({Marcin Lewandowski}[https://github.com/saepia])
146
+
147
+ === 0.0.2 (September 9, 2012)
148
+
149
+ * Fixed bug that caused date/time fields' validations to always fail on record update if such field was not modified ({Marcin Lewandowski}[https://github.com/saepia])
127
150
 
128
- === 0.0.1
151
+ === 0.0.1 (September 7, 2012)
129
152
 
130
- * Initial release
153
+ * Initial release ({Marcin Lewandowski}[https://github.com/saepia])
data/Rakefile CHANGED
@@ -1,35 +1,2 @@
1
- # -*- encoding: utf-8 -*-
2
-
3
- require 'jeweler'
4
- Jeweler::Tasks.new do |s|
5
- s.name = "just-datetime-picker"
6
- s.version = '0.0.2'
7
- s.authors = ["Marcin Lewandowski"]
8
- s.email = ["marcin@saepia.net"]
9
- s.summary = %q{Gem that just creates date/time picker in active admin and propably any other formtastic-based form}
10
- s.description = %q{Gem that just creates date/time picker in active admin and propably any other formtastic-based form}
11
- s.homepage = "https://github.com/saepia/just-datetime-picker"
12
- s.files =
13
- ["Rakefile",
14
- "LICENSE",
15
- "lib/",
16
- "lib/just-datetime-picker.rb",
17
- "lib/just-datetime-picker/locales/",
18
- "lib/just-datetime-picker/locales/pl.yml",
19
- "lib/just-datetime-picker/locales/en.yml",
20
- "lib/just-datetime-picker/",
21
- "lib/just-datetime-picker/activerecord.rb",
22
- "lib/just-datetime-picker/core.rb",
23
- "lib/just-datetime-picker/formtastic-input.rb",
24
- "lib/generators/",
25
- "lib/generators/just-datetime-picker/",
26
- "lib/generators/just-datetime-picker/install_generator.rb",
27
- "lib/generators/just-datetime-picker/templates/",
28
- "lib/generators/just-datetime-picker/templates/just_datetime.css" ]
29
-
30
- s.require_paths = ["lib"]
31
-
32
- s.add_dependency 'formtastic', '>= 2.0.0'
33
- end
34
- Jeweler::RubygemsDotOrgTasks.new
35
-
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
@@ -0,0 +1,4 @@
1
+ $('body.active_admin a.button').live('click', function() {
2
+ $('input.datepicker:not(.hasDatepicker)').datepicker();
3
+ });
4
+
File without changes
@@ -0,0 +1,16 @@
1
+ body.active_admin .input.just_datetime_picker input.just-datetime-picker-field {
2
+ width: auto !important;
3
+ }
4
+
5
+ body.active_admin .input.just_datetime_picker input.just-datetime-picker-date {
6
+ margin-right: 2ex;
7
+ }
8
+
9
+ body.active_admin .input.just_datetime_picker input.just-datetime-picker-time-hour {
10
+ margin-right: 1ex;
11
+ }
12
+
13
+ body.active_admin .input.just_datetime_picker input.just-datetime-picker-time-minute {
14
+ margin-left: 1ex;
15
+ }
16
+
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ Gem::Specification.new do |gem|
3
+ gem.authors = ["Marcin Lewandowski"]
4
+ gem.email = ["marcin@saepia.net"]
5
+ gem.description = %q{Gem that just creates date/time picker in Active Admin forms}
6
+ gem.summary = %q{Gem that just creates date/time picker in Active Admin forms}
7
+ gem.homepage = "https://github.com/saepia/just-datetime-picker"
8
+
9
+ gem.files = `git ls-files`.split($\)
10
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
11
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
12
+ gem.name = "just-datetime-picker"
13
+ gem.require_paths = ["lib"]
14
+ gem.version = '0.0.3'
15
+ gem.add_dependency 'formtastic', '>= 2.0.0'
16
+ gem.add_dependency 'activeadmin', '>= 0.5.0'
17
+ end
@@ -1,19 +1,22 @@
1
1
  require 'formtastic'
2
2
 
3
3
  module Just
4
- module DateTime
4
+ module DateTimePicker
5
5
  class Railtie < ::Rails::Railtie
6
6
  config.after_initialize do
7
7
  # Add load paths straight to I18n, so engines and application can overwrite it.
8
8
  require 'active_support/i18n'
9
-
9
+
10
10
  I18n.load_path += Dir[File.expand_path('../just-datetime-picker/locales/*.yml', __FILE__)]
11
11
  end
12
12
  end
13
13
  end
14
14
  end
15
15
 
16
+
17
+ require 'just-datetime-picker/engine'
16
18
  require 'just-datetime-picker/core'
17
- require 'just-datetime-picker/activerecord'
19
+ require 'just-datetime-picker/databases/common'
20
+ require 'just-datetime-picker/databases/activerecord' if defined?(ActiveRecord::Base)
21
+ require 'just-datetime-picker/databases/mongoid' if defined?(Mongoid::Document)
18
22
  require 'just-datetime-picker/formtastic-input'
19
-
@@ -1,5 +1,5 @@
1
1
  module Just
2
- module DateTime
2
+ module DateTimePicker
3
3
  HOUR_MULTIPLIER = 10000
4
4
  MINUTE_MULTIPLIER = 100
5
5
 
@@ -0,0 +1 @@
1
+ ActiveRecord::Base.send :include, Just::DateTimePicker::DatabaseAbstraction::Common
@@ -0,0 +1,113 @@
1
+ module Just
2
+ module DateTimePicker
3
+ module DatabaseAbstraction
4
+ module Common
5
+ extend ActiveSupport::Concern
6
+
7
+ class JustDateValidator < ActiveModel::EachValidator
8
+ def validate_each(record, attribute, value)
9
+ begin
10
+ Date.parse(value)
11
+ rescue ArgumentError
12
+ if defined?(Mongoid) and record.class.included_modules.include? Mongoid::Document
13
+ record.errors[attribute] << I18n.t("mongoid.errors.messages.just_datetime_invalid_date")
14
+ else
15
+ record.errors[attribute] << I18n.t("activerecord.errors.messages.just_datetime_invalid_date")
16
+ end
17
+ end
18
+ end
19
+ end
20
+
21
+ included do
22
+ # Defines attribute specified as +field_name+ as field that will
23
+ # be underlying storage for Just Date/Time Picker.
24
+ #
25
+ # It should accept saving values of type +ActiveSupport::TimeWithZone+.
26
+ #
27
+ # You can pass options by passing a Hash to the +options+ parameter.
28
+ # Currently the only supported option is +:add_to_attr_accessible+
29
+ # which if set to +true+ automatically calls +attr_accessible+ for
30
+ # attribute passed as +field_name+ and all virtual attributes created
31
+ # by Just Date/Time Picker.
32
+ #
33
+ # * *Arguments* :
34
+ # - +field_name+ -> attribute to turn into +Just Date/Time Picker+ storage
35
+ # - +options+ -> +Hash+ with options
36
+ # - +:add_to_attr_accessible+ -> call automatically attr_accessible for attributes? (+boolean+)
37
+ #
38
+ def self.just_define_datetime_picker(field_name, options = {})
39
+ attr_reader "#{field_name}_time_hour"
40
+ attr_reader "#{field_name}_time_minute"
41
+
42
+ validates "#{field_name}_date", :just_date => true, :allow_nil => true, :allow_blank => false
43
+ validates "#{field_name}_time_hour", :numericality => { :only_integer => true, :greater_than_or_equal_to => 0, :less_than_or_equal_to => 23, :message => :just_datetime_invalid_time_hour }, :allow_nil => true, :allow_blank => false
44
+ validates "#{field_name}_time_minute", :numericality => { :only_integer => true, :greater_than_or_equal_to => 0, :less_than_or_equal_to => 59, :message => :just_datetime_invalid_time_minute }, :allow_nil => true, :allow_blank => false
45
+
46
+ after_validation do
47
+ date_attribute = "#{field_name}_date".to_sym
48
+ hour_attribute = "#{field_name}_time_hour".to_sym
49
+ minute_attribute = "#{field_name}_time_minute".to_sym
50
+ hour_value = self.send(hour_attribute)
51
+ minute_value = self.send(minute_attribute)
52
+
53
+ self.errors[hour_attribute].each{ |e| self.errors[field_name] << e }
54
+ self.errors[minute_attribute].each{ |e| self.errors[field_name] << e }
55
+ self.errors[date_attribute].each{ |e| self.errors[field_name] << e }
56
+
57
+ self.errors[field_name].uniq!
58
+ end
59
+
60
+
61
+ define_method "#{field_name}_date" do
62
+ return instance_variable_get("@#{field_name}_date") if instance_variable_get("@#{field_name}_date")
63
+ return nil if self.send(field_name).nil?
64
+
65
+ self.send(field_name).to_date.to_s
66
+ end
67
+
68
+ define_method "#{field_name}_date=" do |v|
69
+ instance_variable_set("@#{field_name}_date", v)
70
+ just_combine_datetime field_name
71
+ end
72
+
73
+ define_method "#{field_name}_time_hour=" do |v|
74
+ instance_variable_set("@#{field_name}_time_hour", v.to_i)
75
+ just_combine_datetime field_name
76
+ end
77
+
78
+ define_method "#{field_name}_time_minute=" do |v|
79
+ instance_variable_set("@#{field_name}_time_minute", v.to_i)
80
+ just_combine_datetime field_name
81
+ end
82
+
83
+
84
+ if options.has_key? :add_to_attr_accessible and options[:add_to_attr_accessible] == true
85
+ attr_accessible "#{field_name}_date".to_sym, "#{field_name}_time_hour".to_sym, "#{field_name}_time_minute".to_sym
86
+ end
87
+ end # just_define_datetime_picker
88
+
89
+ protected
90
+ def just_combine_datetime(field_name)
91
+ 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?
92
+
93
+ combined = "#{instance_variable_get("@#{field_name}_date")} #{sprintf("%02d", instance_variable_get("@#{field_name}_time_hour"))}:#{sprintf("%02d", instance_variable_get("@#{field_name}_time_minute"))}:00"
94
+ begin
95
+ self.send("#{field_name}=", Time.zone.parse(combined))
96
+
97
+ rescue ArgumentError
98
+ logger.warn "Just error while trying to set #{field_name} attribute: \"#{combined}\" is not valid date/time"
99
+ end
100
+ end
101
+
102
+ end
103
+
104
+
105
+ end # included
106
+
107
+
108
+ end
109
+ end
110
+ end
111
+ end
112
+
113
+
@@ -0,0 +1,2 @@
1
+ Mongoid::Document.send :include, Just::DateTimePicker::DatabaseAbstraction::Common
2
+
@@ -0,0 +1,12 @@
1
+ module Just
2
+ module DateTimePicker
3
+ class Engine < Rails::Engine
4
+ if Rails.version >= "3.1"
5
+ initializer "Just DateTime Picker precompile hook" do |app|
6
+ app.config.assets.precompile += %w(just_datetime_picker/base.css just_datetime_picker/nested_form_workaround.js)
7
+ end
8
+ end
9
+ end
10
+ end
11
+ end
12
+
@@ -5,3 +5,9 @@ en:
5
5
  just_datetime_invalid_date: "Invalid date"
6
6
  just_datetime_invalid_time_hour: "Invalid hour"
7
7
  just_datetime_invalid_time_minute: "Invalid minutes"
8
+ mongoid:
9
+ errors:
10
+ messages:
11
+ just_datetime_invalid_date: "Invalid date"
12
+ just_datetime_invalid_time_hour: "Invalid hour"
13
+ just_datetime_invalid_time_minute: "Invalid minutes"
@@ -5,3 +5,9 @@ pl:
5
5
  just_datetime_invalid_date: "Nieprawidłowa data"
6
6
  just_datetime_invalid_time_hour: "Nieprawidłowa godzina"
7
7
  just_datetime_invalid_time_minute: "Nieprawidłowa ilość minut"
8
+ mongoid:
9
+ errors:
10
+ messages:
11
+ just_datetime_invalid_date: "Nieprawidłowa data"
12
+ just_datetime_invalid_time_hour: "Nieprawidłowa godzina"
13
+ just_datetime_invalid_time_minute: "Nieprawidłowa ilość minut"
@@ -0,0 +1,13 @@
1
+ zh-CN:
2
+ activerecord:
3
+ errors:
4
+ messages:
5
+ just_datetime_invalid_date: "无效的日期"
6
+ just_datetime_invalid_time_hour: "无效的小时"
7
+ just_datetime_invalid_time_minute: "无效的分钟"
8
+ mongoid:
9
+ errors:
10
+ messages:
11
+ just_datetime_invalid_date: "无效的日期"
12
+ just_datetime_invalid_time_hour: "无效的小时"
13
+ just_datetime_invalid_time_minute: "无效的分钟"
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.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-09-09 00:00:00.000000000 Z
12
+ date: 2012-09-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: formtastic
@@ -27,27 +27,49 @@ dependencies:
27
27
  - - ! '>='
28
28
  - !ruby/object:Gem::Version
29
29
  version: 2.0.0
30
- description: Gem that just creates date/time picker in active admin and propably any
31
- other formtastic-based form
30
+ - !ruby/object:Gem::Dependency
31
+ name: activeadmin
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: 0.5.0
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: 0.5.0
46
+ description: Gem that just creates date/time picker in Active Admin forms
32
47
  email:
33
48
  - marcin@saepia.net
34
49
  executables: []
35
50
  extensions: []
36
- extra_rdoc_files:
37
- - LICENSE
38
- - README.rdoc
51
+ extra_rdoc_files: []
39
52
  files:
53
+ - .gitignore
54
+ - Gemfile
40
55
  - LICENSE
56
+ - README.rdoc
41
57
  - Rakefile
42
- - lib/generators/just-datetime-picker/install_generator.rb
43
- - lib/generators/just-datetime-picker/templates/just_datetime.css
58
+ - app/assets/javascripts/just_datetime_picker/nested_form_workaround.js
59
+ - app/assets/stylesheets/.gitkeep
60
+ - app/assets/stylesheets/just_datetime_picker/base.css
61
+ - doc/just-datetime-picker.png
62
+ - just-datetime-picker.gemspec
44
63
  - lib/just-datetime-picker.rb
45
- - lib/just-datetime-picker/activerecord.rb
46
64
  - lib/just-datetime-picker/core.rb
65
+ - lib/just-datetime-picker/databases/activerecord.rb
66
+ - lib/just-datetime-picker/databases/common.rb
67
+ - lib/just-datetime-picker/databases/mongoid.rb
68
+ - lib/just-datetime-picker/engine.rb
47
69
  - lib/just-datetime-picker/formtastic-input.rb
48
70
  - lib/just-datetime-picker/locales/en.yml
49
71
  - lib/just-datetime-picker/locales/pl.yml
50
- - README.rdoc
72
+ - lib/just-datetime-picker/locales/zh-CN.yml
51
73
  homepage: https://github.com/saepia/just-datetime-picker
52
74
  licenses: []
53
75
  post_install_message:
@@ -60,17 +82,22 @@ required_ruby_version: !ruby/object:Gem::Requirement
60
82
  - - ! '>='
61
83
  - !ruby/object:Gem::Version
62
84
  version: '0'
85
+ segments:
86
+ - 0
87
+ hash: 3099708817768725854
63
88
  required_rubygems_version: !ruby/object:Gem::Requirement
64
89
  none: false
65
90
  requirements:
66
91
  - - ! '>='
67
92
  - !ruby/object:Gem::Version
68
93
  version: '0'
94
+ segments:
95
+ - 0
96
+ hash: 3099708817768725854
69
97
  requirements: []
70
98
  rubyforge_project:
71
99
  rubygems_version: 1.8.24
72
100
  signing_key:
73
101
  specification_version: 3
74
- summary: Gem that just creates date/time picker in active admin and propably any other
75
- formtastic-based form
102
+ summary: Gem that just creates date/time picker in Active Admin forms
76
103
  test_files: []
@@ -1,14 +0,0 @@
1
- module Just
2
- module DateTime
3
- module Generators
4
- class InstallGenerator < Rails::Generators::Base
5
- source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
6
-
7
- desc "Installs Just DateTime Picker"
8
- def copy__file
9
- copy_file 'just_datetime.css', 'app/assets/stylesheets/just_datetime.css'
10
- end
11
- end
12
- end
13
- end
14
- end
@@ -1,15 +0,0 @@
1
- input.just-datetime-picker-field {
2
- width: auto !important;
3
- }
4
-
5
- input.just-datetime-picker-date {
6
- margin-right: 2ex;
7
- }
8
-
9
- input.just-datetime-picker-time-hour {
10
- margin-right: 1ex;
11
- }
12
-
13
- input.just-datetime-picker-time-minute {
14
- margin-left: 1ex;
15
- }
@@ -1,96 +0,0 @@
1
- module Just
2
- module DateTime
3
- module ActiveRecord
4
- class JustDateValidator < ActiveModel::EachValidator
5
- def validate_each(record, attribute, value)
6
- begin
7
- Date.parse(value)
8
- rescue ArgumentError
9
- record.errors[attribute] << I18n.t("activerecord.errors.messages.just_datetime_invalid_date")
10
- end
11
- end
12
- end
13
-
14
- def self.included(mod)
15
- mod.extend(ClassMethods)
16
- end
17
-
18
- module ClassMethods
19
- def just_define_datetime_picker(field_name, options = {})
20
- include ::Just::DateTime::ActiveRecord::InstanceMethods
21
-
22
- attr_reader "#{field_name}_time_hour"
23
- attr_reader "#{field_name}_time_minute"
24
-
25
- validates "#{field_name}_date", :just_date => true, :allow_nil => true, :allow_blank => false
26
- validates "#{field_name}_time_hour", :numericality => { :only_integer => true, :greater_than_or_equal_to => 0, :less_than_or_equal_to => 23, :message => :just_datetime_invalid_time_hour }, :allow_nil => true, :allow_blank => false
27
- validates "#{field_name}_time_minute", :numericality => { :only_integer => true, :greater_than_or_equal_to => 0, :less_than_or_equal_to => 59, :message => :just_datetime_invalid_time_minute }, :allow_nil => true, :allow_blank => false
28
-
29
- after_validation do
30
- date_attribute = "#{field_name}_date".to_sym
31
- hour_attribute = "#{field_name}_time_hour".to_sym
32
- minute_attribute = "#{field_name}_time_minute".to_sym
33
- hour_value = self.send(hour_attribute)
34
- minute_value = self.send(minute_attribute)
35
-
36
- self.errors[hour_attribute].each{ |e| self.errors[field_name] << e }
37
- self.errors[minute_attribute].each{ |e| self.errors[field_name] << e }
38
- self.errors[date_attribute].each{ |e| self.errors[field_name] << e }
39
-
40
- self.errors[field_name].uniq!
41
- end
42
-
43
-
44
- define_method "#{field_name}_date" do
45
- return instance_variable_get("@#{field_name}_date") if instance_variable_get("@#{field_name}_date")
46
- return nil if self.send(field_name).nil?
47
-
48
- self.send(field_name).to_date.to_s
49
- end
50
-
51
- define_method "#{field_name}_date=" do |v|
52
- instance_variable_set("@#{field_name}_date", v)
53
- just_combine_datetime field_name
54
- end
55
-
56
- define_method "#{field_name}_time_hour=" do |v|
57
- instance_variable_set("@#{field_name}_time_hour", v.to_i)
58
- just_combine_datetime field_name
59
- end
60
-
61
- define_method "#{field_name}_time_minute=" do |v|
62
- instance_variable_set("@#{field_name}_time_minute", v.to_i)
63
- just_combine_datetime field_name
64
- end
65
-
66
-
67
- if options.has_key? :add_to_attr_accessible and options[:add_to_attr_accessible] == true
68
- attr_accessible "#{field_name}_date".to_sym, "#{field_name}_time_hour".to_sym, "#{field_name}_time_minute".to_sym
69
- end
70
- end # just_define_datetime_picker
71
-
72
- end # ClassMethods
73
-
74
-
75
- module InstanceMethods
76
- protected
77
- def just_combine_datetime(field_name)
78
- 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?
79
-
80
- combined = "#{instance_variable_get("@#{field_name}_date")} #{sprintf("%02d", instance_variable_get("@#{field_name}_time_hour"))}:#{sprintf("%02d", instance_variable_get("@#{field_name}_time_minute"))}:00"
81
- begin
82
- self.send("#{field_name}=", Time.zone.parse(combined))
83
-
84
- rescue ArgumentError
85
- logger.warn "Just error while trying to set #{field_name} attribute: \"#{combined}\" is not valid date/time"
86
- end
87
- end
88
-
89
- end
90
-
91
- end # InstanceMethods
92
- end
93
- end
94
- end
95
-
96
- ActiveRecord::Base.send :include, Just::DateTime::ActiveRecord