From 18e79ba9b3f127d5ad3f5a7cbd3599104c46e93c Mon Sep 17 00:00:00 2001 From: ouyangxuhua Date: Wed, 20 Jan 2016 09:25:12 +0800 Subject: [PATCH 01/11] =?UTF-8?q?=E6=9C=AA=E7=99=BB=E9=99=86=E6=83=85?= =?UTF-8?q?=E5=86=B5=E4=B8=8B=EF=BC=8C=E5=8F=AF=E4=BB=A5=E7=9C=8B=E5=88=B0?= =?UTF-8?q?=E7=BB=84=E7=BB=87=E6=96=87=E7=AB=A0=E5=88=97=E8=A1=A8=E5=8F=8A?= =?UTF-8?q?=E9=A6=96=E9=A1=B5=E5=85=A8=E9=83=A8=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/views/layouts/base_org.html.erb | 28 +++++++++---------- .../organizations/_show_home_page.html.erb | 4 +-- 2 files changed, 14 insertions(+), 18 deletions(-) diff --git a/app/views/layouts/base_org.html.erb b/app/views/layouts/base_org.html.erb index 2007aec5a..9d3f76cc6 100644 --- a/app/views/layouts/base_org.html.erb +++ b/app/views/layouts/base_org.html.erb @@ -120,21 +120,19 @@
- <% if User.current.logged? %> -
- <%= link_to '文章', organization_org_document_comments_path(@organization) %>  - <% if User.current.logged? %> - ( - <%= link_to OrgDocumentComment.where("organization_id =? and parent_id is null", @organization.id).count, organization_org_document_comments_path(@organization), :class => "linkBlue" %> - ) - <% end %> -  |  - <%= link_to '成员', members_organization_path(@organization.id) %>  - <% if User.current.logged? %> - (<%= link_to @organization.org_members.count, members_organization_path(@organization.id), :id => 'org_members_count_id', :class => "linkBlue" %>) - <% end %> -
- <% end %> +
+ <%= link_to '文章', organization_org_document_comments_path(@organization) %>  + <%# if User.current.logged? %> + ( + <%= link_to OrgDocumentComment.where("organization_id =? and parent_id is null", @organization.id).count, organization_org_document_comments_path(@organization), :class => "linkBlue" %> + ) + <%# end %> + <% if User.current.logged? %> +  |  + <%= link_to '成员', members_organization_path(@organization.id) %>  + (<%= link_to @organization.org_members.count, members_organization_path(@organization.id), :id => 'org_members_count_id', :class => "linkBlue" %>) + <% end %> +
<%= render :partial => "organizations/org_left_subfield_list", :locals => {:organization => @organization} %> diff --git a/app/views/organizations/_show_home_page.html.erb b/app/views/organizations/_show_home_page.html.erb index 32d3ad10d..f6d5fc9ea 100644 --- a/app/views/organizations/_show_home_page.html.erb +++ b/app/views/organizations/_show_home_page.html.erb @@ -2,15 +2,13 @@
- <% if User.current.logged? %>
<%= link_to document.title, org_document_comment_path(:id => document.id, :organization_id => document.organization.id) %>
- <% end %> <% unless document.content.blank? %>
<%= document.content.html_safe %>
<% end %> - <% if params[:show_homepage].nil? and User.current.logged? %> + <% if params[:show_homepage].nil? %>
发布时间:<%= format_activity_day(document.created_at) %> <%= format_time(document.created_at, false) %>
From a487d814cfe6fba42fced637dec6dccfa83fce0b Mon Sep 17 00:00:00 2001 From: ouyangxuhua Date: Wed, 20 Jan 2016 16:24:14 +0800 Subject: [PATCH 02/11] =?UTF-8?q?=E9=80=9A=E7=9F=A5=E5=88=86=E4=BA=AB?= =?UTF-8?q?=E5=8A=9F=E8=83=BD=E5=AE=9E=E7=8E=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/comments_controller.rb | 4 +- app/controllers/organizations_controller.rb | 6 +- app/controllers/users_controller.rb | 54 ++++++- app/models/news.rb | 1 + app/models/org_subfield.rb | 1 + app/views/comments/create.js.erb | 6 +- app/views/news/index.html.erb | 116 +++++++++++++++ .../org_subfields/_show_details.html.erb | 4 + .../org_subfields/_show_post_type.html.erb | 115 +++++++++++++++ .../organizations/_org_activities.html.erb | 4 + .../organizations/_org_subfield_news.html.erb | 132 ++++++++++++++++++ app/views/users/_course_news.html.erb | 11 ++ .../users/_share_news_to_course.html.erb | 56 ++++++++ app/views/users/_share_news_to_org.html.erb | 59 ++++++++ .../users/_share_news_to_project.html.erb | 54 +++++++ app/views/users/search_user_course.js.erb | 6 +- app/views/users/search_user_org.js.erb | 6 +- app/views/users/search_user_project.js.erb | 6 +- app/views/users/share_news_to_course.js.erb | 2 + app/views/users/share_news_to_org.js.erb | 2 + app/views/users/share_news_to_project.js.erb | 2 + config/routes.rb | 3 + db/schema.rb | 17 ++- 23 files changed, 652 insertions(+), 15 deletions(-) create mode 100644 app/views/organizations/_org_subfield_news.html.erb create mode 100644 app/views/users/_share_news_to_course.html.erb create mode 100644 app/views/users/_share_news_to_org.html.erb create mode 100644 app/views/users/_share_news_to_project.html.erb create mode 100644 app/views/users/share_news_to_course.js.erb create mode 100644 app/views/users/share_news_to_org.js.erb create mode 100644 app/views/users/share_news_to_project.js.erb diff --git a/app/controllers/comments_controller.rb b/app/controllers/comments_controller.rb index c8dcf0b8e..5966b310f 100644 --- a/app/controllers/comments_controller.rb +++ b/app/controllers/comments_controller.rb @@ -25,7 +25,9 @@ class CommentsController < ApplicationController def create raise Unauthorized unless @news.commentable? - + if !@news.org_subfield_id.nil? + @org_subfield = OrgSubfield.find(@news.org_subfield_id) + end @comment = Comment.new #@project ? @comment.comments = params[:comment][:comments] : @comment.comments = params[:comment] if params[:user_activity_id] diff --git a/app/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb index 39ece6fbe..0ba6d35a6 100644 --- a/app/controllers/organizations_controller.rb +++ b/app/controllers/organizations_controller.rb @@ -300,7 +300,11 @@ class OrganizationsController < ApplicationController def org_resources_subfield @org = Organization.find(params[:id]) - @subfield = @org.org_subfields.where('field_type = "Resource" ') + if params[:send_type].present? and params[:send_type] == 'news' + @subfield = @org.org_subfields.where("field_type = 'Post'") + else + @subfield = @org.org_subfields.where('field_type = "Resource" ') + end respond_to do | format| format.js end diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 449d8b9de..63d55eb37 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -1753,6 +1753,48 @@ class UsersController < ApplicationController end end + def share_news_to_course + news = News.find(params[:send_id]) + course_ids = params[:course_ids] + course_ids.each do |course_id| + if Course.find(course_id).news.map(&:id).exclude?(news.id) + course_news = News.create(:course_id => course_id.to_i, :title => news.title, :summary => news.summary, :description => news.description,:author_id => User.current.id, :created_on => Time.now,:project_id => -1) + news.attachments.each do |attach| + course_news.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 + end + end + end + + def share_news_to_project + news = News.find(params[:send_id]) + project_ids = params[:project_ids] + project_ids.each do |project_id| + if Project.find(project_id).news.map(&:id).exclude?(news.id) + project_news = News.create(:project_id => project_id.to_i, :title => news.title, :summary => news.summary, :description => news.description,:author_id => User.current.id, :created_on => Time.now) + news.attachments.each do |attach| + project_news.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 + end + end + end + + def share_news_to_org + news = News.find(params[:send_id]) + field_id = params[:subfield] + org_news = News.create(:org_subfield_id => field_id.to_i, :title => news.title, :summary => news.summary, :description => news.description,:author_id => User.current.id, :created_on => Time.now,:project_id => -1) + news.attachments.each do |attach| + org_news.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 + OrgActivity.create(:container_type => 'OrgSubfield', :container_id => field_id.to_i, :org_act_type=>'News', :org_act_id => org_news.id, :user_id => User.current.id) + end + def change_org_subfield end @@ -2102,9 +2144,17 @@ class UsersController < ApplicationController @user = User.current if !params[:search].nil? #发送到有栏目类型为资源的组织中 search = "%#{params[:search].to_s.strip.downcase}%" - @orgs = @user.organizations.where("name like ?", search).select{|org| OrgSubfield.where("organization_id = #{org.id} and field_type='Resource'").count > 0} + if params[:send_type].present? and params[:send_type] == 'news' + @orgs = @user.organizations.where("name like ?", search).select{|org| OrgSubfield.where("organization_id = #{org.id} and field_type='Post'").count > 0} + else + @orgs = @user.organizations.where("name like ?", search).select{|org| OrgSubfield.where("organization_id = #{org.id} and field_type='Resource'").count > 0} + end else - @orgs = @user.organizations.select{|org| OrgSubfield.where("organization_id = #{org.id} and field_type='Resource'").count > 0} + if params[:send_type].present? and params[:send_type] == 'news' + @orgs = @user.organizations.select{|org| OrgSubfield.where("organization_id = #{org.id} and field_type='Post'").count > 0} + else + @orgs = @user.organizations.select{|org| OrgSubfield.where("organization_id = #{org.id} and field_type='Resource'").count > 0} + end end @search = params[:search] #这里仅仅是传递需要发送的资源id diff --git a/app/models/news.rb b/app/models/news.rb index 7c44f7e8a..0ff0786ab 100644 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -22,6 +22,7 @@ class News < ActiveRecord::Base has_many_kindeditor_assets :assets, :dependent => :destroy #added by nwb belongs_to :course,:touch => true + belongs_to :org_subfield, :touch => true belongs_to :author, :class_name => 'User', :foreign_key => 'author_id' has_many :comments, :as => :commented, :dependent => :destroy, :order => "created_on" # fq diff --git a/app/models/org_subfield.rb b/app/models/org_subfield.rb index b109ba042..c62cbf4f8 100644 --- a/app/models/org_subfield.rb +++ b/app/models/org_subfield.rb @@ -6,6 +6,7 @@ class OrgSubfield < ActiveRecord::Base has_many :org_subfield_messages, :dependent => :destroy has_many :messages, :through => :org_subfield_messages has_many :boards, :dependent => :destroy + has_many :news, :dependent => :destroy acts_as_attachable after_create :create_board_sync # 创建资源栏目讨论区 diff --git a/app/views/comments/create.js.erb b/app/views/comments/create.js.erb index 8f0c5f38d..f94eda065 100644 --- a/app/views/comments/create.js.erb +++ b/app/views/comments/create.js.erb @@ -1,6 +1,8 @@ <% if @course %> -$("#user_activity_<%= @user_activity_id%>").replaceWith("<%= escape_javascript(render :partial => 'users/course_news', :locals => {:activity => @news,:user_activity_id =>@user_activity_id}) %>"); + $("#user_activity_<%= @user_activity_id%>").replaceWith("<%= escape_javascript(render :partial => 'users/course_news', :locals => {:activity => @news,:user_activity_id =>@user_activity_id}) %>"); +<% elsif @project %> + $("#user_activity_<%= @user_activity_id%>").replaceWith("<%= escape_javascript(render :partial => 'projects/project_news', :locals => {:activity => @news,:user_activity_id =>@user_activity_id}) %>"); <% else %> -$("#user_activity_<%= @user_activity_id%>").replaceWith("<%= escape_javascript(render :partial => 'projects/project_news', :locals => {:activity => @news,:user_activity_id =>@user_activity_id}) %>"); + $("#user_activity_<%= @user_activity_id%>").replaceWith("<%= escape_javascript(render :partial => 'organizations/org_subfield_news', :locals => {:activity => @news,:user_activity_id =>@user_activity_id}) %>"); <% end %> init_activity_KindEditor_data('<%= @user_activity_id%>',"","87%", "UserActivity"); diff --git a/app/views/news/index.html.erb b/app/views/news/index.html.erb index 2635e52a6..bd3c99672 100644 --- a/app/views/news/index.html.erb +++ b/app/views/news/index.html.erb @@ -3,3 +3,119 @@ <% elsif @course %> <%= render :partial => 'course_news', locals: {course: @course} %> <% end %> + + + diff --git a/app/views/org_subfields/_show_details.html.erb b/app/views/org_subfields/_show_details.html.erb index 176034218..eda9c9d57 100644 --- a/app/views/org_subfields/_show_details.html.erb +++ b/app/views/org_subfields/_show_details.html.erb @@ -69,6 +69,10 @@ <%= render :partial => 'organizations/org_subfield_message', :locals => {:activity => message, :user_activity_id => act.id} %> <% end %> <% end %> + <% if act.org_act_type == 'News' and News.where("id=?", act.org_act_id).count > 0 %> + <% news = News.find(act.org_act_id) %> + <%= render :partial => 'organizations/org_subfield_news', :locals => {:activity => news, :user_activity_id => act.id} %> + <% end %> <% end %> <% end %> diff --git a/app/views/org_subfields/_show_post_type.html.erb b/app/views/org_subfields/_show_post_type.html.erb index bc95c0774..6faabd3e9 100644 --- a/app/views/org_subfields/_show_post_type.html.erb +++ b/app/views/org_subfields/_show_post_type.html.erb @@ -29,6 +29,121 @@ :org_act_count=> @org_activities.count} %> <% end %> + + diff --git a/app/views/organizations/_org_activities.html.erb b/app/views/organizations/_org_activities.html.erb index 29bfb4e18..6579ccbca 100644 --- a/app/views/organizations/_org_activities.html.erb +++ b/app/views/organizations/_org_activities.html.erb @@ -97,6 +97,10 @@ <%= render :partial => 'organizations/org_subfield_message', :locals => {:activity => message, :user_activity_id => act.id} %> <% end %> <% end %> + <% if act.org_act_type == 'News' and News.where("id=?", act.org_act_id).count > 0 %> + <% news = News.find(act.org_act_id) %> + <%= render :partial => 'organizations/org_subfield_news', :locals => {:activity => news, :user_activity_id => act.id} %> + <% end %> <% end %> <% end %> diff --git a/app/views/organizations/_org_subfield_news.html.erb b/app/views/organizations/_org_subfield_news.html.erb new file mode 100644 index 000000000..3cb530860 --- /dev/null +++ b/app/views/organizations/_org_subfield_news.html.erb @@ -0,0 +1,132 @@ +
+
+
+ <%= link_to image_tag(url_to_avatar(activity.author), :width => "50", :height => "50"), user_path(activity.author_id), :alt => "用户头像" %> + <%= render :partial => 'users/show_detail_info', :locals => {:user => activity.author} %> +
+
+
+ <% 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.org_subfield.name.to_s+" | 帖子栏目通知", organization_path(activity.org_subfield.organization, :org_subfield_id => activity.org_subfield.id), :class => "newsBlue ml15" %> +
+ + +
+
+ 发布时间:<%= format_time(activity.created_on) %> +
+
+ <%=render :partial =>"users/intro_content", :locals=>{:user_activity_id =>user_activity_id, :content=>activity.description} %> +
+ + +
+
+ <%= render :partial=>"attachments/activity_attach", :locals=>{:activity => activity} %> +
+
+
    +
  • + <% if User.current.logged? %> +
      +
    • <%= link_to("发       送".html_safe, 'javascript:void(0)',:class => "postOptionLink",:onclick=>"show_send('#{activity.id}')") %>
    • +
    + <% end %> +
  • +
