From 65cc07b0e9913449cc56d6e1d006975b5914b4a7 Mon Sep 17 00:00:00 2001 From: Zog Date: Tue, 26 Dec 2017 16:10:45 +0100 Subject: Refs #5367 @2H; Add a ColorSelectInput - Added to PurchaseWindow form - Reuse already exisiting JS + CSS - We may want to change the colors names --- app/assets/javascripts/forms.coffee | 19 +++++++++--- app/assets/stylesheets/_layout.sass | 1 + app/inputs/color_select_input.rb | 46 ++++++++++++++++++++++++++++++ app/models/chouette/purchase_window.rb | 12 +++++--- app/views/purchase_windows/_form.html.slim | 10 +------ config/locales/enumerize.en.yml | 13 ++++++++- config/locales/enumerize.fr.yml | 12 ++++++++ 7 files changed, 95 insertions(+), 18 deletions(-) create mode 100644 app/inputs/color_select_input.rb diff --git a/app/assets/javascripts/forms.coffee b/app/assets/javascripts/forms.coffee index 12d82fef1..b7ae3c6ca 100644 --- a/app/assets/javascripts/forms.coffee +++ b/app/assets/javascripts/forms.coffee @@ -32,14 +32,25 @@ isEdge = !isIE && !!window.StyleMedia @colorSelector = -> $('.form-group .dropdown.color_selector').each -> - selectedStatus = $(this).children('.dropdown-toggle').children('.fa-circle') - + selectedStatusColor = $(this).children('.dropdown-toggle').children('.fa-circle') + selectedStatusLabel = $(this).children('.dropdown-toggle') + self = this $(this).on 'click', "input[type='radio']", (e) -> selectedValue = e.currentTarget.value + selectedText = $(e.currentTarget).parent()[0].textContent + if e.currentTarget.getAttribute("data-for") + hidden = $("[name=\"#{e.currentTarget.getAttribute("data-for")}\"]") + if selectedValue == '' - $(selectedStatus).css('color', 'transparent') + $(selectedStatusColor).css('color', 'transparent') + $(selectedStatusLabel).contents().filter( -> this.nodeType == 3 ).filter(':first').text = "" + hidden?.val "" else - $(selectedStatus).css('color', selectedValue) + $(selectedStatusColor).css('color', selectedValue) + $(selectedStatusLabel).contents().filter( -> this.nodeType == 3 ).first().replaceWith selectedText + hidden?.val selectedValue + + $(self).find('.dropdown-toggle').click() $ -> togglableFilter() diff --git a/app/assets/stylesheets/_layout.sass b/app/assets/stylesheets/_layout.sass index b6b91b2a5..340467e77 100644 --- a/app/assets/stylesheets/_layout.sass +++ b/app/assets/stylesheets/_layout.sass @@ -28,6 +28,7 @@ body // width: 75% border-bottom: 1px solid rgba($blue, 0.5) margin: 30px auto 45px auto + clear: both .content_header font-size: 2.2rem diff --git a/app/inputs/color_select_input.rb b/app/inputs/color_select_input.rb new file mode 100644 index 000000000..963083c08 --- /dev/null +++ b/app/inputs/color_select_input.rb @@ -0,0 +1,46 @@ +class ColorSelectInput < SimpleForm::Inputs::CollectionInput + enable :placeholder + + def input(wrapper_options = {}) + # @collection ||= @builder.object.send(attribute_name) + label_method, value_method = detect_collection_methods + selected_color = object.send(attribute_name) + label = if selected_color + collection.find{|i| i.is_a?(Enumerable) && i.last == selected_color}.try(:first) + end + + out = @builder.hidden_field attribute_name, value: selected_color + tag_name = ActionView::Helpers::Tags::Base.new( ActiveModel::Naming.param_key(object), attribute_name, :dummy ).send(:tag_name) + select = <<-eos + " + select += "" out + select.html_safe end -- cgit v1.2.3 From 17f1a9a7cc9e403f85ddbcdf63e7c551a85dd505 Mon Sep 17 00:00:00 2001 From: Xinhui Date: Thu, 28 Dec 2017 11:38:48 +0100 Subject: Gem country_select Refs #5427 --- Gemfile | 1 + Gemfile.lock | 16 ++++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/Gemfile b/Gemfile index ed71f8bb5..7c10b27e4 100644 --- a/Gemfile +++ b/Gemfile @@ -100,6 +100,7 @@ gem 'simple_form', '~> 3.1.0' gem 'font-awesome-sass', '~> 4.7' gem 'will_paginate-bootstrap' gem 'gretel' +gem 'country_select' # Format Output gem 'json' diff --git a/Gemfile.lock b/Gemfile.lock index 9c59016e6..ade052d8a 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -146,6 +146,14 @@ GEM coffee-script-source (1.12.2) concurrent-ruby (1.0.5) connection_pool (2.2.1) + countries (2.1.3) + i18n_data (~> 0.8.0) + money (~> 6.9) + sixarm_ruby_unaccent (~> 1.1) + unicode_utils (~> 1.4) + country_select (3.1.1) + countries (~> 2.0) + sort_alphabetical (~> 1.0) crack (0.4.3) safe_yaml (~> 1.0.0) cucumber (2.4.0) @@ -269,6 +277,7 @@ GEM parser (>= 2.2.3.0) rainbow (~> 2.2) terminal-table (>= 1.5.1) + i18n_data (0.8.0) inherited_resources (1.7.1) actionpack (>= 3.2, < 5.1) has_scope (~> 0.6) @@ -305,6 +314,8 @@ GEM mimemagic (0.3.2) mini_portile2 (2.3.0) minitest (5.10.3) + money (6.10.1) + i18n (>= 0.6.4, < 1.0) multi_json (1.12.1) multi_test (0.1.2) multi_xml (0.6.0) @@ -487,6 +498,7 @@ GEM rack (~> 1.5) rack-protection (~> 1.4) tilt (>= 1.3, < 3) + sixarm_ruby_unaccent (1.2.0) slim (3.0.7) temple (~> 0.7.6) tilt (>= 1.3.3, < 2.1) @@ -495,6 +507,8 @@ GEM railties (>= 3.1) slim (~> 3.0) slop (3.6.0) + sort_alphabetical (1.1.0) + unicode_utils (>= 1.2.2) spring (2.0.1) activesupport (>= 4.2) spring-commands-rspec (1.0.4) @@ -537,6 +551,7 @@ GEM execjs (>= 0.3.0) json (>= 1.8.0) unicode-display_width (1.3.0) + unicode_utils (1.4.0) warden (1.2.7) rack (>= 1.0) webmock (3.0.1) @@ -584,6 +599,7 @@ DEPENDENCIES cocoon codifligne! coffee-rails (~> 4.0.0) + country_select cucumber-rails daemons database_cleaner -- cgit v1.2.3 From e6715407f59a79473d38048cb22bb025daa68753 Mon Sep 17 00:00:00 2001 From: Xinhui Date: Thu, 28 Dec 2017 11:40:27 +0100 Subject: StopArea form restaure country_code field Refs #5427 --- app/views/stop_areas/_form.html.slim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/stop_areas/_form.html.slim b/app/views/stop_areas/_form.html.slim index e44680499..acf7b4024 100644 --- a/app/views/stop_areas/_form.html.slim +++ b/app/views/stop_areas/_form.html.slim @@ -19,7 +19,7 @@ = f.input :coordinates, :input_html => {:title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.stop_area.coordinates")}, required: true = f.input :street_name - /= f.input :country_code, required: format_restriction_for_locales(@referential) == '.hub' + = f.input :country_code, as: :country, priority: ['FR', 'GB', 'DE', 'ES'] = f.input :zip_code, :input_html => {:title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.stop_area.zip_code")} = f.input :city_name, required: format_restriction_for_locales(@referential) == '.hub', :input_html => {:title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.stop_area.city_name")} -- cgit v1.2.3 From cd08b86d56d484bb40caea38ee82c6c330f626bc Mon Sep 17 00:00:00 2001 From: Alban Peignier Date: Tue, 2 Jan 2018 10:34:04 +0100 Subject: Display StopArea#country_code in stop_areas#show. Refs #5427 --- app/views/stop_areas/show.html.slim | 1 + 1 file changed, 1 insertion(+) diff --git a/app/views/stop_areas/show.html.slim b/app/views/stop_areas/show.html.slim index 0c23710b6..643ab339c 100644 --- a/app/views/stop_areas/show.html.slim +++ b/app/views/stop_areas/show.html.slim @@ -23,6 +23,7 @@ - attributes.merge!({ "Coordonnées" => geo_data(@stop_area, @stop_area_referential), @stop_area.human_attribute_name(:zip_code) => @stop_area.zip_code, @stop_area.human_attribute_name(:city_name) => @stop_area.city_name, + @stop_area.human_attribute_name(:country_code) => @stop_area.country_code.presence || '-', 'Etat' => (@stop_area.deleted_at ? 'Supprimé' : 'Actif'), @stop_area.human_attribute_name(:comment) => @stop_area.try(:comment), }) -- cgit v1.2.3 From 3e9a93ea31f809aec1a80ff709c2362c4c2779fd Mon Sep 17 00:00:00 2001 From: Alban Peignier Date: Tue, 2 Jan 2018 10:37:35 +0100 Subject: Support blank in stop_areas#_form. Refs #5427 --- app/views/stop_areas/_form.html.slim | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/views/stop_areas/_form.html.slim b/app/views/stop_areas/_form.html.slim index acf7b4024..6c1df253a 100644 --- a/app/views/stop_areas/_form.html.slim +++ b/app/views/stop_areas/_form.html.slim @@ -19,9 +19,9 @@ = f.input :coordinates, :input_html => {:title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.stop_area.coordinates")}, required: true = f.input :street_name - = f.input :country_code, as: :country, priority: ['FR', 'GB', 'DE', 'ES'] = f.input :zip_code, :input_html => {:title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.stop_area.zip_code")} = f.input :city_name, required: format_restriction_for_locales(@referential) == '.hub', :input_html => {:title => t("formtastic.titles#{format_restriction_for_locales(@referential)}.stop_area.city_name")} + = f.input :country_code, as: :country, priority: ['FR', 'GB', 'DE', 'ES'], :include_blank => true .stop_areas.stop_area.general_info h3 = t("stop_areas.stop_area.general") -- cgit v1.2.3 From 2a6f499c0d47428d9bfddfc5375beb10d4385da3 Mon Sep 17 00:00:00 2001 From: Alban Peignier Date: Tue, 2 Jan 2018 10:38:49 +0100 Subject: Fixes i18n for StopArea#country_code. Refs #5427 --- config/locales/stop_areas.en.yml | 2 +- config/locales/stop_areas.fr.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/config/locales/stop_areas.en.yml b/config/locales/stop_areas.en.yml index 4d84d1191..ae5d14c08 100644 --- a/config/locales/stop_areas.en.yml +++ b/config/locales/stop_areas.en.yml @@ -103,7 +103,7 @@ en: area_type: "Area type" nearest_topic_name: "Nearest point of interest" street_name: "Street name" - country_code: "INSEE code" + country_code: "Country" fare_code: "Fare code" mobility_restricted_suitability: "Mobility reduced passenger suitable" stairs_availability: "Escalator" diff --git a/config/locales/stop_areas.fr.yml b/config/locales/stop_areas.fr.yml index eda1e4e3d..b4781ac16 100644 --- a/config/locales/stop_areas.fr.yml +++ b/config/locales/stop_areas.fr.yml @@ -103,7 +103,7 @@ fr: area_type: "Type d'arrêt" nearest_topic_name: "Point d'intérêt le plus proche" street_name: "Nom de la rue" - country_code: "Code INSEE" + country_code: "Pays" fare_code: "Zone tarifaire" mobility_restricted_suitability: "Accès pour voyageur à mobilité réduite" stairs_availability: "Escalator" -- cgit v1.2.3