spree_core 0.50.4 → 0.60.0.RC1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (96) hide show
  1. data/app/controllers/admin/adjustments_controller.rb +8 -7
  2. data/app/controllers/admin/base_controller.rb +1 -33
  3. data/app/controllers/admin/configurations_controller.rb +0 -24
  4. data/app/controllers/admin/images_controller.rb +10 -25
  5. data/app/controllers/admin/line_items_controller.rb +41 -26
  6. data/app/controllers/admin/mail_methods_controller.rb +2 -7
  7. data/app/controllers/admin/option_types_controller.rb +17 -21
  8. data/app/controllers/admin/orders_controller.rb +70 -55
  9. data/app/controllers/admin/payment_methods_controller.rb +33 -22
  10. data/app/controllers/admin/payments_controller.rb +25 -27
  11. data/app/controllers/admin/product_groups_controller.rb +22 -20
  12. data/app/controllers/admin/product_properties_controller.rb +2 -6
  13. data/app/controllers/admin/product_scopes_controller.rb +24 -20
  14. data/app/controllers/admin/products_controller.rb +20 -26
  15. data/app/controllers/admin/properties_controller.rb +2 -20
  16. data/app/controllers/admin/prototypes_controller.rb +5 -33
  17. data/app/controllers/admin/resource_controller.rb +221 -0
  18. data/app/controllers/admin/return_authorizations_controller.rb +3 -9
  19. data/app/controllers/admin/shipments_controller.rb +68 -35
  20. data/app/controllers/admin/shipping_categories_controller.rb +1 -15
  21. data/app/controllers/admin/shipping_methods_controller.rb +6 -12
  22. data/app/controllers/admin/states_controller.rb +16 -21
  23. data/app/controllers/admin/tax_categories_controller.rb +1 -12
  24. data/app/controllers/admin/tax_rates_controller.rb +2 -12
  25. data/app/controllers/admin/taxonomies_controller.rb +11 -12
  26. data/app/controllers/admin/taxons_controller.rb +74 -53
  27. data/app/controllers/admin/trackers_controller.rb +1 -6
  28. data/app/controllers/admin/users_controller.rb +36 -35
  29. data/app/controllers/admin/variants_controller.rb +7 -22
  30. data/app/controllers/admin/zones_controller.rb +12 -25
  31. data/app/controllers/checkout_controller.rb +2 -6
  32. data/app/controllers/orders_controller.rb +0 -1
  33. data/app/controllers/products_controller.rb +12 -16
  34. data/app/controllers/taxons_controller.rb +8 -15
  35. data/app/helpers/admin/navigation_helper.rb +4 -0
  36. data/app/models/address.rb +1 -1
  37. data/app/models/app_configuration.rb +2 -3
  38. data/app/models/product.rb +1 -2
  39. data/app/models/product_group.rb +8 -8
  40. data/app/models/product_scope.rb +1 -1
  41. data/app/models/shipping_method.rb +6 -2
  42. data/app/models/tax_rate.rb +1 -1
  43. data/app/views/admin/general_settings/edit.html.erb +10 -15
  44. data/app/views/admin/general_settings/show.html.erb +5 -5
  45. data/app/views/admin/option_types/{new.html.erb → new.erb} +0 -0
  46. data/app/views/admin/orders/_form.html.erb +0 -1
  47. data/app/views/admin/orders/edit.html.erb +2 -2
  48. data/app/views/admin/orders/index.html.erb +2 -2
  49. data/app/views/admin/payment_methods/edit.html.erb +1 -1
  50. data/app/views/admin/payments/new.html.erb +2 -2
  51. data/app/views/admin/payments/show.html.erb +3 -3
  52. data/app/views/admin/product_groups/index.html.erb +1 -1
  53. data/app/views/admin/product_scopes/create.js.erb +3 -3
  54. data/app/views/admin/product_scopes/destroy.js.erb +2 -2
  55. data/app/views/admin/products/{new.html.erb → new.erb} +0 -0
  56. data/app/views/admin/properties/{new.html.erb → new.erb} +0 -0
  57. data/app/views/admin/prototypes/{new.html.erb → new.erb} +0 -0
  58. data/app/views/admin/shared/_product_tabs.html.erb +1 -1
  59. data/app/views/admin/shared/_tabs.html.erb +1 -1
  60. data/app/views/admin/shipments/edit.html.erb +3 -3
  61. data/app/views/admin/shipments/index.html.erb +1 -1
  62. data/app/views/admin/shipments/new.html.erb +1 -1
  63. data/app/views/admin/states/{new.html.erb → new.erb} +0 -0
  64. data/app/views/admin/tax_categories/edit.html.erb +1 -1
  65. data/app/views/admin/taxonomies/{edit.html.erb → edit.erb} +0 -0
  66. data/app/views/admin/taxons/edit.html.erb +1 -1
  67. data/app/views/admin/variants/{new.html.erb → new.erb} +0 -0
  68. data/app/views/admin/zones/index.html.erb +2 -3
  69. data/app/views/checkout/_address.html.erb +2 -2
  70. data/app/views/layouts/admin.html.erb +0 -1
  71. data/app/views/products/_thumbnails.html.erb +2 -2
  72. data/app/views/shared/_admin_head.html.erb +5 -5
  73. data/app/views/shared/_order_details.html.erb +1 -1
  74. data/app/views/states/index.js.erb +1 -1
  75. data/config/initializers/spree.rb +2 -0
  76. data/config/locales/en.yml +12 -9
  77. data/config/routes.rb +2 -6
  78. data/lib/scopes/product.rb +5 -8
  79. data/lib/spree/preference_access.rb +2 -2
  80. data/lib/spree_base.rb +1 -1
  81. data/lib/spree_core.rb +1 -1
  82. data/lib/spree_core/action_callbacks.rb +26 -0
  83. data/lib/spree_core/version.rb +1 -1
  84. data/lib/tasks/taxon.rake +1 -1
  85. data/public/javascripts/admin.js +0 -6
  86. data/public/javascripts/admin/address_states.js +5 -5
  87. data/public/javascripts/application.js +2 -2
  88. data/public/stylesheets/admin/admin.css +0 -29
  89. data/public/stylesheets/screen.css +1 -0
  90. metadata +97 -79
  91. data/app/models/spree/alert.rb +0 -13
  92. data/app/views/account/login.html.erb +0 -4
  93. data/app/views/admin/configurations/new.html.erb +0 -13
  94. data/app/views/admin/payments/_card_form.html.erb +0 -49
  95. data/app/views/admin/shared/_alert.html.erb +0 -6
  96. data/lib/spree_core/find_by_param.rb +0 -119
