effective_addresses 1.4.1 → 1.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 6d7752327a5868c1e62f2ce56ad93133b14ae128
4
- data.tar.gz: 42c709a718ebfa9709554caa9dc1e5ba1da74077
3
+ metadata.gz: ade1e6d3f8bf4f00965f7a1c3c98971538ed7b7e
4
+ data.tar.gz: 26251527f1b9a46efe20d0756b7c9eeb6cbc5c8b
5
5
  SHA512:
6
- metadata.gz: aa4bce735aba4a932c7e605d4980bf2e4197afc34f5622279c02d809abc8b971783548b6c712f8a7c433c8a7f20063bb30615c7eafcd69d6beae68e18ca4cf5a
7
- data.tar.gz: f6027285dc76a5991a22069c9da1b681c90fedfaee5422e524d72deb0c0b7e92c96858fbb3c67671c73ab8e97a11a548615deb2ca8caa4679b027d69e475bf5d
6
+ metadata.gz: 72e935a846ef87ea09701d19bf05f191929d745a8d76cab0fca80e2e7f8b29ec03eb51e1a545900090ec5dea63aa00909d020b23ec6dea27c02abeb33be31939
7
+ data.tar.gz: 5a0ce0fdbc852880d554512eab90177ab177926cb077ea69931e5c6f463c49ff4f6bfd56b2440054feac6c3e7020e8bf0be71f8c77ba394c395ff8feb5faff5b
@@ -18,17 +18,33 @@ loadSubregions = ($countrySelect, clearPostalCode = false) ->
18
18
 
19
19
  if countryCode.length == 0
20
20
  $stateSelect.prop('disabled', true).addClass('disabled').parent('.form-group').addClass('disabled').find('label').addClass('disabled')
21
- $stateSelect.html('<option value="">Please choose a country first</option>')
21
+ reinitialize($stateSelect, 'Please choose a country first')
22
22
  else
23
23
  $stateSelect.removeAttr('disabled').parent('.form-group').removeClass('disabled').find('.disabled').removeClass('disabled')
24
- $stateSelect.find('option').first().text('loading...')
24
+ reinitialize($stateSelect, 'Loading...')
25
+
25
26
  $stateSelect.load url, ->
26
27
  stateSelectAvailable = $(@).find('option:last').val().length > 0
27
28
  if stateSelectAvailable
28
29
  $(@).prop('required', true)
29
30
  $(@).removeAttr('disabled')
31
+ reinitialize($stateSelect, 'Please choose', true)
30
32
  else
31
33
  $(@).removeAttr('required')
32
34
  $(@).prop('disabled', true)
35
+ reinitialize($stateSelect, 'None exist', true)
33
36
 
34
37
  $(document).on 'change', 'select[data-effective-address-country]', -> loadSubregions($(@), true)
38
+
39
+ reinitialize = ($stateSelect, placeholder, keepOptions = false) ->
40
+ if $stateSelect.hasClass('effective_select') == false
41
+ $stateSelect.html("<option value=''>#{placeholder}</option>") unless keepOptions
42
+ return
43
+
44
+ $stateSelect.html('') unless keepOptions
45
+
46
+ opts = $stateSelect.data('input-js-options')
47
+ opts['placeholder'] = placeholder
48
+ $stateSelect.data('input-js-options', opts)
49
+
50
+ $stateSelect.select2().trigger('select2:reinitialize')
@@ -72,7 +72,9 @@ module ActsAsAddressable
72
72
  end
73
73
 
74
74
  def set_effective_address(category, atts)
75
- raise ArgumentError.new("Effective::Address #{category}_address= expecting an Effective::Address or Hash of attributes") unless (atts.kind_of?(Effective::Address) || atts.kind_of?(Hash) || atts == nil)
75
+ unless (atts.kind_of?(Effective::Address) || atts.kind_of?(Hash) || atts == nil)
76
+ raise ArgumentError.new("Effective::Address #{category}_address= expecting an Effective::Address or Hash of attributes")
77
+ end
76
78
 
77
79
  atts = HashWithIndifferentAccess.new(atts.kind_of?(Effective::Address) ? atts.attributes : atts)
78
80
 
@@ -23,23 +23,30 @@
23
23
 
24
24
  - when :country_code
25
25
  = fa.input :country_code,
26
- :as => :select,
26
+ :as => (defined?(EffectiveFormInputs) ? :effective_select : :select),
27
27
  :label => 'Country',
28
28
  :prompt => 'Country...',
29
29
  :collection => region_options_for_select(EffectiveAddresses.country_codes == :all ? Carmen::Country.all : Carmen::Country.all.select{ |c| EffectiveAddresses.country_codes.include?(c.code) rescue true}, fa.object.country_code, :priority => EffectiveAddresses.country_codes_priority),
