app/views/shared/_select_categories.html.erb
<% extend CategoriesHelper %>
<div class="category-helper-label">
<%= _('Select a %s and click on the Add button') % _(kind.to_s.singularize) %>
</div>
<div class="categories-chain">
<% if !@current_category.nil? %>
<%= hidden_field_tag "#{object_name}[#{object_name}_category_id]", @current_category.id unless multiple %>
<%= hidden_field_tag "#{object_name}[category_ids][]", @current_category.id if multiple %>
<%= button_without_text(:trash, _('Cancel'),
{ :action => "update_categories", :category_id => nil, :id => @object, :kind => kind },
:remote => true, :id => 'cancel-category-button', :class => 'icon-cancel' ) %>
<%
categories = [@current_category]
categories.push(@current_category) while @current_category = @current_category.parent
%>
<%= categories.compact.reverse.map do |i| %>
<% link_to i.name,
{ :action => "update_categories", :category_id => i.id, :id => @object, :kind => kind },
{ :id => "select-category-#{i.id}-link", :remote => true, :class => "select-subcategory-link", 'data-id' => i.id } %>
<% end.join(' → ').html_safe %>
<script>
// TODO: use js.erb to render those items
function add_category() {
jQuery('#selected-categories ').append('<%= j(render :partial => "shared/category_row", :locals => {:category => categories.first, :object_name => object_name}) %>');
jQuery('#selected-categories #empty-row').hide()
var subcategories = '<%= j(render :partial => "shared/select_subcategories", :locals => { :object_name => object_name, :categories => @toplevel_categories, :kind => kind }) %>';
jQuery('#select-categories').html(subcategories);
filter_category_links()
}
</script>
<%= button_to_function_without_text(:add, _('Add'), 'add_category()', :id => 'save-category-button') %>
<% end %>
</div>
<%= render :partial => 'shared/select_subcategories',
:locals => { :object_name => object_name, :categories => @categories, :kind => kind } %>