@@ -1,13 +1,2 @@
1
- class Admin::TaxCategoriesController < Admin::BaseController
2
- resource_controller
3
-
4
- create.response do |wants|
5
- wants.html { redirect_to collection_url }
6
- end
7
-
8
- update.response do |wants|
9
- wants.html { redirect_to collection_url }
10
- end
11
-
12
- destroy.success.wants.js { render_js_for_destroy }
1
+ class Admin::TaxCategoriesController < Admin::ResourceController
13
2
  end
@@ -1,21 +1,11 @@
1
- class Admin::TaxRatesController < Admin::BaseController
2
- resource_controller
1
+ class Admin::TaxRatesController < Admin::ResourceController
3
2
  before_filter :load_data
4
3
 
5
- create.success.wants.html { redirect_to collection_url }
6
- update.success.wants.html { redirect_to collection_url }
7
- destroy.success.wants.js { render_js_for_destroy }
8
-
9
4
  update.after :update_after
10
5
  create.after :create_after
11
6
 
12
7
  private
13
- def build_object
14
- @object ||= end_of_association_chain.send((parent? ? :build : :new), object_params)
15
- @object.calculator = params[:tax_rate][:calculator_type].constantize.new if params[:tax_rate]
16
- @object.calculator ||= Calculator::SalesTax.new
17
- @object
18
- end
8
+
19
9
  def load_data
