diff --git a/app/controllers/forums_controller.rb b/app/controllers/forums_controller.rb index a8d3adb0a..ab17acb3f 100644 --- a/app/controllers/forums_controller.rb +++ b/app/controllers/forums_controller.rb @@ -185,13 +185,10 @@ class ForumsController < ApplicationController end @memo = Memo.new(:forum => @forum) @topic_count = @forum.topics.count - @topic_pages = Paginator.new @topic_count, per_page_option, params['page'] - @memos = @forum.topics.includes(:last_reply). - limit(@topic_pages.per_page). - offset(@topic_pages.offset). - reorder(order). - preload(:author, {:last_reply => :author}). - all + @limit = 20 + @is_remote = true + @topic_pages = Paginator.new @topic_count, @limit, params['page'] || 1 + @memos = paginateHelper @forum.topics.includes(:last_reply).reorder(order).preload(:author, {:last_reply => :author}), @limit @my_topic_count = Memo.where("forum_id = #{@memo.forum_id} and parent_id is null").count @my_replies_count = Memo.where("forum_id = #{@memo.forum_id} and parent_id is not null").count @errors = params[:errors] diff --git a/app/controllers/memos_controller.rb b/app/controllers/memos_controller.rb index 7f4c1d48e..047d7bd9b 100644 --- a/app/controllers/memos_controller.rb +++ b/app/controllers/memos_controller.rb @@ -1,6 +1,6 @@ class MemosController < ApplicationController default_search_scope :memos - before_filter :find_forum, :only => [:new, :create, :preview, :update] + before_filter :find_forum, :only => [:new, :create, :preview, :update, :reply] before_filter :find_attachments, :only => [:preview] before_filter :find_memo, :except => [:new, :create, :preview] before_filter :authenticate_user_edit, :only => [:edit, :update] @@ -88,6 +88,7 @@ class MemosController < ApplicationController REPLIES_PER_PAGE = 20 unless const_defined?(:REPLIES_PER_PAGE) def show + @user = User.current # 更新贴吧帖子留言对应的memo_messages的viewed字段 unless @memo.children.blank? @memo.children.each do |child| @@ -141,7 +142,7 @@ class MemosController < ApplicationController respond_to do |format| format.js - format.html {render :layout => 'base_new_forum'} + format.html {render :layout => 'base_edu'} format.json { render json: @memo } format.xml { render xml: @memo } end @@ -182,6 +183,52 @@ class MemosController < ApplicationController end end + def reply + if params[:parent_id] + parent = Memo.find params[:memo][:parent_id] + @memo = params[:activity_id].blank? ? parent : Memo.find(params[:activity_id].to_i) + @reply = Memo.new + @reply.author = User.current + @reply.forum_id = parent.forum_id + @reply.content = params[:memo][:content] + @reply.subject = "RE: #{@memo.subject}" + #@reply.reply_id = params[:id] + @reply.root_id = parent.root_id.nil? ? parent.id : parent.root_id + # @reply.reply_id = params[:id] + parent.children << @reply + else + @reply = Memo.new() + @reply.content = params[:content] + @reply.subject = @memo.subject + @reply.author = User.current + @reply.forum_id = @forum.id + #@reply.content = @quote + @reply.content + #@reply.subject = "RE: #{@topic.subject}" unless params[:reply][:subject] + @reply.root_id = @memo.id + @reply.safe_attributes = params[:reply] + @memo.children << @reply + # @reply.reply_id = params[:id] + end + + redirect_to message_replies_forum_memo_path(@memo.forum, @memo) + end + + def message_replies + @replies = Memo.where(:root_id => @memo.id).order("created_at desc") + @reply_count = @replies.count + @replies = get_no_children_comments_all @replies + #@limit_count = @replies.count + #@page = params[:page] ? params[:page].to_i + 1 : 0 + #@limit = 10 + #@replies = @replies[@page * @limit..@page * @limit + 9] + @reply = Message.new() + @user_activity_id = params[:user_activity_id].blank? ? @memo.id : params[:user_activity_id].to_i + respond_to do |format| + format.js + end + + end + def destroy @memo.destroy diff --git a/app/views/forums/index.html.erb b/app/views/forums/index.html.erb index f8dfd5fd1..dfc448213 100644 --- a/app/views/forums/index.html.erb +++ b/app/views/forums/index.html.erb @@ -29,11 +29,13 @@
<% @memos.each_with_index do |memo, index| %>
- + + <%= image_tag(url_to_avatar(memo.author), :width => 50, :height => 50,:alt=>'用户头像', :class=>"bor-radius-all mt3" ) %> +
- <%= User.find(memo.author_id).try(:show_name) %> + <%= User.find(memo.author_id).try(:show_name) %>

