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
@@ -0,0 +1,221 @@
1
+ require 'spree_core/action_callbacks'
2
+ class Admin::ResourceController < Admin::BaseController
3
+ helper_method :new_object_url, :edit_object_url, :object_url, :collection_url
4
+ before_filter :load_resource
5
+
6
+ respond_to :html
7
+
8
+ def new
9
+ render :layout => !request.xhr?
10
+ end
11
+
12
+ def edit
13
+ render :layout => !request.xhr?
14
+ end
15
+
16
+ def update
17
+ invoke_callbacks(:update, :before)
18
+ if @object.update_attributes(params[object_name])
19
+ invoke_callbacks(:update, :after)
20
+ resource_desc = I18n.t(object_name)
21
+ resource_desc += " \"#{@object.name}\"" if @object.respond_to?(:name)
22
+ flash[:notice] = I18n.t(:successfully_updated, :resource => resource_desc)
23
+ respond_to do |format|
24
+ format.html { redirect_to location_after_save }
25
+ format.js { render :layout => false }
26
+ end
27
+ else
28
+ invoke_callbacks(:update, :fails)
29
+ render :edit
30
+ end
31
+ end
32
+
33
+ def create
34
+ invoke_callbacks(:create, :before)
35
+ if @object.save
36
+ invoke_callbacks(:create, :after)
37
+ resource_desc = I18n.t(object_name)
38
+ resource_desc += " \"#{@object.name}\"" if @object.respond_to?(:name)
39
+ flash[:notice] = I18n.t(:successfully_created, :resource => resource_desc)
40
+ respond_to do |format|
41
+ format.html { redirect_to location_after_save }
42
+ format.js { render :layout => false }
43
+ end
44
+ else
45
+ invoke_callbacks(:create, :fails)
46
+ render :new
47
+ end
48
+ end
49
+
50
+ def destroy
51
+ invoke_callbacks(:destroy, :before)
52
+ if @object.destroy
53
+ invoke_callbacks(:destroy, :after)
54
+ resource_desc = I18n.t(object_name)
55
+ resource_desc += " \"#{@object.name}\"" if @object.respond_to?(:name)
56
+ flash[:notice] = I18n.t(:successfully_removed, :resource => resource_desc)
57
+ respond_to do |format|
58
+ format.html { redirect_to collection_url }
59
+ format.js { render :partial => "/admin/shared/destroy" }
60
+ end
61
+ else
62
+ invoke_callbacks(:destroy, :fails)
63
+ redirect_to collection_url
64
+ end
65
+ end
66
+
67
+ protected
68
+
69
+ class << self
70
+ attr_accessor :parent_data
71
+ attr_accessor :callbacks
72
+
73
+ def belongs_to(model_name, options = {})
74
+ @parent_data ||= {}
75
+ @parent_data[:model_name] = model_name
76
+ @parent_data[:model_class] = model_name.to_s.classify.constantize
77
+ @parent_data[:find_by] = options[:find_by] || :id
78
+ end
79
+
80
+ def create
81
+ @callbacks ||= {}
82
+ @callbacks[:create] ||= Spree::ActionCallbacks.new
83
+ end
84
+
85
+ def update
86
+ @callbacks ||= {}
87
+ @callbacks[:update] ||= Spree::ActionCallbacks.new
88
+ end
89
+
90
+ def destroy
91
+ @callbacks ||= {}
92
+ @callbacks[:destroy] ||= Spree::ActionCallbacks.new
93
+ end
94
+ end
95
+
96
+ def model_class
97
+ controller_name.classify.constantize
98
+ end
99
+
100
+ def object_name
101
+ controller_name.singularize
102
+ end
103
+
104
+ def load_resource
105
+ if member_action?
106
+ @object ||= load_resource_instance
107
+ instance_variable_set("@#{object_name}", @object)
108
+ else
109
+ @collection ||= collection
110
+ instance_variable_set("@#{controller_name}", @collection)
111
+ end
112
+ end
113
+
114
+ def load_resource_instance
115
+ if new_actions.include?(params[:action].to_sym)
116
+ build_resource
117
+ elsif params[:id]
118
+ find_resource
119
+ end
120
+ end
121
+
122
+ def parent_data
123
+ self.class.parent_data
124
+ end
125
+
126
+ def parent
127
+ if parent_data.present?
128
+ @parent ||= parent_data[:model_class].where(parent_data[:find_by] => params["#{parent_data[:model_name]}_id"]).first
129
+ instance_variable_set("@#{parent_data[:model_name]}", @parent)
130
+ else
131
+ nil
132
+ end
133
+ end
134
+
135
+ def find_resource
136
+ if parent_data.present?
137
+ parent.send(controller_name).find(params[:id])
138
+ else
139
+ model_class.find(params[:id])
140
+ end
141
+ end
142
+
143
+ def build_resource
144
+ if parent_data.present?
145
+ parent.send(controller_name).build(params[object_name])
146
+ else
147
+ model_class.new(params[object_name])
148
+ end
149
+ end
150
+
151
+ def collection
152
+ return parent.send(controller_name) if parent_data.present?
153
+
154
+ if model_class.respond_to?(:accessible_by) && !current_ability.has_block?(params[:action], model_class)
155
+ model_class.accessible_by(current_ability)
156
+ else
157
+ model_class.scoped
158
+ end
159
+ end
160
+
161
+ def location_after_save
162
+ collection_url
163
+ end
164
+
165
+ def invoke_callbacks(action, callback_type)
166
+ callbacks = self.class.callbacks || {}
167
+ return if callbacks[action].nil?
168
+ case callback_type.to_sym
169
+ when :before then callbacks[action].before_methods.each {|method| send method }
170
+ when :after then callbacks[action].after_methods.each {|method| send method }
171
+ when :fails then callbacks[action].fails_methods.each {|method| send method }
172
+ end
173
+ end
174
+
175
+ # URL helpers
176
+
177
+ def new_object_url(options = {})
178
+ if parent_data.present?
179
+ new_polymorphic_url([:admin, parent, model_class], options)
180
+ else
181
+ new_polymorphic_url([:admin, model_class], options)
182
+ end
183
+ end
184
+
185
+ def edit_object_url(object, options = {})
186
+ if parent_data.present?
187
+ send "edit_admin_#{parent_data[:model_name]}_#{object_name}_url", parent, object, options
188
+ else
189
+ send "edit_admin_#{object_name}_url", object, options
190
+ end
191
+ end
192
+
193
+ def object_url(object = nil, options = {})
194
+ target = object ? object : @object
195
+ if parent_data.present?
196
+ send "admin_#{parent_data[:model_name]}_#{object_name}_url", parent, target, options
197
+ else
198
+ send "admin_#{object_name}_url", target, options
199
+ end
200
+ end
201
+
202
+ def collection_url(options = {})
203
+ if parent_data.present?
204
+ polymorphic_url([:admin, parent, model_class], options)
205
+ else
206
+ polymorphic_url([:admin, model_class], options)
207
+ end
208
+ end
209
+
210
+ def collection_actions
211
+ [:index]
212
+ end
213
+
214
+ def member_action?
215
+ !collection_actions.include? params[:action].to_sym
216
+ end
217
+
218
+ def new_actions
219
+ [:new, :create]
220
+ end
221
+ end
@@ -1,22 +1,16 @@
1
- class Admin::ReturnAuthorizationsController < Admin::BaseController
2
- resource_controller
3
- belongs_to :order
4
-
5
- update.wants.html { redirect_to collection_url }
6
- create.wants.html { redirect_to collection_url }
7
- destroy.success.wants.js { render_js_for_destroy }
1
+ class Admin::ReturnAuthorizationsController < Admin::ResourceController
2
+ belongs_to :order, :find_by => :number
8
3
 
