diff --git a/plugins/context_content/controllers/profile/context_content_plugin_profile_controller.rb b/plugins/context_content/controllers/profile/context_content_plugin_profile_controller.rb index b829dce..bdf9a78 100644 --- a/plugins/context_content/controllers/profile/context_content_plugin_profile_controller.rb +++ b/plugins/context_content/controllers/profile/context_content_plugin_profile_controller.rb @@ -7,9 +7,11 @@ class ContextContentPluginProfileController < ProfileController contents = block.contents(profile.articles.find(params[:article_id]), p) if contents + @page = Article.find(params[:article_id]) + render :update do |page| - page.replace_html "context_content_#{block.id}", :file => "blocks/context_content", :locals => {:block => block, :contents => contents} - page.replace_html "context_content_more_#{block.id}", :partial => 'blocks/more', :locals => {:block => block, :contents => contents, :article_id => params[:article_id] } + page.replace_html "context_content_#{block.id}", :file => "blocks/context_content", :locals => {:block => block} + page.replace_html "context_content_more_#{block.id}", :file => 'blocks/footers/context_content', :locals => {:block => block} end else render :text => "invalid page", :status => 500 diff --git a/plugins/context_content/test/unit/context_content_block_test.rb b/plugins/context_content/test/unit/context_content_block_test.rb index 54cc4f9..e598929 100644 --- a/plugins/context_content/test/unit/context_content_block_test.rb +++ b/plugins/context_content/test/unit/context_content_block_test.rb @@ -123,26 +123,6 @@ class ContextContentBlockTest < ActiveSupport::TestCase assert_equal [UploadedFile, Event, TinyMceArticle, TextileArticle, RawHTMLArticle, Folder, Blog, Forum, Gallery, RssFeed, SomePluginContent], @block.available_content_types end - should 'do not display pagination links if page is nil' do - @page = nil - assert_equal '', instance_eval(&@block.footer) - end - - should 'do not display pagination links if it has until one page' do - assert_equal '', instance_eval(&@block.footer) - end - - should 'display pagination links if it has more than one page' do - @block.limit = 2 - @page = fast_create(Folder) - article1 = fast_create(TinyMceArticle, :parent_id => @page.id) - article2 = fast_create(TinyMceArticle, :parent_id => @page.id) - article3 = fast_create(TinyMceArticle, :parent_id => @page.id) - expects(:content_tag).once - expects(:render).with(has_entry(:partial => 'blocks/more')) - instance_eval(&@block.footer) - end - should 'return box owner on profile method call' do profile = fast_create(Community) box = Box.create!(:owner => profile) @@ -180,7 +160,34 @@ class ContextContentBlockViewTest < ActionView::TestCase article.expects(:view_url).returns('http://test.noosfero.plugins') @block.expects(:contents).with(@page).returns(contents) @block.expects(:parent_title).with(contents).returns(@page.name) - ActionView::Base.any_instance.expects(:block_title).returns(@page.name, @block.subtitle) + ActionView::Base.any_instance.expects(:block_title).with(@page.name, @block.subtitle).returns("") + + render_block_content(@block) + end + + should 'do not display pagination links if page is nil' do + @page = nil + + assert_equal "\n", render_block_content(@block) + end + + should 'do not display pagination links if it has until one page' do + assert_equal "\n", render_block_content(@block) + end + + should 'display pagination links if it has more than one page' do + @block.limit = 2 + @page = fast_create(Folder) + article1 = fast_create(TinyMceArticle, :parent_id => @page.id) + article2 = fast_create(TinyMceArticle, :parent_id => @page.id) + article3 = fast_create(TinyMceArticle, :parent_id => @page.id) + contents = [article1, article2, article3] + contents.each do |article| + article.expects(:view_url).returns('http://test.noosfero.plugins') + end + + ActionView::Base.any_instance.expects(:block_title).returns("") + @block.expects(:contents).with(@page).returns(contents) render_block_content(@block) end diff --git a/plugins/context_content/views/blocks/_more.html.erb b/plugins/context_content/views/blocks/_more.html.erb deleted file mode 100644 index 15c85ce..0000000 --- a/plugins/context_content/views/blocks/_more.html.erb +++ /dev/null @@ -1,4 +0,0 @@ -<% if contents.total_pages > 1 %> - <%= link_to_remote(nil, :url => {:profile => block.owner.identifier, :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'});" )%> - <%= link_to_remote(nil, :url => {:profile => block.owner.identifier, :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'});" )%> -<% end %> diff --git a/plugins/context_content/views/blocks/footers/context_content.html.erb b/plugins/context_content/views/blocks/footers/context_content.html.erb new file mode 100644 index 0000000..385c060 --- /dev/null +++ b/plugins/context_content/views/blocks/footers/context_content.html.erb @@ -0,0 +1,9 @@ +<% contents = block.contents(@page) + unless contents.blank? %> +
+ <% if contents.total_pages > 1 %> + <%= link_to_remote(nil, :url => {:profile => block.owner.identifier, :id => block.id, :controller => 'context_content_plugin_profile', :action => 'view_content', :page => contents.previous_page, :article_id => @page.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'});" )%> + <%= link_to_remote(nil, :url => {:profile => block.owner.identifier, :id => block.id, :controller => 'context_content_plugin_profile', :action => 'view_content', :page => contents.next_page, :article_id => @page.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'});" )%> + <% end %> +
+<% end %> -- libgit2 0.21.2