Commit ac6da245d710953fe1f015f29600b9afc8182194
1 parent
6ec69965
Exists in
master
and in
28 other branches
Organize type selection at context content block
Show main types first and render a link to display more types at context content block edition
Showing
3 changed files
with
63 additions
and
7 deletions
Show diff stats
plugins/context_content/lib/context_content_block.rb
@@ -18,7 +18,21 @@ class ContextContentBlock < Block | @@ -18,7 +18,21 @@ class ContextContentBlock < Block | ||
18 | end | 18 | end |
19 | 19 | ||
20 | def available_content_types | 20 | def available_content_types |
21 | - @available_content_types ||= [TinyMceArticle, TextileArticle, RawHTMLArticle, Event, Folder, Blog, UploadedFile, Forum, Gallery, RssFeed] + plugins.dispatch(:content_types) | 21 | + @available_content_types ||= [UploadedFile, Event, TinyMceArticle, TextileArticle, RawHTMLArticle, Folder, Blog, Forum, Gallery, RssFeed] + plugins.dispatch(:content_types) |
22 | + checked_types = types.map {|t| t.constantize} | ||
23 | + checked_types + (@available_content_types - checked_types) | ||
24 | + end | ||
25 | + | ||
26 | + def first_content_types | ||
27 | + available_content_types.first(first_types_count) | ||
28 | + end | ||
29 | + | ||
30 | + def more_content_types | ||
31 | + available_content_types.drop(first_types_count) | ||
32 | + end | ||
33 | + | ||
34 | + def first_types_count | ||
35 | + [2, types.length].max | ||
22 | end | 36 | end |
23 | 37 | ||
24 | def types=(new_types) | 38 | def types=(new_types) |
plugins/context_content/test/unit/context_content_block_test.rb
@@ -84,8 +84,37 @@ class ContextContentBlockTest < ActiveSupport::TestCase | @@ -84,8 +84,37 @@ class ContextContentBlockTest < ActiveSupport::TestCase | ||
84 | assert_equal nil, @block.contents(folder) | 84 | assert_equal nil, @block.contents(folder) |
85 | end | 85 | end |
86 | 86 | ||
87 | + should 'return available content types with checked types first' do | ||
88 | + @block.types = ['TinyMceArticle', 'Folder'] | ||
89 | + assert_equal [TinyMceArticle, Folder, UploadedFile, Event, TextileArticle, RawHTMLArticle, Blog, Forum, Gallery, RssFeed], @block.available_content_types | ||
90 | + end | ||
91 | + | ||
87 | should 'return available content types' do | 92 | should 'return available content types' do |
88 | - assert_equal [TinyMceArticle, TextileArticle, RawHTMLArticle, Event, Folder, Blog, UploadedFile, Forum, Gallery, RssFeed], @block.available_content_types | 93 | + @block.types = [] |
94 | + assert_equal [UploadedFile, Event, TinyMceArticle, TextileArticle, RawHTMLArticle, Folder, Blog, Forum, Gallery, RssFeed], @block.available_content_types | ||
95 | + end | ||
96 | + | ||
97 | + should 'return first 2 content types' do | ||
98 | + assert_equal 2, @block.first_content_types.length | ||
99 | + end | ||
100 | + | ||
101 | + should 'return all but first 2 content types' do | ||
102 | + assert_equal @block.available_content_types.length - 2, @block.more_content_types.length | ||
103 | + end | ||
104 | + | ||
105 | + should 'return 2 as default value for first_types_count' do | ||
106 | + assert_equal 2, @block.first_types_count | ||
107 | + end | ||
108 | + | ||
109 | + should 'return types length if it has more than 2 selected types' do | ||
110 | + @block.types = ['UploadedFile', 'Event', 'Folder'] | ||
111 | + assert_equal 3, @block.first_types_count | ||
112 | + end | ||
113 | + | ||
114 | + should 'return selected types at first_content_types' do | ||
115 | + @block.types = ['UploadedFile', 'Event', 'Folder'] | ||
116 | + assert_equal [UploadedFile, Event, Folder], @block.first_content_types | ||
117 | + assert_equal @block.available_content_types - [UploadedFile, Event, Folder], @block.more_content_types | ||
89 | end | 118 | end |
90 | 119 | ||
91 | should 'include plugin content at available content types' do | 120 | should 'include plugin content at available content types' do |
@@ -93,7 +122,8 @@ class ContextContentBlockTest < ActiveSupport::TestCase | @@ -93,7 +122,8 @@ class ContextContentBlockTest < ActiveSupport::TestCase | ||
93 | class SomePlugin; def content_types; SomePluginContent end end | 122 | class SomePlugin; def content_types; SomePluginContent end end |
94 | Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([SomePlugin.new]) | 123 | Noosfero::Plugin::Manager.any_instance.stubs(:enabled_plugins).returns([SomePlugin.new]) |
95 | 124 | ||
96 | - assert_equal [TinyMceArticle, TextileArticle, RawHTMLArticle, Event, Folder, Blog, UploadedFile, Forum, Gallery, RssFeed, SomePluginContent], @block.available_content_types | 125 | + @block.types = [] |
126 | + assert_equal [UploadedFile, Event, TinyMceArticle, TextileArticle, RawHTMLArticle, Folder, Blog, Forum, Gallery, RssFeed, SomePluginContent], @block.available_content_types | ||
97 | end | 127 | end |
98 | 128 | ||
99 | should 'display thumbnail for image content' do | 129 | should 'display thumbnail for image content' do |
plugins/context_content/views/box_organizer/_context_content_block.rhtml
@@ -4,8 +4,20 @@ | @@ -4,8 +4,20 @@ | ||
4 | <%= labelled_form_field check_box(:block, :show_image) + _('Show content image'), '' %> | 4 | <%= labelled_form_field check_box(:block, :show_image) + _('Show content image'), '' %> |
5 | <%= labelled_form_field check_box(:block, :show_parent_content) + _('Show parent content when children is empty'), '' %> | 5 | <%= labelled_form_field check_box(:block, :show_parent_content) + _('Show parent content when children is empty'), '' %> |
6 | 6 | ||
7 | - <p>Display content types:</p> | ||
8 | - <% @block.available_content_types.each do |type| %> | ||
9 | - <%= labelled_form_field check_box(:block, 'types', {:multiple => true}, type.name, nil) + _(type.short_description), '' %> | ||
10 | - <% end %> | 7 | + <br/> |
8 | + <%= label :block, :types, _('Display content types:'), :class => 'formlabel' %> | ||
9 | + <div class="content_types"> | ||
10 | + <% @block.first_content_types.each do |type| %> | ||
11 | + <%= labelled_form_field check_box(:block, 'types', {:multiple => true}, type.name, nil) + _(type.short_description), '' %> | ||
12 | + <% end %> | ||
13 | + <% if !@block.more_content_types.empty? %> | ||
14 | + <a href="#" onclick="jQuery('.content_types .more').toggle(); return false;"><%= _('more') %></a> | ||
15 | + <% end %> | ||
16 | + <div class="more" style="display: none"> | ||
17 | + <% @block.more_content_types.each do |type| %> | ||
18 | + <%= labelled_form_field check_box(:block, 'types', {:multiple => true}, type.name, nil) + _(type.short_description), '' %> | ||
19 | + <% end %> | ||
20 | + </div> | ||
21 | + </div> | ||
22 | + <br/> | ||
11 | </div> | 23 | </div> |