diff --git a/app/controllers/words_controller.rb b/app/controllers/words_controller.rb index 6304055ed..6ad1a66b4 100644 --- a/app/controllers/words_controller.rb +++ b/app/controllers/words_controller.rb @@ -243,7 +243,45 @@ class WordsController < ApplicationController flash[:error] = feedback.errors.full_messages[0] redirect_to course_feedback_url(params[:id]) end + end + + #作业的回复 + def leave_homework_message + if User.current.logged? + @user = User.current + @homework_common = HomeworkCommon.find(params[:id]); + if params[:homework_message].size>0 && User.current.logged? && @user + feedback = HomeworkCommon.add_homework_jour(@user, params[:homework_message], params[:id]) + if (feedback.errors.empty?) + if params[:asset_id] + ids = params[:asset_id].split(',') + update_kindeditor_assets_owner ids,feedback[:id],OwnerTypeHelper::JOURNALSFORMESSAGE + end + course_activity = CourseActivity.where("course_act_type='HomeworkCommon' and course_act_id =#{@homework_common.id}").first + if course_activity + course_activity.updated_at = Time.now + course_activity.save + end + user_activity = UserActivity.where("act_type='HomeworkCommon' and act_id =#{@homework_common.id}").first + if user_activity + user_activity.updated_at = Time.now + user_activity.save + end + respond_to do |format| + format.js{ + @user_activity_id = params[:user_activity_id] + @is_in_course = params[:is_in_course] + @homework_common_id = params[:homework_common_id] + } + end + else + flash[:error] = feedback.errors.full_messages[0] + end + end + else + render_403 + end end def add_brief_introdution diff --git a/app/models/homework_common.rb b/app/models/homework_common.rb index 796080645..03a7644a2 100644 --- a/app/models/homework_common.rb +++ b/app/models/homework_common.rb @@ -12,6 +12,7 @@ class HomeworkCommon < ActiveRecord::Base has_many :homework_tests, :dependent => :destroy has_many :student_works, :dependent => :destroy, :conditions => "is_test=0" has_many :student_works_evaluation_distributions, :through => :student_works #一个作业的分配的匿评列表 + has_many :journals_for_messages, :as => :jour, :dependent => :destroy has_many :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy #用户活动 # 课程动态 has_many :course_acts, :class_name => 'CourseActivity',:as =>:course_act ,:dependent => :destroy @@ -60,6 +61,18 @@ class HomeworkCommon < ActiveRecord::Base self.homework_type == 2 && self.homework_detail_programing end + ###添加回复 + def self.add_homework_jour(user, notes, id , options = {}) + homework = HomeworkCommon.find(id) + if options.count == 0 + jfm = homework.journals_for_messages.build(:user_id => user.id, :notes => notes, :reply_id => 0) + else + jfm = homework.journals_for_messages.build(options) + end + jfm.save + jfm + end + delegate :language_name, :language, :to => :homework_detail_programing end diff --git a/app/views/users/_course_homework.html.erb b/app/views/users/_course_homework.html.erb index 2d3bc68de..df42f6ee9 100644 --- a/app/views/users/_course_homework.html.erb +++ b/app/views/users/_course_homework.html.erb @@ -1,5 +1,5 @@ <% is_teacher = User.current.allowed_to?(:as_teacher,activity.course) %> -
+
<%= link_to image_tag(url_to_avatar(activity.user), :width => "50", :height => "50"), user_path(activity.user_id), :alt => "用户头像" %> @@ -71,4 +71,74 @@
+ + <% count=activity.journals_for_messages.count %> +
+
+
+
+ 回复(<%= count %>) +
+
+ <%if count>3 %> + + <% end %> +
+ + <% replies_all_i = 0 %> + <% if count > 0 %> +
+
    + <% activity.journals_for_messages.reorder("created_on desc").each do |comment| %> + + <% replies_all_i = replies_all_i + 1 %> +
  • +
    + <%= link_to image_tag(url_to_avatar(comment.user), :width => "33", :height => "33", :class =>"mt8"), user_path(comment.user_id), :alt => "用户头像" %> +
    +
    +
    + <% if comment.try(:user).try(:realname) == ' ' %> + <%= link_to comment.try(:user), user_path(comment.user_id), :class => "newsBlue mr10 f14" %> + <% else %> + <%= link_to comment.try(:user).try(:realname), user_path(comment.user_id), :class => "newsBlue mr10 f14" %> + <% end %> + <%= format_time(comment.created_on) %> +
    +
    + <%= comment.notes.html_safe %>
    +
    +
    +
  • + <% end %> +
