aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorLuc Donnet2012-06-29 10:00:32 +0200
committerLuc Donnet2012-06-29 10:00:32 +0200
commit5d324978dbe910ce247e08ac423da811773bbc42 (patch)
tree119731c0f704af61169f69bd0b109b89a1fe63f2
parente23bf6c2789b174d7ce847270f45d15b8633000c (diff)
downloadchouette-core-5d324978dbe910ce247e08ac423da811773bbc42.tar.bz2
Add datepicker with html5 and jquery
-rw-r--r--Gemfile2
-rw-r--r--Gemfile.lock5
-rw-r--r--app/assets/javascripts/jquery.ui.datepicker-i18n.js30
-rw-r--r--app/views/networks/_form.erb2
4 files changed, 31 insertions, 8 deletions
diff --git a/Gemfile b/Gemfile
index a1414957c..b58de2e41 100644
--- a/Gemfile
+++ b/Gemfile
@@ -33,7 +33,7 @@ gem 'ransack'
gem 'squeel'
gem 'RedCloth'
gem 'jquery-rails'
-gem 'modernizr'
+gem "modernizr-rails", "~> 2.0.6"
gem "acts_as_tree", :git => "git://github.com/dryade/acts_as_tree.git"
gem 'ninoxe', :git => 'git://chouette.dryade.priv/ninoxe' #, :path => '~/Projects/Ninoxe'
diff --git a/Gemfile.lock b/Gemfile.lock
index 97f1ed577..9739f9904 100644
--- a/Gemfile.lock
+++ b/Gemfile.lock
@@ -218,8 +218,7 @@ GEM
treetop (~> 1.4.8)
map_layers (0.0.5)
mime-types (1.19)
- modernizr (2.5.3)
- sprockets (~> 2.0)
+ modernizr-rails (2.0.6)
multi_json (1.3.6)
net-scp (1.0.4)
net-ssh (>= 1.99.1)
@@ -381,7 +380,7 @@ DEPENDENCIES
json
launchy
map_layers (~> 0.0.4)
- modernizr
+ modernizr-rails (~> 2.0.6)
ninoxe!
pg (~> 0.11.0)
rails (= 3.1.3)
diff --git a/app/assets/javascripts/jquery.ui.datepicker-i18n.js b/app/assets/javascripts/jquery.ui.datepicker-i18n.js
index 637c7b999..3d0d55b46 100644
--- a/app/assets/javascripts/jquery.ui.datepicker-i18n.js
+++ b/app/assets/javascripts/jquery.ui.datepicker-i18n.js
@@ -39,9 +39,33 @@ jQuery(function($){
isRTL: false,
showMonthAfterYear: false,
yearSuffix: ''};
+
+ if(!(Modernizr.inputtypes && Modernizr.inputtypes.date))
+ {
+ $.datepicker.setDefaults($.datepicker.regional[ "" ]);
+ $("input[type='date']").each( function(index, element)
+ {
+ $(element).datepicker(
+ {
+ dateFormat: "dd/mm/y",
+ dayNamesShort: $.datepicker.regional[ $('html').attr('lang') ].dayNamesShort,
+ dayNames: $.datepicker.regional[ $('html').attr('lang') ].dayNames,
+ monthNamesShort: $.datepicker.regional[ $('html').attr('lang') ].monthNamesShort,
+ monthNames: $.datepicker.regional[ $('html').attr('lang') ].monthNames
+ } );
+ $(element).datepicker("setDate", $.datepicker.parseDate('yy-mm-dd', $(element).val() ) );
+ });
- $.datepicker.setDefaults($.datepicker.regional[ "" ]);
- $("input[type='date']").datepicker( $.datepicker.regional[ "fr" ] );
- $("input[type='date']").datepicker( "option", $.datepicker.regional[ $('html').attr('lang') ] );
+ $("form").submit(function(event) {
+ var $this = $(event.target);
+ $this.find("input[type='date']").each(
+ function(index, element)
+ {
+ var date = $.datepicker.formatDate('yy-mm-dd', $.datepicker.parseDate('dd/mm/y', $(element).val() ) );
+ $(element).val(date);
+ }
+ );
+ });
+ }
});
diff --git a/app/views/networks/_form.erb b/app/views/networks/_form.erb
index cf1764136..3122448ef 100644
--- a/app/views/networks/_form.erb
+++ b/app/views/networks/_form.erb
@@ -3,7 +3,7 @@
<%= form.input :name %>
<%= form.input :registration_number %>
<%= form.input :comment %>
- <%= form.input :versiondate, :as => :date , :label => @network.human_attribute_name("version_date")%>
+ <%= form.input :version_date, :as => :date_picker %>
<%= form.input :description %>
<%= form.input :source_name %>
<%= form.input :source_identifier %>