mirror of
https://github.com/openfoodfoundation/openfoodnetwork
synced 2026-01-24 20:36:49 +00:00
Added 'Add Another' link to new product page. Altered redirects
This commit is contained in:
@@ -5,6 +5,13 @@ Spree::Admin::ProductsController.class_eval do
|
||||
|
||||
respond_to :json, :only => :clone
|
||||
|
||||
respond_override create: { html: { success: lambda {
|
||||
if params[:button] == "add_another"
|
||||
redirect_to new_admin_product_path
|
||||
else
|
||||
redirect_to '/admin/products/bulk_edit'
|
||||
end
|
||||
} } }
|
||||
#respond_override :clone => { :json => {:success => lambda { redirect_to bulk_index_admin_products_url+"?q[id_eq]=#{@new.id}" } } }
|
||||
|
||||
def product_distributions
|
||||
|
||||
@@ -68,7 +68,14 @@
|
||||
.row
|
||||
= button "Select An image"
|
||||
.sixteen.columns.alpha
|
||||
= render :partial => 'spree/admin/shared/new_resource_links'
|
||||
.form-buttons.filter-actions.actions{ 'data-hook' => "buttons" }
|
||||
= button t('actions.create'), 'icon-ok', :submit, value: "create"
|
||||
%span.or
|
||||
= t(:or)
|
||||
= button "Create And Add Another", 'icon-repeat', :submit, value: 'add_another'
|
||||
%span.or
|
||||
= t(:or)
|
||||
= link_to_with_icon 'icon-remove', t('actions.cancel'), collection_url, :class => 'button'
|
||||
|
||||
|
||||
|
||||
|
||||
51
spec/controllers/spree/admin/products_controller_spec.rb
Normal file
51
spec/controllers/spree/admin/products_controller_spec.rb
Normal file
@@ -0,0 +1,51 @@
|
||||
require 'spec_helper'
|
||||
|
||||
describe Spree::Admin::ProductsController do
|
||||
context "Creating a new product" do
|
||||
let(:user) do
|
||||
user = create(:user)
|
||||
user.spree_roles << Spree::Role.find_or_create_by_name!('admin')
|
||||
user
|
||||
end
|
||||
|
||||
before do
|
||||
controller.stub spree_current_user: user
|
||||
end
|
||||
|
||||
it "redirects to bulk_edit when the user hits 'create'" do
|
||||
s = create(:supplier_enterprise)
|
||||
spree_post :create, {
|
||||
product: {
|
||||
name: "Product1",
|
||||
supplier_id: s.id,
|
||||
price: 5.0,
|
||||
on_hand: 5,
|
||||
variant_unit: 'weight',
|
||||
variant_unit_scale: 1000,
|
||||
unit_value: 10,
|
||||
unit_description: ""
|
||||
},
|
||||
button: 'create'
|
||||
}
|
||||
response.should redirect_to "/admin/products/bulk_edit"
|
||||
end
|
||||
|
||||
it "redirects to new when the user hits 'add_another'" do
|
||||
s = create(:supplier_enterprise)
|
||||
spree_post :create, {
|
||||
product: {
|
||||
name: "Product1",
|
||||
supplier_id: s.id,
|
||||
price: 5.0,
|
||||
on_hand: 5,
|
||||
variant_unit: 'weight',
|
||||
variant_unit_scale: 1000,
|
||||
unit_value: 10,
|
||||
unit_description: ""
|
||||
},
|
||||
button: 'add_another'
|
||||
}
|
||||
response.should redirect_to "/admin/products/new"
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user