30
- :input_html => { 'data-effective-address-country' => uuid }
30
+ :input_html => { 'data-effective-address-country' => uuid },
31
+ :input_js => { placeholder: 'Please choose' }
31
32
 
32
33
  - when :state_code
33
34
  - if fa.object.country_code.present?
34
- = fa.input :state_code, :as => :select, :label => 'Province / State',
35
+ = fa.input :state_code,
36
+ :as => (defined?(EffectiveFormInputs) ? :effective_select : :select),
37
+ :label => 'Province / State',
35
38
  :collection => region_options_for_select(Carmen::Country.coded(fa.object.country_code).subregions, fa.object.state_code),
36
39
  :prompt => 'please select a country',
37
- :input_html => { 'data-effective-address-state' => uuid }
40
+ :input_html => { 'data-effective-address-state' => uuid },
41
+ :input_js => { :placeholder => 'Please choose' }
38
42
  - else
39
- = fa.input :state_code, :as => :select, :label => 'Province / State',
43
+ = fa.input :state_code,
44
+ :as => (defined?(EffectiveFormInputs) ? :effective_select : :select),
45
+ :label => 'Province / State',
40
46
  :collection => [],
41
47
  :prompt => 'please select a country',
42
- :input_html => {:disabled => 'disabled', 'data-effective-address-state' => uuid}
48
+ :input_html => {:disabled => 'disabled', 'data-effective-address-state' => uuid},
49
+ :input_js => { :placeholder => 'Please choose a country first' }
43
50
 
44
51
  - when :postal_code
45
52
  = fa.input :postal_code, :label => 'Postal / Zip code', :placeholder => 'Postal / Zip code'
@@ -10,25 +10,42 @@
10
10
  - case field
11
11
  - when :full_name
12
12
  - if use_full_name || fa.object.errors.include?(:full_name)
13
- = fa.input :full_name, :required => required
13
+ = fa.input :full_name, required: required
14
14
 
15
15
  - when :address1
16
- = fa.input :address1, :required => required
16
+ = fa.input :address1, required: required
17
17
 
18
18
  - when :address2
19
19
  = fa.input :address2
20
20
 
21
21
  - when :city
22
- = fa.input :city, :input_html => { 'data-effective-address-city' => uuid }, :required => required
22
+ = fa.input :city, required: required, input_html: { 'data-effective-address-city' => uuid }
23
23
 
24
24
  - when :country_code
25
- = fa.input :country_code, :as => :select, :collection => region_options_for_simple_form_select(), :input_html => {'data-effective-address-country' => uuid}, :required => required
25
+ = fa.input :country_code,
26
+ as: (defined?(EffectiveFormInputs) ? :effective_select : :select),
27
+ required: required,
28
+ collection: region_options_for_simple_form_select(),
29
+ input_html: {'data-effective-address-country' => uuid}
26
30
 
27
31
  - when :state_code
28
32
  - if fa.object.try(:country_code).present?
29
- = fa.input :state_code, :as => :select, :collection => region_options_for_simple_form_select(Carmen::Country.coded(fa.object.country_code).subregions), :input_html => {'data-effective-address-state' => uuid}, :required => required
33
+ = fa.input :state_code,
34
+ as: (defined?(EffectiveFormInputs) ? :effective_select : :select),
35
+ required: required,
36
+ collection: region_options_for_simple_form_select(Carmen::Country.coded(fa.object.country_code).subregions),
37
+ prompt: 'Please choose',
38
+ input_html: {'data-effective-address-state' => uuid},
39
+ input_js: { placeholder: 'Please choose' }
30
40
  - else
31
- = fa.input :state_code, :as => :select, :disabled => true, :collection => [], :input_html => { 'data-effective-address-state' => uuid }, :required => required
41
+ = fa.input :state_code,
42
+ as: (defined?(EffectiveFormInputs) ? :effective_select : :select),
43
+ required: required,
44
+ disabled: true,
45
+ collection: [],
46
+ prompt: 'Please choose a country first',
47
+ input_html: { 'data-effective-address-state' => uuid },
48
+ input_js: { placeholder: 'Please choose a country first' }
32
49
 
33
50
  - when :postal_code
34
- = fa.input :postal_code, :input_html => { 'data-effective-address-postal-code' => uuid }, :required => required
51
+ = fa.input :postal_code, required: required, input_html: { 'data-effective-address-postal-code' => uuid }
@@ -1,3 +1,3 @@
1
1
  module EffectiveAddresses
2
- VERSION = '1.4.1'.freeze
2
+ VERSION = '1.5.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.4.1
4
+ version: 1.5.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: 2016-03-04 00:00:00.000000000 Z
11
+ date: 2016-03-30 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails