app/views/companies/_form.html.slim
= simple_form_for [@workbench, :line_referential, @company], html: { class: 'form-horizontal', id: 'company_form' }, wrapper: :horizontal_form do |f|
.row
.col-lg-12
h2.mb-lg= t("companies.form.sections.identification")
= f.input :name, input_html: {title: t("formtastic.titles#{format_restriction_for_locales(@line_referential)}.company.name")}
= f.input :short_name
= f.input :code
= custom_fields_for_section(f, "identification")
.separator.section_separator
.row
.col-lg-12 x-data="{ isReferentActivated: #{@company.is_referent} }"
h2.mb-lg= t("stop_areas.form.sections.referent")
= f.input :is_referent, as: :switchable_checkbox, input_html: { checked: @company.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_line_referential_companies_path(@workbench, {referent_only: true})), initvalue: {id: f.object.referent_id, text: f.object.referent.try(:name)}}}, wrapper_html: { id: 'referent_input', class: 'inline-form', 'x-bind:class': "{ 'disabled': isReferentActivated }" }
.separator.section_separator
.row
.col-lg-12
h2.mb-lg= t("companies.form.sections.address")
= f.input :house_number
= f.input :address_line_1
= f.input :address_line_2
= f.input :street
= f.input :town
= f.input :postcode
= f.input :postcode_extension
= f.input :country_code, as: :country, priority: ['FR', 'GB', 'DE', 'ES'], include_blank: true, input_html: { data: { select2ed: true } }
= custom_fields_for_section(f, "address")
.separator.section_separator
.row
.col-lg-12
h2.mb-lg= t("companies.form.sections.general")
= f.input :default_language
= f.input :time_zone, as: :full_time_zone, include_blank: false
= f.input :fare_url
= custom_fields_for_section(f, "general")
- if resource.custom_fields.without_section.present?
- resource.custom_fields.without_section.each do |_code, field|
= field.input(f).to_s
.separator.section_separator
.row
.col-lg-12
h2.mb-lg= t("companies.form.sections.internals")
= f.association :line_provider, as: :select, collection: candidate_line_providers, include_blank: false
.separator.section_separator
.row
.col-lg-12
h2.mb-lg= Chouette::Company.tmf(:default_contact)
- %w(name email phone fax url organizational_unit operating_department_name more).each do |attr|
= f.input "default_contact_#{attr}", as: (attr == 'more' ? :text : :string)
= custom_fields_for_section(f, "contact")
.separator.section_separator.private_contact class=(f.object.has_private_contact? ? '' : 'hidden')
.row.private_contact class=(f.object.has_private_contact? ? '' : 'hidden')
.col-lg-12
h2.mb-lg= Chouette::Company.tmf(:private_contact)
- %w(name email phone url more).each do |attr|
= f.input "private_contact_#{attr}", as: (attr == 'more' ? :text : :string)
.col-lg-12
= link_to '#', class: 'btn btn-primary clear-contact pull-right' do
= fa_icon :trash
span= 'actions.delete'.t
.separator.section_separator.customer_service_contact class=(f.object.has_customer_service_contact? ? '' : 'hidden')
.row.customer_service_contact class=(f.object.has_customer_service_contact? ? '' : 'hidden')
.col-lg-12
h2.mb-lg= Chouette::Company.tmf(:customer_service_contact)
- %w(name email phone url more).each do |attr|
= f.input "customer_service_contact_#{attr}", as: (attr == 'more' ? :text : :string)
.col-lg-12
= link_to '#', class: 'btn btn-primary clear-contact pull-right' do
= fa_icon :trash
span= 'actions.delete'.t
.separator
.row.pull-right.form-group
.col-lg-12
- unless f.object.has_private_contact?
p
= link_to '#', class: 'btn btn-primary add-private_contact' do
= fa_icon :plus
span= 'companies.actions.add_private_contact'.t
- unless f.object.has_customer_service_contact?
p
= link_to '#', class: 'btn btn-primary add-customer_service_contact' do
= fa_icon :plus
span= 'companies.actions.add_customer_service_contact'.t
.separator.section_separator
= render 'codes/form', form: f
- other_custom_fields = resource.custom_fields.except_for_sections(%w(identification contact general))
- if other_custom_fields.present?
- other_custom_fields.map { |code, field| field.options["section"] }.each do |section|
.separator.section_separator
.row
.col-lg-12
h2.mb-lg= t("companies.form.sections.#{section}")
- resource.custom_fields.for_section(section).each do |code, field|
= field.input(f).to_s
= cancel_button
= f.button :submit, t('actions.submit'), class: 'btn btn-default formSubmitr', form: 'company_form'
- content_for :javascript do
coffee:
$('.add-private_contact').click (e) ->
$('.private_contact').show().removeClass('hidden')
$(e.currentTarget).hide()
e.preventDefault()
false
$('.add-customer_service_contact').click (e) ->
$('.customer_service_contact').show().removeClass('hidden')
$(e.currentTarget).hide()
e.preventDefault()
false
$('.clear-contact').click (e) ->
row = $($(e.target).parents('.row')[0])
row.addClass('hidden')
row.find('input').val ''
if row.hasClass 'customer_service_contact'
$('.separator.customer_service_contact').hide()
$('.add-customer_service_contact').show()
else
$('.separator.private_contact').hide()
$('.add-private_contact').show()
$(e.currentTarget).hide()
e.preventDefault()
false