From e19efc1c8a8b75def63caec6280ab792c0bd238d Mon Sep 17 00:00:00 2001 From: cxt Date: Thu, 14 Jul 2016 14:44:47 +0800 Subject: [PATCH] =?UTF-8?q?=E5=8D=9A=E5=AE=A2=E7=9A=84=E4=BA=8C=E7=BA=A7?= =?UTF-8?q?=E5=9B=9E=E5=A4=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/blog_comments_controller.rb | 25 +++-- app/controllers/users_controller.rb | 8 +- .../_simple_ke_reply_form.html.erb | 9 +- app/views/blog_comments/destroy.js.erb | 7 ++ app/views/blog_comments/quote.js.erb | 4 +- app/views/blog_comments/show.html.erb | 99 ++++++++++--------- app/views/blogs/_homepage.html.erb | 10 +- app/views/messages/_course_show.html.erb | 2 +- .../users/_blog_comment_reply_banner.html.erb | 18 ++++ .../users/_blog_comments_replies.html.erb | 9 +- app/views/users/_reply_to.html.erb | 8 +- app/views/users/_user_blog.html.erb | 7 +- app/views/users/all_journals.js.erb | 4 +- app/views/users/show_all_replies.js.erb | 2 +- public/javascripts/application.js | 34 +++++++ 15 files changed, 169 insertions(+), 77 deletions(-) create mode 100644 app/views/blog_comments/destroy.js.erb create mode 100644 app/views/users/_blog_comment_reply_banner.html.erb diff --git a/app/controllers/blog_comments_controller.rb b/app/controllers/blog_comments_controller.rb index a6e383504..dcab1b360 100644 --- a/app/controllers/blog_comments_controller.rb +++ b/app/controllers/blog_comments_controller.rb @@ -70,6 +70,10 @@ class BlogCommentsController < ApplicationController @course.outline = 0 @course.save redirect_to course_path(:id=>params[:course_id]) + elsif params[:user_activity_id] + @article.children.destroy + @article.destroy + redirect_to user_path(User.current.id) else @article.children.destroy @article.destroy @@ -80,6 +84,17 @@ class BlogCommentsController < ApplicationController if params[:course_id] #如果带了course_id过来了,那么这是要跳到课程大纲去的 @article.destroy redirect_to syllabus_course_path(:id=>params[:course_id]) + elsif params[:user_activity_id] + if params[:homepage] && params[:homepage] == "1" + @in_user_homepage = true + end + @user_activity_id = params[:user_activity_id] + @blog_comment = @article.root + @article.destroy + respond_to do |format| + format.js + return + end else root = @article.root @article.destroy @@ -102,13 +117,9 @@ class BlogCommentsController < ApplicationController def quote @blogComment = BlogComment.find(params[:id]) - @subject = @blogComment.title - @subject = "RE: #{@subject}" unless @subject.starts_with?('RE:') - @content = "> #{ll(Setting.default_language, :text_user_wrote, @blogComment.author.realname)}\n> " @temp = BlogComment.new @course_id = params[:course_id] - @temp.content = "
#{ll(Setting.default_language, :text_user_wrote, @blogComment.author.realname)}
#{@blogComment.content.html_safe}
".html_safe respond_to do | format| format.js end @@ -116,14 +127,13 @@ class BlogCommentsController < ApplicationController #回复 def reply - if params[:homepage] + if params[:homepage] && params[:homepage] == "1" @in_user_homepage = true end if params[:in_user_center] @in_user_center = true end @article = BlogComment.find(params[:id]).root - @quote = params[:quote][:quote] @blogComment = BlogComment.new @blogComment.author = User.current @blogComment.blog = Blog.find(params[:blog_id]) @@ -131,12 +141,13 @@ class BlogCommentsController < ApplicationController params[:blog_comment][:locked] = params[:blog_comment][:locked] || 0 @blogComment.safe_attributes = params[:blog_comment] @blogComment.title = "RE: #{@article.title}" unless params[:blog_comment][:title] - if params[:activity_id] + if params[:parent_id] @blogComment.content = params[:blog_comment][:content] parent = BlogComment.find params[:parent_id] @blogComment.reply_id = params[:reply_id] parent.children << @blogComment else + @quote = params[:quote][:quote] || "" @blogComment.content = @quote + @blogComment.content @article.children << @blogComment end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 633254978..e7c75eb13 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -92,6 +92,8 @@ class UsersController < ApplicationController @comment = JournalsForMessage.find params[:comment].to_i when 'Message' @comment = Message.find params[:comment].to_i + when 'BlogComment' + @comment = BlogComment.find params[:comment].to_i end end @@ -124,6 +126,7 @@ class UsersController < ApplicationController @reply = BlogComment.find params[:reply_id] @user_activity_id = params[:user_activity_id] @activity_id = params[:activity_id] + @homepage = params[:homepage] @type = 'BlogComment' end respond_to do |format| @@ -3310,7 +3313,10 @@ class UsersController < ApplicationController @journals = obj.journals.reorder("created_on desc") when 'BlogComment' obj = BlogComment.where('id = ?', params[:id].to_i).first - @journals = obj.children.reorder("created_on desc") + @user_activity_id = params[:div_id].to_i if params[:div_id] + @homepage = params[:homepage].to_i + comments = [] + @journals = get_all_children(comments, obj) when 'HomeworkCommon' obj = HomeworkCommon.where('id = ?', params[:id].to_i).first @journals = obj.journals_for_messages.reorder("created_on desc") diff --git a/app/views/blog_comments/_simple_ke_reply_form.html.erb b/app/views/blog_comments/_simple_ke_reply_form.html.erb index 8339ae5ad..7318aaec9 100644 --- a/app/views/blog_comments/_simple_ke_reply_form.html.erb +++ b/app/views/blog_comments/_simple_ke_reply_form.html.erb @@ -3,12 +3,15 @@
<% if User.current.logged? %>
- <%= form_for @blog_comment, :as => :reply, :url => {:controller => 'blog_comments',:action => 'reply', :id => @blogComment.id}, :html => {:multipart => true, :id => 'new_form'} do |f| %> - + <%= form_for('new_form', :url => {:controller => 'blog_comments',:action => 'reply', :id => reply.id, :blog_id => reply.blog.id, :user_id => User.current.id}, :method => "post", :html => {:multipart => true}) do |f| %> + + <%#= form_for @blog_comment, :as => :reply, :url => {:controller => 'blog_comments',:action => 'reply', :id => @blogComment.id}, :html => {:multipart => true, :id => 'new_form'} do |f| %> + <% if course_id%> <% end %> - + <%= hidden_field_tag 'parent_id', params[:parent_id], :value => reply.id %> + <%= hidden_field_tag 'reply_id', params[:reply_id], :value => reply.author_id %>
diff --git a/app/views/blog_comments/destroy.js.erb b/app/views/blog_comments/destroy.js.erb new file mode 100644 index 000000000..c34986977 --- /dev/null +++ b/app/views/blog_comments/destroy.js.erb @@ -0,0 +1,7 @@ +<% if @in_user_homepage %> + <% homepage = BlogComment.find(User.current.blog.homepage_id) %> + $("#user_activity_<%= @user_activity_id%>").replaceWith("<%= escape_javascript(render :partial => 'blogs/homepage', :locals => {:activity => @blog_comment, :user_activity_id => homepage.id}) %>"); +<% else%> + $("#user_activity_<%= @user_activity_id%>").replaceWith("<%= escape_javascript(render :partial => 'users/user_blog', :locals => {:activity => @blog_comment,:user_activity_id =>@user_activity_id}) %>"); +<% end %> +sd_create_editor_from_data(<%= @user_activity_id%>,"","100%", 'UserActivity'); \ No newline at end of file diff --git a/app/views/blog_comments/quote.js.erb b/app/views/blog_comments/quote.js.erb index 9bd226ce1..6d3264a22 100644 --- a/app/views/blog_comments/quote.js.erb +++ b/app/views/blog_comments/quote.js.erb @@ -1,8 +1,6 @@ if($("#reply_message_<%= @blogComment.id%>").length > 0) { - $("#reply_message_<%= @blogComment.id%>").replaceWith("<%= escape_javascript(render :partial => 'blog_comments/simple_ke_reply_form', :locals => {:reply => @blogComment,:temp =>@temp,:subject =>@subject,:course_id=>@course_id}) %>"); + $("#reply_message_<%= @blogComment.id%>").replaceWith("<%= escape_javascript(render :partial => 'blog_comments/simple_ke_reply_form', :locals => {:reply => @blogComment,:temp =>@temp,:course_id=>@course_id}) %>"); $(function(){ - $('#reply_subject').val("<%= raw escape_javascript(@subject) %>"); - $('#quote_quote').val("<%= raw escape_javascript(@temp.content.html_safe) %>"); sd_create_editor_from_data(<%= @blogComment.id%>,null,"100%", "<%=@blogComment.class.to_s%>"); }); }else if($("#reply_to_message_<%= @blogComment.id%>").length >0) { diff --git a/app/views/blog_comments/show.html.erb b/app/views/blog_comments/show.html.erb index b1cd86484..bde98d456 100644 --- a/app/views/blog_comments/show.html.erb +++ b/app/views/blog_comments/show.html.erb @@ -91,9 +91,7 @@
<%= format_time( @article.created_on)%>
- - - + <%=render :partial =>"users/intro_content", :locals=>{:user_activity_id =>@article.id, :content=>@article.content} %>
@@ -107,73 +105,84 @@
- <% count=0 %> - <% if @article.parent %> - <% count=@article.parent.children.count%> - <% else %> - <% count=@article.children.count%> - <% end %> + <% all_comments = []%> + <% count=get_all_children(all_comments, @article).count %>
- <%# unless count == 0 %> -
-
回复 - <%= count>0 ? "(#{count})" : "" %> - - <%=render :partial=> "praise_tread/praise", :locals => {:activity=>@article, :user_activity_id=>@article.id,:type=>"activity"}%> +
+
回复 + <%= count>0 ? "(#{count})" : "" %> + + + <%= render :partial => "praise_tread/praise", :locals => {:activity => @article, :user_activity_id => @article.id, :type => "activity"} %> -
-
-
-
- <%@article.children.reorder('created_on desc').each_with_index do |reply,i| %> +
+
+
+ + <% all_comments = []%> + <% comments = get_all_children(all_comments, @article) %> + <% if count > 0 %> +
+ <% comments.each do |comment| %> -
+
  • - <%= link_to image_tag(url_to_avatar(reply.author), :width => 33,:height => 33), user_path(reply.author) %> + <%= link_to image_tag(url_to_avatar(comment.creator_user), :width => 33, :height => 33, :alt => "用户头像"), user_url_in_org(comment.creator_user.id) %>
    - <%= link_to reply.author.show_name, user_path(reply.author_id,:host=>Setting.host_user), :class => "newsBlue mr10 f14" %> + <%= link_to comment.creator_user.show_name, user_url_in_org(comment.creator_user.id), :class => "newsBlue mr10 f14" %> + <%= time_from_now(comment.created_on) %>
    -
    - <%= reply.content.html_safe%> -
    -
    - <%= format_time(reply.created_on) %> - - <%=render :partial=> "praise_tread/praise", :locals => {:activity=>reply, :user_activity_id=>reply.id,:type=>"reply"}%> + <% if !comment.parent.nil? && !comment.parent.parent.nil? %> + <%= render :partial => 'users/message_contents', :locals => {:comment => comment}%> + <% end %> + <% if !comment.content_detail.blank? %> +
    + <%= comment.content_detail.html_safe %> +
    +
    +
    + + + <%=render :partial=> "praise_tread/praise", :locals => {:activity=>comment, :user_activity_id=>comment.id,:type=>"reply"}%> - -
    -

    + ) %> + <% end %> + +
    +
    +
    +

    + <% end %>
    -
  • - <% end %> + <% end %>
    + <% end %> - <%# end %>
    <% if !@article.locked? && User.current.logged?%>
    diff --git a/app/views/blogs/_homepage.html.erb b/app/views/blogs/_homepage.html.erb index 140f547cb..d5a5c0d64 100644 --- a/app/views/blogs/_homepage.html.erb +++ b/app/views/blogs/_homepage.html.erb @@ -48,14 +48,16 @@
    - <% count=activity.children.count %> + <% all_comments = []%> + <% count=get_all_children(all_comments, activity).count %>
    - <%= render :partial => 'users/reply_banner', :locals => {:count => count, :activity => activity, :user_activity_id => user_activity_id} %> + <%= render :partial => 'users/blog_comment_reply_banner', :locals => {:count => count, :activity => activity, :user_activity_id => user_activity_id, :homepage => 1} %> - <% comments = activity.children.reorder("created_on desc").limit(3) %> + <% all_comments = []%> + <% comments = get_all_children(all_comments, activity)[0..2] %> <% if count > 0 %>
    - <%= render :partial => 'users/all_replies', :locals => {:comments => comments}%> + <%= render :partial => 'users/blog_comments_replies', :locals => {:comments => comments, :user_activity_id => user_activity_id, :type => 'BlogComment', :activity_id =>activity.id, :homepage => 1}%>
    <% end %> diff --git a/app/views/messages/_course_show.html.erb b/app/views/messages/_course_show.html.erb index 232be1f35..b37540810 100644 --- a/app/views/messages/_course_show.html.erb +++ b/app/views/messages/_course_show.html.erb @@ -116,7 +116,7 @@
    <% if !reply.parent.nil? && !reply.parent.parent.nil? %> <%= render :partial => 'users/message_contents', :locals => {:comment => reply}%> - <% end %> + <% end %>
    <%= reply.content.html_safe%>
    diff --git a/app/views/users/_blog_comment_reply_banner.html.erb b/app/views/users/_blog_comment_reply_banner.html.erb new file mode 100644 index 000000000..496cd2c7c --- /dev/null +++ b/app/views/users/_blog_comment_reply_banner.html.erb @@ -0,0 +1,18 @@ +
    +
    + 回复 + ︿ + <%= count>0 ? "(#{count})" : "" %> + + <%=render :partial=> "praise_tread/praise", :locals => {:activity=>activity, :user_activity_id=>user_activity_id,:type=>"activity"}%> + +
    +
    <%#= format_date(activity.updated_on) %>
    + <%if count>3 %> + + <% end %> +
    \ No newline at end of file diff --git a/app/views/users/_blog_comments_replies.html.erb b/app/views/users/_blog_comments_replies.html.erb index 181f6698a..b4a134b7b 100644 --- a/app/views/users/_blog_comments_replies.html.erb +++ b/app/views/users/_blog_comments_replies.html.erb @@ -31,18 +31,19 @@ <%= link_to( l(:button_reply), - {:controller => 'users' ,:action => 'reply_to', :reply_id => comment.id, :type => type, :user_activity_id => user_activity_id, :activity_id => activity_id}, + {:controller => 'users' ,:action => 'reply_to', :reply_id => comment.id, :type => type, :user_activity_id => user_activity_id, :activity_id => activity_id, :homepage => homepage}, :remote => true, :method => 'get', - :title => l(:button_reply)) %> + :title => l(:button_reply)) if !comment.root.locked? %> <% if comment.author == User.current %> <%= link_to( l(:button_delete), - {:controller => 'blog_comments',:action => 'destroy', :id => comment.id}, + {:controller => 'blog_comments',:action => 'destroy', :id => comment.id, :user_activity_id => user_activity_id, :homepage => homepage}, :method => :delete, - :class => 'fr newsGrey mr10', + :remote => true, + :class => 'fr mr20', :data => {:confirm => l(:text_are_you_sure)}, :title => l(:button_delete)) %> <% end %> diff --git a/app/views/users/_reply_to.html.erb b/app/views/users/_reply_to.html.erb index 8358a7d23..5c3f2a70b 100644 --- a/app/views/users/_reply_to.html.erb +++ b/app/views/users/_reply_to.html.erb @@ -36,8 +36,6 @@ <%= hidden_field_tag 'reply_id', params[:reply_id], :value => reply.author.id %> <%= hidden_field_tag 'activity_id',params[:activity_id],:value =>@activity_id %> <%= hidden_field_tag 'user_activity_id',params[:user_activity_id],:value =>@user_activity_id %> -
    @@ -45,12 +43,14 @@

    <% end%> <% elsif @type == 'BlogComment' %> - <%= form_for('new_form', :url => {:controller => 'blog_comments',:action => 'reply', :id => reply.id, :blog_id => reply.blog.id}, :method => "post", :remote => true) do |f| %> + <%#= form_for reply, :as => :reply, :url => {:controller => 'blog_comments',:action => 'reply', :id => reply.id, :blog_id => reply.blog.id}, :html => {:multipart => true, :id => 'new_form'} do |f| %> + + <%= form_for('new_form', :url => {:controller => 'blog_comments',:action => 'reply', :id => reply.id, :blog_id => reply.blog.id, :user_id => User.current.id}, :method => "post", :remote => true) do |f| %> <%= hidden_field_tag 'user_activity_id',params[:user_activity_id],:value =>@user_activity_id %> - <%= hidden_field_tag 'activity_id',params[:activity_id],:value =>@activity_id %> <%= hidden_field_tag 'parent_id', params[:parent_id], :value => reply.id %> <%= hidden_field_tag 'reply_id', params[:reply_id], :value => reply.author_id %> + <%= hidden_field_tag 'homepage', params[:homepage], :value => @homepage %>
    diff --git a/app/views/users/_user_blog.html.erb b/app/views/users/_user_blog.html.erb index 868f92979..a19bfc016 100644 --- a/app/views/users/_user_blog.html.erb +++ b/app/views/users/_user_blog.html.erb @@ -41,15 +41,16 @@
    - <% count=activity.children.count %> + <% all_comments = []%> + <% count=get_all_children(all_comments, activity).count %>
    - <%= render :partial => 'users/reply_banner', :locals => {:count => count, :activity => activity, :user_activity_id => user_activity_id} %> + <%= render :partial => 'users/blog_comment_reply_banner', :locals => {:count => count, :activity => activity, :user_activity_id => user_activity_id, :homepage => 0} %> <% all_comments = []%> <% comments = get_all_children(all_comments, activity)[0..2] %> <% if count > 0 %>
    - <%= render :partial => 'users/blog_comments_replies', :locals => {:comments => comments, :user_activity_id => user_activity_id, :type => 'BlogComment', :activity_id =>activity.id}%> + <%= render :partial => 'users/blog_comments_replies', :locals => {:comments => comments, :user_activity_id => user_activity_id, :type => 'BlogComment', :activity_id =>activity.id, :homepage => 0}%>
    <% end %> diff --git a/app/views/users/all_journals.js.erb b/app/views/users/all_journals.js.erb index d03e13742..30ae23bfb 100644 --- a/app/views/users/all_journals.js.erb +++ b/app/views/users/all_journals.js.erb @@ -3,7 +3,9 @@ $('#reply_div_<%= params[:div_id].to_i %>').html('<%=escape_javascript(render :p <% elsif params[:type] == 'JournalsForMessage' %> $('#reply_div_<%= @user_activity_id %>').html('<%=escape_javascript(render :partial => 'users/journal_replies', :locals => {:comments => @journals,:user_activity_id => @user_activity_id, :type => @type, :allow_delete => @allow_delete, :activity_id =>params[:id].to_i}) %>'); <% elsif params[:type] == 'Message' %> -$('#reply_div_<%= params[:div_id].to_i %>').html('<%=escape_javascript(render :partial => 'users/message_replies', :locals => {:comments => @journals,:user_activity_id => @user_activity_id, :type => @type, :activity_id =>params[:id].to_i,:is_course => @is_course, :is_board => @is_board}) %>'); +$('#reply_div_<%= params[:div_id].to_i %>').html('<%=escape_javascript(render :partial => 'users/message_replies', :locals => {:comments => @journals,:user_activity_id => @user_activity_id, :type => @type, :activity_id => params[:id].to_i,:is_course => @is_course, :is_board => @is_board}) %>'); +<% elsif params[:type] == 'BlogComment' %> +$('#reply_div_<%= params[:div_id].to_i %>').html('<%=escape_javascript(render :partial => 'users/blog_comments_replies', :locals => {:comments => @journals,:user_activity_id => @user_activity_id, :type => @type, :activity_id => params[:id].to_i, :homepage => @homepage}) %>'); <% else %> $('#reply_div_<%= params[:div_id].to_i %>').html('<%=escape_javascript(render :partial => 'users/all_replies', :locals => {:comments => @journals}) %>'); <% end %> diff --git a/app/views/users/show_all_replies.js.erb b/app/views/users/show_all_replies.js.erb index ae8803653..2d4321bce 100644 --- a/app/views/users/show_all_replies.js.erb +++ b/app/views/users/show_all_replies.js.erb @@ -1,7 +1,7 @@ <% unless @comment.parent.nil? %> <% if params[:type] == 'JournalsForMessage' && (@comment.jour_type == 'Principal' || @comment.jour_type == 'Course') %> $('#comment_reply_<%=@comment.id %>').html("<%= escape_javascript(render :partial => 'users/journal_comment_reply', :locals => {:comment => @comment.parent})%>"); - <% elsif @comment.class.to_s == 'Message' %> + <% elsif (@comment.class.to_s == 'Message' || @comment.class.to_s == 'BlogComment' ) %> $('#comment_reply_<%=@comment.id %>').html("<%= escape_javascript(render :partial => 'users/journal_comment_reply', :locals => {:comment => @comment.parent})%>"); <% else %> $('#comment_reply_<%=@comment.id %>').html("<%= escape_javascript(render :partial => 'users/comment_reply', :locals => {:comment => @comment.parent})%>"); diff --git a/public/javascripts/application.js b/public/javascripts/application.js index a342a9608..fb7c6cda2 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -1409,6 +1409,40 @@ function expand_message_reply(container, btnid, id, type, div_id, is_course, is_ } } +function expand_blog_comment_reply(container, btnid, id, type, div_id, homepage) { + var target = $(container); + var btn = $(btnid); + if (btn.data('init') == '0') { + btn.data('init', 1); + $.get( + '/users/all_journals', + { + type: type, + id: id, + div_id: div_id, + homepage: homepage + }, + function(data) { + + } + ); + btn.html('收起回复'); + //target.show(); + } else if(btn.data('init') == '1') { + btn.data('init', 3); + btn.html('展开更多'); + target.hide(); + target.eq(0).show(); + target.eq(1).show(); + target.eq(2).show(); + } + else { + btn.data('init', 1); + btn.html('收起回复'); + target.show(); + } +} + function expand_reply_homework(container, btnid, id, type, div_id, is_in_course, course_activity, user_activity_id) { var target = $(container); var btn = $(btnid);