From 1f1b23528399d06832603129def941d4d6c4c095 Mon Sep 17 00:00:00 2001 From: Xavier J Date: Thu, 22 Sep 2016 11:31:24 +0200 Subject: [PATCH] Fix bug Chrome datepicker --- Gemfile | 2 ++ Gemfile.lock | 2 ++ app/assets/javascripts/description.js | 8 ++++---- app/assets/stylesheets/description.scss | 8 ++++---- app/controllers/application_controller.rb | 5 +++++ app/models/champ.rb | 2 +- config/initializers/browser.rb | 3 +++ 7 files changed, 21 insertions(+), 9 deletions(-) create mode 100644 config/initializers/browser.rb diff --git a/Gemfile b/Gemfile index 7ae9eeaf0..026ba7955 100644 --- a/Gemfile +++ b/Gemfile @@ -92,6 +92,8 @@ gem "maruku" # for Markdown support in apipie gem 'openstack' +gem 'browser' + group :test do gem 'capybara' gem 'factory_girl' diff --git a/Gemfile.lock b/Gemfile.lock index a5430abe3..a7599faa6 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -84,6 +84,7 @@ GEM sass (~> 3.0) slim (>= 1.3.6, < 4.0) terminal-table (~> 1.4) + browser (2.2.0) builder (3.2.2) byebug (5.0.0) columnize (= 0.9.0) @@ -627,6 +628,7 @@ DEPENDENCIES bootstrap-sass (~> 3.3.5) bootstrap-wysihtml5-rails (~> 0.3.3.8) brakeman + browser byebug capybara carrierwave diff --git a/app/assets/javascripts/description.js b/app/assets/javascripts/description.js index 98d18a906..fab66068a 100644 --- a/app/assets/javascripts/description.js +++ b/app/assets/javascripts/description.js @@ -14,12 +14,12 @@ function action_type_de_champs() { toggleErrorClass(this, validatePhone(val)); }); - $("#liste_champs input").on('focus', function (){ - $("#description_"+this.id).slideDown(); + $("#liste_champs input").on('focus', function () { + $("#description_" + this.id).slideDown(); }); - $("#liste_champs input").on('blur', function (){ - $("#description_"+this.id).slideUp(); + $("#liste_champs input").on('blur', function () { + $("#description_" + this.id).slideUp(); }); address_type_init(); diff --git a/app/assets/stylesheets/description.scss b/app/assets/stylesheets/description.scss index 1c6129833..c87faa0f0 100644 --- a/app/assets/stylesheets/description.scss +++ b/app/assets/stylesheets/description.scss @@ -111,16 +111,16 @@ @extend .col-lg-2; input[type='date'] { - width: 120px; + width: 160px; } } .type_champ-datetime { - @extend .col-md-4; - @extend .col-lg-4; + @extend .col-md-5; + @extend .col-lg-5; input[type='datetime'] { - width: 120px; + width: 160px; } } diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 94730501d..103ca5526 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -2,9 +2,14 @@ class ApplicationController < ActionController::Base # Prevent CSRF attacks by raising an exception. # For APIs, you may want to use :null_session instead. protect_from_forgery with: :exception + before_filter :check_browser def default_url_options return { protocol: 'https' } if Rails.env.staging? || Rails.env.production? {} end + + def check_browser + BROWSER.value = Browser.new(request.user_agent) + end end diff --git a/app/models/champ.rb b/app/models/champ.rb index ca8e1b531..baf204324 100644 --- a/app/models/champ.rb +++ b/app/models/champ.rb @@ -9,7 +9,7 @@ class Champ < ActiveRecord::Base end def data_provide - return 'datepicker' if type_champ == 'datetime' || type_champ == 'date' + return 'datepicker' if (type_champ == 'datetime' || type_champ == 'date') && !BROWSER.value.chrome? return 'typeahead' if type_champ == 'address' end diff --git a/config/initializers/browser.rb b/config/initializers/browser.rb new file mode 100644 index 000000000..d00cff7ca --- /dev/null +++ b/config/initializers/browser.rb @@ -0,0 +1,3 @@ +BROWSER = Hashie::Mash.new ({ + value: nil + }) \ No newline at end of file