_select_categories.rhtml 1.69 KB
<% extend CategoriesHelper %>

<% 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_to_remote_without_text(:back, _('Back'),
      { :update => "select-categories",
        :url => { :action => 'update_categories', :id => @object },
        :loaded => visual_effect(:highlight, "select-categories")
      },
      :id => 'cancel-category-button') %>
  <%
    categories = [@current_category]
    categories.push(@current_category) while @current_category = @current_category.parent
  %>
  <%= categories.compact.reverse.map{|i|
    link_to_remote(i.name,
      :update => "select-categories",
      :url => { :action => 'update_categories', :category_id => i.id, :id => @object },
      :loaded => visual_effect(:highlight, "select-categories"),
      :class => 'select-current-category-link')}.join(' &rarr; ')
  %>
  <%= button_to_function_without_text(:add, _('Add'), nil, :id => 'save-category-button') do |page|
    page.insert_html :bottom, 'selected-categories', content_tag('div',
      hidden_field_tag("#{object_name}[category_ids][]", categories.first.id) +
      selected_category_link(categories.first), :id => "selected-category-#{categories.first.id}")
    page.replace_html 'select-categories', :partial => 'shared/select_subcategories',
      :locals => {:object_name => object_name, :categories => @toplevel_categories}
  end if multiple %>
<% end %>

<div class="toplevel-categories">
  <%= render :partial => 'shared/select_subcategories', :locals => {:object_name => object_name, :categories => @categories} %>
</div>