- <%= memo.subject %> + <%= memo.subject %>

<%= memo.content %>

@@ -46,7 +48,7 @@

@@ -58,11 +60,7 @@
    -
  • 上一页
  • -
  • 1
  • -
  • 2
  • -
  • 3
  • -
  • 下一页
  • + <%= pagination_links_full @topic_pages, @topic_count, :per_page_links => false, :remote => @is_remote, :flag => true, :is_new => true %>
diff --git a/app/views/memos/_common_reply_box.html.erb b/app/views/memos/_common_reply_box.html.erb new file mode 100644 index 000000000..9234613c8 --- /dev/null +++ b/app/views/memos/_common_reply_box.html.erb @@ -0,0 +1,112 @@ +
+

全部回复(<%= count %>)

+

+ 回复 + + + + <%= render :partial => 'praise_tread/activity_praise', :locals => {:activity => memo, :user_activity_id => memo.id, :type => "Memo"} %> + +

+
+
+ <% no_children_comments.each do |comment| %> + <% unless comment.nil? %> + +
+
+ <%= link_to image_tag(url_to_avatar(comment.creator_user), :width => 50, :height => 50, :alt => "用户头像"), user_url_in_org(comment.creator_user), :target => '_blank' %> +
+
+
+
+ <% if !comment.parent.nil? && !comment.parent.parent.nil? %> + <% parents_rely = [] %> + <% parents_rely = get_reply_parents_no_root parents_rely, comment %> + <% length = parents_rely.length %> +
+ <% if length <= 5 %> + <%=render :partial => 'messages/message_reply', :locals => {:comment => comment.parent, :parent_id => comment.id, :user_activity_id => memo.id, :type => memo.class.to_s} %> + <% else %> +
+
+
+
+
+ <%=render :partial => 'student_work/homework_reply_detail', :locals => {:comment => parents_rely[length - 1], :type => memo.class.to_s, :user_activity_id => memo.id, :parent_id => comment.id} %> +
+
+ + <%= link_to '点击展开隐藏楼层', show_all_replies_users_path(:comment => comment, :type => comment.class, :user_activity_id => memo.id, :parent_id => comment.id),:remote=>true, :class => '' %> +
+ <%=render :partial => 'student_work/homework_reply_detail', :locals => {:comment => parents_rely[3], :type => memo.class.to_s, :user_activity_id => memo.id, :parent_id => comment.id} %> +
+ <%=render :partial => 'student_work/homework_reply_detail', :locals => {:comment => parents_rely[2], :type => memo.class.to_s, :user_activity_id => memo.id, :parent_id => comment.id} %> +
+ <%=render :partial => 'student_work/homework_reply_detail', :locals => {:comment => parents_rely[1], :type => memo.class.to_s, :user_activity_id => memo.id, :parent_id => comment.id} %> +
+ <%=render :partial => 'student_work/homework_reply_detail', :locals => {:comment => parents_rely[0], :type => memo.class.to_s, :user_activity_id => memo.id, :parent_id => comment.id} %> +
+ <% end %> +
+ <% end %> + +
+
<%= comment.content_detail.html_safe %>
+
+
+
+
+
+ +
+
+ +
+
+ <%= link_to comment.creator_user.show_real_name, user_url_in_org(comment.creator_user), :class => "content-username hide fl" %> + <%= time_from_now(comment.created_at) %> +
+