+
+
+
+
+ <% count=activity.comments.count %> +
+
+
回复 + <%= count>0 ? "(#{count})" : "" %> + + <% if activity.author == User.current %> + + <% else %> + <%=render :partial=> "praise_tread/praise", :locals => {:activity=>activity, :user_activity_id=>user_activity_id,:type=>"activity"}%> + <% end %> + +
+
<%#= format_date(activity.updated_on) %>
+ <%if count>3 %> + + <% end %> +
+ + <% replies_all_i = 0 %> + <% if count > 0 %> +
+
    + <% activity.comments.reorder("created_on desc").each do |comment| %> + + <% replies_all_i = replies_all_i + 1 %> +
  • +
    + <%= link_to image_tag(url_to_avatar(comment.author), :width => "33", :height => "33"), user_path(comment.author_id), :alt => "用户头像" %> +
    +
    +
    + <% if comment.try(:author).try(:realname) == ' ' %> + <%= link_to comment.try(:author), user_path(comment.author_id), :class => "newsBlue mr10 f14" %> + <% else %> + <%= link_to comment.try(:author).try(:realname), user_path(comment.author_id), :class => "newsBlue mr10 f14" %> + <% end %> + <%= format_time(comment.created_on) %> + + <% if comment.author == User.current %> + + <% else %> + <%=render :partial=> "praise_tread/praise", :locals => {:activity=>comment, :user_activity_id=>comment.id,:type=>"reply"}%> + <% end %> + +
    +
    + <%= comment.comments.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 => 'comments', :action => 'create', :id => activity},:method => "post", :remote => true) do |f|%> + + +
