From 40a44c3568949b39b10dfc6df3421e4587d61b1a Mon Sep 17 00:00:00 2001 From: ouyangxuhua Date: Fri, 20 Nov 2015 10:52:26 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E6=96=87=E7=AB=A0=E4=BA=8C?= =?UTF-8?q?=E7=BA=A7=E5=9B=9E=E5=A4=8D=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../org_document_comments_controller.rb | 71 ++++++++- .../_reply_form.html.erb | 2 + .../_simple_ke_reply_form.html.erb | 31 ++++ .../add_reply_in_doc.js.erb | 1 + app/views/org_document_comments/edit.html.erb | 2 +- .../org_document_comments/index.html.erb | 2 +- app/views/org_document_comments/quote.js.erb | 10 ++ app/views/org_document_comments/reply.js.erb | 1 + app/views/org_document_comments/show.html.erb | 147 ++++++++++++++++++ .../organizations/_show_org_document.html.erb | 2 +- config/routes.rb | 4 + ...116070906_add_created_at_to_org_members.rb | 5 - 12 files changed, 269 insertions(+), 9 deletions(-) create mode 100644 app/views/org_document_comments/_reply_form.html.erb create mode 100644 app/views/org_document_comments/_simple_ke_reply_form.html.erb create mode 100644 app/views/org_document_comments/add_reply_in_doc.js.erb create mode 100644 app/views/org_document_comments/quote.js.erb create mode 100644 app/views/org_document_comments/reply.js.erb delete mode 100644 db/migrate/20151116070906_add_created_at_to_org_members.rb diff --git a/app/controllers/org_document_comments_controller.rb b/app/controllers/org_document_comments_controller.rb index af229635c..5b02a4e9b 100644 --- a/app/controllers/org_document_comments_controller.rb +++ b/app/controllers/org_document_comments_controller.rb @@ -20,7 +20,7 @@ class OrgDocumentCommentsController < ApplicationController end end def show - + @document = OrgDocumentComment.find(params[:id]) end def index @@ -48,6 +48,17 @@ class OrgDocumentCommentsController < ApplicationController @document.save end + def add_reply_in_doc + @document = OrgDocumentComment.find(params[:id]).root + @comment = OrgDocumentComment.new(:organization_id => @document.organization_id, :creator_id => User.current.id, :reply_id => params[:id]) + @comment.content = params[:org_comment][:org_content] + @document.children << @comment + @document.save + respond_to do |format| + format.html {redirect_to org_document_comment_path(:id => @document.id, :organization_id => @document.organization_id)} + end + end + def find_organization @organization = Organization.find(params[:organization_id]) end @@ -61,4 +72,62 @@ class OrgDocumentCommentsController < ApplicationController end end end + + def delete_reply + @org_document_comment = OrgDocumentComment.find(params[:id]) + @document = @org_document_comment.root + org = @org_document_comment.organization + @org_document_comment.destroy + respond_to do |format| + format.html {redirect_to org_document_comment_path(:id => @document.id, :organization_id => @document.organization_id)} + end + end + def quote + @org_comment = OrgDocumentComment.find(params[:id]) + @subject = @org_comment.content + @subject = "RE: #{@subject}" unless @subject.starts_with?('RE:') + + @content = "> #{ll(Setting.default_language, :text_user_wrote, User.find(@org_comment.creator_id).realname)}\n> " + @temp = OrgDocumentComment.new + #@course_id = params[:course_id] + @temp.content = "
#{ll(Setting.default_language, :text_user_wrote, User.find(@org_comment.creator_id).realname)}
#{@org_comment.content.html_safe}
".html_safe + respond_to do | format| + format.js + end + end + + def reply + @document = OrgDocumentComment.find(params[:id]).root + @quote = params[:quote][:quote] + @org_document = OrgDocumentComment.new(:creator_id => User.current.id, :reply_id => params[:id]) + + # params[:blog_comment][:sticky] = params[:blog_comment][:sticky] || 0 + # params[:blog_comment][:locked] = params[:blog_comment][:locked] || 0 + @org_document.title = params[:org_document_comment][:title] + @org_document.content = params[:org_document_comment][:content] + @org_document.content = @quote + @org_document.content + #@org_document.title = "RE: #{@article.title}" unless params[:blog_comment][:title] + @document.children << @org_document + # @user_activity_id = params[:user_activity_id] + # user_activity = UserActivity.where("act_type='BlogComment' and act_id =#{@article.id}").first + # if user_activity + # user_activity.updated_at = Time.now + # user_activity.save + # end + # attachments = Attachment.attach_files(@org_document, params[:attachments]) + # render_attachment_warning_if_needed(@org_document) + #@article.save + # redirect_to user_blogs_path(:user_id=>params[:user_id]) + respond_to do |format| + format.html { + # if params[:course_id] #如果呆了course_id过来了,那么这是要跳到课程大纲去的 + # redirect_to syllabus_course_path(:id=>params[:course_id]) + # else + redirect_to org_document_comment_path(:id => @document.id, :organization_id => @document.organization_id) + # end + + } + format.js + end + end end diff --git a/app/views/org_document_comments/_reply_form.html.erb b/app/views/org_document_comments/_reply_form.html.erb new file mode 100644 index 000000000..7871b910d --- /dev/null +++ b/app/views/org_document_comments/_reply_form.html.erb @@ -0,0 +1,2 @@ +$("#user_activity_<%= @user_activity_id%>").replaceWith("<%= escape_javascript(render :partial => 'users/user_blog', :locals => {:activity => @article,:user_activity_id =>@user_activity_id}) %>"); +init_activity_KindEditor_data(<%= @user_activity_id%>,"","87%"); diff --git a/app/views/org_document_comments/_simple_ke_reply_form.html.erb b/app/views/org_document_comments/_simple_ke_reply_form.html.erb new file mode 100644 index 000000000..cfa197ff4 --- /dev/null +++ b/app/views/org_document_comments/_simple_ke_reply_form.html.erb @@ -0,0 +1,31 @@ + + +
+
<%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_path(User.current), :alt => "用户头像" %>
+
+
+ <%= form_for @org_comment, :as => :reply, :url => {:controller => 'org_document_comments',:action => 'reply', :id => @org_comment.id}, :method => 'post', :html => {:multipart => true, :id => 'new_form'} do |f| %> + + + +
+ +
+

