diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb index 9c073afa8..444446ef4 100644 --- a/app/controllers/exercise_controller.rb +++ b/app/controllers/exercise_controller.rb @@ -450,7 +450,7 @@ class ExerciseController < ApplicationController if params[:answer_text].nil? || params[:answer_text].blank? #用户提交空答案,视作不作答 @percent = get_percent(@exercise,User.current) - render :json => {:text => ea.answer_text,:percent => format("%.2f", @percent)} + render :json => {:text => "",:percent => format("%.2f", @percent)} else #添加答案 ea = ExerciseAnswer.new @@ -476,7 +476,7 @@ class ExerciseController < ApplicationController # 用户提交空答案,视为删除答案 if ea.delete @percent = get_percent(@exercise,User.current) - render :json => {:text => ea.answer_text,:percent => format("%.2f", @percent)} + render :json => {:text => "",:percent => format("%.2f", @percent)} else render :json => {:text => "failure"} end diff --git a/app/controllers/messages_controller.rb b/app/controllers/messages_controller.rb index 7b70dffe5..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,15 +348,25 @@ 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| - OrgSubfieldMessage.create(:org_subfield_id => field_id.to_i, :message_id => @message.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) - else - OrgActivity.create(:container_type => 'OrgSubfield', :container_id => field_id.to_i, :org_act_type=>'Message', :org_act_id => @message.id, :user_id => User.current.id) + @message.quotes = @message.quotes.nil? ? 1 : (@message.quotes + 1) + @message.save + 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) + # 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) + # else + OrgActivity.create(:container_type => 'OrgSubfield', :container_id => field_id.to_i, :org_act_type=>'Message', :org_act_id => mes.id, :user_id => User.current.id) + # end end end @@ -347,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/controllers/organizations_controller.rb b/app/controllers/organizations_controller.rb index aba656750..466fbd8e3 100644 --- a/app/controllers/organizations_controller.rb +++ b/app/controllers/organizations_controller.rb @@ -14,7 +14,7 @@ class OrganizationsController < ApplicationController include PollHelper helper :user_score helper :journals - + helper :attachments # added by liuping 关注 helper :watchers diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index f26f6c118..78d8e2b46 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -497,7 +497,7 @@ class UsersController < ApplicationController #提交作品时,计算是否迟交 if Time.parse(homework.end_time.to_s).strftime("%Y-%m-%d") < Time.parse(Time.now.to_s).strftime("%Y-%m-%d") - student_work.late_penalty = 1 + student_work.late_penalty = homework.late_penalty else student_work.late_penalty = 0 end diff --git a/app/models/message.rb b/app/models/message.rb index 19531e270..f59f778a8 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? || self.author == usr ||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/_show_org_subfields.html.erb b/app/views/messages/_show_org_subfields.html.erb index 659e1230e..cbd316ea4 100644 --- a/app/views/messages/_show_org_subfields.html.erb +++ b/app/views/messages/_show_org_subfields.html.erb @@ -2,10 +2,14 @@ <% if !org.nil? %> 组织:<%= org.name %> - <% org.org_subfields.where("field_type='Post'").each do |subfield| %> -
  • - -
  • + <% if org.org_subfields.where("field_type='Post'").count > 0 %> + <% org.org_subfields.where("field_type='Post'").each do |subfield| %> +
  • + +
  • + <% end %> + <% else %> +
  • 暂无资源栏目
  • <% end %> <% else %> 请在左侧选择组织 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 4e4ee3d4c..2a5543a66 100644 --- a/app/views/organizations/_org_activities.html.erb +++ b/app/views/organizations/_org_activities.html.erb @@ -50,31 +50,22 @@ <% end %> <% end %> <% if act.container_type == 'OrgSubfield' %> - <% if act.org_act_type == 'Message' %> + <% 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 %> <% end %> - - <%#= pagination_links_full @obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true%> - + <% end %> <% if org_act_count == 10 %> - <%= link_to "点击展开更多",organization_path(org,:page => page.to_i + 1, :show_homepage =>params[:show_homepage],:type => params[:type]),:id => "show_more_activities",:remote => "true",:class => "loadMore mt10 f_grey"%> <% end%> - + +
    + <% 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 %> +
    + +
    + <% 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/_show_org_document.html.erb b/app/views/organizations/_show_org_document.html.erb index 2b0f11cdd..25f6d5044 100644 --- a/app/views/organizations/_show_org_document.html.erb +++ b/app/views/organizations/_show_org_document.html.erb @@ -18,6 +18,9 @@ <%= document.content.html_safe %> <% end %> +
    + <%= link_to_attachments_course document, :author => false %> +
    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/app/views/organizations/show.html.erb b/app/views/organizations/show.html.erb index 37f4d00ed..a79271add 100644 --- a/app/views/organizations/show.html.erb +++ b/app/views/organizations/show.html.erb @@ -69,10 +69,10 @@ <% end %> <% if @org_activities %> <%= render :partial => 'organizations/org_activities', - :locals => {:org_activities =>@org_activities, - :page=>@page, - :org => @organization, - :org_act_count=>@org_activities.count}%> + :locals => {:org_activities => @org_activities, + :page=> @page, + :org => @organization, + :org_act_count=> @org_activities.count} %> <% end %> diff --git a/app/views/student_work/_evaluation_title.html.erb b/app/views/student_work/_evaluation_title.html.erb index 7398dbee1..2ef5ee9af 100644 --- a/app/views/student_work/_evaluation_title.html.erb +++ b/app/views/student_work/_evaluation_title.html.erb @@ -1,19 +1,25 @@ -