+ <% if comment.creator_user == User.current %> + 删除 + <% end %> + | + <%= link_to( + '回复'.html_safe, + {:controller => 'users' ,:action => 'reply_to',:reply_id => comment.id, :type => memo.class.to_s, :user_activity_id => memo.id}, + :remote => true, + :method => 'get', + :title => l(:button_reply),:class => "color-grey") %> + | + + <%=render :partial=> "praise_tread/edu_praise", :locals => {:activity=>comment, :user_activity_id=>comment.id,:type=>"reply"}%> + +

+
+
+
+
+ <% end %> + <% end %> +
+ \ No newline at end of file diff --git a/app/views/memos/_memo_all_replies.html.erb b/app/views/memos/_memo_all_replies.html.erb index 3e5e69938..086617444 100644 --- a/app/views/memos/_memo_all_replies.html.erb +++ b/app/views/memos/_memo_all_replies.html.erb @@ -1,40 +1,65 @@ -<% @replies.each do |reply| %> - + $(".homepagePostReplyDes").mouseover(function(){ + $(this).find("a[id*='delete_memo_reply']").show(); + }).mouseout(function(){ + $(this).find("a[id*='delete_memo_reply']").hide(); + }); + -
-
- <%= link_to image_tag(url_to_avatar(reply.author), :width => 33,:height => 33), user_path(reply.author) %> -
-
-
- <%= render :partial => 'users/message_contents', :locals => {:comment => reply, :type => 'Memo', :user_activity_id => @memo.id}%> -
-
-

<%= reply.content.gsub(/\/script/, "script").gsub(/script/, " script").html_safe %>

-
-
-
+
+
+ <%= link_to image_tag(url_to_avatar(reply.author), :width => 33,:height => 33), user_path(reply.author) %> +
+
+
+ <%= render :partial => 'users/message_contents', :locals => {:comment => reply, :type => 'Memo', :user_activity_id => @memo.id}%> +
+
+

<%= reply.content.gsub(/\/script/, "script").gsub(/script/, " script").html_safe %>

+
+
+
<%= render :partial => "praise_tread/praise", :locals => {:activity => reply, :user_activity_id => reply.id, :type => "reply"} %> @@ -58,20 +83,21 @@ :title => l(:button_delete) ) if @memo.author.id == User.current.id || User.current.admin? || User.current == @forum.creator %> -
+
+
+
+
+
+
+
+ <% end %> + <% if @limit_count > @page * @limit + 10 %> +
+
+ + + <%= link_to '点击展开更多回复', forum_memo_path(@memo.forum_id, @memo, :page => @page),:remote=>true %>
-
-
-
-
-<% end %> -<% if @limit_count > @page * @limit + 10 %> -
-
- - - <%= link_to '点击展开更多回复', forum_memo_path(@memo.forum_id, @memo, :page => @page),:remote=>true %> -
-
+ <% end %> <% end %> \ No newline at end of file diff --git a/app/views/memos/create.js.erb b/app/views/memos/create.js.erb index 410c82d79..d6405143a 100644 --- a/app/views/memos/create.js.erb +++ b/app/views/memos/create.js.erb @@ -1 +1 @@ -window.location.href='<%= forum_memo_path(:forum_id=>@memo.forum_id,:id=>@memo.id ) %>' \ No newline at end of file +window.location.href='<%= forum_memo_path(:forum_id => @memo.forum_id, :id => @memo.id ) %>'; \ No newline at end of file diff --git a/app/views/memos/message_replies.js.erb b/app/views/memos/message_replies.js.erb new file mode 100644 index 000000000..a4683ca59 --- /dev/null +++ b/app/views/memos/message_replies.js.erb @@ -0,0 +1,9 @@ +<%# if @user_activity_id != @memo.id %> +/* $("#activity_post_reply_<%#= @user_activity_id %>").html("<%#= escape_javascript(render :partial => 'users/course_message_post_reply', + :locals => { :activity => @memo, + :user_activity_id => @user_activity_id}) %>"); + sd_create_editor_from_data(<%#= @user_activity_id%>,"","100%", "UserActivity");*/ +<%# else %> + $("#message_replies_box").html("<%= escape_javascript(render :partial => 'memos/memo_all_replies') %>"); + sd_create_editor_from_data(<%= @memo.id %>,"","100%", "<%= @memo.class.to_s %>"); +<%# end %> \ No newline at end of file diff --git a/app/views/memos/show.html.erb b/app/views/memos/show.html.erb index c5cf514a3..e4908b901 100644 --- a/app/views/memos/show.html.erb +++ b/app/views/memos/show.html.erb @@ -1,131 +1,206 @@ <%= content_for(:header_tags) do %> <%= import_ke(enable_at: false, prettify: false, init_activity: true) %> - <%= javascript_include_tag 'forum' %> <% end %> +
+
+

