spree_address_book 0.50.0 → 0.50.1

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.
@@ -1,12 +1,33 @@
1
1
  class AddressesController < Spree::BaseController
2
- def destroy
3
- @address = Address.find(params[:id])
4
- if @address && @address.user == current_user
5
- if @address.can_be_deleted?
6
- @address.destroy
7
- else
8
- @address.update_attribute(:deleted_at, Time.now)
2
+ rescue_from ActiveRecord::RecordNotFound, :with => :render_404
3
+ load_and_authorize_resource
4
+
5
+ def edit
6
+ session["user_return_to"] = request.env['HTTP_REFERER']
7
+ end
8
+
9
+ def update
10
+ if @address.editable?
11
+ if @address.update_attributes(params[:address])
12
+ flash[:notice] = I18n.t(:successfully_updated, :resource => I18n.t(:address))
13
+ end
14
+ else
15
+ new_address = @address.clone
16
+ new_address.attributes = params[:address]
17
+ @address.update_attribute(:deleted_at, Time.now)
18
+ if new_address.save
19
+ flash[:notice] = I18n.t(:successfully_updated, :resource => I18n.t(:address))
9
20
  end
10
21
  end
22
+ redirect_back_or_default(account_path)
23
+ end
24
+
25
+ def destroy
26
+ if @address.can_be_deleted?
27
+ @address.destroy
28
+ else
29
+ @address.update_attribute(:deleted_at, Time.now)
30
+ end
31
+ redirect_to(request.env['HTTP_REFERER'] || account_path) unless request.xhr?
11
32
  end
12
33
  end
@@ -1,3 +1,3 @@
1
1
  User.class_eval do
2
- has_many :addresses, :conditions => {:deleted_at => nil}
2
+ has_many :addresses, :conditions => {:deleted_at => nil}, :order => "updated_at DESC"
3
3
  end
@@ -0,0 +1,18 @@
1
+ <style>
2
+ form p.field input[type=text], form p.field select { width: 80%; float: none; }
3
+ .hidden { display: none; }
4
+ div.inner label { width: 15%; display: inline-block; }
5
+ form p.field span.req { float: none; }
6
+ </style>
7
+ <%= form_for @address do |f| %>
8
+ <fieldset>
9
+ <div class="inner">
10
+ <%= render :partial => 'addresses/form', :locals => {
11
+ :address_name => 'address',
12
+ :address_form => f,
13
+ :address => @address
14
+ } %>
15
+ </div>
16
+ <%= f.submit t(:update) %>
17
+ </fieldset>
18
+ <% end %>
@@ -4,6 +4,8 @@
4
4
  .hidden { display: none; }
5
5
  div#checkout #checkout_form_address #billing .select_address label { float:none; }
6
6
  div#checkout #checkout_form_address #shipping .select_address label { float:none; }
7
+ div#checkout #checkout_form_address #billing input[type=radio] { width: auto; }
8
+ div#checkout #checkout_form_address #shipping input[type=radio] { width: auto; }
7
9
  </style>
8
10
 
9
11
  <% ['billing', 'shipping'].each do |address_type|
@@ -21,9 +23,9 @@
21
23
  <div class="select_address">
22
24
  <p class="field">
23
25
  <% if @addresses.present? %>
24
- <% @addresses.each do |address| %>
26
+ <% @addresses.each_with_index do |address, idx| %>
25
27
  <span id="<%= [address_type, dom_id(address)].join('_') %>">
26
- <label><%= form.radio_button "#{address_name}_id", address.id %> <%= address %></label> <%= link_to t(:remove), address, :method => :delete, :remote => true %><br />
28
+ <label><%= form.radio_button "#{address_name}_id", address.id, :checked => (idx == 0) %> <%= address %></label> <%= link_to t(:edit), edit_address_path(address) %><br />
27
29
  </span>
28
30
  <% end %>
29
31
  <label><%= form.radio_button "#{address_name}_id", 0 %> <%= t('other_address') %></label>
@@ -36,7 +38,7 @@
36
38
  <%= render :partial => 'addresses/form', :locals => {
37
39
  :address_name => address_name,
38
40
  :address_form => address_form,
39
- :address => @order.send(address_name)
41
+ :address => Address.default
40
42
  } %>
41
43
  </div>
42
44
  <% end %>
@@ -0,0 +1,20 @@
1
+ <% if current_user.addresses.present? %>
2
+ <h2><%= Address.human_name(:count => 2) %></h2>
3
+ <table class="order-summary" width="545">
4
+ <thead>
5
+ <tr>
6
+ <th><%= Address.human_name %></th>
7
+ <th></th>
8
+ </tr>
9
+ </thead>
10
+ <tbody>
11
+ <% current_user.addresses.each do |address| %>
12
+ <tr class="<%= cycle('even', 'odd') %>">
13
+ <td><%= address %></td>
14
+ <td><%= link_to t(:edit), edit_address_path(address) %></td>
15
+ <td><%= link_to t(:remove), address_path(address), :method => :delete, :confirm => t(:are_you_sure) %></td>
16
+ </tr>
17
+ <% end %>
18
+ </tbody>
19
+ </table>
20
+ <% end %>
@@ -0,0 +1,9 @@
1
+ class AddressAbility
2
+ include CanCan::Ability
3
+
4
+ def initialize(user)
5
+ can :manage, Address do |address|
6
+ address.user == user
7
+ end
8
+ end
9
+ end
@@ -10,6 +10,7 @@ module SpreeAddressBook
10
10
  Dir.glob(File.join(File.dirname(__FILE__), "../app/**/*_decorator*.rb")) do |c|
11
11
  Rails.env.production? ? require(c) : load(c)
12
12
  end
13
+ Ability.register_ability(AddressAbility)
13
14
  end
14
15
 
15
16
  config.to_prepare &method(:activate).to_proc
@@ -1,3 +1,3 @@
1
1
  class SpreeAddressBookHooks < Spree::ThemeSupport::HookListener
2
- # custom hooks go here
3
- end
2
+ insert_after :account_my_orders, :partial => 'users/addresses'
3
+ end
@@ -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.0'
4
+ s.version = '0.50.1'
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
- - 0
9
- version: 0.50.0
8
+ - 1
9
+ version: 0.50.1
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-04-28 00:00:00 +04:00
17
+ date: 2011-05-12 00:00:00 +04:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -66,7 +66,9 @@ files:
66
66
  - app/models/user_decorator.rb
67
67
  - app/views/addresses/_form.html.erb
68
68
  - app/views/addresses/destroy.js.erb
69
+ - app/views/addresses/edit.html.erb
69
70
  - app/views/checkout/_address.html.erb
71
+ - app/views/users/_addresses.html.erb
70
72
  - config/initializers/address_fields.rb
71
73
  - config/locales/en.yml
72
74
  - config/locales/ru.yml
@@ -76,6 +78,7 @@ files:
76
78
  - features/step_definitions/address_book_steps.rb
77
79
  - features/support/env.rb
78
80
  - features/support/paths.rb
81
+ - lib/address_ability.rb
79
82
  - lib/spree_address_book.rb
80
83
  - lib/spree_address_book_hooks.rb
81
84
  - lib/tasks/install.rake