effective_addresses 1.7.4 → 1.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1e242bd222bdf45a2b873aea1cb4a99966fbd3d7
4
- data.tar.gz: 510cde83910aee2c94fda85928003375da8bf9e5
3
+ metadata.gz: 742ed0f8a13e8cd868c30a9ea21bcc5127ce1d83
4
+ data.tar.gz: 906cbb169041cecb056b26dad96ca16987377a8c
5
5
  SHA512:
6
- metadata.gz: a2ddc40defbc7a58d324f33e83329e3ee6b133eebf2542e44d605c973a38f11f861156362dc93ebd4e33fce0a061f2a41322038301260dcc0dfc2d3f112ef438
7
- data.tar.gz: 4ce4c776b7ab5a11c985005151ff0522dee5440938675cefd7b415c0d30c8909725aca9d828954091b038f85297ff8b89e49e1321e72ce5e4e4c80763642cf5d
6
+ metadata.gz: 9c8cc534ac07028ef8ff23c14ef7f4412e0b6f3864f89b20d262cee16c5e53598a518f7f5853a98d011637ea4d6aa271727a0b111be026baf571e888d6ef40d1
7
+ data.tar.gz: 966f184e10f6d77dbd88daa0ef11d02830ed2ef834b0e71a6ea025cf806df85c05068a0f208406d09233e55e3bba30630cc53fe56d239575050c3f3328d27fad
data/MIT-LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright 2017 Code and Effect Inc.
1
+ Copyright 2018 Code and Effect Inc.
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
@@ -8,12 +8,13 @@ $(document).on 'change', "input[name$='[shipping_address][shipping_address_same_
8
8
  div[class*='_shipping_address_city'],
9
9
  div[class*='_shipping_address_country_code'],
10
10
  div[class*='_shipping_address_state_code'],
11
- div[class*='_shipping_address_postal_code']
11
+ div[class*='_shipping_address_postal_code'],
12
+ div[class*='shipping_address_form_group']
12
13
  ")
13
14
 
14
15
  if $obj.is(':checked')
15
- shipping_fields.hide().find('input,select').prop('disabled', true)
16
+ shipping_fields.hide().find('input,select').prop('disabled', true).prop('required', true)
16
17
  else
17
- shipping_fields.show().find('input,select').removeAttr('disabled')
18
+ shipping_fields.show().find('input,select').removeAttr('disabled').removeAttr('required')
18
19
 
19
20
 
@@ -7,17 +7,20 @@ module EffectiveAddressesHelper
7
7
  required = (form.object._validators[method.to_sym].any? { |v| v.kind_of?(ActiveRecord::Validations::PresenceValidator) && (v.options[:if].blank? || (v.options[:if].respond_to?(:call) ? f.object.instance_exec(&v.options[:if]) : v.options[:if])) } rescue true)
8
8
  use_full_name = form.object._validators[method.to_sym].any? { |v| v.kind_of?(EffectiveAddressFullNamePresenceValidator) }
9
9
 
10
- address = form.object.send(method) || form.object.addresses.build(:category => method.to_s.gsub('_address', ''))
10
+ address = form.object.send(method) || form.object.addresses.build(category: method.to_s.gsub('_address', ''))
11
11
  effective_address_pre_select(address) if address.new_record?
12
12
 
13
- opts = {:required => required, :use_full_name => use_full_name, :field_order => [:full_name, :address1, :address2, :city, :country_code, :state_code, :postal_code]}.merge(options).merge({:f => form, :address => address, :method => method})
13
+ opts = { required: required, use_full_name: use_full_name, field_order: [:full_name, :address1, :address2, :city, :country_code, :state_code, :postal_code] }.merge(options).merge({:f => form, :address => address, :method => method})
14
14
 
15
- if form.class.name == 'SimpleForm::FormBuilder'
16
- render :partial => 'effective/addresses/address_fields_simple_form', :locals => opts
17
- elsif form.class.name == 'Formtastic::FormBuilder'
18
- render :partial => 'effective/addresses/address_fields_formtastic', :locals => opts
15
+ case form.class.name
16
+ when 'Effective::FormBuilder'
17
+ render partial: 'effective/addresses/form_with', locals: opts
18
+ when 'SimpleForm::FormBuilder'
19
+ render partial: 'effective/addresses/simple_form', locals: opts
20
+ when 'Formtastic::FormBuilder'
21
+ render partial: 'effective/addresses/formtastic', locals: opts
19
22
  else
20
- raise 'Unsupported FormBuilder. You must use formtastic or simpleform. Sorry.'
23
+ raise 'Unsupported FormBuilder. You must use formtastic, simpleform or effective_bootstrap. Sorry.'
21
24
  end
