新闻、通知的回复分页

This commit is contained in:
cxt 2016-09-30 16:09:10 +08:00
parent a63f58de5b
commit b25e4ed5d7
5 changed files with 90 additions and 58 deletions

View File

@ -171,6 +171,10 @@ class NewsController < ApplicationController
result = cs.show_course_news params,User.current result = cs.show_course_news params,User.current
@news = result[:news] @news = result[:news]
@comments = result[:comments] @comments = result[:comments]
@comments_count = @comments.count
@page = params[:page] ? params[:page].to_i + 1 : 0
@limit = 10
@comments = @comments[@page * @limit..@page * @limit + 9]
@comment = Comment.new @comment = Comment.new
#@comments = @news.comments #@comments = @news.comments
#@comments.reverse! if User.current.wants_comments_in_reverse_order? #@comments.reverse! if User.current.wants_comments_in_reverse_order?
@ -179,12 +183,23 @@ class NewsController < ApplicationController
@course = Course.find(@news.course_id) @course = Course.find(@news.course_id)
if @course if @course
@left_nav_type = 4 @left_nav_type = 4
render :layout => 'base_courses' respond_to do |format|
format.js
format.html {render :layout => 'base_courses'}
end
end
elsif @project
respond_to do |format|
format.js
format.html {render :layout => 'base_projects'}
end end
elsif @news.org_subfield_id elsif @news.org_subfield_id
@org_subfield = OrgSubfield.find(@news.org_subfield_id) @org_subfield = OrgSubfield.find(@news.org_subfield_id)
@organization = @org_subfield.organization @organization = @org_subfield.organization
render :layout => 'base_org' respond_to do |format|
format.js
format.html {render :layout => 'base_org'}
end
end end
end end

View File

@ -1,6 +1,6 @@
<div class="homepagePostReplyBanner"> <div class="homepagePostReplyBanner">
<div class="homepagePostReplyBannerCount">回复 <div class="homepagePostReplyBannerCount">回复
<sapn class="mr15"><%= @comments.count>0 ? "#{@comments.count}" : "" %></sapn><span style="color: #cecece;">▪</span> <sapn class="mr15"><%= @comments_count>0 ? "#{@comments_count}" : "" %></sapn><span style="color: #cecece;">▪</span>
<span id="praise_count_<%=@news.id %>"> <span id="praise_count_<%=@news.id %>">
<%=render :partial=> "praise_tread/praise", :locals => {:activity=>@news, :user_activity_id=>@news.id,:type=>"activity"}%> <%=render :partial=> "praise_tread/praise", :locals => {:activity=>@news, :user_activity_id=>@news.id,:type=>"activity"}%>
</span> </span>
@ -8,60 +8,7 @@
</div> </div>
<% unless @comments.empty? %> <% unless @comments.empty? %>
<div class="" id="reply_div_<%=@news.id %>"> <div class="" id="reply_div_<%=@news.id %>">
<% @comments.each_with_index do |comment,i| %> <%= render :partial => 'news/news_replies_detail', :locals => {:object => object} %>
<script type="text/javascript">
$(function(){
showNormalImage('reply_message_description_<%= comment.id %>');
autoUrl('reply_message_description_<%= comment.id %>');
});
</script>
<li class="homepagePostReplyContainer" nhname="reply_rec">
<div class="homepagePostReplyPortrait">
<%= link_to image_tag(url_to_avatar(comment.creator_user), :width => 33, :height => 33, :alt => "用户头像"), user_url_in_org(comment.creator_user.id) %>
</div>
<div class="homepagePostReplyDes" onmouseover="$('#delete_reply_<%=comment.id %>').show();" onmouseout="$('#delete_reply_<%=comment.id %>').hide();">
<%= render :partial => 'users/news_contents', :locals => {:comment => comment}%>
<% if !comment.content_detail.blank? %>
<div class="homepagePostReplyContent break_word list_style upload_img table_maxWidth" id="reply_content_<%= comment.id %>">
<%= comment.content_detail.html_safe %>
</div>
<div class="orig_reply mb10 mt-10">
<div class="reply">
<span class="reply-right">
<span id="reply_praise_count_<%=comment.id %>">
<%=render :partial=> "praise_tread/praise", :locals => {:activity=>comment, :user_activity_id=>comment.id,:type=>"reply"}%>
</span>
<span style="position: relative" class="fr mr20">
<%= link_to(
l(:button_reply),
{:controller => 'comments',:action => 'quote', :id => comment},
:remote => true,
:method => 'get',
:title => l(:button_reply))%>
<span id="reply_iconup_<%= comment.id %>" class="reply_iconup02" style="display: none"> ︿</span>
</span>
<%= link_to(
l(:button_delete),
{:controller => 'comments',
:action => 'destroy', :id => @news,
:comment_id => comment},
:method => :delete,
:id => "delete_reply_#{comment.id}",
:class => 'fr mr20 undis',
:data => {:confirm => l(:text_are_you_sure)},
:title => l(:button_delete)
) if User.current.allowed_to?(:manage_news, object) %>
</span>
<div class="cl"></div>
</div>
</div>
<p id="reply_message_<%= comment.id%>"></p>
<% end %>
</div>
<div class="cl"></div>
</li>
<% end %>
</div> </div>
<% end %> <% end %>

