Commit 2be42e591c913abc01acb3efc5e55ed7eb808959
1 parent
a70c44b1
Exists in
master
and in
29 other branches
ActionItem726: new products begin selecting top level categories
Showing
3 changed files
with
26 additions
and
20 deletions
Show diff stats
app/controllers/my_profile/manage_products_controller.rb
| ... | ... | @@ -23,9 +23,8 @@ class ManageProductsController < ApplicationController |
| 23 | 23 | end |
| 24 | 24 | |
| 25 | 25 | def new |
| 26 | - @current_category = ProductCategory.top_level_for(environment).first | |
| 27 | 26 | @object = Product.new |
| 28 | - @categories = @current_category.nil? ? [] : @current_category.children | |
| 27 | + @categories = @current_category.nil? ? ProductCategory.top_level_for(environment) : @current_category.children | |
| 29 | 28 | @product = @profile.products.build(params[:product]) |
| 30 | 29 | @product.build_image unless @product.image |
| 31 | 30 | if request.post? |
| ... | ... | @@ -75,9 +74,10 @@ class ManageProductsController < ApplicationController |
| 75 | 74 | end |
| 76 | 75 | render :partial => 'shared/select_categories', :locals => {:object_name => 'product', :multiple => false}, :layout => false |
| 77 | 76 | end |
| 77 | + | |
| 78 | 78 | def update_subcategories |
| 79 | - @current_category = ProductCategory.find(params[:id]) | |
| 80 | - @categories = @current_category.children | |
| 79 | + @current_category = ProductCategory.find(params[:id]) if params[:id] | |
| 80 | + @categories = @current_category ? @current_category.children : ProductCategory.top_level_for(environment) | |
| 81 | 81 | render :partial => 'subcategories' |
| 82 | 82 | end |
| 83 | 83 | ... | ... |
app/views/manage_products/_subcategories.rhtml
| 1 | -<% if !@current_category.nil? and !@current_category.top_level? %> | |
| 1 | +<% if !@current_category.nil? %> | |
| 2 | 2 | |
| 3 | 3 | <p><%= _('Current category:') %></p> |
| 4 | 4 | <%= hidden_field_tag 'product[product_category_id]', @current_category.id %> |
| 5 | - <% | |
| 6 | - categories = [@current_category] | |
| 7 | - categories.push(@current_category) while @current_category = @current_category.parent | |
| 8 | - categories.last.name = _('Back') | |
| 5 | + <%= link_to_remote( _('Back'), | |
| 6 | + :update => "subcategories", | |
| 7 | + :url => { :action => 'update_subcategories', :id => nil, :loaded => visual_effect(:highlight, "subcategories") }, | |
| 8 | + :class => 'select-current-category-link') + ' → ' | |
| 9 | + %> | |
| 10 | + <%= ([@current_category] + @current_category.ancestors).reverse.map{|i| | |
| 11 | + link_to_remote(i.name, | |
| 12 | + :update => "subcategories", | |
| 13 | + :url => { :action => 'update_subcategories', :id => i, :loaded => visual_effect(:highlight, "subcategories") }, | |
| 14 | + :class => 'select-current-category-link')}.join(' → ') | |
| 9 | 15 | %> |
| 10 | - <% if categories.size > 1 %> | |
| 11 | - <%= categories.compact.reverse.map{|i| | |
| 12 | - link_to_remote(i.name, | |
| 13 | - :update => "subcategories", | |
| 14 | - :url => { :action => 'update_subcategories', :id => i, :loaded => visual_effect(:highlight, "subcategories") }, | |
| 15 | - :class => 'select-current-category-link')}.join(' → ') | |
| 16 | - %> | |
| 17 | - <% end %> | |
| 18 | - | |
| 19 | 16 | <% end %> |
| 20 | 17 | |
| 21 | -<% if @current_category %> | |
| 18 | +<% if @current_category.nil? %> | |
| 22 | 19 | <p><%= _('Select a category:') %></p> |
| 23 | 20 | <% elsif !@categories.empty? %> |
| 24 | 21 | <p><%= _('Select a subcategory:') %></p> | ... | ... |
test/functional/manage_products_controller_test.rb
| ... | ... | @@ -120,7 +120,7 @@ class ManageProductsControllerTest < Test::Unit::TestCase |
| 120 | 120 | category3 = ProductCategory.create!(:name => 'Category 3', :environment => environment, :parent => category2) |
| 121 | 121 | get :new, :profile => @enterprise.identifier |
| 122 | 122 | assert_tag :tag => 'p', :content => /Select a category:/ |
| 123 | - assert_tag :tag => 'a', :content => /#{category2.name}/ | |
| 123 | + assert_tag :tag => 'a', :content => /#{category1.name}/ | |
| 124 | 124 | end |
| 125 | 125 | |
| 126 | 126 | should 'show current category' do |
| ... | ... | @@ -265,5 +265,14 @@ class ManageProductsControllerTest < Test::Unit::TestCase |
| 265 | 265 | |
| 266 | 266 | assert_template 'not_found.rhtml' |
| 267 | 267 | end |
| 268 | + | |
| 269 | + should 'show top level product categories for the user to choose' do | |
| 270 | + pc1 = ProductCategory.create!(:name => 'test_category1', :environment => Environment.default) | |
| 271 | + pc2 = ProductCategory.create!(:name => 'test_category2', :environment => Environment.default) | |
| 272 | + | |
| 273 | + get :new, :profile => @enterprise.identifier | |
| 274 | + | |
| 275 | + assert_equivalent [pc1, pc2], assigns(:categories) | |
| 276 | + end | |
| 268 | 277 | |
| 269 | 278 | end | ... | ... |