_select_categories.rhtml
2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
<div id="category-ajax-selector">
<% if !@current_category.nil? %>
<h3 class="box-title"><%= _('Current category:') %></h3>
<%= hidden_field_tag "#{object_name}[#{object_name}_category_id]", @current_category.id unless multiple %>
<%
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(' → ')
%>
<strong>
<%= button_to_function_without_text(:save, _('Save'), nil, :id => 'save-category-button') do |page|
page.insert_html :bottom, 'selected-categories', content_tag('li', categories.first.full_name +
hidden_field_tag("#{object_name}[category_ids][]", categories.first.id) +
button_to_function_without_text(:cancel, _('Remove'), nil, :id => "remove-selected-category-#{categories.first.id}-button") {|page| page["selected-category-#{categories.first.id}"].remove}, :id => "selected-category-#{categories.first.id}")
end if multiple %>
<%= button_to_remote_without_text(:cancel, _('Cancel'),
{ :update => "select-categories",
:url => { :action => 'update_categories', :id => @object },
:loaded => visual_effect(:highlight, "select-categories")
},
:id => 'cancel-category-button') %>
</strong>
<% else %>
<h3 class="box-title"><%= _('Select a category:') %></h3>
<% end %>
<% if !@categories.empty? %>
<h3><%= _('Categories:') %></h3>
<% @categories.select{|i| !@object.respond_to?(:accept_category?) || @object.accept_category?(i)}.each do |category| %>
<%= link_to_remote category.name,
{ :update => "select-categories",
:url => { :action => "update_categories", :category_id => category.id, :id => @object},
:loaded => visual_effect(:highlight, "select-categories")
},
:class => 'select-subcategory-link',
:id => "select-category-#{category.id}-link"
%>
<% end %>
<% end %>
</div>