22
25
  end
23
26
 
@@ -0,0 +1,66 @@
1
+ = f.fields_for method, (address || f.object.send(method) || f.object.addresses.build(category: method.to_s.gsub('_address', ''))) do |fa|
2
+ - uuid = fa.object_id
3
+ - method = method.to_sym
4
+ - same_as_billing = (fa.object.category == 'shipping') && (f.object.try(:shipping_address_same_as_billing?) || false)
5
+ - required = (required && !same_as_billing)
6
+ - wrapper_options = (same_as_billing ? { style: 'display: none;', class: 'form-group shipping_address_form_group' } : {})
7
+
8
+ - if ((f.object.errors.include?(method) && !f.object.errors.include?(:addresses)) rescue false)
9
+ = f.errors method
10
+
11
+ - if use_full_name || fa.object.errors.include?(:full_name)
12
+ = fa.text_field :full_name,
13
+ required: required,
14
+ disabled: same_as_billing,
15
+ wrapper: wrapper_options
16
+
17
+ = fa.text_field :address1,
18
+ label: 'Address',
19
+ required: required,
20
+ disabled: same_as_billing,
21
+ wrapper: wrapper_options
22
+
23
+ = fa.text_field :address2,
24
+ label: false,
25
+ required: required,
26
+ disabled: same_as_billing,
27
+ wrapper: wrapper_options
28
+
29
+ = fa.text_field :city,
30
+ required: required,
31
+ disabled: same_as_billing,
32
+ input_html: { 'data-effective-address-city' => uuid },
33
+ wrapper: wrapper_options
34
+
35
+ = fa.select :country_code, region_options_for_simple_form_select(),
36
+ required: required,
37
+ disabled: same_as_billing,
38
+ input_html: { 'data-effective-address-country' => uuid },
39
+ wrapper: wrapper_options
40
+
41
+ - if fa.object.try(:country_code).present?
42
+ = fa.select :state_code, region_options_for_simple_form_select(Carmen::Country.coded(fa.object.country_code).subregions),
43
+ required: required,
44
+ disabled: same_as_billing,
45
+ input_html: { 'data-effective-address-state' => uuid },
46
+ wrapper: wrapper_options
47
+ - else
48
+ = fa.select :state_code, [],
49
+ required: required,
50
+ disabled: true,
51
+ input_html: { 'data-effective-address-state' => uuid },
52
+ input_js: { placeholder: 'Please choose a country first' },
53
+ wrapper: wrapper_options
54
+
55
+ = fa.text_field :postal_code,
56
+ required: required,
57
+ disabled: same_as_billing,
58
+ input_html: { 'data-effective-address-postal-code' => uuid },
59
+ wrapper: wrapper_options
60
+
61
+ - if fa.object.category == 'shipping' && f.object.respond_to?(:shipping_address_same_as_billing?)
62
+ = fa.check_box :shipping_address_same_as_billing,
63
+ label: 'Shipping address is same as billing address',
64
+ required: false,
65
+ feedback: false,
66
+ input_html: { checked: same_as_billing }
data/config/routes.rb CHANGED
@@ -3,7 +3,7 @@ Rails.application.routes.draw do
3
3
  end
4
4
 
5
5
  EffectiveAddresses::Engine.routes.draw do
6
- scope :module => 'effective' do
7
- match 'addresses/subregions/:country_code', :to => 'addresses#subregions', :as => 'address_subregions', :via => :get
6
+ scope module: 'effective' do
7
+ match 'addresses/subregions/:country_code', to: 'addresses#subregions', as: 'address_subregions', via: :get
8
8
  end
9
9
  end
@@ -1,3 +1,3 @@
1
1
  module EffectiveAddresses
2
- VERSION = '1.7.4'.freeze
2
+ VERSION = '1.8.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_addresses
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.7.4
4
+ version: 1.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-19 00:00:00.000000000 Z
11
+ date: 2018-02-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -72,8 +72,9 @@ files:
72
72
  - app/models/validators/effective_address_full_name_presence_validator.rb
73
73
  - app/models/validators/effective_address_valid_validator.rb
74
74
  - app/views/effective/addresses/_address.html.haml
75
- - app/views/effective/addresses/_address_fields_formtastic.html.haml
76
- - app/views/effective/addresses/_address_fields_simple_form.html.haml
75
+ - app/views/effective/addresses/_form_with.html.haml
76
+ - app/views/effective/addresses/_formtastic.html.haml
77
+ - app/views/effective/addresses/_simple_form.html.haml
77
78
  - app/views/effective/addresses/_subregions.html.haml
78
79
  - config/effective_addresses.rb
79
80
  - config/locales/simple_form.en.yml