diff --git a/app/controllers/my_profile/manage_products_controller.rb b/app/controllers/my_profile/manage_products_controller.rb index a26f302..84d267c 100644 --- a/app/controllers/my_profile/manage_products_controller.rb +++ b/app/controllers/my_profile/manage_products_controller.rb @@ -35,7 +35,7 @@ class ManageProductsController < ApplicationController end def categories_for_selection - @category = Category.find(params[:category_id]) if params[:category_id] + @category = environment.categories.find_by_id params[:category_id] @object_name = params[:object_name] if @category @categories = @category.children @@ -95,6 +95,20 @@ class ManageProductsController < ApplicationController end end + def show_category_tree + @category = environment.categories.find params[:category_id] + render :partial => 'selected_category_tree' + end + + def search_categories + @term = params[:term].downcase + conditions = ['LOWER(name) LIKE ? OR LOWER(name) LIKE ?', "#{@term}%", "% #{@term}%"] + @categories = ProductCategory.all :conditions => conditions, :limit => 10 + render :json => (@categories.map do |category| + {:label => category.name, :value => category.id} + end) + end + def add_input @product = @profile.products.find(params[:id]) @input = @product.inputs.build diff --git a/app/helpers/manage_products_helper.rb b/app/helpers/manage_products_helper.rb index f0b57d4..6e05369 100644 --- a/app/helpers/manage_products_helper.rb +++ b/app/helpers/manage_products_helper.rb @@ -75,9 +75,12 @@ module ManageProductsHelper end def categories_container(categories_selection_html, hierarchy_html = '') - hidden_field_tag('selected_category_id') + - content_tag('div', hierarchy_html, :id => 'hierarchy_navigation') + - content_tag('div', categories_selection_html, :id => 'categories_container_wrapper') + content_tag 'div', + render('categories_autocomplete') + + hidden_field_tag('selected_category_id') + + content_tag('div', hierarchy_html, :id => 'hierarchy_navigation') + + content_tag('div', categories_selection_html, :id => 'categories_container_wrapper'), + :id => 'categories-container' end def select_for_categories(categories, level = 0) diff --git a/app/views/manage_products/_categories_autocomplete.html.erb b/app/views/manage_products/_categories_autocomplete.html.erb new file mode 100644 index 0000000..a6f7bfa --- /dev/null +++ b/app/views/manage_products/_categories_autocomplete.html.erb @@ -0,0 +1,8 @@ +<%= text_field_tag 'product_category_id', '', :placeholder => _('type a category for the product') %> + +<%= javascript_include_tag '/javascripts/product_categories.js' %> +<% javascript_tag do %> + product_categories.autocomplete.search_url = <%= url_for(:controller => :manage_products, :action => :search_categories).to_json %> + product_categories.autocomplete.select_url = <%= url_for(:controller => :manage_products, :action => :show_category_tree).to_json %> + product_categories.autocomplete.load('#product_category_id') +<% end %> diff --git a/app/views/manage_products/_selected_category_tree.html.erb b/app/views/manage_products/_selected_category_tree.html.erb new file mode 100644 index 0000000..120d6b5 --- /dev/null +++ b/app/views/manage_products/_selected_category_tree.html.erb @@ -0,0 +1,2 @@ +<%= categories_container selects_for_all_ancestors(@category), hierarchy_category_navigation(@category, :make_links => true) %> + diff --git a/app/views/manage_products/edit_category.html.erb b/app/views/manage_products/edit_category.html.erb index 748c3d5..7980257 100644 --- a/app/views/manage_products/edit_category.html.erb +++ b/app/views/manage_products/edit_category.html.erb @@ -16,7 +16,7 @@