Commit 2b5e621cf631a9638719ba691084dbbed72e4938
1 parent
a770c8f3
Exists in
master
and in
29 other branches
rails3: fix context_content block
Showing
10 changed files
with
51 additions
and
49 deletions
Show diff stats
plugins/context_content/lib/context_content_plugin/context_content_block.rb
@@ -6,6 +6,8 @@ class ContextContentPlugin::ContextContentBlock < Block | @@ -6,6 +6,8 @@ class ContextContentPlugin::ContextContentBlock < Block | ||
6 | settings_items :types, :type => Array, :default => ['UploadedFile'] | 6 | settings_items :types, :type => Array, :default => ['UploadedFile'] |
7 | settings_items :limit, :type => :integer, :default => 6 | 7 | settings_items :limit, :type => :integer, :default => 6 |
8 | 8 | ||
9 | + attr_accessible :show_image, :show_name, :show_parent_content, :types | ||
10 | + | ||
9 | alias :profile :owner | 11 | alias :profile :owner |
10 | 12 | ||
11 | include Noosfero::Plugin::HotSpot | 13 | include Noosfero::Plugin::HotSpot |
@@ -42,7 +44,7 @@ class ContextContentPlugin::ContextContentBlock < Block | @@ -42,7 +44,7 @@ class ContextContentPlugin::ContextContentBlock < Block | ||
42 | 44 | ||
43 | def content_image(content) | 45 | def content_image(content) |
44 | block = self | 46 | block = self |
45 | - lambda do | 47 | + proc do |
46 | if content.image? | 48 | if content.image? |
47 | image_tag(content.public_filename(:thumb)) | 49 | image_tag(content.public_filename(:thumb)) |
48 | else | 50 | else |
@@ -65,7 +67,7 @@ class ContextContentPlugin::ContextContentBlock < Block | @@ -65,7 +67,7 @@ class ContextContentPlugin::ContextContentBlock < Block | ||
65 | 67 | ||
66 | def footer | 68 | def footer |
67 | block = self | 69 | block = self |
68 | - lambda do | 70 | + proc do |
69 | contents = block.contents(@page) | 71 | contents = block.contents(@page) |
70 | if contents | 72 | if contents |
71 | content_tag('div', | 73 | content_tag('div', |
@@ -78,7 +80,7 @@ class ContextContentPlugin::ContextContentBlock < Block | @@ -78,7 +80,7 @@ class ContextContentPlugin::ContextContentBlock < Block | ||
78 | 80 | ||
79 | def content(args={}) | 81 | def content(args={}) |
80 | block = self | 82 | block = self |
81 | - lambda do | 83 | + proc do |
82 | contents = block.contents(@page) | 84 | contents = block.contents(@page) |
83 | if !contents.blank? | 85 | if !contents.blank? |
84 | block_title(block.title) + content_tag('div', | 86 | block_title(block.title) + content_tag('div', |
plugins/context_content/test/functional/content_viewer_controller_test.rb
@@ -14,7 +14,7 @@ class ContentViewerControllerTest < ActionController::TestCase | @@ -14,7 +14,7 @@ class ContentViewerControllerTest < ActionController::TestCase | ||
14 | @page = fast_create(Folder, :profile_id => @profile.id) | 14 | @page = fast_create(Folder, :profile_id => @profile.id) |
15 | 15 | ||
16 | box = Box.create!(:owner => @profile) | 16 | box = Box.create!(:owner => @profile) |
17 | - @block = ContextContentPlugin::ContextContentBlock.new(:box => box) | 17 | + @block = ContextContentPlugin::ContextContentBlock.new(:box_id => box.id) |
18 | @block.types = ['TinyMceArticle'] | 18 | @block.types = ['TinyMceArticle'] |
19 | @block.limit = 1 | 19 | @block.limit = 1 |
20 | @block.save! | 20 | @block.save! |
plugins/context_content/test/functional/profile_design_controller_test.rb
@@ -19,7 +19,7 @@ class ProfileDesignControllerTest < ActionController::TestCase | @@ -19,7 +19,7 @@ class ProfileDesignControllerTest < ActionController::TestCase | ||
19 | @page = fast_create(Folder, :profile_id => @profile.id) | 19 | @page = fast_create(Folder, :profile_id => @profile.id) |
20 | 20 | ||
21 | box = Box.create!(:owner => @profile) | 21 | box = Box.create!(:owner => @profile) |
22 | - @block = ContextContentPlugin::ContextContentBlock.new(:box => box) | 22 | + @block = ContextContentPlugin::ContextContentBlock.new(:box_id => box.id) |
23 | @block.types = ['TinyMceArticle'] | 23 | @block.types = ['TinyMceArticle'] |
24 | @block.limit = 1 | 24 | @block.limit = 1 |
25 | @block.save! | 25 | @block.save! |
@@ -35,7 +35,7 @@ class ProfileDesignControllerTest < ActionController::TestCase | @@ -35,7 +35,7 @@ class ProfileDesignControllerTest < ActionController::TestCase | ||
35 | assert_tag :tag => 'input', :attributes => { :id => 'block_show_image' } | 35 | assert_tag :tag => 'input', :attributes => { :id => 'block_show_image' } |
36 | assert_tag :tag => 'input', :attributes => { :id => 'block_show_name' } | 36 | assert_tag :tag => 'input', :attributes => { :id => 'block_show_name' } |
37 | assert_tag :tag => 'input', :attributes => { :id => 'block_show_parent_content' } | 37 | assert_tag :tag => 'input', :attributes => { :id => 'block_show_parent_content' } |
38 | - assert_tag :tag => 'input', :attributes => { :id => 'block_types' } | 38 | + assert_tag :tag => 'input', :attributes => { :name => 'block[types][]' } |
39 | end | 39 | end |
40 | 40 | ||
41 | should 'be able to save TrackListBlock' do | 41 | should 'be able to save TrackListBlock' do |
plugins/context_content/test/unit/context_content_block_test.rb
@@ -163,14 +163,14 @@ class ContextContentBlockTest < ActiveSupport::TestCase | @@ -163,14 +163,14 @@ class ContextContentBlockTest < ActiveSupport::TestCase | ||
163 | article2 = fast_create(TinyMceArticle, :parent_id => @page.id) | 163 | article2 = fast_create(TinyMceArticle, :parent_id => @page.id) |
164 | article3 = fast_create(TinyMceArticle, :parent_id => @page.id) | 164 | article3 = fast_create(TinyMceArticle, :parent_id => @page.id) |
165 | expects(:content_tag).once | 165 | expects(:content_tag).once |
166 | - expects(:render).with(:partial => 'blocks/more', :locals => {:block => @block, :contents => [article1, article2], :article_id => @page.id}).once | 166 | + expects(:render).with(has_entry(:partial => 'blocks/more')) |
167 | instance_eval(&@block.footer) | 167 | instance_eval(&@block.footer) |
168 | end | 168 | end |
169 | 169 | ||
170 | should 'return box owner on profile method call' do | 170 | should 'return box owner on profile method call' do |
171 | profile = fast_create(Community) | 171 | profile = fast_create(Community) |
172 | - box = Box.create(:owner_type => 'Profile', :owner_id => profile.id) | ||
173 | - block = ContextContentPlugin::ContextContentBlock.create!(:box => box) | 172 | + box = Box.create!(:owner => profile) |
173 | + block = ContextContentPlugin::ContextContentBlock.create!(:box_id => box.id) | ||
174 | assert_equal profile, block.profile | 174 | assert_equal profile, block.profile |
175 | end | 175 | end |
176 | 176 |
@@ -0,0 +1,4 @@ | @@ -0,0 +1,4 @@ | ||
1 | +<% if contents.total_pages > 1 %> | ||
2 | + <%= link_to_remote(nil, :url => {:id => block.id, :controller => 'context_content_plugin_profile', :action => 'view_content', :page => contents.previous_page, :article_id => article_id }, :html => {:class => "button icon-button icon-left #{contents.previous_page ? '':'disabled'}".strip}, :condition => "#{!contents.previous_page.nil?}", :success => "jQuery('#context_content_#{block.id}').effect('slide', {direction: 'left'});" )%> | ||
3 | + <%= link_to_remote(nil, :url => {:id => block.id, :controller => 'context_content_plugin_profile', :action => 'view_content', :page => contents.next_page, :article_id => article_id }, :html => {:class => "button icon-button icon-right #{contents.next_page ? '':'disabled'}".strip}, :condition => "#{!contents.next_page.nil?}", :success => "jQuery('#context_content_#{block.id}').effect('slide', {direction: 'right'});" )%> | ||
4 | +<% end %> |
plugins/context_content/views/blocks/_more.rhtml
@@ -1,4 +0,0 @@ | @@ -1,4 +0,0 @@ | ||
1 | -<% if contents.total_pages > 1 %> | ||
2 | - <%= link_to_remote(nil, :url => {:id => block.id, :controller => 'context_content_plugin_profile', :action => 'view_content', :page => contents.previous_page, :article_id => article_id }, :html => {:class => "button icon-button icon-left #{contents.previous_page ? '':'disabled'}".strip}, :condition => "#{!contents.previous_page.nil?}", :success => "jQuery('#context_content_#{block.id}').effect('slide', {direction: 'left'});" )%> | ||
3 | - <%= link_to_remote(nil, :url => {:id => block.id, :controller => 'context_content_plugin_profile', :action => 'view_content', :page => contents.next_page, :article_id => article_id }, :html => {:class => "button icon-button icon-right #{contents.next_page ? '':'disabled'}".strip}, :condition => "#{!contents.next_page.nil?}", :success => "jQuery('#context_content_#{block.id}').effect('slide', {direction: 'right'});" )%> | ||
4 | -<% end %> |
plugins/context_content/views/blocks/context_content.html.erb
0 → 100644
@@ -0,0 +1,13 @@ | @@ -0,0 +1,13 @@ | ||
1 | +<% contents.each do |content| %> | ||
2 | + <% content = FilePresenter.for(content) %> | ||
3 | + <span class="item"> | ||
4 | + <a href="<%= url_for(content.view_url) %>"> | ||
5 | + <div class="image"> | ||
6 | + <%= instance_eval(&block.content_image(content)) if block.show_image %> | ||
7 | + </div> | ||
8 | + <% if block.show_name %> | ||
9 | + <div class="name"><%= short_filename(content.name, 30) %></div> | ||
10 | + <% end %> | ||
11 | + </a> | ||
12 | + </span> | ||
13 | +<% end %> |
plugins/context_content/views/blocks/context_content.rhtml
@@ -1,13 +0,0 @@ | @@ -1,13 +0,0 @@ | ||
1 | -<% contents.each do |content| %> | ||
2 | - <% content = FilePresenter.for(content) %> | ||
3 | - <span class="item"> | ||
4 | - <a href="<%= url_for(content.view_url) %>"> | ||
5 | - <div class="image"> | ||
6 | - <%= instance_eval(&block.content_image(content)) if block.show_image %> | ||
7 | - </div> | ||
8 | - <% if block.show_name %> | ||
9 | - <div class="name"><%= short_filename(content.name, 30) %></div> | ||
10 | - <% end %> | ||
11 | - </a> | ||
12 | - </span> | ||
13 | -<% end %> |
plugins/context_content/views/box_organizer/context_content_plugin/_context_content_block.html.erb
0 → 100644
@@ -0,0 +1,23 @@ | @@ -0,0 +1,23 @@ | ||
1 | +<div id='edit-context-content-block'> | ||
2 | + <%= labelled_form_field _('Limit of items'), text_field(:block, :limit, :size => 3) %> | ||
3 | + <%= labelled_form_field check_box(:block, :show_name) + _('Show content name'), '' %> | ||
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'), '' %> | ||
6 | + | ||
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/> | ||
23 | +</div> |
plugins/context_content/views/box_organizer/context_content_plugin/_context_content_block.rhtml
@@ -1,23 +0,0 @@ | @@ -1,23 +0,0 @@ | ||
1 | -<div id='edit-context-content-block'> | ||
2 | - <%= labelled_form_field _('Limit of items'), text_field(:block, :limit, :size => 3) %> | ||
3 | - <%= labelled_form_field check_box(:block, :show_name) + _('Show content name'), '' %> | ||
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'), '' %> | ||
6 | - | ||
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/> | ||
23 | -</div> |