diff --git a/app/controllers/my_profile/cms_controller.rb b/app/controllers/my_profile/cms_controller.rb index 11c715a..4d55fed 100644 --- a/app/controllers/my_profile/cms_controller.rb +++ b/app/controllers/my_profile/cms_controller.rb @@ -3,6 +3,7 @@ class CmsController < MyProfileController protect 'edit_profile', :profile, :only => [:set_home_page] include ArticleHelper + include CategoriesHelper def search_tags arg = params[:term].downcase @@ -256,12 +257,7 @@ class CmsController < MyProfileController def update_categories @object = params[:id] ? @profile.articles.find(params[:id]) : Article.new - @categories = @toplevel_categories = environment.top_level_categories - if params[:category_id] - @current_category = Category.find(params[:category_id]) - @categories = @current_category.children - end - render :template => 'shared/update_categories', :locals => { :category => @current_category, :object_name => 'article' } + render_categories 'article' end def search_communities_to_publish diff --git a/app/controllers/my_profile/profile_design_controller.rb b/app/controllers/my_profile/profile_design_controller.rb index f04db5a..08e0554 100644 --- a/app/controllers/my_profile/profile_design_controller.rb +++ b/app/controllers/my_profile/profile_design_controller.rb @@ -6,6 +6,7 @@ class ProfileDesignController < BoxOrganizerController before_filter :protect_uneditable_block, :only => [:save] before_filter :protect_fixed_block, :only => [:move_block] + include CategoriesHelper def protect_uneditable_block block = boxes_holder.blocks.find(params[:id].gsub(/^block-/, '')) @@ -69,12 +70,7 @@ class ProfileDesignController < BoxOrganizerController def update_categories @object = params[:id] ? @profile.blocks.find(params[:id]) : Block.new - @categories = @toplevel_categories = environment.top_level_categories - if params[:category_id] - @current_category = Category.find(params[:category_id]) - @categories = @current_category.children - end - render :template => 'shared/update_categories', :locals => { :category => @current_category, :object_name => 'block' } + render_categories 'block' end end diff --git a/app/controllers/my_profile/profile_editor_controller.rb b/app/controllers/my_profile/profile_editor_controller.rb index 46b2c0c..2680c0a 100644 --- a/app/controllers/my_profile/profile_editor_controller.rb +++ b/app/controllers/my_profile/profile_editor_controller.rb @@ -9,6 +9,7 @@ class ProfileEditorController < MyProfileController before_filter :check_user_can_edit_header_footer, :only => [:header_footer] helper_method :has_welcome_page helper CustomFieldsHelper + include CategoriesHelper def index @pending_tasks = Task.to(profile).pending.without_spam.select{|i| user.has_permission?(i.permission, profile)} @@ -60,12 +61,7 @@ class ProfileEditorController < MyProfileController def update_categories @object = profile - @categories = @toplevel_categories = environment.top_level_categories - if params[:category_id] - @current_category = Category.find(params[:category_id]) - @categories = @current_category.children - end - render :template => 'shared/update_categories', :locals => { :category => @current_category, :object_name => 'profile_data' } + render_categories 'profile_data' end def header_footer diff --git a/app/helpers/categories_helper.rb b/app/helpers/categories_helper.rb index 9321a88..8a47344 100644 --- a/app/helpers/categories_helper.rb +++ b/app/helpers/categories_helper.rb @@ -34,4 +34,15 @@ module CategoriesHelper {:id => category_id ? "select-category-#{category_id}-link" : nil, :remote => true, :class => html_class}.merge(html_options) end + def render_categories object_name + @toplevel_categories = environment.top_level_categories + if params[:category_id] + @current_category = Category.find(params[:category_id]) + @categories = @current_category.children + else + @categories = @toplevel_categories + end + render :template => 'shared/update_categories', :locals => { :category => @current_category, :object_name => object_name } + end + end diff --git a/app/models/block.rb b/app/models/block.rb index 2fd43d0..234f9b6 100644 --- a/app/models/block.rb +++ b/app/models/block.rb @@ -4,8 +4,6 @@ class Block < ActiveRecord::Base :visualization_format, :language, :display_user, :box, :edit_modes, :move_modes, :mirror - # to be able to generate HTML - include ActionView::Helpers::UrlHelper include ActionView::Helpers::TagHelper # Block-specific stuff diff --git a/plugins/community_track/lib/community_track_plugin/track_list_block.rb b/plugins/community_track/lib/community_track_plugin/track_list_block.rb index 4bebc24..3dd0dc2 100644 --- a/plugins/community_track/lib/community_track_plugin/track_list_block.rb +++ b/plugins/community_track/lib/community_track_plugin/track_list_block.rb @@ -62,26 +62,10 @@ class CommunityTrackPlugin::TrackListBlock < Block tracks end - def content(args={}) - block = self - proc do - instance_eval(&block.set_seed(true)) - render :file => 'blocks/track_list', :locals => {:block => block} - end - end - def has_page?(page, per_page=limit) return (page-1) * per_page < count_tracks end - def footer - block = self - return nil if !has_page?(2) - proc do - render :partial => 'blocks/track_list_more', :locals => {:block => block, :page => 2, :per_page => block.limit} - end - end - def self.expire_on { :profile => [:article, :category], :environment => [:article, :category] } end diff --git a/plugins/community_track/test/unit/community_track_plugin/track_list_block_test.rb b/plugins/community_track/test/unit/community_track_plugin/track_list_block_test.rb index 654a01e..46c716c 100644 --- a/plugins/community_track/test/unit/community_track_plugin/track_list_block_test.rb +++ b/plugins/community_track/test/unit/community_track_plugin/track_list_block_test.rb @@ -34,16 +34,6 @@ class TrackListBlockTest < ActiveSupport::TestCase assert_equal @block.limit, @block.tracks.to_a.size end - should 'return more link if has more tracks to show' do - @block.limit.times { |i| create_track("track#{i}", profile) } - assert @block.footer - end - - should 'do not return more link if there is no more tracks to show' do - (@block.limit-1).times { |i| create_track("track#{i}", profile) } - refute @block.footer - end - should 'count all tracks' do @block.owner.articles.destroy_all tracks_to_insert = @block.limit + 1 diff --git a/plugins/community_track/views/blocks/_track_list_more.html.erb b/plugins/community_track/views/blocks/_track_list_more.html.erb index 86bb473..00210c9 100644 --- a/plugins/community_track/views/blocks/_track_list_more.html.erb +++ b/plugins/community_track/views/blocks/_track_list_more.html.erb @@ -6,7 +6,7 @@ <% else %>
- <%= link_to_remote(c_('More'), :url => {:id => block.id, :controller => 'community_track_plugin_public', :action => 'view_tracks', :page => page, :per_page => per_page, :force_same_page => force_same_page}, :method => :get) %> + <%= link_to c_('More'), :id => block.id, :controller => 'community_track_plugin_public', :action => 'view_tracks', :page => page, :per_page => per_page, :force_same_page => force_same_page, :remote => true %>
<% end %> diff --git a/plugins/community_track/views/blocks/footers/track_list.html.erb b/plugins/community_track/views/blocks/footers/track_list.html.erb new file mode 100644 index 0000000..5cfcc2f --- /dev/null +++ b/plugins/community_track/views/blocks/footers/track_list.html.erb @@ -0,0 +1,3 @@ +<% if block.has_page?(2)%> + <%=render :partial => 'blocks/track_list_more', :locals => {:block => block, :page => 2, :per_page => block.limit} %> +<% end%> -- libgit2 0.21.2