From dcfe89c544edd943b344fe3060ced6f2f960ae41 Mon Sep 17 00:00:00 2001 From: ouyangxuhua Date: Wed, 30 Dec 2015 15:46:01 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B8=96=E5=AD=90=E5=8F=91=E9=80=81=E5=88=B0?= =?UTF-8?q?=E7=BB=84=E7=BB=87=E8=B5=84=E6=BA=90=E6=A0=8F=E7=9B=AE=EF=BC=8C?= =?UTF-8?q?=E5=90=8C=E6=97=B6=E5=A2=9E=E5=8A=A0=E5=A2=9E=E5=88=A0=E6=9F=A5?= =?UTF-8?q?=E6=94=B9=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/messages_controller.rb | 43 +++- app/models/message.rb | 12 +- .../_org_subfield_message_edit.html.erb | 16 ++ app/views/boards/_org_subfield_new.html.erb | 74 +++++++ app/views/layouts/base_org.html.erb | 2 +- app/views/messages/_course_show.html.erb | 2 +- .../messages/_org_subfield_show.html.erb | 199 ++++++++++++++++++ app/views/messages/_project_show.html.erb | 2 +- app/views/messages/edit.html.erb | 12 ++ app/views/messages/reply.js.erb | 2 + app/views/messages/show.html.erb | 2 + .../organizations/_org_activities.html.erb | 6 +- .../_org_subfield_message.html.erb | 118 +++++++++++ .../org_subfield_message_edit.html.erb | 16 ++ config/routes.rb | 1 + public/javascripts/organization.js | 39 ++++ 16 files changed, 532 insertions(+), 14 deletions(-) create mode 100644 app/views/boards/_org_subfield_message_edit.html.erb create mode 100644 app/views/boards/_org_subfield_new.html.erb create mode 100644 app/views/messages/_org_subfield_show.html.erb create mode 100644 app/views/organizations/_org_subfield_message.html.erb create mode 100644 app/views/organizations/org_subfield_message_edit.html.erb create mode 100644 public/javascripts/organization.js diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 543521e0f..ae13b7e78 100644 --- a/app/controllers/messages_controller.rb +++ b/app/controllers/messages_controller.rb @@ -75,7 +75,7 @@ class MessagesController < ApplicationController @replies = paginateHelper messages_replies,10 @reply = Message.new(:subject => "RE: #{@message.subject}") render :action => "show", :layout => "base_courses"#by young - else + elsif @project @reply_pages = Paginator.new @reply_count, REPLIES_PER_PAGE, page @replies = @topic.children. includes(:author, :attachments, {:board => :project}). @@ -86,6 +86,18 @@ class MessagesController < ApplicationController @reply = Message.new(:subject => "RE: #{@message.subject}") render :action => "show", :layout => "base_projects"#by young + else + @reply_pages = Paginator.new @reply_count, REPLIES_PER_PAGE, page + @replies = @topic.children. + includes(:author, :attachments, {:board => :project}). + reorder("#{Message.table_name}.created_on DESC"). + limit(@reply_pages.per_page). + offset(@reply_pages.offset). + all + + @reply = Message.new(:subject => "RE: #{@message.subject}") + @organization = @org_subfield.organization + render :action => "show", :layout => "base_org"#by young end end @@ -248,7 +260,14 @@ class MessagesController < ApplicationController else respond_to do |format| format.html { - layout_file = @project ? 'base_projects' : 'base_courses' + if @project + layout_file = 'base_projects' + elsif @course + layout_file = 'base_courses' + elsif @org_subfield + @organization = @org_subfield.organization + layout_file = 'base_org' + end render :layout => layout_file } end @@ -287,6 +306,16 @@ class MessagesController < ApplicationController redirect_to course_board_url(@course, @board) end end + elsif @org_subfield + if params[:is_board] + redirect_to organization_path(:id => @org_subfield.organization_id, :org_subfield_id => @org_subfield.id) + else + if @message.parent + redirect_to board_message_url(@board, @message.parent, :r => r) + else + redirect_to organization_path(:id => @org_subfield.organization_id, :org_subfield_id => @org_subfield.id) + end + end end end @@ -319,18 +348,19 @@ class MessagesController < ApplicationController org_subfield_ids = params[:org_subfields] @message = Message.find(params[:id]) # @message.update_attribute(:updated_on, Time.now) - type = @message.board.course_id.nil? ? "Project":"Course" + # type = @message.board.course_id.nil? ? "Project":"Course" org_subfield_ids.each do |field_id| @message.quotes = @message.quotes.nil? ? 1 : (@message.quotes + 1) @message.save - mes = Message.create(:board_id => @message.board_id, :subject => @message.subject, :content => @message.content, :author_id => User.current.id, + board = OrgSubfield.find(field_id).boards.first + mes = Message.create(:board_id => board.id, :subject => @message.subject, :content => @message.content, :author_id => User.current.id, :created_on => Time.now, :updated_on => Time.now, :locked => @message.locked, :sticky => @message.sticky) @message.attachments.each do |attach| mes.attachments << Attachment.new(:filename => attach.filename, :disk_filename => attach.disk_filename, :filesize => attach.filesize, :content_type => attach.content_type, :digest => attach.digest, :downloads => 0, :author_id => User.current.id, :created_on => Time.now, :description => attach.description, :disk_directory => attach.disk_directory, :attachtype => attach.attachtype, :is_public => attach.is_public, :quotes => 0) end - OrgSubfieldMessage.create(:org_subfield_id => field_id.to_i, :message_id => mes.id, :message_type => type) + # OrgSubfieldMessage.create(:org_subfield_id => field_id.to_i, :message_id => mes.id, :message_type => type) # org_acts = OrgActivity.where("container_type='OrgSubfield' and container_id=? and org_act_type='Message' and org_act_id=?", field_id.to_i, @message.id) # if org_acts.all.size() > 0 # org_acts.first.update_attribute(:updated_at, Time.now) @@ -356,6 +386,9 @@ class MessagesController < ApplicationController @project = @board.project elsif @board.course_id @course = @board.course + else + @org_subfield = @board.org_subfield + @organization = @org_subfield end rescue ActiveRecord::RecordNotFound diff --git a/app/models/message.rb b/app/models/message.rb index 19531e270..dafdb767f 100644 --- a/app/models/message.rb +++ b/app/models/message.rb @@ -23,8 +23,8 @@ class Message < ActiveRecord::Base belongs_to :board,:touch => true belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' has_many :praise_tread, as: :praise_tread_object, dependent: :destroy - has_many :org_subfield_messages, :dependent => :destroy - has_many :org_subfields, :through => :org_subfield_messages + # has_many :org_subfield_messages, :dependent => :destroy + # has_many :org_subfields, :through => :org_subfield_messages acts_as_tree :counter_cache => :replies_count, :order => "#{Message.table_name}.created_on ASC" acts_as_attachable @@ -150,6 +150,10 @@ class Message < ActiveRecord::Base usr && usr.logged? && (usr.allowed_to?(:edit_messages, course) || (self.author == usr && usr.allowed_to?(:edit_own_messages, course))) end + def org_subfield_editable_by?(usr) + usr && usr.logged? && usr.admin? && usr.admin_of_org?(self.board.org_subfield.organization) + end + def course_destroyable_by?(usr) usr && usr.logged? && (usr.allowed_to?(:delete_messages, course) || (self.author == usr && usr.allowed_to?(:delete_own_messages, course))) end @@ -192,7 +196,7 @@ class Message < ActiveRecord::Base # Description def act_as_forge_activity # 如果project为空,那么就是课程相关的消息 - if !self.board.project.nil? && self.parent_id.nil? + if self.board.project_id != -1 && self.parent_id.nil? self.forge_acts << ForgeActivity.new(:user_id => self.author_id, :project_id => self.board.project.id) end @@ -227,7 +231,7 @@ class Message < ActiveRecord::Base end end end - else # 项目相关 + elsif self.project # 项目相关 if self.parent_id.nil? # 主贴 self.project.members.each do |m| if m.user_id != self.author_id diff --git a/app/views/boards/_org_subfield_message_edit.html.erb b/app/views/boards/_org_subfield_message_edit.html.erb new file mode 100644 index 000000000..ae22b225b --- /dev/null +++ b/app/views/boards/_org_subfield_message_edit.html.erb @@ -0,0 +1,16 @@ + +
+
+
+ 编辑帖子 +
+
+ <%= render :partial => 'boards/org_subfield_new', + :locals => {:f => f, :edit_mode => edit_mode, :topic => topic, :org_subfield => org_subfield} %> +
\ No newline at end of file diff --git a/app/views/boards/_org_subfield_new.html.erb b/app/views/boards/_org_subfield_new.html.erb new file mode 100644 index 000000000..7664c5c32 --- /dev/null +++ b/app/views/boards/_org_subfield_new.html.erb @@ -0,0 +1,74 @@ +<%= content_for(:header_tags) do %> + <%= import_ke(enable_at: true, prettify: false) %> +<% end %> + +<%= error_messages_for 'message' %> +
+
+
+
+ +