+ +
+

+ <% end%> +
+
+
+
+
+
+
+ diff --git a/app/views/users/_course_news.html.erb b/app/views/users/_course_news.html.erb index 902a142a0..fdb8f2476 100644 --- a/app/views/users/_course_news.html.erb +++ b/app/views/users/_course_news.html.erb @@ -35,6 +35,17 @@
<%= render :partial=>"attachments/activity_attach", :locals=>{:activity => activity} %>
+
+
    +
  • + <% if User.current.logged? %> +
      +
    • <%= link_to("发       送".html_safe, 'javascript:void(0)',:class => "postOptionLink",:onclick=>"show_send('#{activity.id}')") %>
    • +
    + <% end %> +
  • +
+
diff --git a/app/views/users/_share_news_to_course.html.erb b/app/views/users/_share_news_to_course.html.erb new file mode 100644 index 000000000..9865f6af2 --- /dev/null +++ b/app/views/users/_share_news_to_course.html.erb @@ -0,0 +1,56 @@ + + +
+
+
发送到
+
+ +
+
+
+ +
+ <%= form_tag search_user_course_user_path(user),:method => 'get', + :remote=>true,:id=>'search_user_course_form',:class=>'resourcesSearchBox' do %> + <%= hidden_field_tag(:send_id, send_id) %> + <%= hidden_field_tag(:send_ids, send_ids) %> + + + + <%= submit_tag '',:class=>'searchIcon2',:onfocus=>"this.blur();",:style=>'border-style:none' %> + <% end %> +
+ <%= form_tag share_news_to_course_user_path(user),:remote=>true,:id=>'course_list_form' %> +
+ + <%= hidden_field_tag(:send_id, send_id) %> + <%= hidden_field_tag(:send_ids, send_ids) %> +
+ <% if !courses.empty? %> + <% courses.each do |course| %> +
    +
  • + +
  • +
  • <%= truncate(course.name,:lendght=>25) + '['+course.time.to_s+course.term + ']'%>
  • +
