af83/chouette-core

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

Summary

Maintainability
Test Coverage
= simple_form_for [@workbench, @referential], html: {class: 'form-horizontal', id: 'referential_form'}, wrapper: :horizontal_form do |form|

  .row
    .col-lg-12
      = form.input :name
      - if @referential.new_record?
        - if @referential.created_from
          = form.input :created_from, disabled: true, input_html: { value: Referential.find(@referential.created_from_id).name }
          .hidden = form.input :created_from_id, as: :hidden
        - elsif has_feature?(:create_referential_from_merge) && @workbench.output.present?
          = form.input :from_current_offer, as: :switchable_checkbox

      - else
        - if @referential.created_from
          = form.input :created_from, disabled: true, input_html: { value: Referential.find(@referential.created_from_id).name }

      - if resource_policy.flag_urgent? && !@referential.in_referential_suite?
        = form.input :urgent, as: :switchable_checkbox, input_html: { checked: @referential.urgent || @referential.contains_urgent_offer?  }

  .separator

  = form.simple_fields_for :metadatas do |subform|
    .row
      .col-lg-12
        - if %i(metadatas metadatas.periodes).any?{|k| @referential.errors.has_key?(k) }
          .row.metadatas-errors
            .col-lg-12
              .alert.alert-danger
                - %i(metadatas metadatas.periodes).each do |k|
                  - (@referential.errors[k] || []).each do |msg|
                    p.small= msg

        .subform
          .nested-head
            .wrapper
              div
                .form-group
                  label.control-label.required
                    = t('simple_form.labels.referential.metadatas.periods.begin')
                    abbr title='requis' *
              div
                .form-group
                  label.control-label.required
                    = t('simple_form.labels.referential.metadatas.periods.end')
                    abbr title='requis' *
              div

          = subform.simple_fields_for :periods do |period_form|
            = render 'period_fields', f: period_form

          .links.nested-linker
            = link_to_add_association t('simple_form.labels.referential.actions.add_period'), subform, :periods, class: 'btn btn-primary'

    .separator
    .row
      .col-lg-11
        = subform.input :lines, as: :select, collection: @workbench.lines, selected: subform.object.line_ids, input_html: { 'data-select2-ajax': 'true', 'data-select2ed-placeholder': t('simple_form.labels.referential.placeholders.select_lines'), 'multiple': 'multiple', 'data-url': lines_workbench_autocomplete_index_path(@workbench), style: 'width: 100%' }
      .col-lg-1
        a.clear-lines.btn.btn-danger href='#'
          .fa.fa-trash


  .hidden = form.input :workbench_id, as: :hidden

  = cancel_button

  = form.button :submit,
      t('actions.submit'),
      class: 'btn btn-default formSubmitr',
      data: { disable_with: t('actions.processing') },
      form: 'referential_form'

  - content_for :javascript do
    coffee:
      $(".clear-lines").click (e)->
        e.preventDefault()
        $(e.currentTarget).parents('.row').first().find('[name*=line]').val('').trigger('change')
        false