+
+ <% end %> + +
+
<%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), :alt => "用户头像" %>
+
+
+ <%= form_for('new_form',:url => {:controller => 'words', :action => 'leave_homework_message', :id => activity.id},:method => "post", :remote => true) do |f|%> + <%= hidden_field_tag 'user_activity_id',params[:user_activity_id],:value =>user_activity_id %> + +
+ +
+

+ <% end%> +
+
+
+
+
+
\ No newline at end of file diff --git a/app/views/users/_user_homework_detail.html.erb b/app/views/users/_user_homework_detail.html.erb new file mode 100644 index 000000000..40400c71e --- /dev/null +++ b/app/views/users/_user_homework_detail.html.erb @@ -0,0 +1,150 @@ +<% is_teacher = User.current.allowed_to?(:as_teacher,homework_common.course) %> +
+
+
+ <%=link_to image_tag(url_to_avatar(homework_common.user),width:"50px", height: "50px"), user_activities_path(homework_common.user.id)%> +
+
+
+ <%= link_to homework_common.user.show_name, user_activities_path(homework_common.user_id), :class => "newsBlue mr15"%> + TO + <%= link_to homework_common.course.name, course_path(homework_common.course_id), :class => "newsBlue ml15"%> +
+ + + <% if homework_common.homework_detail_manual%> + <% if homework_common.homework_detail_manual.comment_status == 1%> + 未开启匿评 + <% elsif homework_common.homework_detail_manual.comment_status == 2%> + 匿评中 + <% elsif homework_common.homework_detail_manual.comment_status == 3%> + 匿评已结束 + <% end%> + <% end%> + +
+
+ <%= user_for_homework_common homework_common,is_teacher %> +
+ <% if homework_common.homework_type == 2 && is_teacher%> +
+ <%= link_to "模拟答题", new_user_commit_homework_users_path(homework_id: homework_common.id, is_test: true), class: 'c_blue test-program-btn', title: '教师可以通过模拟答题设置作业的标准答案' %> +
+ <% end %> + <% if homework_common.homework_type == 2%> +
+ 语言: + <%= homework_common.language_name%> +
+ <% end %> +
+ <%= l(:label_end_time)%>:<%= homework_common.end_time%> +
+
+
+ <%= homework_common.description.html_safe %> +
+
+ <%= render :partial => 'student_work/work_attachments', :locals => {:attachments => homework_common.attachments} %> +
+
+ <% if is_teacher%> + <%# if false%> +
+
    +
  • +
      +
    • + <%= link_to l(:button_edit),edit_homework_common_path(homework_common,:is_in_course => is_in_course), :class => "postOptionLink"%> +
    • +
    • + <%= link_to(l(:label_bid_respond_delete), homework_common_path(homework_common,:is_in_course => is_in_course),:method => 'delete', :confirm => l(:text_are_you_sure), :class => "postOptionLink") %> +
    • +
    • + <%= link_to("匿评设置", start_evaluation_set_homework_common_path(homework_common),:class => "postOptionLink", :remote => true) if homework_common.homework_detail_manual.comment_status == 1%> +
    • +
    • + <%= homework_anonymous_comment homework_common %> +
    • +
    +
  • +