+ <% end %> +
+
+
+
+ + <%= submit_tag '确定',:class=>'sendSourceText',:onfocus=>'this.blur();' %> +
+ +
+
+ <% end %> +
+ diff --git a/app/views/users/_share_news_to_org.html.erb b/app/views/users/_share_news_to_org.html.erb new file mode 100644 index 000000000..f57a91ae6 --- /dev/null +++ b/app/views/users/_share_news_to_org.html.erb @@ -0,0 +1,59 @@ +
+
发送到
+
+ +
+ <%= form_tag search_user_org_user_path(user),:method => 'get', + :remote=>true,:id=>'search_user_org_form' do %> + <%= hidden_field_tag(:send_id, send_id) %> + <%= hidden_field_tag(:send_ids, send_ids) %> + + + <% end %> +
+
+<%= form_tag share_news_to_org_user_path(user),:remote=>true,:id=>'orgs_list_form' do %> + <%= hidden_field_tag(:send_id, send_id) %> + <%= hidden_field_tag(:send_ids, send_ids) %> +
+ +
    + <% unless @orgs.empty? %> + <% @orgs.each do |org|%> +
  • + +
  • + <%end%> + <%end%> +
+
+
+
    + + + <%= render :partial => 'users/org_resources_subfield',:locals => {:subfield=>nil}%> + + + + + +
