Added 'Add Another' link to new product page. Altered redirects

This commit is contained in:
Rob H
2014-05-29 12:13:55 +10:00
parent e110677b3b
commit 9b10a2cb94
3 changed files with 66 additions and 1 deletions

View File

@@ -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

View File

@@ -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'

View 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