+ + <%= @user.show_name %> > 讨论 +

+
+

<%= h @memo.subject %>

+ +
+
+
+
+ + <%= image_tag(url_to_avatar(@memo.author), :width => 60, :height => 60, :alt=>'用户头像', :class=>"panel-list-img mr15" ) %> + +
+

<%= @memo.author.show_name %>

+

+ 发表于<%= time_from_now @memo.updated_at %> +

+
- +
+ + <%= @memo.content.html_safe %> +
+
    + + <% if @memo.attachments.any?%> + <% options = {:author => true, :deletable => @memo.deleted_attach_able_by?(User.current) } %> + <%= render :partial => 'attachments_links', :locals => {:attachments => @memo.attachments, :options => options, :is_float => true} %> + <% end %> +
+
+
+ <%= render :partial => "memo_all_replies" %> +
+
+
-
-
-
- <%= link_to image_tag(url_to_avatar(@memo.author),:width=>50,:height => 50,:alt=>'贴吧图像' ),user_path(@memo.author) %> -
-
- <% if @memo.author.id == User.current.id || User.current.admin? || User.current == @forum.creator %> -
-
    -
  • -
      - <% if @memo.author.id == User.current.id || User.current.admin? %> -
    • 编辑
    • - <% end %> - <% if User.current.admin? || User.current == @forum.creator %> - <% if @memo.sticky %> -
    • 取消置顶
    • - <% else %> -
    • 置顶
    • - <% end %> - <% end %> -
    • 删除
    • -
    • -
    -
  • -
-
- <% end %> - - <%= render :partial => "memos/praise_tread",:locals => {:obj => @memo,:show_flag => true,:user_id =>User.current.id,:horizontal => true}%> -
-
- <%= link_to @memo.author.show_name, user_path(@memo.author), :class => "linkBlue2", :target=> "_blank"%>
-
<%= format_date( @memo.created_at)%>
-
-
- <%= @memo.content.html_safe%> -
-
-
- <% if @memo.attachments.any?%> - <% options = {:author => true, :deletable => @memo.deleted_attach_able_by?(User.current) } %> - <%= render :partial => 'attachments_links', :locals => {:attachments => @memo.attachments, :options => options, :is_float => true} %> - <% end %> -
-
- 更新时间:<%= format_date(@memo.updated_at)%> + + +<% if false %> + <%= content_for(:header_tags) do %> + <%= import_ke(enable_at: false, prettify: false, init_activity: true) %> + <%= javascript_include_tag 'forum' %> + <% end %> + + -
-
-
-
-
-
回复(<%= @reply_count %>)
-
-
-
- <%= render :partial => 'memos/memo_all_replies' %> -
-
-
-
<%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_path(User.current), :alt => "用户头像" %>
-
- <% if User.current.logged? %> -
- <%= form_for('memo',:url=>forum_memos_path,:method => "post") do |f|%> - <%= f.hidden_field :subject, :required => true, value: @memo.subject %> - <%= f.hidden_field :forum_id, :required => true, value: @memo.forum_id %> - <%= f.hidden_field :parent_id, :required => true, value: @memo.id %> - <%= hidden_field_tag :quote,"",:required => false,:style => 'display:none' %> -
- - -
-

