effective_addresses 1.7.4 → 1.8.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/MIT-LICENSE +1 -1
- data/app/assets/javascripts/effective_addresses/shipping_address_same_as_billing.js.coffee +4 -3
- data/app/helpers/effective_addresses_helper.rb +10 -7
- data/app/views/effective/addresses/_form_with.html.haml +66 -0
- data/app/views/effective/addresses/{_address_fields_formtastic.html.haml → _formtastic.html.haml} +0 -0
- data/app/views/effective/addresses/{_address_fields_simple_form.html.haml → _simple_form.html.haml} +0 -0
- data/config/routes.rb +2 -2
- data/lib/effective_addresses/version.rb +1 -1
- metadata +5 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 742ed0f8a13e8cd868c30a9ea21bcc5127ce1d83
|
4
|
+
data.tar.gz: 906cbb169041cecb056b26dad96ca16987377a8c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9c8cc534ac07028ef8ff23c14ef7f4412e0b6f3864f89b20d262cee16c5e53598a518f7f5853a98d011637ea4d6aa271727a0b111be026baf571e888d6ef40d1
|
7
|
+
data.tar.gz: 966f184e10f6d77dbd88daa0ef11d02830ed2ef834b0e71a6ea025cf806df85c05068a0f208406d09233e55e3bba30630cc53fe56d239575050c3f3328d27fad
|
data/MIT-LICENSE
CHANGED
@@ -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(:
|
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 = {:
|
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
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
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/app/views/effective/addresses/{_address_fields_formtastic.html.haml → _formtastic.html.haml}
RENAMED
File without changes
|
data/app/views/effective/addresses/{_address_fields_simple_form.html.haml → _simple_form.html.haml}
RENAMED
File without changes
|
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 :
|
7
|
-
match 'addresses/subregions/:country_code', :
|
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
|
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.
|
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:
|
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/
|
76
|
-
- app/views/effective/addresses/
|
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
|