diff options
| author | jpl | 2017-02-22 10:23:31 +0100 | 
|---|---|---|
| committer | jpl | 2017-02-22 10:23:31 +0100 | 
| commit | be6d884601150fc96c29a7ad17ec9340caba0087 (patch) | |
| tree | 035cc6e82f83697e267ac167aca047b540c2c190 | |
| parent | 0777b3af6bc7c24ef9b98e00bb7b76bffdc5d632 (diff) | |
| download | chouette-core-be6d884601150fc96c29a7ad17ec9340caba0087.tar.bz2 | |
Refs #2629: adding switch comp. updating route form
| -rw-r--r-- | app/assets/javascripts/forms.coffee | 11 | ||||
| -rw-r--r-- | app/assets/stylesheets/components/_forms.sass | 65 | ||||
| -rw-r--r-- | app/controllers/routes_controller.rb | 2 | ||||
| -rw-r--r-- | app/models/chouette/route.rb | 2 | ||||
| -rw-r--r-- | app/views/referential_lines/show.html.slim | 2 | ||||
| -rw-r--r-- | app/views/routes/_form.html.slim | 28 | ||||
| -rw-r--r-- | app/views/routes/edit.html.slim | 30 | ||||
| -rw-r--r-- | spec/features/routes_spec.rb | 2 | 
8 files changed, 103 insertions, 39 deletions
| diff --git a/app/assets/javascripts/forms.coffee b/app/assets/javascripts/forms.coffee index bffaf809b..2baeb02cc 100644 --- a/app/assets/javascripts/forms.coffee +++ b/app/assets/javascripts/forms.coffee @@ -4,6 +4,16 @@        $(this).siblings().removeClass 'open'        $(this).toggleClass 'open' +@switchInput = -> +  $('.form-group.has_switch').each -> +    $(this).on 'click', "input[type='checkbox']", -> +      labelCont = $(this).siblings('.switch-label') + +      if labelCont.text() == labelCont.data('checkedvalue') +        labelCont.text(labelCont.data('uncheckedvalue')) +      else +        labelCont.text(labelCont.data('checkedvalue')) +  @submitMover = ->    $('.formSubmitr').appendTo('.page-action') @@ -20,3 +30,4 @@  $(document).on 'ready page:load', togglableFilter  $(document).on 'ready page:load', submitMover +$(document).on 'ready page:load', switchInput diff --git a/app/assets/stylesheets/components/_forms.sass b/app/assets/stylesheets/components/_forms.sass index a85dd921f..e0c4c89b8 100644 --- a/app/assets/stylesheets/components/_forms.sass +++ b/app/assets/stylesheets/components/_forms.sass @@ -131,6 +131,71 @@ $cbx-size: 20px      &[type='checkbox']:checked + label:before        background-color: $blue +// Switch +.has_switch +  &.form-group +    > .form-group +      margin: 0 + +    .checkbox +      padding: 0 +      margin: 0 +      display: inline-block +      min-height: 0 +      width: auto +      height: 34px +      line-height: 34px + +      > label +        position: relative +        min-height: 0 +        padding: 0 +        margin: 0 + +        > input[type='checkbox'] +          position: absolute +          left: -9999px +          margin: 0 + +          + .switch-label +            position: relative +            display: inline-block +            width: 50px +            height: 30px +            padding-left: 60px +            line-height: 30px +            color: $blue + +            &:before +              content: '' +              position: absolute +              left: 0 +              top: 0 +              display: inline-block +              width: 50px +              height: 30px +              background-color: $blue +              border-radius: 18px + +            &:after +              content: '' +              position: absolute +              left: 0 +              top: 0 +              margin: 2px +              width: 26px +              height: 26px +              border-radius: 50% +              background-color: #fff +              transition: 0.2s + +          &:checked + .switch-label:after +            left: 0 +            transition: 0.2s +          &:not(:checked) + .switch-label:after +            left: 20px +            transition: 0.2s +  // Form filter  .form.form-filter    display: block diff --git a/app/controllers/routes_controller.rb b/app/controllers/routes_controller.rb index 29b9144e9..6a38b022d 100644 --- a/app/controllers/routes_controller.rb +++ b/app/controllers/routes_controller.rb @@ -97,7 +97,7 @@ class RoutesController < ChouetteController    private    def sort_sp_column -    @route_sp.column_names.include?(params[:sort]) ? params[:sort] : 'position' +    route.stop_points.column_names.include?(params[:sort]) ? params[:sort] : 'position'    end    def sort_sp_direction      %w[asc desc].include?(params[:direction]) ?  params[:direction] : 'asc' diff --git a/app/models/chouette/route.rb b/app/models/chouette/route.rb index 020220a19..436f19e9f 100644 --- a/app/models/chouette/route.rb +++ b/app/models/chouette/route.rb @@ -29,7 +29,7 @@ class Chouette::Route < Chouette::TridentActiveRecord      end    end    belongs_to :opposite_route, :class_name => 'Chouette::Route', :foreign_key => :opposite_route_id -  has_many :stop_points, -> { order('position ASC') }, :dependent => :destroy do +  has_many :stop_points, :dependent => :destroy do      def find_by_stop_area(stop_area)        stop_area_ids = Integer === stop_area ? [stop_area] : (stop_area.children_in_depth + [stop_area]).map(&:id)        where( :stop_area_id => stop_area_ids).first or diff --git a/app/views/referential_lines/show.html.slim b/app/views/referential_lines/show.html.slim index 2e06d33a8..3bf9a11a2 100644 --- a/app/views/referential_lines/show.html.slim +++ b/app/views/referential_lines/show.html.slim @@ -11,7 +11,7 @@        = link_to t('lines.actions.show_company'), [@referential, @line.company], class: 'btn btn-primary'        = link_to @line.human_attribute_name(:footnotes), referential_line_footnotes_path(@referential, @line), class: 'btn btn-primary' -      = link_to Chouette::RoutingConstraintZone.model_name.human.pluralize(:fr), referential_line_routing_constraint_zones_path(@referential, @line), class: 'btn btn-primary disabled' +      = link_to Chouette::RoutingConstraintZone.model_name.human.pluralize(:fr), referential_line_routing_constraint_zones_path(@referential, @line), class: 'btn btn-primary'        - if policy(Chouette::Line).create? && @referential.organisation == current_organisation          = link_to t('lines.actions.new'), new_referential_line_path(@referential), class: 'btn btn-primary' diff --git a/app/views/routes/_form.html.slim b/app/views/routes/_form.html.slim index a4da376cc..6ad9d5e50 100644 --- a/app/views/routes/_form.html.slim +++ b/app/views/routes/_form.html.slim @@ -1,28 +1,24 @@ -= simple_form_for [@referential, @line, @route] do |f| += simple_form_for [@referential, @line, @route], html: {class: 'form-horizontal', id: 'route_form'}, wrapper: :horizontal_form do |f| +    .row -    .col-lg-6.col-md-6.col-sm-12.col-xs-12 +    .col-lg-12        = f.input :name -    .col-lg-6.col-md-6.col-sm-12.col-xs-12        = f.input :published_name -  .row -    .col-lg-4.col-md-6.col-sm-8.col-xs-8 -      = f.input :opposite_route_id, collection: @candidate_opposite_routes +      .form-group.has_switch +        = f.label :wayback, class: 'col-sm-4 control-label' +        = f.input :wayback, as: :boolean, checked_value: :straight_forward, unchecked_value: :backward, label: content_tag(:span, @route.wayback_text, class: 'switch-label', data: {checkedValue: t('enumerize.route.direction.straight_forward'), uncheckedValue: t('enumerize.route.direction.backward')}), wrapper_html: { class: 'col-sm-8'} -    / .col-lg-4.col-md-4.col-sm-4.col-xs-4 -    /   = f.input :direction, include_blank: false +      = f.input :opposite_route_id, collection: @candidate_opposite_routes -    .col-lg-4.col-md-4.col-sm-4.col-xs-4 -      = f.input :wayback, include_blank: false +  .separator -  .row style="margin-top:20px" -    .col-lg-12.col-md-12.col-sm-12.col-xs-12 +  .row +    .col-lg-12        #stop_points -  .row style="margin-top:20px" -    .col-lg-12.col-md-12.col-sm-12.col-xs-12.text-right -      = link_to 'Annuler', :back, class: 'btn btn-link' -      = f.button :submit, class: 'btn btn-danger' +  = f.button :submit, 'Enregistrer', class: 'btn btn-default formSubmitr', form: 'route_form' +  // Get JSON data for route stop points  = javascript_tag do diff --git a/app/views/routes/edit.html.slim b/app/views/routes/edit.html.slim index 22a828efe..5421250d5 100644 --- a/app/views/routes/edit.html.slim +++ b/app/views/routes/edit.html.slim @@ -1,20 +1,12 @@ -= title_tag t('routes.edit.title', route: @route.name ) +/ PageHeader += pageheader 'map-marker', +             @route.name, +             'Lorem ipsum dolor sit amet', +             t('last_update', time: l(@route.updated_at, format: :short)) do -/ #CUSTOM_map style='height:250px' -/   = javascript_tag do -/     | var map = new ol.Map({ -/     |   target: 'CUSTOM_map', -/     |   layers: [ -/     |     new ol.layer.Tile({ -/     |       source: new ol.source.OSM() -/     |     }) -/     |   ], -/     |   view: new ol.View({ -/     |     center: ol.proj.fromLonLat([37.41, 8.82]), -/     |     zoom: 4 -/     |   }) -/     | }); - -.row -  .col-lg-8.col-lg-offset-2.col-md-8.col-md-offset-2.col-sm-8.col-sm-offset-2 -    == render 'form' +/ PageContent +.page_content +  .container-fluid +    .row +      .col-lg-8.col-lg-offset-2.col-md-8.col-md-offset-2.col-sm-10.col-sm-offset-1 +        == render 'form' diff --git a/spec/features/routes_spec.rb b/spec/features/routes_spec.rb index af0a4520a..9bfb070c1 100644 --- a/spec/features/routes_spec.rb +++ b/spec/features/routes_spec.rb @@ -38,7 +38,7 @@ describe "Routes", :type => :feature do        fill_in "route_name", :with => "A to B"        # select 'Aller', :from => "route_direction"        select 'Aller', :from => "route_wayback" -      click_button("Créer un itinéraire") +      click_button("Enregistrer")        expect(page).to have_content("A to B")      end    end | 