+ <% end%> +
+
+
+
+
\ No newline at end of file diff --git a/app/views/org_document_comments/add_reply_in_doc.js.erb b/app/views/org_document_comments/add_reply_in_doc.js.erb new file mode 100644 index 000000000..bcebe9d37 --- /dev/null +++ b/app/views/org_document_comments/add_reply_in_doc.js.erb @@ -0,0 +1 @@ +location.reload(); \ No newline at end of file diff --git a/app/views/org_document_comments/edit.html.erb b/app/views/org_document_comments/edit.html.erb index 498ac46a6..e0224afea 100644 --- a/app/views/org_document_comments/edit.html.erb +++ b/app/views/org_document_comments/edit.html.erb @@ -37,7 +37,7 @@
确定 - 取消 + 取消
diff --git a/app/views/org_document_comments/index.html.erb b/app/views/org_document_comments/index.html.erb index 6019dae14..d967c42fd 100644 --- a/app/views/org_document_comments/index.html.erb +++ b/app/views/org_document_comments/index.html.erb @@ -16,7 +16,7 @@ <% @documents.each do |document| %> <%= render :partial => 'organizations/show_org_document', :locals => {:document => document, :act => OrgActivity.where("org_act_type='OrgDocumentComment'and org_act_id=?", document.id).first} %> diff --git a/app/views/org_document_comments/quote.js.erb b/app/views/org_document_comments/quote.js.erb new file mode 100644 index 000000000..a71b23f0e --- /dev/null +++ b/app/views/org_document_comments/quote.js.erb @@ -0,0 +1,10 @@ +if($("#reply_message_<%= @org_comment.id%>").length > 0) { + $("#reply_message_<%= @org_comment.id%>").replaceWith("<%= escape_javascript(render :partial => 'org_document_comments/simple_ke_reply_form', :locals => {:reply => @org_comment,:temp =>@temp,:subject =>@subject}) %>"); + $(function(){ + $('#reply_subject').val("<%= raw escape_javascript(@subject) %>"); + $('#quote_quote').val("<%= raw escape_javascript(@temp.content.html_safe) %>"); + init_activity_KindEditor_data(<%= @org_comment.id%>,null,"85%"); + }); +}else if($("#reply_to_message_<%= @org_comment.id %>").length >0) { + $("#reply_to_message_<%= @org_comment.id%>").replaceWith("

"); +} \ No newline at end of file diff --git a/app/views/org_document_comments/reply.js.erb b/app/views/org_document_comments/reply.js.erb new file mode 100644 index 000000000..888613c8c --- /dev/null +++ b/app/views/org_document_comments/reply.js.erb @@ -0,0 +1 @@ +//location.reload(); \ No newline at end of file diff --git a/app/views/org_document_comments/show.html.erb b/app/views/org_document_comments/show.html.erb index e69de29bb..ae90b15bb 100644 --- a/app/views/org_document_comments/show.html.erb +++ b/app/views/org_document_comments/show.html.erb @@ -0,0 +1,147 @@ +<%= javascript_include_tag "/assets/kindeditor/kindeditor",'/assets/kindeditor/pasteimg',"init_activity_KindEditor",'blog' %> + +
+
+
+ <%= link_to image_tag(url_to_avatar(User.find(@document.creator_id)), :width => 45, :heigth => 45), user_path(@document.creator_id) %> +
+
+
+ <%= link_to User.find(@document.creator_id), user_path(@document.creator.id), :class => "newsBlue mr15" %> + TO  <%= link_to @document.organization.name, organization_path(@document.organization), :class => "newsBlue" %> + | + <% if @document.organization.home_id == @document.id %> + 首页 + <% else %> + 组织文章 + <% end %> +
+
<%= link_to @document.title, org_document_comment_path(:id => @document.id, :organization_id => @document.organization.id) %>
+
+ 发布时间:<%= format_activity_day(@document.created_at) %> <%= format_time(@document.created_at, false) %>
+ <% unless @document.content.blank? %> +
+ <%= @document.content.html_safe %> +
+ <% end %> + + <% if User.current.admin? || User.current.admin_of_org?(Organization.find(@document.organization_id) || User.current.id == @document.creator_id) %> +
+
    +
  • +
      +
    • + <%= form_for('new_form', :url => {:controller => 'organizations', :action => 'set_homepage', :id => @document.organization_id, :home_id => @document.id}, :method => "put", :remote => true) do |f| %> + 设为首页 + <% end %> +
    • +
    • + <%= link_to "编辑文章", edit_org_document_comment_path(:id => @document.id, :organization_id => @document.organization_id), :class => "postOptionLink" %> +
    • +
    • + <%= link_to "删除文章", org_document_comment_path(:id => @document.id, :organization_id => @document.organization_id), :method => 'delete', + :data => {:confirm => l(:text_are_you_sure)}, + :remote => true, :class => 'postOptionLink' %> +
    • +
    +
  • +
+
+
+ <% end %> +
+
+ <% comments_for_doc = @document.children.reorder("created_at desc") %> + <% count = @document.children.count() %> + +
+ <% if count > 0 %> +
+
回复(<%= count %>)
+
+
+ <% comments_for_doc.each_with_index do |reply,i| %> + + <% user = User.find(reply.creator_id) %> +
+
+ <%= link_to image_tag(url_to_avatar(user), :width => 33,:height => 33), user_path(user) %> +
+
+
+ <%= reply.content.html_safe unless reply.content.nil? %> +
+
+ <%= format_time(reply.created_at) %> + +
+

+
+
+
+ <% end %> +
+
+ <% end %> + <% if User.current.logged?%> +
+ +
+
+ <%= form_for :org_comment, :url => {:action => 'add_reply_in_doc',:controller => 'org_document_comments', :id => @document.id}, :html => {:multipart => true, :id => 'message_form'} do |f| %> + <%= f.kindeditor :org_content,:width=>'99%',:height => '100px;',:editor_id=>'message_content_editor' %> + <%= link_to l(:button_cancel), "javascript:void(0)", :onclick => 'message_content_editor.html("");', :class => " grey_btn fr c_white mt10 mr5" %> + <%= link_to l(:button_reply), "javascript:void(0)", :onclick => "message_content_editor.sync();$('#message_form').submit();", :class => "blue_btn fr c_white mt10 mb10", :style => "margin-right: 5px;" %> + <% end %> +
+
+
+ <% end %> +
+
+ + \ No newline at end of file diff --git a/app/views/organizations/_show_org_document.html.erb b/app/views/organizations/_show_org_document.html.erb index 1324729ac..e74da846e 100644 --- a/app/views/organizations/_show_org_document.html.erb +++ b/app/views/organizations/_show_org_document.html.erb @@ -14,7 +14,7 @@ 组织文章 <% end %> -
<%= document.title %>
+
<%= link_to document.title, org_document_comment_path(:id => document.id, :organization_id => document.organization.id) %>
发布时间:<%= format_activity_day(document.created_at) %> <%= format_time(document.created_at, false) %>
<% unless document.content.blank? %> diff --git a/config/routes.rb b/config/routes.rb index c68c8a1c1..993c1e243 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -66,6 +66,10 @@ RedmineApp::Application.routes.draw do resources :org_document_comments do member do post 'add_reply' + get 'quote' + post 'reply' + post 'add_reply_in_doc' + delete 'delete_reply' end collection do diff --git a/db/migrate/20151116070906_add_created_at_to_org_members.rb b/db/migrate/20151116070906_add_created_at_to_org_members.rb deleted file mode 100644 index 33d3a2817..000000000 --- a/db/migrate/20151116070906_add_created_at_to_org_members.rb +++ /dev/null @@ -1,5 +0,0 @@ -class AddCreatedAtToOrgMembers < ActiveRecord::Migration - def change - add_column :org_members, :created_at, :timestamp - end -end