diff --git a/app/controllers/box_organizer_controller.rb b/app/controllers/box_organizer_controller.rb
index ab17ee8..976f9bb 100644
--- a/app/controllers/box_organizer_controller.rb
+++ b/app/controllers/box_organizer_controller.rb
@@ -99,6 +99,17 @@ class BoxOrganizerController < ApplicationController
end
end
+ def update_categories
+ @object = params[:id] ? boxes_holder.blocks.find(params[:id]) : nil
+ if params[:category_id]
+ @current_category = Category.find(params[:category_id])
+ @categories = @current_category.children
+ else
+ @categories = environment.top_level_categories
+ end
+ render :partial => 'shared/select_categories', :locals => {:object_name => 'block', :multiple => true}, :layout => false
+ end
+
protected :boxes_editor?
end
diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb
index f945e41..4248ec4 100644
--- a/app/controllers/my_profile/cms_controller.rb
+++ b/app/controllers/my_profile/cms_controller.rb
@@ -208,7 +208,7 @@ class CmsController < MyProfileController
@current_category = Category.find(params[:category_id])
@categories = @current_category.children
else
- @categories = environment.top_level_categories.select{|i| !i.children.empty?}
+ @categories = environment.top_level_categories
end
render :partial => 'shared/select_categories', :locals => {:object_name => 'article', :multiple => true}, :layout => false
end
diff --git a/app/controllers/my_profile/profile_editor_controller.rb b/app/controllers/my_profile/profile_editor_controller.rb
index 9d26ec2..f2dd003 100644
--- a/app/controllers/my_profile/profile_editor_controller.rb
+++ b/app/controllers/my_profile/profile_editor_controller.rb
@@ -59,7 +59,7 @@ class ProfileEditorController < MyProfileController
@current_category = Category.find(params[:category_id])
@categories = @current_category.children
else
- @categories = environment.top_level_categories.select{|i| !i.children.empty?}
+ @categories = environment.top_level_categories
end
render :partial => 'shared/select_categories', :locals => {:object_name => 'profile_data', :multiple => true}, :layout => false
end
diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb
index 66a2e22..9207a4d 100644
--- a/app/helpers/application_helper.rb
+++ b/app/helpers/application_helper.rb
@@ -619,49 +619,18 @@ module ApplicationHelper
end
attr_reader :environment
+
def select_categories(object_name, title=nil, title_size=4)
return nil if environment.enabled?(:disable_categories)
if title.nil?
title = _('Categories')
end
- object = instance_variable_get("@#{object_name}")
-
- result = content_tag 'h'+title_size.to_s(), title
- result << javascript_tag( 'function open_close_cat( link ) {
- var div = link.parentNode.getElementsByTagName("div")[0];
- var end = function(){
- if ( div.style.display == "none" ) {
- this.link.className="button icon-button icon-down"
- } else {
- this.link.className="button icon-button icon-up-red"
- }
- }
- Effect.toggle( div, "slide", { link:link, div:div, afterFinish:end } )
- }')
- environment.top_level_categories.select{|i| !i.children.empty?}.each do |toplevel|
- next unless object.accept_category?(toplevel)
- # FIXME
- ([toplevel] + toplevel.children_for_menu).each do |cat|
- if cat.top_level?
- result << '
+<% extend CategoriesHelper %>
+
+<% categories_for_selection = @categories.select{|i| !@object.respond_to?(:accept_category?) || @object.accept_category?(i)} %>
+
<% if !@current_category.nil? %>
-
<%= _('Current category:') %>
+
<%= _('Selected:') %>
<%= 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
@@ -13,34 +23,28 @@
:loaded => visual_effect(:highlight, "select-categories"),
:class => 'select-current-category-link')}.join(' → ')
%>
-
- <%= 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 +
+ <%= button_to_function_without_text(:add, _('Add'), nil, :id => 'save-category-button') do |page|
+ page.insert_html :bottom, 'selected-categories', content_tag('span',
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}")
+ selected_category_link(categories.first), :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') %>
-
+ <% unless categories_for_selection.empty? %>
+
+
<%= _('Click to select a subcategory') %>
+ <% end %>
<% else %>
-
<%= _('Select a category:') %>
+
<%= _('Click to select a category') %>
<% end %>
-<% if !@categories.empty? %>
-
<%= _('Categories:') %>
- <% @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 %>
+
+<% categories_for_selection.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 %>
diff --git a/app/views/shared/_select_categories_top.rhtml b/app/views/shared/_select_categories_top.rhtml
new file mode 100644
index 0000000..dcf2256
--- /dev/null
+++ b/app/views/shared/_select_categories_top.rhtml
@@ -0,0 +1,28 @@
+<% categories_selected ||= nil %>
+<% title ||= nil %>
+
+<% extend CategoriesHelper %>
+
+<%= content_tag "h#{title_size}", title, :class => "box-title" %>
+
+<%= hidden_field_tag "#{object_name}[category_ids][]", nil %>
+
+
+
+ <%= render :partial => 'shared/select_categories', :locals => {:object_name => object_name, :multiple => true, :categories_selected => categories_selected }, :layout => false %>
+
+
+<% unless categories_selected.nil? %>
+
+
+ <%= _('Selected categories:') %>
+ <% categories_selected.each do |cat| %>
+
+ <%= hidden_field_tag("#{object_name}[category_ids][]", cat.id) %>
+ <%= selected_category_link(cat) %>
+
+ <% end %>
+
+
+<% end %>
+
diff --git a/public/stylesheets/application.css b/public/stylesheets/application.css
index 18c58b6..2495049 100644
--- a/public/stylesheets/application.css
+++ b/public/stylesheets/application.css
@@ -346,21 +346,25 @@ div.pending-tasks {
margin-bottom: 1px;
}
/* * * category ajax selector * * */
-
+#category-ajax-selector .category-helper-label {
+ font-size: 8pt; color: rgb(158, 158, 158);
+ padding: 5px 0px;
+}
#category-ajax-selector {
border: 1px solid #AAA;
- background: #EEE;
- padding: 15px 0px 15px 20px;
- margin: 30px 0px 0px 0px;
+ padding: 3px 10px 10px 10px;
+ margin: 0px 0px 0px 0px;
position: relative;
- font-size: 18px;
+ font-size: 10px;
}
#category-ajax-selector a {
- font-size: 14px;
+ font-size: 12px;
}
-#category-ajax-selector h3 {
- margin: 10px 0px;
- font-size: 14px;
+#selected-categories span {
+ float: left;
+}
+#selected-categories .label {
+ font-weight: bold;
}
#category-ajax-selector .box-title {
position: absolute;
@@ -376,25 +380,28 @@ div.pending-tasks {
.msie6 #category-ajax-selector .box-title {
top: -29px;
}
-#category-ajax-selector .select-subcategory-link {
+#category-ajax-selector .select-subcategory-link,
+.select-subcategory-link {
border: 1px solid #BBB;
padding: 1px 3px;
margin: 0px 1px;
text-decoration: none;
white-space: nowrap;
font-size: 11px;
+ line-height: 18px;
}
-#category-ajax-selector .select-subcategory-link:hover {
+#category-ajax-selector .select-subcategory-link:hover,
+.select-subcategory-link:hover {
background-color: black;
}
#category-ajax-selector .button {
- display: block;
- position: absolute;
top: 4px;
right: 2px;
}
-#category-ajax-selector .icon-save {
+#category-ajax-selector .icon-add {
right: 25px;
+ display: block;
+ position: absolute;
}
#profile-header, #profile-footer {
clear: both;
diff --git a/test/functional/cms_controller_test.rb b/test/functional/cms_controller_test.rb
index 5b0fb39..8a077c2 100644
--- a/test/functional/cms_controller_test.rb
+++ b/test/functional/cms_controller_test.rb
@@ -451,24 +451,23 @@ class CmsControllerTest < ActionController::TestCase
assert_tag :tag => 'h3', :content => /max size #{UploadedFile.max_size.to_humanreadable}/
end
- should 'display link for selecting categories' do
- # FIXME
- assert true
- #env = Environment.default
- #top = env.categories.build(:display_in_menu => true, :name => 'Top-Level category'); top.save!
- #c1 = env.categories.build(:display_in_menu => true, :name => "Test category 1", :parent_id => top.id); c1.save!
- #c2 = env.categories.build(:display_in_menu => true, :name => "Test category 2", :parent_id => top.id); c2.save!
- #c3 = env.categories.build(:display_in_menu => true, :name => "Test Category 3", :parent_id => top.id); c3.save!
-
- #article = Article.new(:name => 'test')
- #article.profile = profile
- #article.save!
-
- #get :edit, :profile => profile.identifier, :id => article.id
-
- #[c1,c2,c3].each do |item|
- # assert_tag :tag => 'a', :attributes => { :id => "select-category-#{item.id}-link" }
- #end
+ should 'display link for selecting top categories' do
+ env = Environment.default
+ top = env.categories.build(:display_in_menu => true, :name => 'Top-Level category'); top.save!
+ top2 = env.categories.build(:display_in_menu => true, :name => 'Top-Level category 2'); top2.save!
+ c1 = env.categories.build(:display_in_menu => true, :name => "Test category 1", :parent_id => top.id); c1.save!
+ c2 = env.categories.build(:display_in_menu => true, :name => "Test category 2", :parent_id => top.id); c2.save!
+ c3 = env.categories.build(:display_in_menu => true, :name => "Test Category 3", :parent_id => top.id); c3.save!
+
+ article = Article.new(:name => 'test')
+ article.profile = profile
+ article.save!
+
+ get :edit, :profile => profile.identifier, :id => article.id
+
+ [top, top2].each do |item|
+ assert_tag :tag => 'a', :attributes => { :id => "select-category-#{item.id}-link" }
+ end
end
should 'be able to associate articles with categories' do
diff --git a/test/functional/environment_design_controller_test.rb b/test/functional/environment_design_controller_test.rb
index 1c473fe..06b79fc 100644
--- a/test/functional/environment_design_controller_test.rb
+++ b/test/functional/environment_design_controller_test.rb
@@ -366,4 +366,16 @@ class EnvironmentDesignControllerTest < ActionController::TestCase
assert @controller.instance_variable_get('@side_block_types').include?(CustomBlock8)
end
+ should 'update categories' do
+ env = Environment.default
+ login_as(create_admin_user(env))
+ top = env.categories.create!(:display_in_menu => true, :name => 'Top-Level category')
+ c1 = env.categories.create!(:display_in_menu => true, :name => "Test category 1", :parent_id => top.id)
+ c2 = env.categories.create!(:display_in_menu => true, :name => "Test category 2", :parent_id => top.id)
+ get :update_categories, :category_id => top.id
+ assert_template 'shared/_select_categories'
+ assert_equal top, assigns(:current_category)
+ assert_equal [c1, c2], assigns(:categories)
+ end
+
end
diff --git a/test/functional/profile_editor_controller_test.rb b/test/functional/profile_editor_controller_test.rb
index e32f2dc..e973b68 100644
--- a/test/functional/profile_editor_controller_test.rb
+++ b/test/functional/profile_editor_controller_test.rb
@@ -73,7 +73,8 @@ class ProfileEditorControllerTest < ActionController::TestCase
get :edit, :profile => profile.identifier
assert_response :success
assert_template 'edit'
- assert_tag :tag => 'input', :attributes => {:name => 'profile_data[category_ids][]', :value => cat2.id}
+ assert_tag :tag => 'input', :attributes => {:name => 'profile_data[category_ids][]'}
+ assert_tag :tag => 'a', :attributes => { :class => 'select-subcategory-link', :id => "select-category-#{cat1.id}-link" }
end
should 'save categorization of profile' do
@@ -236,7 +237,7 @@ class ProfileEditorControllerTest < ActionController::TestCase
cat2 = Environment.default.categories.create!(:display_in_menu => true, :name => 'sub category', :parent => cat1)
person = create_user('testuser').person
get :edit, :profile => 'testuser'
- assert_tag :tag => 'input', :attributes => { :type => 'checkbox', :name => 'profile_data[category_ids][]', :value => cat2.id}
+ assert_tag :tag => 'a', :attributes => { :class => 'select-subcategory-link', :id => "select-category-#{cat1.id}-link" }
end
should 'render edit template' do
--
libgit2 0.21.2