9
4
  update.after :associate_inventory_units
10
5
  create.after :associate_inventory_units
11
6
 
12
7
  def fire
13
- load_object
14
8
  @return_authorization.send("#{params[:e]}!")
15
9
  flash.notice = t('return_authorization_updated')
16
10
  redirect_to :back
17
11
  end
18
12
 
19
- private
13
+ protected
20
14
  def associate_inventory_units
21
15
  params[:return_quantity].each { |variant_id, qty| @return_authorization.add_variant(variant_id.to_i, qty.to_i) }
22
16
  end
@@ -1,29 +1,65 @@
1
1
  class Admin::ShipmentsController < Admin::BaseController
2
- before_filter :load_data, :except => [:country_changed, :index]
2
+ before_filter :load_order
3
+ before_filter :load_shipment, :only => [:destroy, :edit, :update, :fire]
4
+ before_filter :load_shipping_methods, :except => [:country_changed, :index]
3
5
 
4
- resource_controller
5
- belongs_to :order
6
+ respond_to :html
6
7
 
7
- update.wants.html do
8
- if @order.completed?
9
- redirect_to edit_object_url
10
- else
11
- redirect_to admin_order_adjustments_url(@order)
12
- end
8
+ def index
9
+ @shipments = @order.shipments
10
+ respond_with(@shipments)
13
11
  end