+
+ +
+ <%#= render :partial => 'course_new_topic', :locals => {:f => f, :topic => @message} %> + +
+
\ No newline at end of file diff --git a/app/views/layouts/base_org.html.erb b/app/views/layouts/base_org.html.erb index 808e80239..83bcb4dc9 100644 --- a/app/views/layouts/base_org.html.erb +++ b/app/views/layouts/base_org.html.erb @@ -13,7 +13,7 @@ <%= javascript_heads %> <%= heads_for_theme %> <%= stylesheet_link_tag 'pleft','prettify','jquery/jquery-ui-1.9.2','header','new_user','repository','courses','org' %> - <%= javascript_include_tag 'cookie','project', 'header','prettify','select_list_move','org'%> + <%= javascript_include_tag 'cookie','project', 'organization','header','prettify','select_list_move','org'%> <%= javascript_include_tag 'attachments' %> <%= call_hook :view_layouts_base_html_head %> diff --git a/app/views/messages/_course_show.html.erb b/app/views/messages/_course_show.html.erb index cc93d99b9..294f9b7d4 100644 --- a/app/views/messages/_course_show.html.erb +++ b/app/views/messages/_course_show.html.erb @@ -57,7 +57,7 @@ :data => {:confirm => l(:text_are_you_sure)}, :class => 'postOptionLink' ) if @message.course_destroyable_by?(User.current) %> - <%#= link_to "发送",messages_join_org_subfield_path(:message_id => @topic.id) , :remote=> true,:class => 'postOptionLink' %> + <%= link_to "发送",messages_join_org_subfield_path(:message_id => @topic.id) , :remote=> true,:class => 'postOptionLink' %> diff --git a/app/views/messages/_org_subfield_show.html.erb b/app/views/messages/_org_subfield_show.html.erb new file mode 100644 index 000000000..9eb082d33 --- /dev/null +++ b/app/views/messages/_org_subfield_show.html.erb @@ -0,0 +1,199 @@ +<%= content_for(:header_tags) do %> + <%= import_ke(enable_at: false, prettify: false, init_activity: true) %> +<% end %> + + + + +
+
+
+ <%= link_to image_tag(url_to_avatar(@topic.author),:width=>50,:height => 50,:alt=>'图像' ),user_path(@topic.author) %> +
+
+ <% if @topic.author.id == User.current.id%> + + <%end%> + +
+ +
+ <% if @topic.try(:author).try(:realname) == ' ' %> + <%= link_to @topic.try(:author), user_path(@topic.author,:host=>Setting.host_user), :class => "linkBlue2", :target=> "_blank" %> + <% else %> + <%= link_to @topic.try(:author).try(:realname), user_path(@topic.author,:host=>Setting.host_user), :class => "linkBlue2", :target=> "_blank" %> + <% end %> +
+
<%= format_time( @topic.created_on)%>
+
+
+ <%= @topic.content.html_safe%> +
+
+
+ <%= link_to_attachments_course @topic, :author => false %> +
+
+
+
+
+
+ <% unless @replies.empty? %> +
+
回复(<%=@reply_count %>)
+
+ +
+
+ <% @replies.each_with_index do |reply,i| %> + +
+
+ <%= link_to image_tag(url_to_avatar(reply.author), :width => 33,:height => 33), user_path(reply.author) %> +
+
+
+ <% if reply.try(:author).try(:realname) == ' ' %> + <%= link_to reply.try(:author), user_path(reply.author_id,:host=>Setting.host_user), :class => "newsBlue mr10 f14" %> + <% else %> + <%= link_to reply.try(:author).try(:realname), user_path(reply.author_id,:host=>Setting.host_user), :class => "newsBlue mr10 f14" %> + <% end %> +
+
+ <%= reply.content.html_safe%> +
+
+ <%= format_time(reply.created_on) %> + +
+

