appirits/comable

View on GitHub
frontend/app/views/comable/orders/orderer.slim

Summary

Maintainability
Test Coverage
#comable-order
  .comable-bill_address
    h1
      = @order.class.human_state_name(:orderer)

    - if @order.bill_address.try(:persisted?)
      .comable-email
        = @order.email
      = render 'comable/shared/address', address: @order.bill_address
      = link_to Comable.t('next_step'), next_order_path

      .edit.row
        h2
          = Comable.t('edit_billing_address')
        = form_for @order, as: :order, url: update_order_path, method: :put do |f|
          .form-group
            .col-sm-2.control-label
              = f.label :email
            .col-sm-10
              = f.email_field :email, placeholder: @order.class.human_attribute_name(:email)

          = f.fields_for :bill_address do |ff|
            = render 'comable/shared/address_form', address: ff

          = f.submit Comable.t('next_step')

      - if current_comable_user.other_addresses.any?
        .other_addresses.row
          h2
            = Comable.t('other_addresses')
          ul.list-unstyled
            - current_comable_user.addresses.each do |address|
              - next if @order.bill_address.same_as? address
              li.col-sm-4
                = render 'comable/shared/address', address: address
                = form_for @order, as: :order, url: update_order_path, method: :put do |f|
                  .hidden
                    = f.fields_for :bill_address, address.clone do |ff|
                      = render 'comable/shared/address_form', address: ff
                  = f.submit Comable.t('use_this_address'), class: 'btn btn-default'

    - else
      / TODO: Standardize
      - if @order.errors.any?
        .error_messages
          ul
            - @order.errors.full_messages.each do |full_message|
              li = full_message

      .new
        h2
          = Comable.t('new_billing_address')
        - @order.bill_address ||= @order.build_bill_address
        = form_for @order, as: :order, url: update_order_path, method: :put do |f|
          .form-group
            .col-sm-2.control-label
              = f.label :email
            .col-sm-10
              = f.email_field :email, placeholder: @order.class.human_attribute_name(:email)

          = f.fields_for :bill_address do |ff|
            = render 'comable/shared/address_form', address: ff

          = f.submit Comable.t('next_step')