+
+ <% end%> +
+
+
+ + <% count=homework_common.journals_for_messages.count %> +
+
+
+
+ 回复(<%= count %>) +
+
+ <%if count>3 %> + + <% end %> +
+ + <% replies_all_i = 0 %> + <% if count > 0 %> +
+
    + <% homework_common.journals_for_messages.reorder("created_on desc").each do |comment| %> + + <% replies_all_i = replies_all_i + 1 %> +
  • +
    + <%= link_to image_tag(url_to_avatar(comment.user), :width => "33", :height => "33", :class =>"mt8"), user_path(comment.user_id), :alt => "用户头像" %> +
    +
    +
    + <% if comment.try(:user).try(:realname) == ' ' %> + <%= link_to comment.try(:user), user_path(comment.user_id), :class => "newsBlue mr10 f14" %> + <% else %> + <%= link_to comment.try(:user).try(:realname), user_path(comment.user_id), :class => "newsBlue mr10 f14" %> + <% end %> + <%= format_time(comment.created_on) %> +
    +
    + <%= comment.notes.html_safe %>
    +
    +
    +
  • + <% end %> +
+
+ <% end %> + +
+
<%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), :alt => "用户头像" %>
+
+
+ <%= form_for('new_form',:url => {:controller => 'words', :action => 'leave_homework_message', :id => homework_common.id},:method => "post", :remote => true) do |f|%> + <%= hidden_field_tag 'homework_common_id',params[:homework_common_id],:value =>homework_common.id %> + <%= hidden_field_tag 'is_in_course',params[:is_in_course],:value =>is_in_course %> + +
+ +
+

+ <% end%> +
+
+
+
+
+
+
\ No newline at end of file diff --git a/app/views/users/_user_homework_list.html.erb b/app/views/users/_user_homework_list.html.erb index 44f992bb4..ad39ad14f 100644 --- a/app/views/users/_user_homework_list.html.erb +++ b/app/views/users/_user_homework_list.html.erb @@ -1,83 +1,41 @@ +<%= javascript_include_tag "/assets/kindeditor/kindeditor",'/assets/kindeditor/pasteimg',"init_activity_KindEditor" %> + <% homework_commons.each do |homework_common|%> - <% is_teacher = User.current.allowed_to?(:as_teacher,homework_common.course) %> -
-
-
- <%=link_to image_tag(url_to_avatar(homework_common.user),width:"50px", height: "50px"), user_activities_path(homework_common.user.id)%> -
-
-
- <%= link_to homework_common.user.show_name, user_activities_path(homework_common.user_id), :class => "newsBlue mr15"%> - TO - <%= link_to homework_common.course.name, course_path(homework_common.course_id), :class => "newsBlue ml15"%> -
- + + <%= render :partial => 'users/user_homework_detail', :locals => {:homework_common => homework_common,:is_in_course => is_in_course} %> <% end%> <% if homework_commons.count == 10%> <% if is_in_course == 1%> diff --git a/app/views/words/leave_homework_message.js.erb b/app/views/words/leave_homework_message.js.erb new file mode 100644 index 000000000..91525c889 --- /dev/null +++ b/app/views/words/leave_homework_message.js.erb @@ -0,0 +1,7 @@ +<% if @user_activity_id %> + $("#user_activity_<%= @user_activity_id%>").replaceWith("<%= escape_javascript(render :partial => 'users/course_homework', :locals => {:activity => @homework_common,:user_activity_id =>@user_activity_id}) %>"); + init_activity_KindEditor_data(<%= @user_activity_id%>,"","87%"); +<% elsif @homework_common_id && @is_in_course %> + $("#homework_common_<%= @homework_common_id %>").replaceWith("<%= escape_javascript(render :partial => 'users/user_homework_detail', :locals => {:homework_common => @homework_common,:is_in_course => @is_in_course}) %>"); + init_activity_KindEditor_data(<%= @homework_common_id%>,"","87%"); +<% end %> diff --git a/config/routes.rb b/config/routes.rb index 810c22e7a..d140c240a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -855,6 +855,7 @@ RedmineApp::Application.routes.draw do match 'projects/:id/feedback', :to => 'projects#feedback', :via => :get, :as => 'project_feedback' match 'project/:id/share', :to => 'projects#share', :as => 'share_show' #share post 'words/:id/leave_user_message', :to => 'words#leave_user_message', :as => "leave_user_message" + post 'words/:id/leave_homework_message', :to => 'words#leave_homework_message', :as => "leave_homework_message" post 'join_in/join', :to => 'courses#join', :as => 'join' delete 'join_in/join', :to => 'courses#unjoin'