+
+
+
目标地址:
+
+ <%= submit_tag '确定',:class=>'sendSourceText',:onfocus=>'this.blur();',:onclick=>"check_des(event);" %> +
+
+ 取消 +
+
+<%end %> \ No newline at end of file diff --git a/app/views/users/_share_news_to_project.html.erb b/app/views/users/_share_news_to_project.html.erb new file mode 100644 index 000000000..0ae011caf --- /dev/null +++ b/app/views/users/_share_news_to_project.html.erb @@ -0,0 +1,54 @@ +
+
+
发送到
+
+ +
+
+
+ +
+ <%= form_tag search_user_project_user_path(user),:method => 'get', + :remote=>true,:id=>'search_user_project_form',:class=>'resourcesSearchBox' do %> + <%= hidden_field_tag(:send_id, send_id) %> + <%= hidden_field_tag(:send_ids, send_ids) %> + + + + <%= submit_tag '',:class=>'searchIcon2',:onfocus=>"this.blur();",:style=>'border-style:none' %> + <% end %> +
+ <%= form_tag share_news_to_project_user_path(user), :remote => true, :id=>'projects_list_form' %> +
+ + <%= hidden_field_tag(:send_id, send_id) %> + <%= hidden_field_tag(:send_ids, send_ids) %> +
+ <% if !projects.empty? %> + <% projects.each do |project| %> +
    +
  • + +
  • +
  • <%= project.name%>
  • +
