From 340d404ecd2f626689b35f06caf5e286ef3cde49 Mon Sep 17 00:00:00 2001 From: ouyangxuhua Date: Wed, 20 Jan 2016 17:23:02 +0800 Subject: [PATCH] =?UTF-8?q?=E7=BB=84=E7=BB=87=E6=A0=8F=E7=9B=AE=E7=9A=84?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E5=A2=9E=E5=8A=A0=E6=9F=A5=E3=80=81=E6=94=B9?= =?UTF-8?q?=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 %>