+
+
+
+ <% end %> +
+ + <% end %> +
+ <% if !@topic.locked? && authorize_for_course('messages', 'reply') %> +
+ +
+
+ <%= form_for @reply, :as => :reply, :url => {:action => 'reply', :id => @topic}, :html => {:multipart => true, :id => 'message_form'} do |f| %> + <%= render :partial => 'form_course', :locals => {:f => f, :replying => true} %> + <%= link_to l(:button_cancel), "javascript:void(0)", :onclick => 'course_board_canel_message_replay();', :class => "blue_btn grey_btn fr c_white mt10 mr5" %> + <%= link_to l(:button_submit), "javascript:void(0)", :onclick => 'course_board_submit_message_replay();', :class => "blue_btn fr c_white mt10", :style => "margin-left: 50px;" %> + <% end %> +
+
+
+ <% end %> +
+
\ No newline at end of file diff --git a/app/views/messages/_project_show.html.erb b/app/views/messages/_project_show.html.erb index a0a340a2a..1cbd606ab 100644 --- a/app/views/messages/_project_show.html.erb +++ b/app/views/messages/_project_show.html.erb @@ -112,8 +112,8 @@ :data => {:confirm => l(:text_are_you_sure)}, :class => 'postOptionLink' ) if @message.destroyable_by?(User.current) %> - <%#= link_to "发送",messages_join_org_subfield_path(:message_id => @topic.id) , :remote=> true,:class => 'postOptionLink' %> +
  • <%= link_to "发送",messages_join_org_subfield_path(:message_id => @topic.id) , :remote=> true,:class => 'postOptionLink' %>
  • diff --git a/app/views/messages/edit.html.erb b/app/views/messages/edit.html.erb index 7543e16e2..6e54a88e1 100644 --- a/app/views/messages/edit.html.erb +++ b/app/views/messages/edit.html.erb @@ -22,6 +22,18 @@ <%= render :partial => 'boards/course_message_edit', :locals => {:f => f, :edit_mode => true, :topic => @message, :course => @message.course} %> <% end %> + +<% elsif @message.board.org_subfield %> + <%= form_for @message, { + :as => :message, + :url => {:action => 'edit'}, + :html => {:multipart => true, + :id => 'message-form', + :method => :post} + } do |f| %> + <%= render :partial => 'boards/org_subfield_message_edit', + :locals => {:f => f, :edit_mode => true, :topic => @message, :org_subfield => @message.board.org_subfield} %> + <% end %> <% end %>
    diff --git a/app/views/messages/reply.js.erb b/app/views/messages/reply.js.erb index 518479344..c0da5ab9b 100644 --- a/app/views/messages/reply.js.erb +++ b/app/views/messages/reply.js.erb @@ -2,5 +2,7 @@ $("#user_activity_<%= @user_activity_id%>").replaceWith("<%= escape_javascript(render :partial => 'users/project_message', :locals => {:activity => @topic,:user_activity_id =>@user_activity_id}) %>"); <%elsif @course%> $("#user_activity_<%= @user_activity_id%>").replaceWith("<%= escape_javascript(render :partial => 'users/course_message', :locals => {:activity => @topic,:user_activity_id =>@user_activity_id}) %>"); +<% elsif @org_subfield %> + $("#user_activity_<%= @user_activity_id%>").replaceWith("<%= escape_javascript(render :partial => 'organizations/org_subfield_message', :locals => {:activity => @topic,:user_activity_id =>@user_activity_id}) %>"); <%end%> init_activity_KindEditor_data(<%= @user_activity_id%>,"","87%", "UserActivity"); \ No newline at end of file diff --git a/app/views/messages/show.html.erb b/app/views/messages/show.html.erb index 5996852ef..428c51f22 100644 --- a/app/views/messages/show.html.erb +++ b/app/views/messages/show.html.erb @@ -2,4 +2,6 @@ <%= render :partial => 'project_show', locals: {project: @project} %> <% elsif @course %> <%= render :partial => 'course_show', locals: {course: @course} %> +<% else %> + <%= render :partial => 'org_subfield_show', :locals => {:org_subfield => @org_subfield} %> <% end %> diff --git a/app/views/organizations/_org_activities.html.erb b/app/views/organizations/_org_activities.html.erb index e7a4f6afa..8bffb7c47 100644 --- a/app/views/organizations/_org_activities.html.erb +++ b/app/views/organizations/_org_activities.html.erb @@ -50,12 +50,14 @@ <% end %> <% end %> <% if act.container_type == 'OrgSubfield' %> - <% if act.org_act_type == 'Message' and act.org_act_id %> + <% if act.org_act_type == 'Message' and act.org_act_id and Message.where("id=#{act.org_act_id}").count > 0 %> <% message = Message.find(act.org_act_id) %> <% if !message.board.course_id.nil? %> <%= render :partial => 'org_course_message', :locals => {:activity => message,:user_activity_id =>act.id} %> - <% else %> + <% elsif message.board.project_id != -1 %> <%= render :partial => 'organizations/project_message', :locals => {:activity => message,:user_activity_id =>act.id} %> + <% elsif message.board.org_subfield_id %> + <%= render :partial => 'organizations/org_subfield_message', :locals => {:activity => message, :user_activity_id => act.id} %> <% end %> <% end %> <% end %> diff --git a/app/views/organizations/_org_subfield_message.html.erb b/app/views/organizations/_org_subfield_message.html.erb new file mode 100644 index 000000000..57c50486b --- /dev/null +++ b/app/views/organizations/_org_subfield_message.html.erb @@ -0,0 +1,118 @@ +
    +
    +
    + <%= link_to image_tag(url_to_avatar(activity.author), :width => "50", :height => "50"), user_path(activity.author_id), :alt => "用户头像" %> +
    +
    +
    + <% if activity.try(:author).try(:realname) == ' ' %> + <%= link_to activity.try(:author), user_path(activity.author_id), :class => "newsBlue mr15" %> + <% else %> + <%= link_to activity.try(:author).try(:realname), user_path(activity.author_id), :class => "newsBlue mr15" %> + <% end %> + TO + <%= link_to activity.board.org_subfield.name.to_s+" | 资源栏目讨论区",org_subfield_boards_path(activity.board.org_subfield), :class => "newsBlue ml15 mr5"%> + +
    +
    + <% if activity.parent_id.nil? %> + <%= link_to activity.subject.to_s.html_safe, board_message_path(activity.board,activity), :class=> "postGrey" + %> + <% else %> + <%= link_to activity.parent.subject.to_s.html_safe, board_message_path(activity.board,activity), :class=> "postGrey" + %> + <% end %> +
    +
    + 时间:<%= format_time(activity.created_on) %> +
    +
    +
    + <% if activity.parent_id.nil? %> + <%= activity.content.to_s.html_safe%> + <% else %> + <%= activity.parent.content.to_s.html_safe%> + <% end %> +
    +
    +
    + + +
    +
    +
    +
    + <% count = 0 %> + <% if activity.parent %> + <% count=activity.parent.children.count%> + <% else %> + <% count=activity.children.count%> + <% end %> +
    +
    +
    +
    回复( + <%=count %> + )
    +
    <%#=format_date(activity.updated_on)%>
    + <%if count>3 %> + + <% end %> +
    + + <% activity= activity.parent_id.nil? ? activity : activity.parent %> + <% replies_all_i = 0 %> + <% if count > 0 %> +
    +
      + <% activity.children.reorder("created_on desc").each do |reply| %> + + <% replies_all_i=replies_all_i+1 %> +
    • +
      + <%= link_to image_tag(url_to_avatar(reply.author), :width => "33", :height => "33"), user_path(reply.author_id), :alt => "用户头像" %> +
      +
      +
      + <% if reply.try(:author).try(:realname) == ' ' %> + <%= link_to reply.try(:author), user_path(reply.author_id), :class => "newsBlue mr10 f14" %> + <% else %> + <%= link_to reply.try(:author).try(:realname), user_path(reply.author_id), :class => "newsBlue mr10 f14" %> + <% end %> + <%= format_time(reply.created_on) %> +
      +
      + <%= reply.content.html_safe %>
      +
      +
      +
    • + <% end %> +
    +
    + <% end %> + +
    +
    <%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), user_path(activity.author_id), :alt => "用户头像" %>
    +
    +
    + <%= form_for('new_form',:url => {:controller=>'messages',:action => 'reply', :id => activity.id, :board_id => activity.board_id, :is_board => 'true'},:method => "post", :remote => true) do |f|%> + + + +
    + +
    +

    + <% end%> +
    +
    +
    +
    +
    + +
    +
    \ No newline at end of file diff --git a/app/views/organizations/org_subfield_message_edit.html.erb b/app/views/organizations/org_subfield_message_edit.html.erb new file mode 100644 index 000000000..caa389945 --- /dev/null +++ b/app/views/organizations/org_subfield_message_edit.html.erb @@ -0,0 +1,16 @@ + +
    +
    +
    + 编辑帖子 +
    +
    + <%= render :partial => 'boards/course_new', + :locals => {:f => f, :edit_mode => edit_mode, :topic => topic, :course => course} %> +
    \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index be9843a80..36e6dff59 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -84,6 +84,7 @@ RedmineApp::Application.routes.draw do match "quote_resource_show_org_subfield", :via => [:get] end end + resource :boards end resources :org_document_comments do diff --git a/public/javascripts/organization.js b/public/javascripts/organization.js new file mode 100644 index 000000000..e04a8b282 --- /dev/null +++ b/public/javascripts/organization.js @@ -0,0 +1,39 @@ +/** + * Created by ouyangxuhua on 2015/12/30. + */ +function submit_topic() +{ + if(regexTopicSubject() && regexTopicDescription()) + { + message_content_editor.sync(); + $("#message-form").submit(); + } +} + +function regexTopicSubject() { + var name = $("#message_subject").val(); + if(name.length ==0) + { + $("#subjectmsg").text("标题不能为空"); + $("#subjectmsg").css('color','#ff0000'); + $("#message_subject").focus(); + return false; + } + else if(name.length <= 255) + { + $("#subjectmsg").text("填写正确"); + $("#subjectmsg").css('color','#008000'); + return true; + } + else + { + $("#subjectmsg").text("标题超过255个字符"); + $("#subjectmsg").css('color','#ff0000'); + $("#message_subject").focus(); + return false; + } +} + +function reset_topic(){ + +}