+ <% end %> +
+
+
+
+ + <%= submit_tag '确定',:class=>'sendSourceText',:onfocus=>'this.blur();' %> +
+ +
+
+ <% end %> +
+ diff --git a/app/views/users/search_user_course.js.erb b/app/views/users/search_user_course.js.erb index d0ac40ed0..138eab6f9 100644 --- a/app/views/users/search_user_course.js.erb +++ b/app/views/users/search_user_course.js.erb @@ -9,7 +9,11 @@ //$("#upload_box").css('left','').css('top',''); //$("#upload_box").html('<%#= escape_javascript( render :partial => "resource_share_popup" ,:locals => {:courses=>@course,:user=>@user,:send_id=>@send_id,:send_ids=>@send_ids})%>'); //$("#upload_box").css('display','block'); -$("#ajax-modal").html('<%= escape_javascript( render :partial => 'users/resource_share_popup' ,:locals => {:courses=>@course,:user=>@user,:send_id=>@send_id,:send_ids=>@send_ids})%>'); +<% if params[:send_type].present? && params[:send_type] == 'news' %> + $("#ajax-modal").html('<%= escape_javascript( render :partial => 'users/share_news_to_course' ,:locals => {:courses=>@course,:user=>@user,:send_id=>@send_id,:send_ids=>@send_ids})%>'); +<% else %> + $("#ajax-modal").html('<%= escape_javascript( render :partial => 'users/resource_share_popup' ,:locals => {:courses=>@course,:user=>@user,:send_id=>@send_id,:send_ids=>@send_ids})%>'); +<% end %> showModal('ajax-modal', '452px'); $('#ajax-modal').siblings().remove(); $('#ajax-modal').before(""); diff --git a/app/views/users/search_user_org.js.erb b/app/views/users/search_user_org.js.erb index db099fe72..fb6efec9a 100644 --- a/app/views/users/search_user_org.js.erb +++ b/app/views/users/search_user_org.js.erb @@ -1,4 +1,8 @@ -$("#ajax-modal").html('<%= escape_javascript( render :partial => 'users/resource_share_for_orgs' ,:locals => {:orgs=>@orgs,:user=>@user,:send_id=>@send_id,:send_ids=>@send_ids})%>'); +<% if params[:send_type].present? && params[:send_type] == 'news' %> + $("#ajax-modal").html('<%= escape_javascript( render :partial => 'users/share_news_to_org' ,:locals => {:orgs=>@orgs,:user=>@user,:send_id=>@send_id,:send_ids=>@send_ids})%>'); +<% else %> + $("#ajax-modal").html('<%= escape_javascript( render :partial => 'users/resource_share_for_orgs' ,:locals => {:orgs=>@orgs,:user=>@user,:send_id=>@send_id,:send_ids=>@send_ids})%>'); +<% end %> showModal('ajax-modal', '452px'); $('#ajax-modal').siblings().remove(); $('#ajax-modal').before(""); diff --git a/app/views/users/search_user_project.js.erb b/app/views/users/search_user_project.js.erb index 5218c22ab..926b7aa58 100644 --- a/app/views/users/search_user_project.js.erb +++ b/app/views/users/search_user_project.js.erb @@ -1,4 +1,8 @@ -$("#ajax-modal").html('<%= escape_javascript( render :partial => 'users/resource_share_for_project_popup', :locals => {:projects => @projects, :user => @user, :send_id => @send_id, :send_ids => @send_ids}) %>'); +<% if params[:send_type].present? && params[:send_type] == 'news' %> + $("#ajax-modal").html('<%= escape_javascript( render :partial => 'users/share_news_to_project', :locals => {:projects => @projects, :user => @user, :send_id => @send_id, :send_ids => @send_ids}) %>'); +<% else %> + $("#ajax-modal").html('<%= escape_javascript( render :partial => 'users/resource_share_for_project_popup', :locals => {:projects => @projects, :user => @user, :send_id => @send_id, :send_ids => @send_ids}) %>'); +<% end %> showModal('ajax-modal', '452px'); $('#ajax-modal').siblings().remove(); $('#ajax-modal').before(""); diff --git a/app/views/users/share_news_to_course.js.erb b/app/views/users/share_news_to_course.js.erb new file mode 100644 index 000000000..5a5046dfa --- /dev/null +++ b/app/views/users/share_news_to_course.js.erb @@ -0,0 +1,2 @@ +hideModal(); +alert("发送成功!"); \ No newline at end of file diff --git a/app/views/users/share_news_to_org.js.erb b/app/views/users/share_news_to_org.js.erb new file mode 100644 index 000000000..5a5046dfa --- /dev/null +++ b/app/views/users/share_news_to_org.js.erb @@ -0,0 +1,2 @@ +hideModal(); +alert("发送成功!"); \ No newline at end of file diff --git a/app/views/users/share_news_to_project.js.erb b/app/views/users/share_news_to_project.js.erb new file mode 100644 index 000000000..5a5046dfa --- /dev/null +++ b/app/views/users/share_news_to_project.js.erb @@ -0,0 +1,2 @@ +hideModal(); +alert("发送成功!"); \ No newline at end of file diff --git a/config/routes.rb b/config/routes.rb index ccbe67004..c2b089c02 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -532,6 +532,9 @@ RedmineApp::Application.routes.draw do post "add_exist_file_to_course" post "add_exist_file_to_project" post 'add_exist_file_to_org' + post 'share_news_to_course' + post 'share_news_to_project' + post 'share_news_to_org' get 'resource_preview' get 'rename_resource' get 'search_user_project' diff --git a/db/schema.rb b/db/schema.rb index bac1882c5..92cf224fc 100644 --- a/db/schema.rb +++ b/db/schema.rb @@ -11,7 +11,7 @@ # # It's strongly recommended to check this file into your version control system. -ActiveRecord::Schema.define(:version => 20160115125217) do +ActiveRecord::Schema.define(:version => 20160120032758) do create_table "activities", :force => true do |t| t.integer "act_id", :null => false @@ -1082,14 +1082,15 @@ ActiveRecord::Schema.define(:version => 20160115125217) do create_table "news", :force => true do |t| t.integer "project_id" - t.string "title", :limit => 60, :default => "", :null => false - t.string "summary", :default => "" + t.string "title", :limit => 60, :default => "", :null => false + t.string "summary", :default => "" t.text "description" - t.integer "author_id", :default => 0, :null => false + t.integer "author_id", :default => 0, :null => false t.datetime "created_on" - t.integer "comments_count", :default => 0, :null => false + t.integer "comments_count", :default => 0, :null => false t.integer "course_id" - t.integer "sticky", :default => 0 + t.integer "sticky", :default => 0 + t.integer "org_subfield_id" end add_index "news", ["author_id"], :name => "index_news_on_author_id" @@ -1709,6 +1710,10 @@ ActiveRecord::Schema.define(:version => 20160115125217) do t.string "extra" end + create_table "temp", :id => false, :force => true do |t| + t.integer "id", :default => 0, :null => false + end + create_table "time_entries", :force => true do |t| t.integer "project_id", :null => false t.integer "user_id", :null => false From 340d404ecd2f626689b35f06caf5e286ef3cde49 Mon Sep 17 00:00:00 2001 From: ouyangxuhua Date: Wed, 20 Jan 2016 17:23:02 +0800 Subject: [PATCH 03/11] =?UTF-8?q?=E7=BB=84=E7=BB=87=E6=A0=8F=E7=9B=AE?= =?UTF-8?q?=E7=9A=84=E9=80=9A=E7=9F=A5=E5=A2=9E=E5=8A=A0=E6=9F=A5=E3=80=81?= =?UTF-8?q?=E6=94=B9=E3=80=81=E5=88=A0=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/controllers/news_controller.rb | 15 ++ app/models/news.rb | 6 +- .../news/_edit_for_org_subfield.html.erb | 49 +++++ app/views/news/_organization_show.html.erb | 173 ++++++++++++++++++ app/views/news/edit.html.erb | 8 +- app/views/news/show.html.erb | 2 + ...60120032758_add_org_subfield_id_to_news.rb | 5 + public/javascripts/project.js | 21 ++- 8 files changed, 273 insertions(+), 6 deletions(-) create mode 100644 app/views/news/_edit_for_org_subfield.html.erb create mode 100644 app/views/news/_organization_show.html.erb create mode 100644 db/migrate/20160120032758_add_org_subfield_id_to_news.rb diff --git a/app/controllers/news_controller.rb b/app/controllers/news_controller.rb index d3ac71b99..8d0309588 100644 --- a/app/controllers/news_controller.rb +++ b/app/controllers/news_controller.rb @@ -144,6 +144,10 @@ class NewsController < ApplicationController if @course render :layout => 'base_courses' end + elsif @news.org_subfield_id + @org_subfield = OrgSubfield.find(@news.org_subfield_id) + @organization = @org_subfield.organization + render :layout => 'base_org' end end @@ -221,8 +225,14 @@ class NewsController < ApplicationController end def edit + if @news.org_subfield_id + @org_subfield = OrgSubfield.find(@news.org_subfield_id) + @organization = @org_subfield.organization + end if @course render :layout => "base_courses" + elsif @org_subfield + render :layout => 'base_org' end end @@ -240,12 +250,17 @@ class NewsController < ApplicationController end def destroy + if @news.org_subfield_id + @org_subfield = OrgSubfield.find(@news.org_subfield_id) + end @news.destroy # modify by nwb if @project redirect_to project_news_index_url(@project) elsif @course redirect_to course_news_index_url(@course) + elsif @org_subfield + redirect_to organization_path(@org_subfield.organization, :org_subfield_id => @org_subfield.id) end end diff --git a/app/models/news.rb b/app/models/news.rb index 0ff0786ab..fee5d2801 100644 --- a/app/models/news.rb +++ b/app/models/news.rb @@ -58,7 +58,7 @@ class News < ActiveRecord::Base after_create :act_as_activity,:act_as_forge_activity, :act_as_course_activity,:act_as_system_message, :add_author_as_watcher, :send_mail, :add_news_count after_update :update_activity - after_destroy :delete_kindeditor_assets, :decrease_news_count + after_destroy :delete_kindeditor_assets, :decrease_news_count, :delete_org_activities scope :visible, lambda {|*args| includes(:project).where(Project.allowed_to_condition(args.shift || User.current, :view_news, *args)) @@ -188,4 +188,8 @@ class News < ActiveRecord::Base Mailer.run.news_added(self) if Setting.notified_events.include?('news_added') end + def delete_org_activities + OrgActivity.where("container_type='OrgSubfield' and org_act_type='News' and org_act_id=?", self.id).destroy_all + end + end \ No newline at end of file diff --git a/app/views/news/_edit_for_org_subfield.html.erb b/app/views/news/_edit_for_org_subfield.html.erb new file mode 100644 index 000000000..75f24e6b7 --- /dev/null +++ b/app/views/news/_edit_for_org_subfield.html.erb @@ -0,0 +1,49 @@ +<%= content_for(:header_tags) do %> + <%= import_ke(enable_at: true, prettify: false) %> +<% end %> + +
+
+
+
+ +