20
10
  @available_zones = Zone.order(:name)
21
11
  @available_categories = TaxCategory.order(:name)
@@ -1,17 +1,16 @@
1
- class Admin::TaxonomiesController < Admin::BaseController
2
- resource_controller
3
-
4
- create.wants.html {redirect_to edit_admin_taxonomy_url(@taxonomy)}
5
- update.wants.html {redirect_to collection_url}
6
-
7
- edit.response do |wants|
8
- wants.html
9
- wants.js do
10
- render :partial => 'edit.html.erb'
11
- end
12
- end
1
+ class Admin::TaxonomiesController < Admin::ResourceController
13
2
 
14
3
  def get_children
15
4
  @taxons = Taxon.find(params[:parent_id]).children
16
5
  end
6
+
7
+ private
8
+
9
+ def location_after_save
10
+ if @taxonomy.created_at == @taxonomy.updated_at
11
+ edit_admin_taxonomy_url(@taxonomy)
12
+ else
13
+ admin_taxonomies_url
14
+ end
15
+ end
17
16
  end
@@ -1,60 +1,26 @@
1
1
  class Admin::TaxonsController < Admin::BaseController
2
2
  include Railslove::Plugins::FindByParam::SingletonMethods
3
- resource_controller
4
- before_filter :load_object, :only => [:selected, :available, :remove]
5
- before_filter :load_permalink_part, :only => :edit
6
- belongs_to :product, :taxonomy
7
3
 
8
- create.wants.html {render :text => @taxon.id}
9
- update.wants.html {redirect_to edit_admin_taxonomy_url(@taxonomy)}
10
- update.wants.json {render :json => @taxon.to_json()}
11
-
12
- destroy.wants.html {render :text => ""}
13
- destroy.success.wants.js { render_js_for_destroy }
14
-
15
- create.before :create_before
16
- update.before :update_before
17
- update.after :update_after
18
-
19
- def selected
20
- @taxons = @product.taxons
21
- end
22
-
23
- def available
24
- if params[:q].blank?
25
- @available_taxons = []
4
+ def create
5
+ @taxonomy = Taxonomy.find(params[:taxonomy_id])
6
+ @taxon = @taxonomy.taxons.build(params[:taxon])
7
+ if @taxon.save
8
+ render :text => @taxon
26
9
  else
27
- @available_taxons = Taxon.where('lower(name) LIKE ?', "%#{params[:q].mb_chars.downcase}%")
28
- end
29
- @available_taxons.delete_if { |taxon| @product.taxons.include?(taxon) }
30
- respond_to do |format|
31
- format.js {render :layout => false}
10
+ flash[:error] = I18n.t('errors.messages.could_not_create_taxon')
11
+ redirect_to @taxonomy ? edit_admin_taxonomy_url(@taxonomy) : admin_taxonomies_url
32
12
  end
33
-
34
13
  end
35
14
 
36
- def remove
37
- @product.taxons.delete(@taxon)
38
- @product.save
39
- @taxons = @product.taxons
40
- render_js_for_destroy
41
- end
42
-
43
- def select
44
- @product = Product.find_by_param!(params[:product_id])
45
- @taxon = Taxon.find(params[:id])
46
- @product.taxons << @taxon
47
- @product.save
48
- @taxons = @product.taxons
49
- render :layout => false
15
+ def edit
16
+ @taxonomy = Taxonomy.find(params[:taxonomy_id])
17
+ @taxon = @taxonomy.taxons.find(params[:id])
18
+ @permalink_part = @taxon.permalink.split("/").last
50
19
  end
51
20
 
52
- private
53
- def create_before
54
- @taxon.taxonomy_id = params[:taxonomy_id]
55
- end
56
-
57
- def update_before
21
+ def update
22
+ @taxonomy = Taxonomy.find(params[:taxonomy_id])
23
+ @taxon = @taxonomy.taxons.find(params[:id])
58
24
  parent_id = params[:taxon][:parent_id]
