From 25c24c03f9bf4d8a88a8c79935d5029cbe6b4a81 Mon Sep 17 00:00:00 2001 From: Christophe Vilayphiou Date: Wed, 28 Mar 2012 19:40:12 +0800 Subject: [PATCH] Add pagination to bulletin index and remove ajax to make it simple --- app/assets/javascripts/orbit-1.0.js | 5 --- .../back_end/bulletins_controller.rb | 26 +++++++------ .../back_end/bulletins/_bulletins.html.erb | 36 ------------------ .../back_end/bulletins/_filter.html.erb | 37 ++++++++----------- .../back_end/bulletins/index.html.erb | 2 + .../back_end/bulletins/index.js.erb | 1 - 6 files changed, 32 insertions(+), 75 deletions(-) delete mode 100644 vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/index.js.erb diff --git a/app/assets/javascripts/orbit-1.0.js b/app/assets/javascripts/orbit-1.0.js index d91e3533..ffd16e82 100644 --- a/app/assets/javascripts/orbit-1.0.js +++ b/app/assets/javascripts/orbit-1.0.js @@ -39,11 +39,6 @@ $(document).ready(function(){ break; } }); - - $(document).on('click', '.sort-header > .sort', function() { - $.getScript($(this).attr('rel')); - }); - var $role = $('.select-role'); var method =$('.privacy:eq(1)').attr('checked'); diff --git a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb index 648c8d55..3642fe4f 100644 --- a/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb +++ b/vendor/built_in_modules/announcement/app/controllers/panel/announcement/back_end/bulletins_controller.rb @@ -8,19 +8,19 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController # @bulletins = Bulletin.desc("postdate desc") get_categorys(params[:bulletin_category_id]) get_tags - + # @bulletins = Bulletin.where("bulletin_category_id" => params[:bulletin_category_id]).desc("postdate") if params[:bulletin_category_id] # @bulletins = Bulletin.search(params[:search], params[:category_id]) # @bulletins = Bulletin.all.order_by([params[:sort], params[:direction]]) - @bulletins = params[:sort] ? get_sorted_bulletins : Bulletin.all.desc("postdate") + @bulletins = params[:sort] ? get_sorted_bulletins : Bulletin.all.desc("postdate").page(params[:page]).per(10) @bulletin_categories = BulletinCategory.all - + @bulletin_link = BulletinLink.new - @link_url = panel_announcement_back_end_bulletins_path + @link_url = panel_announcement_back_end_bulletins_path @bulletin_file = BulletinFile.new - @file_url = panel_announcement_back_end_bulletins_path + @file_url = panel_announcement_back_end_bulletins_path respond_to do |format| format.html # index.html.erb @@ -299,7 +299,7 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController bulletins = Bulletin.all case params[:sort] when 'postdate', 'deadline' - bulletins.order_by([params[:sort], params[:direction]]) + bulletins.order_by([params[:sort], params[:direction]]).page(params[:page]).per(10) when 'category' category_ids = bulletins.distinct(:bulletin_category_id) categories = BulletinCategory.find(category_ids) rescue nil @@ -308,7 +308,8 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController categories.each { |category| h[category.i18n_variable[I18n.locale]] = category.id } sorted = params[:direction].eql?('asc') ? h.sort : h.sort.reverse! sorted_categorys = sorted.collect {|a| bulletins.where(:bulletin_category_id => a[1]).entries } - sorted_categorys.flatten + sorted_categorys.flatten! + Kaminari.paginate_array(sorted_categorys).page(params[:page]).per(10) else nil end @@ -316,9 +317,10 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController h = Hash.new bulletins.each { |bulletin| h[bulletin.title[I18n.locale]] = bulletin } sorted = params[:direction].eql?('asc') ? h.sort : h.sort.reverse! - sorted.collect {|a| a[1] } + sorted_titles = sorted.collect {|a| a[1] } + Kaminari.paginate_array(sorted_titles).page(params[:page]).per(10) when 'status' - bulletins.order_by(:is_top, params[:direction]).order_by(:is_hot, params[:direction]).order_by(:is_hidden, params[:direction]) + bulletins.order_by(:is_top, params[:direction]).order_by(:is_hot, params[:direction]).order_by(:is_hidden, params[:direction]).page(params[:page]).per(10) when 'update_user_id' user_ids = bulletins.distinct(:update_user_id) users = User.find(user_ids) rescue nil @@ -327,7 +329,8 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController users.each { |user| h[user.name] = user.id } sorted = params[:direction].eql?('asc') ? h.sort : h.sort.reverse! sorted_users = sorted.collect {|a| bulletins.where(:update_user_id => a[1]).entries } - sorted_users.flatten + sorted_users.flatten! + Kaminari.paginate_array(sorted_users).page(params[:page]).per(10) else nil end @@ -335,7 +338,8 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController a = Array.new AnnouncementTag.all.order_by(I18n.locale, params[:direction]).each { |tag| a << tag.bulletins } a.flatten! - a.uniq + a.uniq! + Kaminari.paginate_array(a).page(params[:page]).per(10) end end diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletins.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletins.html.erb index 979f3f4a..81daae8b 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletins.html.erb +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_bulletins.html.erb @@ -1,39 +1,3 @@ - diff --git a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_filter.html.erb b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_filter.html.erb index 09222a36..f8ea5418 100644 --- a/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_filter.html.erb +++ b/vendor/built_in_modules/announcement/app/views/panel/announcement/back_end/bulletins/_filter.html.erb @@ -1,4 +1,4 @@ -