af83/chouette-core

View on GitHub
app/views/stop_areas/_form.html.slim

Summary

Maintainability
Test Coverage
= simple_form_for [@workbench, :stop_area_referential, @stop_area], html: {class: 'form-horizontal', id: 'stop_area_form'}, wrapper: :horizontal_form do |f|
  .row
    .col-lg-12
      h2.mb-lg= t("stop_areas.form.sections.identification")
      = f.input :id, as: :hidden
      = f.input :name
      - if has_feature?(:stop_area_localized_names)
        .form-group
          .col-sm-3.col-xs-5
          .col-sm-9.col-xs-7.locales
            - default = f.object.stop_area_referential.sorted_locales.select{|l| l[:default] || f.object.localized_names[l[:code]].present? }.map{|l| l[:code]}
            - default.each do |k|
              .col-md-6= f.input "localized_names[#{k}]", input_html: { value: f.object.localized_names[k.to_s] }, label: label_for_country(k)

        .row.add-locales.mb-md
          - countries = f.object.stop_area_referential.sorted_locales.map{|l| l[:code]} - default
          - if countries.present?
            - options = countries.map { |c| "<option id='#{c}' country_name='#{@stop_area_referential.locale_name(code: c)}'>#{@stop_area_referential.locale_name(code: c)}</option>" }.join('')
            .col-sm-4.col-xs-5
            .col-sm-8.col-xs-7
              = select_tag :add_locale, raw(options), 'data-select2ed': 'true', class: 'select2-resize'
              = link_to '#', class: 'btn btn-primary add-locale' do
                = fa_icon :plus, {text: 'actions.add'.t}
      = f.input :public_code

  .separator.section_separator

  .row
    .col-lg-12 x-data="{ kind: '#{@stop_area.kind}' || 'commercial'}"
      h2.mb-lg= t("stop_areas.form.sections.hierarchy")
        // as: :radio_buttons
      - if has_feature?("route_stop_areas_all_types")
        = f.input :kind,
            as: :radio_buttons,
            checked: @stop_area.new_record? ? :commercial : @stop_area.kind,
            input_html: { disabled: !@stop_area.new_record?, 'x-on:change': 'kind = $event.target.value' },
            include_blank: false,
            item_wrapper_class: 'radio-inline',
            wrapper: :horizontal_form,
            disabled: !@stop_area.new_record?
        - unless @stop_area.new_record?
            = f.input :kind, as: :hidden, input_html: { value: @stop_area.kind }
      - else
        = f.input :kind, as: :hidden, input_html: { value: :commercial }
      - %i(non_commercial commercial).each do |kind|
          .kind x-show="kind === '#{kind}'"
            = f.input :area_type, as: :select, input_html: { id: kind, disabled: !@stop_area.new_record?, 'x-bind:disabled': "kind != '#{kind}'" }, collection: area_type_options(kind), include_blank: false, disabled: !@stop_area.new_record?
      = f.input :parent_id, as: :select, collection: [f.object.parent_id], input_html: {'x-bind:disabled': "kind === 'non_commercial' || #{@stop_area.kind == 'non_commercial' }", data: { select2ed_placeholder: Chouette::StopArea.tmf('parent'), select2ed_allow_clear: 'true', select2_ajax: 'true', url: autocomplete_workbench_stop_area_referential_stop_areas_path(@workbench), initvalue: {id: f.object.parent_id, text: f.object.parent.try(:formatted_selection_details)}}}

  .separator.section_separator

  .row
    .col-lg-12 x-data="{ isReferentActivated: #{@stop_area.is_referent} }"
      h2.mb-lg= t("stop_areas.form.sections.referent")
      = f.input :is_referent, as: :switchable_checkbox, input_html: { checked: @stop_area.is_referent, 'x-on:click': 'isReferentActivated = !isReferentActivated' }
      = f.input :referent_id, as: :select, collection: [f.object.referent_id], input_html: { style: 'width: 100%', 'x-bind:disabled': "isReferentActivated", data: { select2ed_placeholder: Chouette::StopArea.tmf('referent'), select2ed_allow_clear: 'true', select2_ajax: 'true', url: (autocomplete_workbench_stop_area_referential_stop_areas_path(@workbench)+"?referent_only=true"), initvalue: {id: f.object.referent_id, text: f.object.referent.try(:formatted_selection_details)}}}, wrapper_html: { id: 'referent_input', class: 'inline-form', 'x-bind:class': "{ 'disabled': isReferentActivated }" }

  .separator.section_separator

  .row
    .col-lg-12
      h2.mb-lg= t("stop_areas.form.sections.internals")
      = f.input :status, as: :select, collection: stop_area_status_options, include_blank: false
      = f.association :stop_area_provider, as: :select, collection: candidate_stop_area_providers, include_blank: false
      = f.input :comment, as: :text, input_html: {rows: 5, title: t("formtastic.titles#{format_restriction_for_locales(@referential)}.stop_area.comment")}

  .separator.section_separator

  .row
    .col-lg-12
      h2.mb-lg= t("stop_areas.form.sections.location")

      - if @stop_area.projection.present? && @stop_area.projection_type_label.present?
        = f.input :projection_xy, label: t("activerecord.attributes.stop_area.projection_xy", projection: @referential.projection_type_label), input_html: { title: t("formtastic.titles#{format_restriction_for_locales(@referential)}.stop_area.projection_xy") }

      = f.input :coordinates, input_html: { title: t("formtastic.titles#{format_restriction_for_locales(@referential)}.stop_area.coordinates") }
      = f.input :compass_bearing
      = f.input :street_name
      = f.input :zip_code, input_html: { title: t("formtastic.titles#{format_restriction_for_locales(@referential)}.stop_area.zip_code") }
      = f.input :city_name, input_html: {title: t("formtastic.titles#{format_restriction_for_locales(@referential)}.stop_area.city_name")}
      = f.input :postal_region
      = f.input :country_code, as: :country, priority: ['FR', 'GB', 'DE', 'ES'], include_blank: true, input_html: { data: { select2ed: true } }
      = f.input :time_zone, as: :full_time_zone, include_blank: false

  .separator.section_separator

  .row
    .col-lg-12
      h2.mb-lg= t("stop_areas.form.sections.usage")
      - if has_feature?(:stop_area_waiting_time)
        = f.input :waiting_time, input_html: { min: 0 }
      = f.input :url
      = f.input :transport_mode, as: :transport_mode, required: false, collection: @stop_area.candidate_transport_modes

  .separator.section_separator

  .row
    .col-lg-12
      h2.mb-lg= t("stop_areas.form.sections.fare")
      = f.association :fare_zones, as: :autocomplete_select, collection: @stop_area.candidate_fare_zones.order(:name), include_blank: true, input_html: { multiple: true}

  .separator.section_separator

  .row
    .col-lg-12
      h2.mb-lg= t("stop_areas.form.sections.accessibility")
      = f.input :mobility_impaired_accessibility, as: :select, include_blank: false
  .row
    .col-md-6
      = f.input :wheelchair_accessibility, as: :select, include_blank: false
      = f.input :step_free_accessibility, as: :select, include_blank: false
      = f.input :escalator_free_accessibility, as: :select, include_blank: false
    .col-md-6
      = f.input :lift_free_accessibility, as: :select, include_blank: false
      = f.input :audible_signals_availability, as: :select, include_blank: false
      = f.input :visual_signs_availability, as: :select, include_blank: false
  .row
    .col-lg-12
      = f.input :accessibility_limitation_description

  .separator.section_separator

  - if @stop_area.custom_fields.present?
    .row
      .col-lg-12
        h2.mb-lg= t("stop_areas.form.sections.custom_fields")
        - @stop_area.custom_fields.by_group do |custom_field_group, custom_fields|
          - if custom_field_group
            .form-group.mt-20
              .col-sm-4.col-xs-5.control-label.strong
                = custom_field_group.name

          - custom_fields.each do |field|
            = field.input(f).to_s

    .separator.section_separator

  = render 'codes/form', form: f

  = cancel_button
  = f.button :submit, t('actions.submit'), class: 'btn btn-default formSubmitr', form: 'stop_area_form'

coffee:
  $('.add-locale').click (e)->
    option = $('#add_locale').find('option:selected')
    return unless option.length > 0

    row  = $("<div class='col-md-6'><div class='form-group'><label class='col-sm-4 col-xs-5 control-label string optional' for='stop_area_localized_names[#{option.attr('id')}]'><span title='#{option.attr('country_name')}' class='mr-xs flag-icon flag-icon-#{option.attr('id').split('_')[1].toLowerCase()}'></span></label><div class='col-sm-8 col-xs-7'><input class='form-control string optional' value='' type='text' name='stop_area[localized_names[#{option.attr('id')}]' id='stop_area_localized_names[#{option.attr('id')}]'></div></div></div>")
    row.appendTo $('.locales')
    option.remove()
    unless $('#add_locale').find('option:selected').length > 0
      $('.row.add-locales').remove()
    e.preventDefault()
    false