14
12
 
15
- create do
16
- wants.html { redirect_to edit_object_url }
13
+ def new
14
+ build_shipment
15
+ @shipment.address ||= @order.ship_address
16
+ @shipment.address ||= Address.new(:country_id => Spree::Config[:default_country_id])
17
+ @shipment.shipping_method = @order.shipping_method
18
+ respond_with(@shipment)
17
19
  end
18
20
 
19
- edit.before :edit_before
21
+ def create
22
+ build_shipment
23
+ assign_inventory_units
24
+ if @shipment.save
25
+ flash[:notice] = I18n.t(:successfully_created, :resource => 'shipment')
26
+ respond_with(@object) do |format|
27
+ format.html { redirect_to edit_admin_order_shipment_path(@order, @shipment) }
28
+ end
29
+ else
30
+ render :action => 'new'
31
+ end
32
+ end
20
33
 
21
- update.before :assign_inventory_units
22
- update.after :update_after
34
+ def edit
35
+ @shipment.special_instructions = @order.special_instructions
36
+ respond_with(@shipment)
37
+ end
23
38
 
24
- create.before :assign_inventory_units
39
+ def update
40
+ assign_inventory_units
41
+ if @shipment.update_attributes params[:shipment]
42
+ # copy back to order if instructions are enabled
43
+ @order.special_instructions = object_params[:special_instructions] if Spree::Config[:shipping_instructions]
44
+ @order.shipping_method = @order.shipment.shipping_method
45
+ @order.save
46
+
47
+ flash[:notice] = I18n.t(:successfully_updated, :resource => I18n.t('shipment'))
48
+ return_path = @order.completed? ? edit_admin_order_shipment_path(@order, @shipment) : admin_order_adjustments_path(@order)
49
+ respond_with(@object) do |format|
50
+ format.html { redirect_to return_path }
51
+ end
52
+ else
53
+ render :action => 'edit'
54
+ end
55
+ end
25
56
 
26
- destroy.success.wants.js { render_js_for_destroy }
57
+ def destroy
58
+ @shipment.destroy
59
+ respond_to do |format|
60
+ format.js { render_js_for_destroy }
61
+ end
62
+ end
27
63
 
28
64
  def fire
29
65
  if @shipment.send("#{params[:e]}")
@@ -35,33 +71,30 @@ class Admin::ShipmentsController < Admin::BaseController
35
71
  end
36
72
 
37
73
  private
38
- def build_object
39
- @object ||= end_of_association_chain.send parent? ? :build : :new
40
- @object.address ||= @order.ship_address
41
- @object.address ||= Address.new(:country_id => Spree::Config[:default_country_id])
42
- @object.shipping_method ||= @order.shipping_method
43
- @object.attributes = object_params
44
- @object
45
- end
46
74
 
47
- def load_data
48
- load_object
75
+ def load_shipping_methods
49
76
  @shipping_methods = ShippingMethod.all_available(@order, :back_end)
50
77
  end
51
78
 
52
- def edit_before # copy into instance variable before editing
53
- @shipment.special_instructions = @order.special_instructions
79
+ def assign_inventory_units
80
+ return unless params.has_key? :inventory_units
81
+ @shipment.inventory_unit_ids = params[:inventory_units].keys
54
82
  end
