贴吧列表和主题列表 按不同的规则排序的时候,如果翻页了,又回到了综合排序的问题

This commit is contained in:
lizanle 2015-09-19 12:32:11 +08:00
parent 543e9711b3
commit 46c806900e
7 changed files with 65 additions and 12 deletions

View File

@ -98,12 +98,21 @@ class ForumsController < ApplicationController
def index
@offset, @limit = api_offset_and_limit({:limit => 10})
if(params[:reorder_complex])
@type="reorder_complex"
@str=params[:reorder_complex]
@forums_all = Forum.reorder("topic_count #{params[:reorder_complex]},updated_at #{params[:reorder_complex]}")
elsif(params[:reorder_popu])
@type="reorder_popu"
@str=params[:reorder_popu]
@forums_all = Forum.reorder("topic_count #{params[:reorder_popu]}")
elsif(params[:reorder_time])
@type="reorder_time"
@str=params[:reorder_time]
@forums_all = Forum.reorder("updated_at #{params[:reorder_time]}")
else
params[:reorder_complex] = "desc"
@type="reorder_complex"
@str=params[:reorder_complex]
@forums_all = Forum.reorder("topic_count desc,updated_at desc")
end
@forums_count = @forums_all.count
@ -127,14 +136,19 @@ class ForumsController < ApplicationController
# 'replies' => "#{Memo.table_name}.replies_count",
# 'updated_at' => "COALESCE (last_replies_memos.created_at, #{Memo.table_name}.created_at)"
order = ""
@order_str = ""
if(params[:reorder_complex])
order = " last_replies_memos.created_at #{params[:reorder_complex]}, #{Memo.table_name}.created_at #{params[:reorder_complex]}"
@order_str = "reorder_complex="+params[:reorder_complex]
elsif(params[:reorder_popu])
order = "replies_count #{params[:reorder_popu]}"
@order_str = "reorder_popu="+params[:reorder_popu]
elsif(params[:reorder_time])
order = "#{Memo.table_name}.updated_at #{params[:reorder_time]}"
@order_str = "reorder_time="+params[:reorder_time]
else
order = "last_replies_memos.created_at desc, #{Memo.table_name}.created_at desc"
@order_str = "reorder_complex=desc"
end
@memo = Memo.new(:forum => @forum)
@topic_count = @forum.topics.count

View File

@ -0,0 +1,33 @@
<div class="postSort" id="complex"><a href="javascript:void(0);" class="linkGrey2 fl">综合</a>
<% if order_type=='reorder_complex' && order_str == 'desc' %>
<a href="javascript:void(0);" id="reorder_complex" class="sortArrowActiveD"></a>
<% elsif order_type=='reorder_complex' && order_str == 'asc' %>
<a href="javascript:void(0);" id="reorder_complex" class="sortArrowActiveU"></a>
<% else %>
<a href="javascript:void(0);" id="reorder_complex" ></a>
<% end %>
</div>
<div class="postSort" id="popu"><a href="javascript:void(0);" class="linkGrey2 fl">人气</a>
<% if order_type=='reorder_popu' && order_str == 'desc' %>
<a href="javascript:void(0);" id="reorder_popu" class="sortArrowActiveD"></a>
<% elsif order_type=='reorder_popu' && order_str == 'asc' %>
<a href="javascript:void(0);" id="reorder_popu" class="sortArrowActiveU"></a>
<% else %>
<a href="javascript:void(0);" id="reorder_popu" ></a>
<% end %>
</div>
<div class="postSort" id="time"><a href="javascript:void(0);" class="linkGrey2 fl">时间</a>
<% if order_type=='reorder_time' && order_str == 'desc' %>
<a href="javascript:void(0);" id="reorder_time" class="sortArrowActiveD"></a>
<% elsif order_type=='reorder_time' && order_str == 'asc' %>
<a href="javascript:void(0);" id="reorder_time" class="sortArrowActiveU"></a>
<% else %>
<a href="javascript:void(0);" id="reorder_time" ></a>
<% end %>
</div>
<div class="creatPost">
<a href="javascript:void(0);" id="create_btn" class="c_white db creatPostIcon bBlue"
onclick="$('#error').hide();$('#new_forum_div').slideToggle();$(this).parent().slideToggle();">新建贴吧</a></div>
<div class="cl"></div>

View File

