spree_address_book 0.50.1 → 0.50.2
Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,33 @@
|
|
1
|
+
CheckoutHelper.module_eval do
|
2
|
+
def address_field(form, method, id_prefix = "b", &handler)
|
3
|
+
content_tag :p, :id => [id_prefix, method].join, :class => "field" do
|
4
|
+
if handler
|
5
|
+
handler.call
|
6
|
+
else
|
7
|
+
is_required = Address.required_fields.include?(method)
|
8
|
+
separator = is_required ? '<span class="req">*</span><br />' : '<br />'
|
9
|
+
form.label(method) + separator.html_safe +
|
10
|
+
form.text_field(method, :class => is_required ? 'required' : nil)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
def address_state(form, country)
|
16
|
+
country ||= Country.find(Spree::Config[:default_country_id])
|
17
|
+
have_states = !country.states.empty?
|
18
|
+
state_elements = [
|
19
|
+
form.collection_select(:state_id, country.states.order(:name),
|
20
|
+
:id, :name,
|
21
|
+
{:include_blank => true},
|
22
|
+
{:class => have_states ? "required" : "hidden",
|
23
|
+
:disabled => !have_states}) +
|
24
|
+
form.text_field(:state_name,
|
25
|
+
:class => !have_states ? "required" : "hidden",
|
26
|
+
:disabled => have_states)
|
27
|
+
].join.gsub('"', "'").gsub("\n", "")
|
28
|
+
|
29
|
+
form.label(:state, t(:state)) + '<span class="req">*</span><br />'.html_safe +
|
30
|
+
content_tag(:noscript, form.text_field(:state_name, :class => 'required')) +
|
31
|
+
javascript_tag("document.write(\"#{state_elements.html_safe}\");")
|
32
|
+
end
|
33
|
+
end
|
@@ -1,5 +1,10 @@
|
|
1
1
|
Address.class_eval do
|
2
2
|
belongs_to :user
|
3
|
+
|
4
|
+
def self.required_fields
|
5
|
+
validator = Address.validators.find{|v| v.kind_of?(ActiveModel::Validations::PresenceValidator)}
|
6
|
+
validator ? validator.attributes : []
|
7
|
+
end
|
3
8
|
|
4
9
|
# can modify an address if it's not been used in an order
|
5
10
|
def editable?
|
@@ -1,46 +1,15 @@
|
|
1
1
|
<% ADDRESS_FIELDS.each do |field| %>
|
2
2
|
<p id="<%= [address_name, field].join('_') %>" class="field">
|
3
3
|
<% if field == "country" %>
|
4
|
-
<%= address_form.label :country_id, t(field, :scope => [:activerecord, :attributes, :address])
|
4
|
+
<%= address_form.label :country_id, t(field, :scope => [:activerecord, :attributes, :address]) %><span class="req">*</span><br />
|
5
5
|
<span><%= address_form.collection_select :country_id, available_countries, :id, :name, {}, {:class => 'required'} %></span>
|
6
|
-
<span class="req">*</span>
|
7
6
|
<% elsif field == "state" && Spree::Config[:address_requires_state] %>
|
8
|
-
<%= address_form
|
9
|
-
<span id="state">
|
10
|
-
<% have_states = !address.country.states.empty? %>
|
11
|
-
<noscript>
|
12
|
-
<%= address_form.text_field :state_name, :class => 'required' %>
|
13
|
-
</noscript>
|
14
|
-
<% state_elements = [
|
15
|
-
address_form.collection_select(:state_id, address.country.states,
|
16
|
-
:id, :name,
|
17
|
-
{:include_blank => true},
|
18
|
-
{:class => have_states ? "required" : "hidden",
|
19
|
-
:disabled => !have_states}) +
|
20
|
-
address_form.text_field(:state_name,
|
21
|
-
:class => !have_states ? "required" : "hidden",
|
22
|
-
:disabled => have_states)
|
23
|
-
].join.gsub('"', "'").gsub("\n", "")
|
24
|
-
%>
|
25
|
-
<script type="text/javascript" language="javascript" charset="utf-8">
|
26
|
-
// <![CDATA[
|
27
|
-
document.write("<%= raw state_elements %>");
|
28
|
-
// ]]>
|
29
|
-
</script>
|
30
|
-
</span>
|
31
|
-
<span class="req">*</span>
|
32
|
-
<% elsif field == "address2" %>
|
33
|
-
<%= address_form.label field, t(field, :scope => [:activerecord, :attributes, :address]) %>
|
34
|
-
<%= address_form.text_field field %>
|
7
|
+
<%= address_field(address_form, :state, address_name) { address_state(address_form, address.country) } %>
|
35
8
|
<% else %>
|
36
|
-
<%= address_form
|
37
|
-
<%= address_form.text_field field, :class => 'required' %><span class="req">*</span>
|
9
|
+
<%= address_field(address_form, field.to_sym, address_name) %>
|
38
10
|
<% end %>
|
39
11
|
</p>
|
40
12
|
<% end %>
|
41
13
|
<% if Spree::Config["alternative_#{address_name}_phone"] %>
|
42
|
-
|
43
|
-
<%= address_form.label :alternative_phone, t(:alternative_phone) %>
|
44
|
-
<%= address_form.text_field :alternative_phone %>
|
45
|
-
</p>
|
14
|
+
<%= address_field(address_form, :alternative_phone, address_name) %>
|
46
15
|
<% end %>
|
@@ -20,17 +20,18 @@
|
|
20
20
|
</label>
|
21
21
|
</p>
|
22
22
|
<% end %>
|
23
|
-
<div class="select_address">
|
24
|
-
<
|
23
|
+
<div class="select_address" data-role="fieldcontain">
|
24
|
+
<fieldset data-role="controlgroup">
|
25
25
|
<% if @addresses.present? %>
|
26
26
|
<% @addresses.each_with_index do |address, idx| %>
|
27
|
-
|
28
|
-
|
29
|
-
|
27
|
+
<%= form.radio_button "#{address_name}_id", address.id, :checked => (idx == 0) %>
|
28
|
+
<%= form.label ["#{address_name}_id", address.id], address.to_s %>
|
29
|
+
<%= link_to t(:edit), edit_address_path(address) %><br />
|
30
30
|
<% end %>
|
31
|
-
|
31
|
+
<%= form.radio_button "#{address_name}_id", 0 %>
|
32
|
+
<%= form.label ["#{address_name}_id", 0], t('other_address') %>
|
32
33
|
<% end %>
|
33
|
-
</
|
34
|
+
</fieldset>
|
34
35
|
</div>
|
35
36
|
<%= form.fields_for address_name do |address_form| %>
|
36
37
|
<div class="inner">
|
data/spree_address_book.gemspec
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.platform = Gem::Platform::RUBY
|
3
3
|
s.name = 'spree_address_book'
|
4
|
-
s.version = '0.50.
|
4
|
+
s.version = '0.50.2'
|
5
5
|
s.summary = 'Adds address book for users to Spree'
|
6
6
|
#s.description = 'Add (optional) gem description here'
|
7
7
|
s.required_ruby_version = '>= 1.8.7'
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 50
|
8
|
-
-
|
9
|
-
version: 0.50.
|
8
|
+
- 2
|
9
|
+
version: 0.50.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Roman Smirnov
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-
|
17
|
+
date: 2011-06-25 00:00:00 +04:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -61,6 +61,7 @@ files:
|
|
61
61
|
- Versionfile
|
62
62
|
- app/controllers/addresses_controller.rb
|
63
63
|
- app/controllers/checkout_controller_decorator.rb
|
64
|
+
- app/helpers/checkout_helper_decorator.rb
|
64
65
|
- app/models/address_decorator.rb
|
65
66
|
- app/models/order_decorator.rb
|
66
67
|
- app/models/user_decorator.rb
|