- <% end%> -
- <% else %> - <%= render :partial => "users/show_unlogged" %> - <% end %> + + +
+
+
+ <%= link_to image_tag(url_to_avatar(@memo.author),:width=>50,:height => 50,:alt=>'贴吧图像' ),user_path(@memo.author) %> +
+
+ <% if @memo.author.id == User.current.id || User.current.admin? || User.current == @forum.creator %> +
+
    +
  • +
      + <% if @memo.author.id == User.current.id || User.current.admin? %> +
    • 编辑
    • + <% end %> + <% if User.current.admin? || User.current == @forum.creator %> + <% if @memo.sticky %> +
    • 取消置顶
    • + <% else %> +
    • 置顶
    • + <% end %> + <% end %> +
    • 删除
    • +
    • +
    +
  • +
+
+ <% end %> + + <%= render :partial => "memos/praise_tread",:locals => {:obj => @memo,:show_flag => true,:user_id =>User.current.id,:horizontal => true}%> +
+ +
+ <%= link_to @memo.author.show_name, user_path(@memo.author), :class => "linkBlue2", :target=> "_blank"%>
+
<%= format_date( @memo.created_at)%>
+
+
+ <%= @memo.content.html_safe%> +
+
+
+ <% if @memo.attachments.any?%> + <% options = {:author => true, :deletable => @memo.deleted_attach_able_by?(User.current) } %> + <%= render :partial => 'attachments_links', :locals => {:attachments => @memo.attachments, :options => options, :is_float => true} %> + <% end %> +
+
+ 更新时间:<%= format_date(@memo.updated_at)%> +
+
+
+
回复(<%= @reply_count %>)
+
+
+
+ <%= render :partial => 'memos/memo_all_replies' %> +
+
+
+
<%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_path(User.current), :alt => "用户头像" %>
+
+ <% if User.current.logged? %> +
+ <%= form_for('memo',:url=>forum_memos_path,:method => "post") do |f|%> + <%= f.hidden_field :subject, :required => true, value: @memo.subject %> + <%= f.hidden_field :forum_id, :required => true, value: @memo.forum_id %> + <%= f.hidden_field :parent_id, :required => true, value: @memo.id %> + <%= hidden_field_tag :quote,"",:required => false,:style => 'display:none' %> +
+ + +
+