59
25
  new_position = params[:taxon][:position]
60
26
 
@@ -84,7 +50,7 @@ class Admin::TaxonsController < Admin::BaseController
84
50
  end
85
51
  # Reset legacy position, if any extensions still rely on it
86
52
  new_parent.children.reload.each{|t| t.update_attribute(:position, t.position)}
87
-
53
+
88
54
  if parent_id
89
55
  @taxon.reload
90
56
  @taxon.set_permalink
@@ -100,9 +66,11 @@ class Admin::TaxonsController < Admin::BaseController
100
66
  end
101
67
  #check if we need to rename child taxons if parent name or permalink changes
102
68
  @update_children = true if params[:taxon][:name] != @taxon.name || params[:taxon][:permalink] != @taxon.permalink
103
- end
104
69
 
105
- def update_after
70
+ if @taxon.update_attributes(params[:taxon])
71
+ flash[:notice] = I18n.t(:successfully_updated, :resource => I18n.t(:taxon) + " \"#{@taxon.name}\"")
72
+ end
73
+
106
74
  #rename child taxons
107
75
  if @update_children
108
76
  @taxon.descendants.each do |taxon|
@@ -111,9 +79,62 @@ class Admin::TaxonsController < Admin::BaseController
111
79
  taxon.save!
112
80
  end
113
81
  end
82
+
83
+ respond_to do |format|
84
+ format.html {redirect_to edit_admin_taxonomy_url(@taxonomy) }
85
+ format.json {render :json => @taxon.to_json }
86
+ end
87
+ end
88
+
89
+ def destroy
90
+ @taxon = Taxon.find(params[:id])
91
+ @taxon.destroy
92
+ respond_to do |format|
93
+ format.html { render :text => '' }
94
+ format.js { render_js_for_destroy }
95
+ end
96
+ end
97
+
98
+ def selected
99
+ @product = load_product
100
+ @taxons = @product.taxons
114
101
  end
115
102
 
116
- def load_permalink_part
117
- @permalink_part = object.permalink.split("/").last
103
+ def available
104
+ @product = load_product
105
+ if params[:q].blank?
106
+ @available_taxons = []
107
+ else
108
+ @available_taxons = Taxon.where('lower(name) LIKE ?', "%#{params[:q].mb_chars.downcase}%")
109
+ end
110
+ @available_taxons.delete_if { |taxon| @product.taxons.include?(taxon) }
111
+ respond_to do |format|
112
+ format.js {render :layout => false}
113
+ end
118
114
  end
115
+
116
+ def remove
117
+ @product = load_product
118
+ @taxon = Taxon.find(params[:id])
119
+ @product.taxons.delete(@taxon)
120
+ @product.save
121
+ @taxons = @product.taxons
122
+ render_js_for_destroy
123
+ end
124
+
125
+ def select
126
+ @product = load_product
127
+ @taxon = Taxon.find(params[:id])
128
+ @product.taxons << @taxon
129
+ @product.save
130
+ @taxons = @product.taxons
131
+ render :layout => false
132
+ end
133
+
134
+ private
135
+
136
+ def load_product
137
+ Product.find_by_permalink! params[:product_id]
138
+ end
139
+
119
140
  end
@@ -1,7 +1,2 @@
1
- class Admin::TrackersController < Admin::BaseController
2
- resource_controller
3
-
4
- update.wants.html { redirect_to collection_url }
5
- create.wants.html { redirect_to collection_url }
6
-
1
+ class Admin::TrackersController < Admin::ResourceController
7
2
  end
@@ -1,6 +1,4 @@
1
- class Admin::UsersController < Admin::BaseController
2
- resource_controller
3
-
1
+ class Admin::UsersController < Admin::ResourceController
4
2
  # http://spreecommerce.com/blog/2010/11/02/json-hijacking-vulnerability/
5
3
  before_filter :check_json_authenticity, :only => :index