+
+ +
+
+
\ No newline at end of file diff --git a/app/views/news/_organization_show.html.erb b/app/views/news/_organization_show.html.erb new file mode 100644 index 000000000..aa610720c --- /dev/null +++ b/app/views/news/_organization_show.html.erb @@ -0,0 +1,173 @@ +<%= content_for(:header_tags) do %> + <%= import_ke(enable_at: false, prettify: false, init_activity: false) %> +<% end %> + + + + +
+
+
+ <%= link_to image_tag(url_to_avatar(@news.author),:width=>50,:height => 50,:alt=>'图像' ),user_path(@news.author) %> +
+
+ <% if User.current.logged? %> + + <%end%> + +
+ +
+ <% if @news.try(:author).try(:realname) == ' ' %> + <%= link_to @news.try(:author), user_path(@news.author,:host=>Setting.host_user), :class => "linkBlue2", :target=> "_blank" %> + <% else %> + <%= link_to @news.try(:author).try(:realname), user_path(@news.author,:host=>Setting.host_user), :class => "linkBlue2", :target=> "_blank" %> + <% end %> +
+
<%= format_time( @news.created_on)%>
+
+
+ <%= @news.description.html_safe%> +
+
+
+ <%= link_to_attachments_course @news, :author => false %> +
+
+
+
+
+
+ <% unless @comments.empty? %> +
+
回复(<%=@comments.count %>)
+
+
+
+ <% @comments.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.comments.html_safe%> +
+
+ <%= format_time(reply.created_on) %> + +
+

+
+
+
+ <% end %> +
+ + <% end %> +
+ <% if @news.commentable? %> +
+ +
+
+ <%= form_for @comment, :url=>{:controller => 'comments', :action => 'create', :id => @news}, :html => {:multipart => true, :id => 'add_comment_form'} do |f| %> +
+ <%= hidden_field_tag :asset_id,params[:asset_id],:required => false,:style => 'display:none' %> + <%= f.kindeditor :comments, :editor_id => 'comment_editor', + :owner_id => @comment.nil? ? 0: @comment.id, + :owner_type => OwnerTypeHelper::COMMENT, + :width => '99%', + :height => 100, + :minHeight=>100, + :input_html => { :id => 'comment_content', + :class => 'talk_text fl', + :maxlength => 5000 }%> +
+

