diff options
| author | Luc Donnet | 2012-06-29 10:00:32 +0200 |
|---|---|---|
| committer | Luc Donnet | 2012-06-29 10:00:32 +0200 |
| commit | 5d324978dbe910ce247e08ac423da811773bbc42 (patch) | |
| tree | 119731c0f704af61169f69bd0b109b89a1fe63f2 | |
| parent | e23bf6c2789b174d7ce847270f45d15b8633000c (diff) | |
| download | chouette-core-5d324978dbe910ce247e08ac423da811773bbc42.tar.bz2 | |
Add datepicker with html5 and jquery
| -rw-r--r-- | Gemfile | 2 | ||||
| -rw-r--r-- | Gemfile.lock | 5 | ||||
| -rw-r--r-- | app/assets/javascripts/jquery.ui.datepicker-i18n.js | 30 | ||||
| -rw-r--r-- | app/views/networks/_form.erb | 2 |
4 files changed, 31 insertions, 8 deletions
@@ -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 %> |