6
4
  before_filter :load_roles, :only => [:edit, :new, :update, :create]
@@ -8,13 +6,43 @@ class Admin::UsersController < Admin::BaseController
8
6
  create.after :save_user_roles
9
7
  update.before :save_user_roles
10
8
 
11
- index.response do |wants|
12
- wants.html { render :action => :index }
13
- wants.json { render :json => json_data }
9
+ def index
10
+ respond_to do |format|
11
+ format.html
12
+ format.json { render :json => json_data }
13
+ end
14
14
  end
15
15
 
16
- destroy.success.wants.js { render_js_for_destroy }
17
-
16
+ protected
17
+
18
+ def collection
19
+ return @collection if @collection.present?
20
+ unless request.xhr?
21
+ @search = User.registered.metasearch(params[:search])
22
+ @collection = @search.paginate(:per_page => Spree::Config[:admin_products_per_page], :page => params[:page])
23
+ else
24
+ @collection = User.includes(:bill_address => [:state, :country], :ship_address => [:state, :country]).
25
+ where("users.email #{LIKE} :search
26
+ OR addresses.firstname #{LIKE} :search
27
+ OR addresses.lastname #{LIKE} :search
28
+ OR ship_addresses_users.firstname #{LIKE} :search
29
+ OR ship_addresses_users.lastname #{LIKE} :search",
30
+ {:search => "#{params[:q].strip}%"}).
31
+ limit(params[:limit] || 100)
32
+ end
33
+ end
34
+
35
+ def save_user_roles
36
+ return unless params[:user]
37
+ return unless @user.respond_to?(:roles) # since roles are technically added by the auth module
38
+ @user.roles.delete_all
39
+ params[:user][:role] ||= {}
40
+ Role.all.each { |role|
41
+ @user.roles << role unless params[:user][:role][role.name].blank?
42
+ }
43
+ params[:user].delete(:role)
44
+ end
45
+
18
46
  private
19
47
 
20
48
  # Allow different formats of json data to suit different ajax calls
@@ -30,35 +58,8 @@ class Admin::UsersController < Admin::BaseController
30
58
  end
31
59
  end
32
60
 
33
- def collection
34
- return @collection if @collection.present?
35
- unless request.xhr?
36
- @search = User.registered.metasearch(params[:search])
37
- @collection = @search.paginate(:per_page => Spree::Config[:admin_products_per_page], :page => params[:page])
38
-
39
- #scope = scope.conditions "lower(email) = ?", @filter.email.downcase unless @filter.email.blank?
40
- else
41
- @collection = User.includes(:bill_address => [:state, :country], :ship_address => [:state, :country]).where("users.email like :search
42
- OR addresses.firstname like :search
43
- OR addresses.lastname like :search
44
- OR ship_addresses_users.firstname like :search
45
- OR ship_addresses_users.lastname like :search",
46
- {:search => "#{params[:q].strip}%"}).limit(params[:limit] || 100)
47
- end
48
- end
49
-
50
61
  def load_roles
51
62
  @roles = Role.all
52
63
  end
53
64
 
54
- def save_user_roles
55
- return unless params[:user]
56
- return unless @user.respond_to?(:roles) # since roles are technically added by the auth module
57
- @user.roles.delete_all
58
- params[:user][:role] ||= {}
59
- Role.all.each { |role|
60
- @user.roles << role unless params[:user][:role][role.name].blank?
61
- }
62
- params[:user].delete(:role)
63
- end
64
65
  end
@@ -1,23 +1,7 @@
1
- class Admin::VariantsController < Admin::BaseController
2
- resource_controller
3
- belongs_to :product
4
-
5
- new_action.response do |wants|
6
- wants.html {render :action => :new, :layout => !request.xhr?}
7
- end
8
-
1
+ class Admin::VariantsController < Admin::ResourceController
2
+ belongs_to :product, :find_by => :permalink
9
3
  create.before :create_before
10
4
 
