Add pagination to bulletin index and remove ajax to make it simple

This commit is contained in:
Christophe Vilayphiou 2012-03-28 19:40:12 +08:00
parent e7fdcfffa0
commit 25c24c03f9
6 changed files with 32 additions and 75 deletions

View File

@ -39,11 +39,6 @@ $(document).ready(function(){
break; break;
} }
}); });
$(document).on('click', '.sort-header > .sort', function() {
$.getScript($(this).attr('rel'));
});
var $role = $('.select-role'); var $role = $('.select-role');
var method =$('.privacy:eq(1)').attr('checked'); var method =$('.privacy:eq(1)').attr('checked');

View File

@ -8,19 +8,19 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController
# @bulletins = Bulletin.desc("postdate desc") # @bulletins = Bulletin.desc("postdate desc")
get_categorys(params[:bulletin_category_id]) get_categorys(params[:bulletin_category_id])
get_tags get_tags
# @bulletins = Bulletin.where("bulletin_category_id" => params[:bulletin_category_id]).desc("postdate") if params[:bulletin_category_id] # @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.search(params[:search], params[:category_id])
# @bulletins = Bulletin.all.order_by([params[:sort], params[:direction]]) # @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_categories = BulletinCategory.all
@bulletin_link = BulletinLink.new @bulletin_link = BulletinLink.new
@link_url = panel_announcement_back_end_bulletins_path @link_url = panel_announcement_back_end_bulletins_path
@bulletin_file = BulletinFile.new @bulletin_file = BulletinFile.new
@file_url = panel_announcement_back_end_bulletins_path @file_url = panel_announcement_back_end_bulletins_path
respond_to do |format| respond_to do |format|
format.html # index.html.erb format.html # index.html.erb
@ -299,7 +299,7 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController
bulletins = Bulletin.all bulletins = Bulletin.all
case params[:sort] case params[:sort]
when 'postdate', 'deadline' when 'postdate', 'deadline'
bulletins.order_by([params[:sort], params[:direction]]) bulletins.order_by([params[:sort], params[:direction]]).page(params[:page]).per(10)
when 'category' when 'category'
category_ids = bulletins.distinct(:bulletin_category_id) category_ids = bulletins.distinct(:bulletin_category_id)
categories = BulletinCategory.find(category_ids) rescue nil 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 } categories.each { |category| h[category.i18n_variable[I18n.locale]] = category.id }
sorted = params[:direction].eql?('asc') ? h.sort : h.sort.reverse! 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 = 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 else
nil nil
end end
@ -316,9 +317,10 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController
h = Hash.new h = Hash.new
bulletins.each { |bulletin| h[bulletin.title[I18n.locale]] = bulletin } bulletins.each { |bulletin| h[bulletin.title[I18n.locale]] = bulletin }
sorted = params[:direction].eql?('asc') ? h.sort : h.sort.reverse! 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' 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' when 'update_user_id'
user_ids = bulletins.distinct(:update_user_id) user_ids = bulletins.distinct(:update_user_id)
users = User.find(user_ids) rescue nil 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 } users.each { |user| h[user.name] = user.id }
sorted = params[:direction].eql?('asc') ? h.sort : h.sort.reverse! 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 = 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 else
nil nil
end end
@ -335,7 +338,8 @@ class Panel::Announcement::BackEnd::BulletinsController < OrbitBackendController
a = Array.new a = Array.new
AnnouncementTag.all.order_by(I18n.locale, params[:direction]).each { |tag| a << tag.bulletins } AnnouncementTag.all.order_by(I18n.locale, params[:direction]).each { |tag| a << tag.bulletins }
a.flatten! a.flatten!
a.uniq a.uniq!
Kaminari.paginate_array(a).page(params[:page]).per(10)
end end
end end

View File

@ -1,39 +1,3 @@
<!--<thead>
<tr class="sort-header">
<th class="span1 strong">
<input type="checkbox">
<a href class="list-remove"><i class="icon-trash"></i></a>
</th>
<th class="sort span1 <%= is_sort_active?('status') %>" rel="<%= panel_announcement_back_end_bulletins_path(sortable('status')) %>">
<%= t('bulletin.status') %>
<%= content_tag(:b, nil, :class => is_sort?('status')) %>
</th>
<th class="sort span1-2 <%= is_sort_active?('category') %>" rel="<%= panel_announcement_back_end_bulletins_path(sortable('category')) %>">
<%= t('bulletin.category') %>
<%= content_tag(:b, nil, :class => is_sort?('category')) %>
</th>
<th class="sort span7 <%= is_sort_active?('title') %>" rel="<%= panel_announcement_back_end_bulletins_path(sortable('title')) %>">
<%= t('bulletin.title') %>
<%= content_tag(:b, nil, :class => is_sort?('title')) %>
</th>
<th class="sort span1-2 <%= is_sort_active?('postdate') %>" rel="<%= panel_announcement_back_end_bulletins_path(sortable('postdate')) %>">
<%= t('bulletin.start_date') %>
<%= content_tag(:b, nil, :class => is_sort?('postdate')) %>
</th>
<th class="sort span1-2 <%= is_sort_active?('deadline') %>" rel="<%= panel_announcement_back_end_bulletins_path(sortable('deadline')) %>">
<%= t('bulletin.end_date') %>
<%= content_tag(:b, nil, :class => is_sort?('deadline')) %>
</th>
<th class="sort span1-2 <%= is_sort_active?('tags') %>" rel="<%= panel_announcement_back_end_bulletins_path(sortable('tags')) %>">
<%= t('bulletin.tags') %>
<%= content_tag(:b, nil, :class => is_sort?('tags')) %>
</th>
<th class="sort span1-2 <%= is_sort_active?('update_user_id') %>" rel="<%= panel_announcement_back_end_bulletins_path(sortable('update_user_id')) %>">
<%= t('bulletin.last_modified') %>
<%= content_tag(:b, nil, :class => is_sort?('update_user_id')) %>
</th>
</tr>
</thead>-->
<thead> <thead>
<tr> <tr>
<th class="span1"></th> <th class="span1"></th>