55
83
 
56
- def update_after # copy back to order if instructions are enabled
57
- @order.special_instructions = object_params[:special_instructions] if Spree::Config[:shipping_instructions]
58
- @order.shipping_method = @order.shipment.shipping_method
59
- @order.save
84
+ def load_order
85
+ @order = Order.find_by_number(params[:order_id])
60
86
  end
61
87
 
62
- def assign_inventory_units
63
- return unless params.has_key? :inventory_units
64
- @shipment.inventory_unit_ids = params[:inventory_units].keys
88
+ def load_shipment
89
+ @shipment = Shipment.find_by_number(params[:id])
90
+ end
91
+
92
+ def build_shipment
93
+ @shipment = @order.shipments.build
94
+ @shipment.address ||= @order.ship_address
95
+ @shipment.address ||= Address.new(:country_id => Spree::Config[:default_country_id])
96
+ @shipment.shipping_method ||= @order.shipping_method
97
+ @shipment.attributes = params[:shipment]
65
98
  end
66
99
 
67
100
  end
@@ -1,16 +1,2 @@
1
- class Admin::ShippingCategoriesController < Admin::BaseController
2
- resource_controller
3
-
4
- layout 'admin'
5
-
6
- update.response do |wants|
7
- wants.html { redirect_to collection_url }
8
- end
9
-
10
- create.response do |wants|
11
- wants.html { redirect_to collection_url }
12
- end
13
-
14
- destroy.success.wants.js { render_js_for_destroy }
15
-
1
+ class Admin::ShippingCategoriesController < Admin::ResourceController
16
2
  end
@@ -1,20 +1,14 @@
1
- class Admin::ShippingMethodsController < Admin::BaseController
2
- resource_controller
3
- before_filter :load_data
4
-
5
- update.wants.html { redirect_to edit_object_url }
6
- create.wants.html { redirect_to edit_object_url }
7
- destroy.success.wants.js { render_js_for_destroy }
1
+ class Admin::ShippingMethodsController < Admin::ResourceController
2
+ before_filter :load_data, :except => [:index]
8
3
 
9
4
  private
10
- def build_object
11
- @object ||= end_of_association_chain.send((parent? ? :build : :new), object_params)
12
- @object.calculator = params[:shipping_method][:calculator_type].constantize.new if params[:shipping_method]
13
- @object
5
+
6
+ def location_after_save
7
+ edit_admin_shipping_method_path(@shipping_method)
14
8
  end
15
9
 
16
10
  def load_data
17
11
  @available_zones = Zone.order(:name)
18
- @calculators = ShippingMethod.calculators.sort_by(&:description)
12
+ @calculators = ShippingMethod.calculators.sort_by(&:name)
19
13
  end
20
14
  end
@@ -1,30 +1,25 @@
1
- class Admin::StatesController < Admin::BaseController
2
- resource_controller
3
-
1
+ class Admin::StatesController < Admin::ResourceController
4
2
  belongs_to :country
5
3
  before_filter :load_data
6
4
 
7
- index.response do |wants|
8
- wants.html
9
- wants.js do
10
- render :partial => 'state_list.html.erb'
5
+ def index
6
+ respond_to do |format|
7
+ format.html
8
+ format.js { render :partial => 'state_list.html.erb' }
11
9
  end
12
10
  end
13
11
 
14
- new_action.response do |wants|
15
- wants.html {render :layout => !request.xhr?}
16
- end
17
-
18
- create.wants.html { redirect_to admin_country_states_url(@country) }
19
- update.wants.html { redirect_to admin_country_states_url(@country) }
20
-
21
- private
12
+ protected
13
+
14
+ def location_after_save
15
+ admin_country_states_url(@country)
16
+ end
22
17
 
23
- def collection
24
- @collection ||= end_of_association_chain.order('name')
25
- end
18
+ def collection
19
+ super.order(:name)
20
+ end
26
21
 
27
- def load_data
28
- @countries = Country.order('name')
29
- end
22
+ def load_data
23
+ @countries = Country.order(:name)
24
+ end
30
25
  end