@ -98,19 +98,21 @@
</div>
<% end %>
</div>
<div class="postBanner">
<div class="postSort" id="complex"><a href="javascript:void(0);" class="linkGrey2 fl">综合</a><a href="javascript:void(0);" id="reorder_complex" class="sortArrowActiveD"></a></div>
<div class="postSort" id="popu"><a href="javascript:void(0);" class="linkGrey2 fl">人气</a><a href="javascript:void(0)" id="reorder_popu" ></a></div>
<div class="postSort" id="time"><a href="javascript:void(0);" class="linkGrey2 fl">时间</a><a href="javascript:void(0)" id="reorder_time" ></a></div>
<div class="creatPost"><a href="javascript:void(0);" id="create_btn" class="c_white db creatPostIcon bBlue" onclick="$('#error').hide();$('#new_forum_div').slideToggle();$(this).parent().slideToggle();">新建贴吧</a></div>
<div class="cl"></div>
<div class="postBanner" id="postBanner">
<%= render :partial => 'post_banner' ,:locals => {:order_type=>@type,:order_str=>@str}%>
<!--<div class="postSort" id="complex"><a href="javascript:void(0);" class="linkGrey2 fl">综合</a><a href="javascript:void(0);" id="reorder_complex" class="sortArrowActiveD"></a></div>-->
<!--<div class="postSort" id="popu"><a href="javascript:void(0);" class="linkGrey2 fl">人气</a><a href="javascript:void(0)" id="reorder_popu" ></a></div>-->
<!--<div class="postSort" id="time"><a href="javascript:void(0);" class="linkGrey2 fl">时间</a><a href="javascript:void(0)" id="reorder_time" ></a></div>-->
<!--<div class="creatPost"><a href="javascript:void(0);" id="create_btn" class="c_white db creatPostIcon bBlue" onclick="$('#error').hide();$('#new_forum_div').slideToggle();$(this).parent().slideToggle();">新建贴吧</a></div>-->
<!--<div class="cl"></div>-->
</div>
<div id="forum_list">
<%= render :partial => 'forum_list',:locals => {:forums=>@forums}%>
</div>
<div class="pagination fr" style="margin-top: 10px;">
<%= pagination_links_full @forums_pages, @forums_count %>
<div class="pagination fr" id="pages" style="margin-top: 10px;">
<%= pagination_links_full @forums_pages, @forums_count ,:per_page_links => false,:remote =>true,:flag=>true%>
</div>
<div class="cl"></div>
</div>

View File

@ -1 +1,4 @@
$("#forum_list").html("<%= escape_javascript(render :partial => 'forum_list',:locals => {:forums=>@forums}) %>");
//$("#postBanner").html("<%#= render :partial => 'post_banner' ,:locals => {:order_type=>@type,:order_str=>@str }%>");
$("#forum_list").html("<%= escape_javascript(render :partial => 'forum_list',:locals => {:forums=>@forums}) %>");
//这里出现一个问题竟然是单双引号引起的。注意!!
$("#pages").html('<%= pagination_links_full @forums_pages, @forums_count,:per_page_links => false,:remote =>true,:flag=>true%>');

View File

@ -88,7 +88,7 @@
<div id="topics_list">
<%= render :partial => 'show_topics',:locals => {:memos=>@memos}%>
</div>
<div class="pagination" style="float: right"><%= pagination_links_full @topic_pages, @topic_count %></div>
<div class="pagination" id="pages" style="float: right"><%= pagination_links_full @topic_pages, @topic_count ,:per_page_links => false, :remote => true, :flag => true %></div>
<!--<div class="pageRoll">-->
<!--<div class="pageCell"><a href="javascript:void(0);" class="linkBlue">上一页</a></div>-->

View File

@ -1 +1,2 @@
$("#topics_list").html("<%= escape_javascript(render :partial => 'show_topics',:locals => {:memos=>@memos})%>")
$("#topics_list").html("<%= escape_javascript(render :partial => 'show_topics',:locals => {:memos=>@memos})%>")
$("#pages").html('<%= pagination_links_full @topic_pages, @topic_count,:per_page_links => false,:remote =>true%>');

View File

@ -5,7 +5,7 @@
<li class="fl"><a href="<%= agreement_path %>" class="f_grey mw20" target="_blank">服务协议</a>|</li>
<li class="fl" style="display: none"><span class="f_grey mw20" title="暂未开放"><%= l(:label_recruitment_information)%></span>|</li>
<li class="fl"><a href="http://forge.trustie.net/forums/1/memos/1168" class="f_grey mw20" target="_blank"><%= l(:label_surpport_group)%></a>|</li>
<li class="fl"><a href="<%= forums_path %>" class="f_grey mw20" target="_blank" ><%= l(:label_forums)%></a></li>
<li class="fl"><a href="<%= forums_path(:reorder_complex=>'desc')%>" class="f_grey mw20" target="_blank" ><%= l(:label_forums)%></a></li>
</ul>
</div>