diff --git a/app/helpers/cms_helper.rb b/app/helpers/cms_helper.rb
index e699f51..4068e85 100644
--- a/app/helpers/cms_helper.rb
+++ b/app/helpers/cms_helper.rb
@@ -22,4 +22,23 @@ module CmsHelper
end
end
+ attr_reader :environment
+
+ def select_categories(object_name)
+ object = instance_variable_get("@#{object_name}")
+
+ result = content_tag('h4', _('Categories'))
+ environment.top_level_categories.each do |toplevel|
+ toplevel.map_traversal do |cat|
+ if cat.top_level?
+ result << content_tag('h5', toplevel.name)
+ else
+ result << content_tag('div', check_box_tag("#{object_name}[category_ids][]", cat.id, object.category_ids.include?(cat.id)) + cat.full_name_without_leading(1))
+ end
+ end
+ end
+
+ content_tag('div', result)
+ end
+
end
diff --git a/app/views/cms/edit.rhtml b/app/views/cms/edit.rhtml
index f4fbd8a..3c19a09 100644
--- a/app/views/cms/edit.rhtml
+++ b/app/views/cms/edit.rhtml
@@ -1,6 +1,3 @@
-
-
-
<%= error_messages_for 'article' %>
<% labelled_form_for 'article', @article, :html => { :multipart => true } do |f| %>
@@ -11,6 +8,8 @@
<%= render :partial => partial_for_class(@article.class), :locals => { :f => f } %>
+ <%= select_categories(:article) %>
+
<%# TODO display the tooltip (title below) in a directly visible way %>
<%= f.text_field('tag_list', :size => 64, :title => _('Separate tags with commas')) %>
diff --git a/app/views/cms/view.rhtml b/app/views/cms/view.rhtml
index 4c20744..0ccb0d7 100644
--- a/app/views/cms/view.rhtml
+++ b/app/views/cms/view.rhtml
@@ -61,6 +61,10 @@
<%= _('Public address of this article: %s') % (@article.public_path) %>
+
+ <%= _('Tags:') %> <%= @article.tag_list %>
+
+ <%= _('Categories:') %> <%= @article.categories.map { |item| item.name }.join(', ') %>
<%= button('edit', _('Edit'), { :action => 'edit', :id => @article}) %>
diff --git a/app/views/content_viewer/view_page.rhtml b/app/views/content_viewer/view_page.rhtml
index b6b13c5..3296d13 100644
--- a/app/views/content_viewer/view_page.rhtml
+++ b/app/views/content_viewer/view_page.rhtml
@@ -25,6 +25,10 @@
<% end %>
-->
+<%= _('Categories') %>
+
+<%= @page.categories.map {|item| link_to_category(item) }.join(', ') %>
+
<%= @comments.size == 0 ? _('No comments yet') : (n_('One comment', '%{comments} comments', @comments.size)) % { :comments => @comments.size} %>
<%= render :partial => 'comment', :collection => @comments %>
<%= render :partial => 'comment_form' %>
diff --git a/test/functional/cms_controller_test.rb b/test/functional/cms_controller_test.rb
index a90ef60..6fa62e0 100644
--- a/test/functional/cms_controller_test.rb
+++ b/test/functional/cms_controller_test.rb
@@ -225,4 +225,20 @@ class CmsControllerTest < Test::Unit::TestCase
end
end
+ should 'be able to associate articles with categories' do
+
+ env = Environment.default
+ c1 = env.categories.build(:name => "Test category 1"); c1.save!
+ c2 = env.categories.build(:name => "Test category 2"); c2.save!
+ c3 = env.categories.build(:name => "Test Category 3"); c3.save!
+
+ # post is in c1 and c3
+ post :new, :type => TextileArticle.name, :profile => profile.identifier, :article => { :name => 'adding-categories-test', :category_ids => [ c1.id, c3.id] }
+
+ saved = TextileArticle.find_by_name('adding-categories-test')
+ assert_includes saved.categories, c1
+ assert_not_includes saved.categories, c2
+ assert_includes saved.categories, c3
+ end
+
end
--
libgit2 0.21.2