11
- # redirect to index (instead of r_c default of show view)
12
- create.response do |wants|
13
- wants.html {redirect_to collection_url}
14
- end
15
-
16
- # redirect to index (instead of r_c default of show view)
17
- update.response do |wants|
18
- wants.html {redirect_to collection_url}
19
- end
20
-
21
5
  # override the destory method to set deleted_at value
22
6
  # instead of actually deleting the product.
23
7
  def destroy
@@ -47,7 +31,7 @@ class Admin::VariantsController < Admin::BaseController
47
31
  end
48
32
  end
49
33
 
50
- private
34
+ protected
51
35
  def create_before
52
36
  option_values = params[:new_variant]
53
37
  option_values.each_value {|id| @object.option_values << OptionValue.find(id)}
@@ -55,12 +39,13 @@ class Admin::VariantsController < Admin::BaseController
55
39
  end
56
40
 
57
41
  def collection
58
- @deleted = (params.key?(:deleted) && params[:deleted] == "on") ? "checked" : ""
42
+ @deleted = (params.key?(:deleted) && params[:deleted] == "on") ? "checked" : ""
59
43
 
60
44
  if @deleted.blank?
61
- @collection ||= end_of_association_chain
45
+ @collection ||= super
62
46
  else
63
- @collection ||= Variant.where(:product_id => @product.id).deleted
47
+ @collection ||= Variant.where(:product_id => parent.id).deleted
64
48
  end
49
+ @collection
65
50
  end
66
51
  end
@@ -1,35 +1,22 @@
1
- class Admin::ZonesController < Admin::BaseController
2
- resource_controller
3
-
4
- before_filter :load_data
5
-
6
- create.response do |wants|
7
- wants.html { redirect_to collection_url }
8
- end
9
-
10
- update.response do |wants|
11
- wants.html { redirect_to collection_url }
12
- end
13
-
14
- destroy.success.wants.js { render_js_for_destroy }
15
-
16
- private
17
- def build_object
18
- @object ||= end_of_association_chain.send parent? ? :build : :new, object_params
19
- @object.zone_members.build() if @object.zone_members.empty?
20
- @object
1
+ class Admin::ZonesController < Admin::ResourceController
2
+ before_filter :load_data, :except => [:index]
3
+
4
+ def new
5
+ @zone.zone_members.build
21
6
  end
7
+
8
+ protected
22
9
 
23
10
  def collection
24
11
  params[:search] ||= {}
25
12
  params[:search][:meta_sort] ||= "ascend_by_name"
26
- @search = end_of_association_chain.metasearch(params[:search])
27
- @collection = @search.paginate(:per_page => Spree::Config[:orders_per_page], :page => params[:page])
13
+ @search = super.metasearch(params[:search])
14
+ @zones = @search.paginate(:per_page => Spree::Config[:orders_per_page], :page => params[:page])
28
15
  end
29
16
 
30
17
  def load_data
31
- @countries = Country.all.sort
32
- @states = State.all.sort
33
- @zones = Zone.all.sort
18
+ @countries = Country.order(:name)
19
+ @states = State.order(:name)
20
+ @zones = Zone.order(:name)
34
21
  end
35
22
  end
@@ -64,8 +64,8 @@ class CheckoutController < Spree::BaseController
64
64
  end
65
65
 
66
66
  def before_address
67
- @order.bill_address ||= Address.new(:country_id => default_country_id)
68
- @order.ship_address ||= Address.new(:country_id => default_country_id)
67
+ @order.bill_address ||= Address.default
68
+ @order.ship_address ||= Address.default
69
69
  end
70
70
 
71
71
  def before_delivery
@@ -81,10 +81,6 @@ class CheckoutController < Spree::BaseController
81
81
  session[:order_id] = nil
82
82
  end
83
83
 
84
- def default_country_id
85
- Spree::Config[:default_country_id]
86
- end
87
-
88
84
  def rescue_from_spree_gateway_error
89
85
  flash[:error] = t('spree_gateway_error_flash_for_checkout')
90
86
  render :edit