+ <% end%> +
+ <% else %> + <%= render :partial => "users/show_unlogged" %> + <% end %> +
+
+
+
+
+
+
+ <%= render :partial => "memos/my_show_count_message" %>
-
-
-
- <%= render :partial => "memos/my_show_count_message" %> -
- \ No newline at end of file + +<% end %> \ No newline at end of file diff --git a/app/views/praise_tread/_activity_praise.html.erb b/app/views/praise_tread/_activity_praise.html.erb index 8f57ec0b6..8bbb6b6b8 100644 --- a/app/views/praise_tread/_activity_praise.html.erb +++ b/app/views/praise_tread/_activity_praise.html.erb @@ -4,8 +4,9 @@ :user_activity_id => user_activity_id, :type => type }) %>' data-remote="true" class="white-btn orange-btn" title="点赞"> 赞 - <% num = activity.praise_tread_cache ? activity.praise_tread_cache.praise_num : 0 %> - <%= (num.nil? ? 0 : num) > 0 ? num : 0 %> + <%# num = activity.praise_tread_cache ? activity.praise_tread_cache.praise_num : 0 %> + + <%= get_praise_num(activity) %> <% else %> 赞 - <% num = activity.praise_tread_cache ? activity.praise_tread_cache.praise_num : 0 %> - <%= (num.nil? ? 0 : num) > 0 ? num : 0 %> + <%= get_praise_num(activity) %> + <%# num = activity.praise_tread_cache ? activity.praise_tread_cache.praise_num : 0 %> + <% end %> \ No newline at end of file diff --git a/app/views/praise_tread/_edu_praise.html.erb b/app/views/praise_tread/_edu_praise.html.erb index afe83633d..0704eebad 100644 --- a/app/views/praise_tread/_edu_praise.html.erb +++ b/app/views/praise_tread/_edu_praise.html.erb @@ -4,8 +4,9 @@ :user_activity_id => user_activity_id, :type => type }) %>' data-remote="true" class="fr mr5 color-grey" title="点赞"> 赞 - <% num = activity.praise_tread_cache ? activity.praise_tread_cache.praise_num : 0 %> - <%= (num.nil? ? 0 : num) > 0 ? num : 0 %> + <%# num = activity.praise_tread_cache ? activity.praise_tread_cache.praise_num : 0 %> + + <%= get_praise_num(activity) %> <% else %> 赞 - <% num = activity.praise_tread_cache ? activity.praise_tread_cache.praise_num : 0 %> - <%= (num.nil? ? 0 : num) > 0 ? num : 0 %> + <%= get_praise_num(activity) %> + <%# num = activity.praise_tread_cache ? activity.praise_tread_cache.praise_num : 0 %> + <% end %> \ No newline at end of file diff --git a/app/views/praise_tread/praise_minus.js.erb b/app/views/praise_tread/praise_minus.js.erb index b187d75dc..3b974fe5c 100644 --- a/app/views/praise_tread/praise_minus.js.erb +++ b/app/views/praise_tread/praise_minus.js.erb @@ -5,6 +5,8 @@ <% else %> $('#praise_count_<%=@user_activity_id %>').html('<%=j(render :partial=> "praise_tread/praise", :locals => {:activity=>@obj, :user_activity_id=>@user_activity_id,:type=>"activity"})%>'); <% end %> + <% elsif @type.to_s == 'Memo' %> + $('#praise_count_<%= @obj.id %>').html('<%= j(render :partial => 'praise_tread/activity_praise', :locals => {:activity => @obj, :user_activity_id => @obj.id, :type => "Memo"})%>'); <% else @type.to_s == 'reply' %> <% if ((@obj_type == 'JournalsForMessage' && @obj.jour_type == 'HomeworkCommon') || @obj_type == 'Message') && @obj_id == @user_activity_id %> $('.reply_praise_count_<%=@user_activity_id %>').html('<%=j(render :partial=> "praise_tread/edu_praise", :locals => {:activity=>@obj, :user_activity_id=>@user_activity_id,:type=>"reply"})%>'); diff --git a/app/views/praise_tread/praise_plus.js.erb b/app/views/praise_tread/praise_plus.js.erb index beea6afae..082f0bf42 100644 --- a/app/views/praise_tread/praise_plus.js.erb +++ b/app/views/praise_tread/praise_plus.js.erb @@ -5,6 +5,8 @@ <% else %> $('#praise_count_<%=@user_activity_id %>').html('<%=j(render :partial=> "praise_tread/praise", :locals => {:activity=>@obj, :user_activity_id=>@user_activity_id,:type=>"activity"})%>'); <% end %> + <% elsif @type.to_s == 'Memo' %> + $('#praise_count_<%= @obj.id %>').html('<%= j(render :partial => 'praise_tread/activity_praise', :locals => {:activity => @obj, :user_activity_id => @obj.id, :type => "Memo"})%>'); <% else @type.to_s == 'reply' %> <% if ((@obj_type == 'JournalsForMessage' && @obj.jour_type == 'HomeworkCommon') || @obj_type == 'Message') && @obj_id == @user_activity_id %> $('.reply_praise_count_<%=@user_activity_id %>').html('<%=j(render :partial=> "praise_tread/edu_praise", :locals => {:activity=>@obj, :user_activity_id=>@user_activity_id,:type=>"reply"})%>'); @@ -13,8 +15,8 @@ <% end %> <% end %> <% elsif @obj_type == 'Memo'%> - $('#praise_tread_<%= @obj.id %>').html('<%= j( - render :partial => "/memos/praise_tread",:locals => {:obj => @obj,:user_id => User.current.id,:horizontal => @horizontal} + $('#praise_count__<%= @obj.id %>').html('<%= j( + render :partial => 'praise_tread/activity_praise', :locals => {:activity => @obj, :user_activity_id => @obj.id, :type => "Memo"} )%>'); <% elsif @obj_type == 'Discuss'%> $('#dis_praise_<%= @obj.id %>').html('<%= j( diff --git a/config/routes.rb b/config/routes.rb index 403cf5eaa..18f6cbb08 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -734,6 +734,8 @@ RedmineApp::Application.routes.draw do end member do get "change_sticky" + post "reply" + match "message_replies", :via => [:get, :post] end end end