View File

@ -0,0 +1,63 @@
<% @comments.each_with_index do |comment,i| %>
<script type="text/javascript">
$(function(){
showNormalImage('reply_message_description_<%= comment.id %>');
autoUrl('reply_message_description_<%= comment.id %>');
});
</script>
<li class="homepagePostReplyContainer" nhname="reply_rec">
<div class="homepagePostReplyPortrait">
<%= link_to image_tag(url_to_avatar(comment.creator_user), :width => 33, :height => 33, :alt => "用户头像"), user_url_in_org(comment.creator_user.id) %>
</div>
<div class="homepagePostReplyDes" onmouseover="$('#delete_reply_<%=comment.id %>').show();" onmouseout="$('#delete_reply_<%=comment.id %>').hide();">
<%= render :partial => 'users/news_contents', :locals => {:comment => comment}%>
<% if !comment.content_detail.blank? %>
<div class="homepagePostReplyContent break_word list_style upload_img table_maxWidth" id="reply_content_<%= comment.id %>">
<%= comment.content_detail.html_safe %>
</div>
<div class="orig_reply mb10 mt-10">
<div class="reply">
<span class="reply-right">
<span id="reply_praise_count_<%=comment.id %>">
<%=render :partial=> "praise_tread/praise", :locals => {:activity=>comment, :user_activity_id=>comment.id,:type=>"reply"}%>
</span>
<span style="position: relative" class="fr mr20">
<%= link_to(
l(:button_reply),
{:controller => 'comments',:action => 'quote', :id => comment},
:remote => true,
:method => 'get',
:title => l(:button_reply))%>
<span id="reply_iconup_<%= comment.id %>" class="reply_iconup02" style="display: none"> ︿</span>
</span>
<%= link_to(
l(:button_delete),
{:controller => 'comments',
:action => 'destroy', :id => @news,
:comment_id => comment},
:method => :delete,
:id => "delete_reply_#{comment.id}",
:class => 'fr mr20 undis',
:data => {:confirm => l(:text_are_you_sure)},
:title => l(:button_delete)
) if ((object.kind_of? Organization) ? User.current.allowed_to?(:manage_news, object) : (User.current.admin_of_org?(object) || User.current == comment.author)) %>
</span>
<div class="cl"></div>
</div>
</div>
<p id="reply_message_<%= comment.id%>"></p>
<% end %>
</div>
<div class="cl"></div>
</li>
<% end %>
<% if @comments_count > @page * @limit + 10 %>
<div id="more_news_replies">
<div class="detail_cont_hide clearfix">
<span class="orig_icon" >&darr; </span>
<span class="orig_icon" style="display:none;" > &uarr;</span>
<%= link_to '点击展开更多回复', news_path(@news, :page => @page), :remote=>true %>
</div>
</div>
<% end %>

View File

@ -72,7 +72,7 @@
</div> </div>
<div class="cl"></div> <div class="cl"></div>
<div class="homepagePostReply"> <div class="homepagePostReply">
<%= render :partial => 'news/news_all_replies' %> <%= render :partial => 'news/news_all_replies', :locals => {:object => @organization} %>
</div> </div>
</div> </div>
<script type="text/javascript"> <script type="text/javascript">

View File

@ -0,0 +1,7 @@
<% if @project %>
$("#more_news_replies").replaceWith("<%= escape_javascript(render :partial => 'news/news_replies_detail', :locals => {:object => @project})%>");
<% elsif @course %>
$("#more_news_replies").replaceWith("<%= escape_javascript(render :partial => 'news/news_replies_detail', :locals => {:object => @course})%>");
<% elsif @organization %>
$("#more_news_replies").replaceWith("<%= escape_javascript(render :partial => 'news/news_replies_detail', :locals => {:object => @organization})%>");
<% end %>