spree_counties 3.0.1 → 3.0.4
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 +4 -4
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +10 -2
- data/README.md +5 -0
- data/app/assets/javascripts/spree/frontend/spree_counties.js.coffee +80 -54
- data/app/models/spree/address_decorator.rb +62 -2
- data/app/models/spree/county.rb +1 -0
- data/app/overrides/spree/address/_form/add_county.html.erb.deface +53 -0
- data/app/overrides/spree/admin/shared/_address_form/add_county_to_form.html.erb.deface +10 -0
- data/config/locales/en.yml +1 -0
- data/config/locales/es.yml +1 -0
- data/config/routes.rb +1 -1
- data/spec/controllers/spree/admin/counties_controller_spec.rb +7 -0
- data/spec/models/spree/county_spec.rb +19 -0
- data/spec/spec_helper.rb +7 -2
- data/spree_counties.gemspec +3 -1
- metadata +39 -6
- data/app/views/spree/address/_form.html.erb +0 -86
- data/app/views/spree/admin/shared/_address_form.html.erb +0 -81
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bf5a39f6e609a2a1690d28637ad712e89830d092
|
4
|
+
data.tar.gz: a4526e64c8460d0d9acd74ac0b35f499e8a66a69
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c99386874d6bb93be2cef1d37d23cb57147e7f252c93a25245fe105a03b1fcb5851e02284b68287070c6220ed058af3432c41fbcc4cf16a702edb580864419a4
|
7
|
+
data.tar.gz: 860119620644d0559493e169edd76260b32454652ec8031e6de3c78eaa8eecca3fb448348fcb469f0e1d164456a40b2501f21f5c49437bb0b153780af828e6cf
|
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
spree_counties
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
2.2.1
|
data/Gemfile
CHANGED
@@ -1,7 +1,15 @@
|
|
1
1
|
source 'https://rubygems.org'
|
2
2
|
|
3
|
-
gem 'spree', github: 'spree/spree', branch: '
|
3
|
+
gem 'spree', github: 'spree/spree', branch: '3-0-stable'
|
4
4
|
# Provides basic authentication functionality for testing parts of your engine
|
5
|
-
gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: '
|
5
|
+
gem 'spree_auth_devise', github: 'spree/spree_auth_devise', branch: '3-0-stable'
|
6
6
|
|
7
7
|
gemspec
|
8
|
+
|
9
|
+
group :development do
|
10
|
+
gem 'better_errors'
|
11
|
+
gem 'binding_of_caller'
|
12
|
+
gem 'pry'
|
13
|
+
|
14
|
+
gem 'spreadsheet'
|
15
|
+
end
|
data/README.md
CHANGED
@@ -1,58 +1,84 @@
|
|
1
1
|
Spree.ready ($) ->
|
2
|
-
($ '#
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
updateCounty
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
fillCounties = (data, region) ->
|
20
|
-
countiesRequired = true
|
21
|
-
counties = data.counties
|
22
|
-
|
23
|
-
countyPara = ($ '#' + region + 'county')
|
24
|
-
countySelect = countyPara.find('select')
|
25
|
-
countyInput = countyPara.find('input')
|
26
|
-
countySpanRequired = countyPara.find('county-required')
|
27
|
-
if counties.length > 0
|
28
|
-
selected = parseInt countySelect.val()
|
29
|
-
countySelect.html ''
|
30
|
-
countyWithBlank = [{ name: '', id: ''}].concat(counties)
|
31
|
-
$.each countyWithBlank, (idx, county) ->
|
32
|
-
opt = ($ document.createElement('option')).attr('value', county.id).html(county.name)
|
33
|
-
opt.prop 'selected', true if selected is county.id
|
34
|
-
countySelect.append opt
|
35
|
-
|
36
|
-
countySelect.prop('disabled', false).show()
|
37
|
-
countyInput.hide().prop 'disabled', true
|
38
|
-
countyPara.show()
|
39
|
-
countySpanRequired.show()
|
40
|
-
countySelect.addClass('required') if countiesRequired
|
41
|
-
countySelect.removeClass('hidden')
|
42
|
-
countyInput.removeClass('required')
|
43
|
-
else
|
44
|
-
countySelect.hide().prop 'disabled', true
|
45
|
-
countyInput.show()
|
46
|
-
if countiesRequired
|
47
|
-
countySpanRequired.show()
|
48
|
-
countyInput.addClass('required')
|
2
|
+
if ($ '#checkout_form_address').is('*')
|
3
|
+
getStateId = (region) ->
|
4
|
+
$('#' + region + 'state select:visible').val()
|
5
|
+
|
6
|
+
Spree.updateCounty = (region) ->
|
7
|
+
stateId = getStateId(region)
|
8
|
+
if stateId? and stateId
|
9
|
+
unless Spree.Checkout[stateId]?
|
10
|
+
$.get '/api/counties', {state_id: stateId}, (data) ->
|
11
|
+
Spree.Checkout[stateId] =
|
12
|
+
counties: data.counties
|
13
|
+
counties_required: false #data.counties_required
|
14
|
+
Spree.fillCounties(Spree.Checkout[stateId], region)
|
15
|
+
else
|
16
|
+
Spree.fillCounties(Spree.Checkout[stateId], region)
|
17
|
+
|
49
18
|
else
|
50
|
-
|
51
|
-
|
19
|
+
countyPara = ($ '#' + region + 'county')
|
20
|
+
countySelect = countyPara.find('select')
|
21
|
+
countyInput = countyPara.find('input')
|
22
|
+
|
23
|
+
countyPara.hide()
|
24
|
+
countySelect.hide().prop('disabled', true).val('')
|
25
|
+
countyInput.hide().prop('disabled', true).val('')
|
26
|
+
|
27
|
+
Spree.fillCounties = (data, region) ->
|
28
|
+
countiesRequired = data.counties_required
|
29
|
+
counties = data.counties
|
30
|
+
|
31
|
+
countyPara = ($ '#' + region + 'county')
|
32
|
+
countySelect = countyPara.find('select')
|
33
|
+
countyInput = countyPara.find('input')
|
34
|
+
countySpanRequired = countyPara.find('[id$="county-required"]')
|
35
|
+
if counties.length > 0
|
36
|
+
selected = parseInt countySelect.val()
|
37
|
+
countySelect.html ''
|
38
|
+
countyWithBlank = [{ name: '', id: ''}].concat(counties)
|
39
|
+
$.each countyWithBlank, (idx, county) ->
|
40
|
+
opt = ($ document.createElement('option')).attr('value', county.id).html(county.name)
|
41
|
+
opt.prop 'selected', true if selected is county.id
|
42
|
+
countySelect.append opt
|
43
|
+
|
44
|
+
countySelect.prop('disabled', false).show()
|
45
|
+
countyInput.hide().prop('disabled', true).val('')
|
46
|
+
countyPara.show()
|
47
|
+
countySpanRequired.show()
|
48
|
+
countySelect.addClass('required') if countiesRequired
|
49
|
+
countySelect.removeClass('hidden')
|
52
50
|
countyInput.removeClass('required')
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
51
|
+
else
|
52
|
+
countySelect.hide().prop('disabled', true).val('')
|
53
|
+
countyInput.show()
|
54
|
+
if countiesRequired
|
55
|
+
countySpanRequired.show()
|
56
|
+
countyInput.addClass('required')
|
57
|
+
else
|
58
|
+
countyInput.val ''
|
59
|
+
countySpanRequired.hide()
|
60
|
+
countyInput.removeClass('required')
|
61
|
+
countyPara.toggle(!!countiesRequired)
|
62
|
+
countyInput.prop('disabled', !countiesRequired)
|
63
|
+
countyInput.removeClass('hidden')
|
64
|
+
countySelect.removeClass('required')
|
65
|
+
|
66
|
+
$(document).on 'change', '#bstate select', ->
|
67
|
+
Spree.updateCounty 'b'
|
68
|
+
|
69
|
+
$(document).on 'change', '#sstate select', ->
|
70
|
+
Spree.updateCounty 's'
|
71
|
+
|
72
|
+
$(document).on 'change', '#bcountry select', ->
|
73
|
+
Spree.updateCounty 'b'
|
74
|
+
|
75
|
+
$(document).on 'change', '#scountry select', ->
|
76
|
+
Spree.updateCounty 's'
|
77
|
+
|
78
|
+
Spree.updateCounty 'b'
|
79
|
+
|
57
80
|
|
58
|
-
|
81
|
+
window.fillStatesOld = Spree.fillStates
|
82
|
+
Spree.fillStates = (data, region) ->
|
83
|
+
fillStatesOld(data, region)
|
84
|
+
Spree.updateCounty(region)
|
@@ -1,7 +1,67 @@
|
|
1
1
|
module Spree
|
2
2
|
Address.class_eval do
|
3
|
-
belongs_to :county, class_name: "Spree::County"
|
4
3
|
Spree::PermittedAttributes.address_attributes << :county_id
|
5
4
|
Spree::PermittedAttributes.address_attributes << :county_name
|
5
|
+
|
6
|
+
before_validation :ensure_state_country_dependency
|
7
|
+
before_validation :ensure_county_state_dependency
|
8
|
+
|
9
|
+
belongs_to :county, class_name: "Spree::County"
|
10
|
+
validate :county_validate
|
11
|
+
|
12
|
+
def require_county?
|
13
|
+
false
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
def county_validate
|
18
|
+
# Skip state validation without state
|
19
|
+
return if state.blank?
|
20
|
+
return if !require_county?
|
21
|
+
|
22
|
+
# ensure associated county belongs to state
|
23
|
+
if county.present?
|
24
|
+
if county.state == state
|
25
|
+
self.county_name = nil #not required as we have a valid county and state combo
|
26
|
+
else
|
27
|
+
if county_name.present?
|
28
|
+
self.county = nil
|
29
|
+
else
|
30
|
+
errors.add(:county, :invalid)
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
# ensure county_name belongs to state without counties, or that it matches a predefined state name
|
36
|
+
if county_name.present?
|
37
|
+
if state.counties.present?
|
38
|
+
counties = state.counties.find_all_by_name(county_name)
|
39
|
+
|
40
|
+
if counties.size == 1
|
41
|
+
self.county = counties.first
|
42
|
+
self.county_name = nil
|
43
|
+
else
|
44
|
+
errors.add(:state, :invalid)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
# ensure at least one county field is populated
|
50
|
+
errors.add :county, :blank if county.blank? && county_name.blank?
|
51
|
+
end
|
52
|
+
|
53
|
+
# ensure associated state belongs to country
|
54
|
+
def ensure_state_country_dependency
|
55
|
+
unless Spree::State.where(country_id: self.country_id).exists?(id: self.state_id)
|
56
|
+
self.state_id = nil
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
# ensure associated county belongs to state
|
61
|
+
def ensure_county_state_dependency
|
62
|
+
unless Spree::County.where(state_id: self.state_id).exists?(id: self.county_id)
|
63
|
+
self.county_id = nil
|
64
|
+
end
|
65
|
+
end
|
6
66
|
end
|
7
|
-
end
|
67
|
+
end
|
data/app/models/spree/county.rb
CHANGED
@@ -0,0 +1,53 @@
|
|
1
|
+
<!-- replace_contents "erb[silent]:contains('Spree::Config[:address_requires_state]')" closing_selector "erb[silent]:contains('end')" -->
|
2
|
+
<p class="form-group" id=<%="#{address_id}state" %>>
|
3
|
+
<% have_states = !address.country.states.empty? %>
|
4
|
+
<%= form.label :state do %>
|
5
|
+
<%= Spree.t(:state) %><abbr class='required' title="required" id=<%="#{address_id}state-required"%>>*</abbr>
|
6
|
+
<% end %>
|
7
|
+
|
8
|
+
<% state_elements = [
|
9
|
+
form.collection_select(:state_id, address.country.states,
|
10
|
+
:id, :name,
|
11
|
+
{:include_blank => true},
|
12
|
+
{:class => have_states ? 'form-control required' : 'form-control hidden',
|
13
|
+
:disabled => !have_states}) +
|
14
|
+
form.text_field(:state_name,
|
15
|
+
:class => !have_states ? 'form-control required' : 'form-control hidden',
|
16
|
+
:disabled => have_states)
|
17
|
+
].join.gsub('"', "'").gsub("\n", "")
|
18
|
+
%>
|
19
|
+
<%= javascript_tag do %>
|
20
|
+
$('#<%="#{address_id}state" %>').append("<%== state_elements %>");
|
21
|
+
<% end %>
|
22
|
+
</p>
|
23
|
+
<noscript>
|
24
|
+
<%= form.text_field :state_name, :class => 'form-control required' %>
|
25
|
+
</noscript>
|
26
|
+
|
27
|
+
<p class="field" id=<%="#{address_id}county" %>>
|
28
|
+
<% have_counties = address.state and !address.state.counties.empty? %>
|
29
|
+
<%= form.label :county do %>
|
30
|
+
<%= Spree.t(:county) %>
|
31
|
+
<% if address.require_county? %>
|
32
|
+
<abbr class="required" id=<%="#{address_id}county-required"%>>*</abbr>
|
33
|
+
<% end %>
|
34
|
+
<% end %>
|
35
|
+
|
36
|
+
<% county_elements = [
|
37
|
+
form.collection_select(:county_id, address.state ? address.state.counties : {},
|
38
|
+
:id, :name,
|
39
|
+
{:include_blank => true},
|
40
|
+
{:class => (have_counties || address.require_county?) ? "form-control required" : "form-control",
|
41
|
+
:disabled => !have_counties}) +
|
42
|
+
form.text_field(:county_name,
|
43
|
+
:class => (!have_counties || address.require_county?) ? 'form-control required' : 'form-control hidden',
|
44
|
+
:disabled => have_counties)
|
45
|
+
].join.gsub('"', "'").gsub("\n", "")
|
46
|
+
%>
|
47
|
+
<%= javascript_tag do %>
|
48
|
+
$('#<%="#{address_id}county" %>').append("<%== county_elements %>");
|
49
|
+
<% end %>
|
50
|
+
</p>
|
51
|
+
<noscript>
|
52
|
+
<%= form.text_field :county_name, :class => 'form-control required' %>
|
53
|
+
</noscript>
|
@@ -0,0 +1,10 @@
|
|
1
|
+
<!-- insert_bottom "div[data-hook=address_fields]" -->
|
2
|
+
<div class="field <%= "#{type}-row" %>">
|
3
|
+
<%= f.label :county_id, Spree.t(:county) %>
|
4
|
+
<span id="<%= s_or_b %>county">
|
5
|
+
<%= f.text_field :county_name,
|
6
|
+
:style => "display: #{f.object.state.counties.empty? ? 'block' : 'none' };",
|
7
|
+
:disabled => !f.object.state.counties.empty?, :class => 'fullwidth county_name' %>
|
8
|
+
<%= f.collection_select :county_id, f.object.state.counties.sort, :id, :name, {:include_blank => true}, {:class => 'select2 fullwidth', :style => "display: #{f.object.state.counties.empty? ? 'none' : 'block' };", :disabled => f.object.state.counties.empty?} %>
|
9
|
+
</span>
|
10
|
+
</div>
|
data/config/locales/en.yml
CHANGED
data/config/locales/es.yml
CHANGED
data/config/routes.rb
CHANGED
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Spree::County do
|
4
|
+
##############
|
5
|
+
# attributes #
|
6
|
+
##############
|
7
|
+
it { expect(subject).to respond_to :name }
|
8
|
+
it { expect(subject).to respond_to :state_id }
|
9
|
+
|
10
|
+
##############
|
11
|
+
# association #
|
12
|
+
##############
|
13
|
+
it { should belong_to(:state) }
|
14
|
+
|
15
|
+
##############
|
16
|
+
# validations #
|
17
|
+
##############
|
18
|
+
it { should validate_presence_of(:name) }
|
19
|
+
end
|
data/spec/spec_helper.rb
CHANGED
@@ -18,6 +18,7 @@ require File.expand_path('../dummy/config/environment.rb', __FILE__)
|
|
18
18
|
require 'rspec/rails'
|
19
19
|
require 'database_cleaner'
|
20
20
|
require 'ffaker'
|
21
|
+
require 'shoulda/matchers'
|
21
22
|
|
22
23
|
# Requires supporting ruby files with custom matchers and macros, etc,
|
23
24
|
# in spec/support/ and its subdirectories.
|
@@ -26,8 +27,10 @@ Dir[File.join(File.dirname(__FILE__), 'support/**/*.rb')].each { |f| require f }
|
|
26
27
|
# Requires factories and other useful helpers defined in spree_core.
|
27
28
|
require 'spree/testing_support/authorization_helpers'
|
28
29
|
require 'spree/testing_support/capybara_ext'
|
29
|
-
require 'spree/testing_support/controller_requests'
|
30
30
|
require 'spree/testing_support/factories'
|
31
|
+
require 'spree/testing_support/preferences'
|
32
|
+
require 'spree/testing_support/controller_requests'
|
33
|
+
require 'spree/testing_support/flash'
|
31
34
|
require 'spree/testing_support/url_helpers'
|
32
35
|
|
33
36
|
# Requires factories defined in lib/spree_counties/factories.rb
|
@@ -35,7 +38,9 @@ require 'spree_counties/factories'
|
|
35
38
|
|
36
39
|
RSpec.configure do |config|
|
37
40
|
config.include FactoryGirl::Syntax::Methods
|
38
|
-
|
41
|
+
config.include Spree::TestingSupport::ControllerRequests, :type => :controller
|
42
|
+
config.include Devise::TestHelpers, :type => :controller
|
43
|
+
|
39
44
|
# Infer an example group's spec type from the file location.
|
40
45
|
config.infer_spec_type_from_file_location!
|
41
46
|
|
data/spree_counties.gemspec
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
Gem::Specification.new do |s|
|
3
3
|
s.platform = Gem::Platform::RUBY
|
4
4
|
s.name = 'spree_counties'
|
5
|
-
s.version = '3.0.
|
5
|
+
s.version = '3.0.4'
|
6
6
|
s.summary = 'Lets your users pick counties from states list in address\'s step'
|
7
7
|
s.description = 'Add county model to address'
|
8
8
|
s.required_ruby_version = '>= 1.9.3'
|
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
|
|
18
18
|
s.requirements << 'none'
|
19
19
|
|
20
20
|
s.add_dependency('spree_core', '~> 3.0')
|
21
|
+
s.add_dependency('spree_backend', '~> 3.0')
|
21
22
|
|
22
23
|
s.add_development_dependency 'capybara', '~> 2.4'
|
23
24
|
s.add_development_dependency 'coffee-rails'
|
@@ -27,6 +28,7 @@ Gem::Specification.new do |s|
|
|
27
28
|
s.add_development_dependency 'rspec-rails', '~> 3.1'
|
28
29
|
s.add_development_dependency 'sass-rails', '~> 4.0.2'
|
29
30
|
s.add_development_dependency 'selenium-webdriver'
|
31
|
+
s.add_development_dependency 'shoulda-matchers'
|
30
32
|
s.add_development_dependency 'simplecov'
|
31
33
|
s.add_development_dependency 'sqlite3'
|
32
34
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spree_counties
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 3.0.
|
4
|
+
version: 3.0.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Gonzalo Moreno
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-07-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: spree_core
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '3.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: spree_backend
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '3.0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '3.0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: capybara
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -136,6 +150,20 @@ dependencies:
|
|
136
150
|
- - ">="
|
137
151
|
- !ruby/object:Gem::Version
|
138
152
|
version: '0'
|
153
|
+
- !ruby/object:Gem::Dependency
|
154
|
+
name: shoulda-matchers
|
155
|
+
requirement: !ruby/object:Gem::Requirement
|
156
|
+
requirements:
|
157
|
+
- - ">="
|
158
|
+
- !ruby/object:Gem::Version
|
159
|
+
version: '0'
|
160
|
+
type: :development
|
161
|
+
prerelease: false
|
162
|
+
version_requirements: !ruby/object:Gem::Requirement
|
163
|
+
requirements:
|
164
|
+
- - ">="
|
165
|
+
- !ruby/object:Gem::Version
|
166
|
+
version: '0'
|
139
167
|
- !ruby/object:Gem::Dependency
|
140
168
|
name: simplecov
|
141
169
|
requirement: !ruby/object:Gem::Requirement
|
@@ -173,6 +201,8 @@ files:
|
|
173
201
|
- ".bundle/config"
|
174
202
|
- ".gitignore"
|
175
203
|
- ".rspec"
|
204
|
+
- ".ruby-gemset"
|
205
|
+
- ".ruby-version"
|
176
206
|
- Gemfile
|
177
207
|
- LICENSE.txt
|
178
208
|
- README.md
|
@@ -187,14 +217,14 @@ files:
|
|
187
217
|
- app/models/spree/address_decorator.rb
|
188
218
|
- app/models/spree/county.rb
|
189
219
|
- app/models/spree/state_decorator.rb
|
220
|
+
- app/overrides/spree/address/_form/add_county.html.erb.deface
|
221
|
+
- app/overrides/spree/admin/shared/_address_form/add_county_to_form.html.erb.deface
|
190
222
|
- app/overrides/spree/admin/states/index.rb
|
191
|
-
- app/views/spree/address/_form.html.erb
|
192
223
|
- app/views/spree/admin/counties/_county_list.html.erb
|
193
224
|
- app/views/spree/admin/counties/_form.html.erb
|
194
225
|
- app/views/spree/admin/counties/edit.html.erb
|
195
226
|
- app/views/spree/admin/counties/index.html.erb
|
196
227
|
- app/views/spree/admin/counties/new.html.erb
|
197
|
-
- app/views/spree/admin/shared/_address_form.html.erb
|
198
228
|
- app/views/spree/api/counties/index.v1.rabl
|
199
229
|
- app/views/spree/api/counties/show.v1.rabl
|
200
230
|
- bin/rails
|
@@ -212,6 +242,8 @@ files:
|
|
212
242
|
- lib/spree_counties/engine.rb
|
213
243
|
- lib/spree_counties/factories.rb
|
214
244
|
- lib/spree_counties/version.rb
|
245
|
+
- spec/controllers/spree/admin/counties_controller_spec.rb
|
246
|
+
- spec/models/spree/county_spec.rb
|
215
247
|
- spec/spec_helper.rb
|
216
248
|
- spree_counties.gemspec
|
217
249
|
homepage: http://www.acid.cl
|
@@ -235,10 +267,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
235
267
|
requirements:
|
236
268
|
- none
|
237
269
|
rubyforge_project:
|
238
|
-
rubygems_version: 2.4.
|
270
|
+
rubygems_version: 2.4.5
|
239
271
|
signing_key:
|
240
272
|
specification_version: 4
|
241
273
|
summary: Lets your users pick counties from states list in address's step
|
242
274
|
test_files:
|
275
|
+
- spec/controllers/spree/admin/counties_controller_spec.rb
|
276
|
+
- spec/models/spree/county_spec.rb
|
243
277
|
- spec/spec_helper.rb
|
244
|
-
has_rdoc:
|
@@ -1,86 +0,0 @@
|
|
1
|
-
<% address_id = address_type.chars.first %>
|
2
|
-
<div class="inner" data-hook=<%="#{address_type}_inner" %>>
|
3
|
-
<p class="field" id=<%="#{address_id}firstname" %>>
|
4
|
-
<%= form.label :firstname, Spree.t(:first_name) %><span class="required">*</span><br />
|
5
|
-
<%= form.text_field :firstname, :class => 'required' %>
|
6
|
-
</p>
|
7
|
-
<p class="field" id=<%="#{address_id}lastname" %>>
|
8
|
-
<%= form.label :lastname, Spree.t(:last_name) %><span class="required">*</span><br />
|
9
|
-
<%= form.text_field :lastname, :class => 'required' %>
|
10
|
-
</p>
|
11
|
-
<% if Spree::Config[:company] %>
|
12
|
-
<p class="field" id=<%="#{address_id}company" %>>
|
13
|
-
<%= form.label :company, Spree.t(:company) %><br />
|
14
|
-
<%= form.text_field :company %>
|
15
|
-
</p>
|
16
|
-
<% end %>
|
17
|
-
<p class="field" id=<%="#{address_id}address1" %>>
|
18
|
-
<%= form.label :address1, Spree.t(:street_address) %><span class="required">*</span><br />
|
19
|
-
<%= form.text_field :address1, :class => 'required' %>
|
20
|
-
</p>
|
21
|
-
<p class="field" id=<%="#{address_id}address2" %>>
|
22
|
-
<%= form.label :address2, Spree.t(:street_address_2) %><br />
|
23
|
-
<%= form.text_field :address2 %>
|
24
|
-
</p>
|
25
|
-
<p class="field" id=<%="#{address_id}city" %>>
|
26
|
-
<%= form.label :city, Spree.t(:city) %><span class="required">*</span><br />
|
27
|
-
<%= form.text_field :city, :class => 'required' %>
|
28
|
-
</p>
|
29
|
-
<p class="field" id=<%="#{address_id}country" %>>
|
30
|
-
<%= form.label :country_id, Spree.t(:country) %><span class="required">*</span><br />
|
31
|
-
<span id=<%="#{address_id}country-selection" %>>
|
32
|
-
<%= form.collection_select :country_id, available_countries, :id, :name, {}, {:class => 'required'} %>
|
33
|
-
</span>
|
34
|
-
</p>
|
35
|
-
|
36
|
-
<% if Spree::Config[:address_requires_state] %>
|
37
|
-
<p class="field" id=<%="#{address_id}state" %>>
|
38
|
-
<% have_states = !address.country.states.empty? %>
|
39
|
-
<%= form.label :state, Spree.t(:state) %><span class='required' id=<%="#{address_id}state-required"%>>*</span><br/>
|
40
|
-
|
41
|
-
<% state_elements = [
|
42
|
-
form.collection_select(:state_id, address.country.states,
|
43
|
-
:id, :name,
|
44
|
-
{:include_blank => true},
|
45
|
-
{:class => have_states ? 'required' : 'hidden',
|
46
|
-
:disabled => !have_states}) +
|
47
|
-
form.text_field(:state_name,
|
48
|
-
:class => !have_states ? 'required' : 'hidden',
|
49
|
-
:disabled => have_states)
|
50
|
-
].join.gsub('"', "'").gsub("\n", "")
|
51
|
-
%>
|
52
|
-
<%= javascript_tag do -%>
|
53
|
-
$('#<%="#{address_id}state" %>').append("<%== state_elements %>");
|
54
|
-
<% end %>
|
55
|
-
</p>
|
56
|
-
<noscript>
|
57
|
-
<%= form.text_field :state_name, :class => 'required' %>
|
58
|
-
</noscript>
|
59
|
-
|
60
|
-
<p class="field" id=<%="#{address_id}county" %>>
|
61
|
-
<%= form.label :county do %>
|
62
|
-
<%= Spree.t(:county) %>
|
63
|
-
<span class="required" id=<%="#{address_id}county-required"%>>*</span>
|
64
|
-
<% end %>
|
65
|
-
<%= form.collection_select(:county_id, [],
|
66
|
-
:id, :name,
|
67
|
-
{:include_blank => true},
|
68
|
-
{:class => "form-control required",}) %>
|
69
|
-
</p>
|
70
|
-
<% end %>
|
71
|
-
|
72
|
-
<p class="field" id=<%="#{address_id}zipcode" %>>
|
73
|
-
<%= form.label :zipcode, Spree.t(:zip) %><% if address.require_zipcode? %><span class="required">*</span><br /><% end %>
|
74
|
-
<%= form.text_field :zipcode, :class => "#{'required' if address.require_zipcode?}" %>
|
75
|
-
</p>
|
76
|
-
<p class="field" id=<%="#{address_id}phone" %>>
|
77
|
-
<%= form.label :phone, Spree.t(:phone) %><% if address.require_phone? %><span class="required">*</span><br /><% end %>
|
78
|
-
<%= form.phone_field :phone, :class => "#{'required' if address.require_phone?}" %>
|
79
|
-
</p>
|
80
|
-
<% if Spree::Config[:alternative_shipping_phone] %>
|
81
|
-
<p class="field" id=<%="#{address_id}altphone" %>>
|
82
|
-
<%= form.label :alternative_phone, Spree.t(:alternative_phone) %><br />
|
83
|
-
<%= form.phone_field :alternative_phone %>
|
84
|
-
</p>
|
85
|
-
<% end %>
|
86
|
-
</div>
|
@@ -1,81 +0,0 @@
|
|
1
|
-
<% s_or_b = type.chars.first %>
|
2
|
-
|
3
|
-
<div id="<%= type %>" data-hook="address_fields">
|
4
|
-
<div class="field <%= "#{type}-row" %>">
|
5
|
-
<%= f.label :firstname, Spree.t(:first_name) %>
|
6
|
-
<%= f.text_field :firstname, :class => 'fullwidth' %>
|
7
|
-
</div>
|
8
|
-
|
9
|
-
<div class="field <%= "#{type}-row" %>">
|
10
|
-
<%= f.label :lastname, Spree.t(:last_name) %>
|
11
|
-
<%= f.text_field :lastname, :class => 'fullwidth' %>
|
12
|
-
</div>
|
13
|
-
|
14
|
-
<% if Spree::Config[:company] %>
|
15
|
-
<div class="field <%= "#{type}-row" %>">
|
16
|
-
<%= f.label :company, Spree.t(:company) %>
|
17
|
-
<%= f.text_field :company, :class => 'fullwidth' %>
|
18
|
-
</div>
|
19
|
-
<% end %>
|
20
|
-
|
21
|
-
<div class="field <%= "#{type}-row" %>">
|
22
|
-
<%= f.label :address1, Spree.t(:street_address) %>
|
23
|
-
<%= f.text_field :address1, :class => 'fullwidth' %>
|
24
|
-
</div>
|
25
|
-
|
26
|
-
<div class="field <%= "#{type}-row" %>">
|
27
|
-
<%= f.label :address2, Spree.t(:street_address_2) %>
|
28
|
-
<%= f.text_field :address2, :class => 'fullwidth' %>
|
29
|
-
</div>
|
30
|
-
|
31
|
-
<div class="field <%= "#{type}-row" %>">
|
32
|
-
<%= f.label :city, Spree.t(:city) %>
|
33
|
-
<%= f.text_field :city, :class => 'fullwidth' %>
|
34
|
-
</div>
|
35
|
-
|
36
|
-
<div class="field <%= "#{type}-row" %>">
|
37
|
-
<%= f.label :zipcode, Spree.t(:zip) %>
|
38
|
-
<%= f.text_field :zipcode, :class => 'fullwidth' %>
|
39
|
-
</div>
|
40
|
-
|
41
|
-
<div class="field <%= "#{type}-row" %>">
|
42
|
-
<%= f.label :country_id, Spree.t(:country) %>
|
43
|
-
<span id="<%= s_or_b %>country">
|
44
|
-
<%= f.collection_select :country_id, available_countries, :id, :name, {}, {:class => 'select2 fullwidth'} %>
|
45
|
-
</span>
|
46
|
-
</div>
|
47
|
-
|
48
|
-
<div class="field <%= "#{type}-row" %>">
|
49
|
-
<%= f.label :state_id, Spree.t(:state) %>
|
50
|
-
<span id="<%= s_or_b %>state">
|
51
|
-
<%= f.text_field :state_name,
|
52
|
-
:style => "display: #{f.object.country.states.empty? ? 'block' : 'none' };",
|
53
|
-
:disabled => !f.object.country.states.empty?, :class => 'fullwidth state_name' %>
|
54
|
-
<%= f.collection_select :state_id, f.object.country.states.sort, :id, :name, {:include_blank => true}, {:class => 'select2 fullwidth', :style => "display: #{f.object.country.states.empty? ? 'none' : 'block' };", :disabled => f.object.country.states.empty?} %>
|
55
|
-
</span>
|
56
|
-
</div>
|
57
|
-
|
58
|
-
<div class="field <%= "#{type}-row" %>">
|
59
|
-
<%= f.label :county_id, Spree.t(:county) %>
|
60
|
-
<span id="<%= s_or_b %>county">
|
61
|
-
<%= f.text_field :county_name,
|
62
|
-
:style => "display: #{f.object.state.counties.empty? ? 'block' : 'none' };",
|
63
|
-
:disabled => !f.object.state.counties.empty?, :class => 'fullwidth county_name' %>
|
64
|
-
<%= f.collection_select :county_id, f.object.state.counties.sort, :id, :name, {:include_blank => true}, {:class => 'select2 fullwidth', :style => "display: #{f.object.state.counties.empty? ? 'none' : 'block' };", :disabled => f.object.state.counties.empty?} %>
|
65
|
-
</span>
|
66
|
-
</div>
|
67
|
-
|
68
|
-
<div class="field <%= "#{type}-row" %>">
|
69
|
-
<%= f.label :phone, Spree.t(:phone) %>
|
70
|
-
<%= f.phone_field :phone, :class => 'fullwidth' %>
|
71
|
-
</div>
|
72
|
-
</div>
|
73
|
-
|
74
|
-
<% content_for :head do %>
|
75
|
-
<%= javascript_tag do -%>
|
76
|
-
$(document).ready(function(){
|
77
|
-
$('span#<%= s_or_b %>country .select2').on('change', function() { update_state('<%= s_or_b %>'); });
|
78
|
-
$('span#<%= s_or_b %>state .select2').on('change', function() { update_county('<%= s_or_b %>'); });
|
79
|
-
});
|
80
|
-
<% end -%>
|
81
|
-
<% end %>
|