View File

@ -1,4 +1,4 @@
<div class="subnav"> <div id='filter' class="subnav">
<ul class="nav nav-pills filter"> <ul class="nav nav-pills filter">
<li class="accordion-group"> <li class="accordion-group">
<div class="accordion-heading"> <div class="accordion-heading">
@ -61,33 +61,26 @@
<input type="checkbox"> <input type="checkbox">
<a href class="list-remove"><i class="icon-trash"></i></a> <a href class="list-remove"><i class="icon-trash"></i></a>
</th> </th>
<th class="sort span1-2 <%= is_sort_active?('status') %>" rel="<%= panel_announcement_back_end_bulletins_path(sortable('status')) %>"> <th class="sort span1-2 <%= is_sort_active?('status') %>">
<%= t('bulletin.status') %> <%= link_to t('bulletin.status') + content_tag(:b, nil, :class => is_sort?('status')), panel_announcement_back_end_bulletins_path(sortable('status')) %>
<%= content_tag(:b, nil, :class => is_sort?('status')) %>
</th> </th>
<th class="sort span1-2 <%= is_sort_active?('category') %>" rel="<%= panel_announcement_back_end_bulletins_path(sortable('category')) %>"> <th class="sort span1-2 <%= is_sort_active?('category') %>">
<%= t('bulletin.category') %> <%= link_to t('bulletin.category') + content_tag(:b, nil, :class => is_sort?('category')), panel_announcement_back_end_bulletins_path(sortable('category')) %>
<%= content_tag(:b, nil, :class => is_sort?('category')) %>
</th> </th>
<th class="sort span7 <%= is_sort_active?('title') %>" rel="<%= panel_announcement_back_end_bulletins_path(sortable('title')) %>"> <th class="sort span7 <%= is_sort_active?('title') %>">
<%= t('bulletin.title') %> <%= link_to t('bulletin.title') + content_tag(:b, nil, :class => is_sort?('title')), panel_announcement_back_end_bulletins_path(sortable('title')) %>
<%= content_tag(:b, nil, :class => is_sort?('title')) %>
</th> </th>
<th class="sort span1-2 <%= is_sort_active?('postdate') %>" rel="<%= panel_announcement_back_end_bulletins_path(sortable('postdate')) %>"> <th class="sort span1-2 <%= is_sort_active?('postdate') %>">
<%= t('bulletin.start_date') %> <%= link_to t('bulletin.start_date') + content_tag(:b, nil, :class => is_sort?('postdate')), panel_announcement_back_end_bulletins_path(sortable('postdate')) %>
<%= content_tag(:b, nil, :class => is_sort?('postdate')) %>
</th> </th>
<th class="sort span1-2 <%= is_sort_active?('deadline') %>" rel="<%= panel_announcement_back_end_bulletins_path(sortable('deadline')) %>"> <th class="sort span1-2 <%= is_sort_active?('deadline') %>">
<%= t('bulletin.end_date') %> <%= link_to t('bulletin.end_date') + content_tag(:b, nil, :class => is_sort?('deadline')), panel_announcement_back_end_bulletins_path(sortable('deadline')) %>
<%= content_tag(:b, nil, :class => is_sort?('deadline')) %>
</th> </th>
<th class="sort span1-2 <%= is_sort_active?('tags') %>" rel="<%= panel_announcement_back_end_bulletins_path(sortable('tags')) %>"> <th class="sort span1-2 <%= is_sort_active?('tags') %>">
<%= t('bulletin.tags') %> <%= link_to t('bulletin.tags') + content_tag(:b, nil, :class => is_sort?('tags')), panel_announcement_back_end_bulletins_path(sortable('tags')) %>
<%= content_tag(:b, nil, :class => is_sort?('tags')) %>
</th> </th>
<th class="sort span1-2 <%= is_sort_active?('update_user_id') %>" rel="<%= panel_announcement_back_end_bulletins_path(sortable('update_user_id')) %>"> <th class="sort span1-2 <%= is_sort_active?('update_user_id') %>">
<%= t('bulletin.last_modified') %> <%= link_to t('bulletin.last_modified') + content_tag(:b, nil, :class => is_sort?('update_user_id')), panel_announcement_back_end_bulletins_path(sortable('update_user_id')) %>
<%= content_tag(:b, nil, :class => is_sort?('update_user_id')) %>
</th> </th>
</tr> </tr>
</thead> </thead>

View File

@ -3,6 +3,8 @@
<%= render 'bulletins' %> <%= render 'bulletins' %>
</table> </table>
<%= paginate @bulletins %>
<div id="bulletin_link_qe"> <div id="bulletin_link_qe">
<div id="modal-link" class="modal fade"> <div id="modal-link" class="modal fade">
<%= render :partial => "bulletin_link_qe" %> <%= render :partial => "bulletin_link_qe" %>

View File

@ -1 +0,0 @@
$("#bulettin_sort_list").html("<%= j render 'bulletins' %>")