diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index 107151f..557bd6b 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -231,7 +231,7 @@ class CmsController < MyProfileController @current_category = Category.find(params[:category_id]) @categories = @current_category.children end - render :partial => 'shared/select_categories', :locals => {:object_name => 'article', :multiple => true}, :layout => false + render :template => 'shared/update_categories', :locals => { :category => @current_category } end def publish diff --git a/app/controllers/my_profile/profile_editor_controller.rb b/app/controllers/my_profile/profile_editor_controller.rb index 41b3f76..1150b14 100644 --- a/app/controllers/my_profile/profile_editor_controller.rb +++ b/app/controllers/my_profile/profile_editor_controller.rb @@ -60,7 +60,7 @@ class ProfileEditorController < MyProfileController @current_category = Category.find(params[:category_id]) @categories = @current_category.children end - render :partial => 'shared/select_categories', :locals => {:object_name => 'profile_data', :multiple => true}, :layout => false + render :template => 'shared/update_categories', :locals => { :category => @current_category } end def header_footer diff --git a/app/helpers/categories_helper.rb b/app/helpers/categories_helper.rb index f473a34..c54fc49 100644 --- a/app/helpers/categories_helper.rb +++ b/app/helpers/categories_helper.rb @@ -50,11 +50,17 @@ module CategoriesHelper #FIXME make this test def selected_category_link(cat) - js_remove = j("jQuery('#selected-category-#{cat.id}').remove();") + js_remove = "jQuery('#selected-category-#{cat.id}').remove();" content_tag('div', button_to_function_without_text(:remove, _('Remove'), js_remove) + link_to_function(cat.full_name(' → '), js_remove, :id => "remove-selected-category-#{cat.id}-button", :class => 'select-subcategory-link'), :class => 'selected-category' ) end + def update_categories_link(body, category_id=nil, html_options={}) + link_to body, + { :action => "update_categories", :category_id => category_id, :id => @object }, + {:id => category_id ? "select-category-#{category_id}-link" : nil, :remote => true, :class => 'select-subcategory-link'}.merge(html_options) + end + end diff --git a/app/views/shared/_select_categories.html.erb b/app/views/shared/_select_categories.html.erb index eb4f485..8aaf995 100644 --- a/app/views/shared/_select_categories.html.erb +++ b/app/views/shared/_select_categories.html.erb @@ -3,30 +3,25 @@ <% 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') %> + + <%= update_categories_link("", nil, :id => "cancel-category-button", :class => "button icon-back") %> <% 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(' → ') - %> - <%= 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 %> + <%= categories.compact.reverse.map{|i| update_categories_link(i.name, i.id)}.join %> + + + + <%= button_to_function_without_text(:add, _('Add'), 'add_category()', :id => 'save-category-button') %> <% end %>