+

+ + <%= l(:label_cancel_with_space) %> + + + <%= l(:label_comment_with_space) %> + +

+ <% end %> +
+
+
+ <% end %> +
+
diff --git a/app/views/news/edit.html.erb b/app/views/news/edit.html.erb index b043b06f8..24d7f2040 100644 --- a/app/views/news/edit.html.erb +++ b/app/views/news/edit.html.erb @@ -16,8 +16,10 @@
<%= labelled_form_for :news, @news, :url => news_path(@news), :html => { :id => 'news-form', :multipart => true, :method => :put } do |f| %> - <%#= labelled_form_for :news, :url =>{:controller=>'news',:action => 'new', :course_id => @course.id}, - :html => {:nhname=>'form',:multipart => true, :id => 'news-form'} do |f| %> - <%= render :partial => 'course_news_new', :locals => {:f => f, :news => @news, :edit_mode => true, :course => @course} %> + <% if @org_subfield %> + <%= render :partial => 'edit_for_org_subfield', :locals => {:f => f, :news => @news} %> + <% else %> + <%= render :partial => 'course_news_new', :locals => {:f => f, :news => @news, :edit_mode => true, :course => @course} %> + <% end %> <% end %> diff --git a/app/views/news/show.html.erb b/app/views/news/show.html.erb index 846be063f..4f6ca056e 100644 --- a/app/views/news/show.html.erb +++ b/app/views/news/show.html.erb @@ -2,6 +2,8 @@ <%= render :partial => 'project_show', locals: {project: @project} %> <% elsif @course %> <%= render :partial => 'course_show', locals: {course: @course} %> +<% elsif @organization %> + <%= render :partial => 'organization_show', :locals => {:org_subfield => @org_subfield} %> <% end %> +
+
+
+ 项目通知 +
+
+ <% if @project && User.current.allowed_to?(:manage_news, @project) %> + <%= labelled_form_for @news, :url =>{:controller=>'news',:action => 'new', :project_id => @project.id}, + :html => {:nhname=>'form',:multipart => true, :id => 'news-form'} do |f| %> + <%= render :partial => 'project_news_new', :locals => {:f => f, :news => @news, :edit_mode => false} %> <% end %> <% end %> + <%= render :partial=> 'project_news_detail',:locals =>{:all_news => @newss, :page => 0} %>
- - - - <% other_formats_links do |f| %> - <%= f.link_to 'Atom', :url => {:project_id => @project, :key => User.current.rss_key} %> - <% end %> - - <% content_for :header_tags do %> - <%= auto_discovery_link_tag(:atom, params.merge({:format => 'atom', :page => nil, :key => User.current.rss_key})) %> - <%= stylesheet_link_tag 'scm' %> - <% end %> - - <% html_title(l(:label_news_plural)) -%> - - diff --git a/app/views/news/_project_news_detail.html.erb b/app/views/news/_project_news_detail.html.erb new file mode 100644 index 000000000..fdb035bf5 --- /dev/null +++ b/app/views/news/_project_news_detail.html.erb @@ -0,0 +1,56 @@ +<%= content_for(:header_tags) do %> + <%= import_ke(enable_at: false, prettify: false) %> + <%= javascript_include_tag "init_activity_KindEditor" %> +<% end %> + + +<% if all_news %> + <% all_news.each do |news| %> + + <% if news %> + <%= render :partial => 'users/project_news', :locals => {:activity => news, :user_activity_id => news.id} %> + <% end %> + <% end %> + + <% if all_news.count == 10 %> + <%= link_to "点击展开更多",news_index_path(:project_id => @project.id ,:page => page),:id => "show_more_project_news",:remote => "true",:class => "loadMore mt10 f_grey"%> + <% end %> +<% end%> + diff --git a/app/views/news/_project_news_new.html.erb b/app/views/news/_project_news_new.html.erb new file mode 100644 index 000000000..0e9b03c6f --- /dev/null +++ b/app/views/news/_project_news_new.html.erb @@ -0,0 +1,60 @@ +<%= content_for(:header_tags) do %> + <%= import_ke(enable_at: true, prettify: false) %> +<% end %> + +
+
+
+
+ +

+
+ +
+
+
\ No newline at end of file diff --git a/app/views/news/_project_show.html.erb b/app/views/news/_project_show.html.erb index 463b0f489..7a62ec314 100644 --- a/app/views/news/_project_show.html.erb +++ b/app/views/news/_project_show.html.erb @@ -1,72 +1,173 @@ -
-

<%= l(:label_news) %>

-
+<%= content_for(:header_tags) do %> + <%= import_ke(enable_at: false, prettify: false, init_activity: false) %> +<% end %> + + + -<% if authorize_for('news', 'edit') %> -