添加作业的回复功能

This commit is contained in:
cxt 2015-10-22 09:20:19 +08:00
parent 0fffed55a6
commit 7e21c00aed
7 changed files with 316 additions and 79 deletions

View File

@ -243,7 +243,45 @@ class WordsController < ApplicationController
flash[:error] = feedback.errors.full_messages[0] flash[:error] = feedback.errors.full_messages[0]
redirect_to course_feedback_url(params[:id]) redirect_to course_feedback_url(params[:id])
end 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 end
def add_brief_introdution def add_brief_introdution

View File

@ -12,6 +12,7 @@ class HomeworkCommon < ActiveRecord::Base
has_many :homework_tests, :dependent => :destroy has_many :homework_tests, :dependent => :destroy
has_many :student_works, :dependent => :destroy, :conditions => "is_test=0" has_many :student_works, :dependent => :destroy, :conditions => "is_test=0"
has_many :student_works_evaluation_distributions, :through => :student_works #一个作业的分配的匿评列表 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 :acts, :class_name => 'Activity', :as => :act, :dependent => :destroy #用户活动
# 课程动态 # 课程动态
has_many :course_acts, :class_name => 'CourseActivity',:as =>:course_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 self.homework_type == 2 && self.homework_detail_programing
end 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 delegate :language_name, :language, :to => :homework_detail_programing
end end

View File

@ -1,5 +1,5 @@
<% is_teacher = User.current.allowed_to?(:as_teacher,activity.course) %> <% is_teacher = User.current.allowed_to?(:as_teacher,activity.course) %>
<div class="resources mt10"> <div class="resources mt10" id="user_activity_<%= user_activity_id%>">
<div class="homepagePostBrief"> <div class="homepagePostBrief">
<div class="homepagePostPortrait"> <div class="homepagePostPortrait">
<%= link_to image_tag(url_to_avatar(activity.user), :width => "50", :height => "50"), user_path(activity.user_id), :alt => "用户头像" %> <%= link_to image_tag(url_to_avatar(activity.user), :width => "50", :height => "50"), user_path(activity.user_id), :alt => "用户头像" %>
@ -71,4 +71,74 @@
</div> </div>
<div class="cl"></div> <div class="cl"></div>
</div> </div>
<% count=activity.journals_for_messages.count %>
<div class="homepagePostReply">
<div class="topBorder" style="display: <%= count>0 ? 'none': '' %>"></div>
<div class="homepagePostReplyBanner" style="display: <%= count>0 ? '': 'none' %>">
<div class="homepagePostReplyBannerCount">
回复(<%= count %>
</div>
<div class="homepagePostReplyBannerTime"></div>
<%if count>3 %>
<div class="homepagePostReplyBannerMore">
<a id="reply_btn_<%=user_activity_id%>" onclick="expand_reply('#reply_div_<%= user_activity_id %> li','#reply_btn_<%=user_activity_id%>')" data-count="<%= count %>" data-init="0" class=" replyGrey" href="javascript:void(0)" value="show_help" >
展开更多
</a>
</div>
<% end %>
</div>
<% replies_all_i = 0 %>
<% if count > 0 %>
<div class="" id="reply_div_<%= user_activity_id %>">
<ul>
<% activity.journals_for_messages.reorder("created_on desc").each do |comment| %>
<script type="text/javascript">
$(function(){
showNormalImage('reply_content_<%= comment.id %>');
});
</script>
<% replies_all_i = replies_all_i + 1 %>
<li class="homepagePostReplyContainer" nhname="reply_rec" style="display:<%= replies_all_i > 3 ? 'none' : '' %>">
<div class="homepagePostReplyPortrait">
<%= link_to image_tag(url_to_avatar(comment.user), :width => "33", :height => "33", :class =>"mt8"), user_path(comment.user_id), :alt => "用户头像" %>
</div>
<div class="homepagePostReplyDes">
<div class="homepagePostReplyPublisher">
<% 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) %>
</div>
<div class="homepagePostReplyContent break_word list_style upload_img" id="reply_content_<%= comment.id %>">
<%= comment.notes.html_safe %></div>
</div>
<div class="cl"></div>
</li>
<% end %>
</ul>
</div>
<% end %>
<div class="homepagePostReplyContainer borderBottomNone minHeight48">
<div class="homepagePostReplyPortrait mr15 imageFuzzy" id="reply_image_<%= user_activity_id%>"><%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), :alt => "用户头像" %></div>
<div class="homepagePostReplyInputContainer mb10">
<div nhname='new_message_<%= user_activity_id%>' style="display:none;">
<%= 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 %>
<textarea placeholder="有问题或有建议,请直接给我留言吧!" style="display: none" nhname='new_message_textarea_<%= user_activity_id%>' name="homework_message"></textarea>
<div nhname='toolbar_container_<%= user_activity_id%>' style="float:left;padding-top:3px; margin-left: 5px;"></div>
<a id="new_message_submit_btn_<%= user_activity_id%>" href="javascript:void(0)" class="blue_n_btn fr" style="display:none;margin-top:6px;">发送</a>
<div class="cl"></div>
<p nhname='contentmsg_<%= user_activity_id%>'></p>
<% end%>
</div>
<div class="cl"></div>
</div>
<div class="cl"></div>
</div>
</div>
</div> </div>

View File

@ -0,0 +1,150 @@
<% is_teacher = User.current.allowed_to?(:as_teacher,homework_common.course) %>
<div class="HomeWork mb10" id="homework_common_<%= homework_common.id %>">
<div class="homepagePostBrief">
<div class="homepagePostPortrait">
<%=link_to image_tag(url_to_avatar(homework_common.user),width:"50px", height: "50px"), user_activities_path(homework_common.user.id)%>
</div>
<div class="homepagePostDes">
<div class="homepagePostTo mt-4">
<%= 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"%>
</div>
<span class="homepagePostTitle hidden m_w530 fl">
<%= link_to homework_common.name,student_work_index_path(:homework => homework_common.id),:class => "postGrey"%>
</span>
<% if homework_common.homework_detail_manual%>
<% if homework_common.homework_detail_manual.comment_status == 1%>
<span class="grey_btn_cir ml10">未开启匿评</span>
<% elsif homework_common.homework_detail_manual.comment_status == 2%>
<span class="green_btn_cir ml10">匿评中</span>
<% elsif homework_common.homework_detail_manual.comment_status == 3%>
<span class="grey_btn_cir ml10">匿评已结束</span>
<% end%>
<% end%>
<div class="homepagePostSubmitContainer">
<div class="homepagePostSubmit">
<%= user_for_homework_common homework_common,is_teacher %>
</div>
<% if homework_common.homework_type == 2 && is_teacher%>
<div class="homepagePostSubmit">
<%= link_to "模拟答题", new_user_commit_homework_users_path(homework_id: homework_common.id, is_test: true), class: 'c_blue test-program-btn', title: '教师可以通过模拟答题设置作业的标准答案' %>
</div>
<% end %>
<% if homework_common.homework_type == 2%>
<div class="homepagePostDeadline mr15">
语言:
<%= homework_common.language_name%>
</div>
<% end %>
<div class="homepagePostDeadline">
<%= l(:label_end_time)%><%= homework_common.end_time%>
</div>
</div>
<div class="homepagePostIntro upload_img break_word list_style" id="homework_description_<%= homework_common.id%>">
<%= homework_common.description.html_safe %>
</div>
<div>
<%= render :partial => 'student_work/work_attachments', :locals => {:attachments => homework_common.attachments} %>
<div class="cl"></div>
</div>
<% if is_teacher%>
<%# if false%>
<div class="homepagePostSetting">
<ul>
<li class="homepagePostSettingIcon">
<ul class="homepagePostSettiongText">
<li>
<%= link_to l(:button_edit),edit_homework_common_path(homework_common,:is_in_course => is_in_course), :class => "postOptionLink"%>
</li>
<li>
<%= 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") %>
</li>
<li>
<%= link_to("匿评设置", start_evaluation_set_homework_common_path(homework_common),:class => "postOptionLink", :remote => true) if homework_common.homework_detail_manual.comment_status == 1%>
</li>
<li>
<%= homework_anonymous_comment homework_common %>
</li>
</ul>
</li>
</ul>
</div>
<% end%>
</div>
<div class="cl"></div>
</div>
<% count=homework_common.journals_for_messages.count %>
<div class="homepagePostReply">
<div class="topBorder" style="display: <%= count>0 ? 'none': '' %>"></div>
<div class="homepagePostReplyBanner" style="display: <%= count>0 ? '': 'none' %>">
<div class="homepagePostReplyBannerCount">
回复(<%= count %>
</div>
<div class="homepagePostReplyBannerTime"></div>
<%if count>3 %>
<div class="homepagePostReplyBannerMore">
<a id="reply_btn_<%=homework_common.id%>" onclick="expand_reply('#reply_div_<%= homework_common.id %> li','#reply_btn_<%=homework_common.id%>')" data-count="<%= count %>" data-init="0" class=" replyGrey" href="javascript:void(0)" value="show_help" >
展开更多
</a>
</div>
<% end %>
</div>
<% replies_all_i = 0 %>
<% if count > 0 %>
<div class="" id="reply_div_<%= homework_common.id %>">
<ul>
<% homework_common.journals_for_messages.reorder("created_on desc").each do |comment| %>
<script type="text/javascript">
$(function(){
showNormalImage('reply_content_<%= comment.id %>');
});
</script>
<% replies_all_i = replies_all_i + 1 %>
<li class="homepagePostReplyContainer" nhname="reply_rec" style="display:<%= replies_all_i > 3 ? 'none' : '' %>">
<div class="homepagePostReplyPortrait">
<%= link_to image_tag(url_to_avatar(comment.user), :width => "33", :height => "33", :class =>"mt8"), user_path(comment.user_id), :alt => "用户头像" %>
</div>
<div class="homepagePostReplyDes">
<div class="homepagePostReplyPublisher">
<% 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) %>
</div>
<div class="homepagePostReplyContent break_word list_style upload_img" id="reply_content_<%= comment.id %>">
<%= comment.notes.html_safe %></div>
</div>
<div class="cl"></div>
</li>
<% end %>
</ul>
</div>
<% end %>
<div class="homepagePostReplyContainer borderBottomNone minHeight48">
<div class="homepagePostReplyPortrait mr15 imageFuzzy" id="reply_image_<%= homework_common.id%>"><%= link_to image_tag(url_to_avatar(User.current), :width => "33", :height => "33"), :alt => "用户头像" %></div>
<div class="homepagePostReplyInputContainer mb10">
<div nhname='new_message_<%= homework_common.id%>' style="display:none;">
<%= 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 %>
<textarea placeholder="有问题或有建议,请直接给我留言吧!" style="display: none" nhname='new_message_textarea_<%= homework_common.id%>' name="homework_message"></textarea>
<div nhname='toolbar_container_<%= homework_common.id%>' style="float:left;padding-top:3px; margin-left: 5px;"></div>
<a id="new_message_submit_btn_<%= homework_common.id%>" href="javascript:void(0)" class="blue_n_btn fr" style="display:none;margin-top:6px;">发送</a>
<div class="cl"></div>
<p nhname='contentmsg_<%= homework_common.id%>'></p>
<% end%>
</div>
<div class="cl"></div>
</div>
<div class="cl"></div>
</div>
</div>
</div><!----HomeWork end-->

View File

@ -1,83 +1,41 @@
<%= javascript_include_tag "/assets/kindeditor/kindeditor",'/assets/kindeditor/pasteimg',"init_activity_KindEditor" %>
<style type="text/css">
/*回复框*/
div.ke-toolbar{display:none;width:400px;border:none;background:none;padding:0px 0px;}
span.ke-toolbar-icon{line-height:26px;font-size:14px;padding-left:26px;}
span.ke-toolbar-icon-url{background-image:url( /images/public_icon.png )}
div.ke-toolbar .ke-outline{padding:0px 0px;line-height:26px;font-size:14px;}
span.ke-icon-emoticons{background-position:0px -671px;width:50px;height:26px;}
span.ke-icon-emoticons:hover{background-position:-79px -671px;width:50px;height:26px;}
div.ke-toolbar .ke-outline{border:none;}
.ke-inline-block{display: none;}
div.ke-container{float:left;}
</style>
<% homework_commons.each do |homework_common|%> <% homework_commons.each do |homework_common|%>
<% is_teacher = User.current.allowed_to?(:as_teacher,homework_common.course) %> <script type="text/javascript">
<div class="HomeWork mb10"> $(function() {
<div class="homepagePostBrief"> init_activity_KindEditor_data(<%= homework_common.id%>, null, "87%");
<div class="homepagePostPortrait"> showNormalImage('homework_description_<%= homework_common.id%>');
<%=link_to image_tag(url_to_avatar(homework_common.user),width:"50px", height: "50px"), user_activities_path(homework_common.user.id)%> });
</div>
<div class="homepagePostDes">
<div class="homepagePostTo mt-4">
<%= 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"%>
</div>
<span class="homepagePostTitle hidden m_w530 fl">
<%= link_to homework_common.name,student_work_index_path(:homework => homework_common.id),:class => "postGrey"%>
</span>
<% if homework_common.homework_detail_manual%> function expand_reply(container,btnid){
<% if homework_common.homework_detail_manual.comment_status == 1%> var target = $(container);
<span class="grey_btn_cir ml10">未开启匿评</span> var btn = $(btnid);
<% elsif homework_common.homework_detail_manual.comment_status == 2%> if(btn.data('init')=='0'){
<span class="green_btn_cir ml10">匿评中</span> btn.data('init',1);
<% elsif homework_common.homework_detail_manual.comment_status == 3%> btn.html('收起回复');
<span class="grey_btn_cir ml10">匿评已结束</span> target.show();
<% end%> }else{
<% end%> btn.data('init',0);
btn.html('展开更多');
<div class="homepagePostSubmitContainer"> target.hide();
<div class="homepagePostSubmit"> target.eq(0).show();
<%= user_for_homework_common homework_common,is_teacher %> target.eq(1).show();
</div> target.eq(2).show();
<% if homework_common.homework_type == 2 && is_teacher%> }
<div class="homepagePostSubmit"> }
<%= link_to "模拟答题", new_user_commit_homework_users_path(homework_id: homework_common.id, is_test: true), class: 'c_blue test-program-btn', title: '教师可以通过模拟答题设置作业的标准答案' %> </script>
</div> <%= render :partial => 'users/user_homework_detail', :locals => {:homework_common => homework_common,:is_in_course => is_in_course} %>
<% end %>
<% if homework_common.homework_type == 2%>
<div class="homepagePostDeadline mr15">
语言:
<%= homework_common.language_name%>
</div>
<% end %>
<div class="homepagePostDeadline">
<%= l(:label_end_time)%><%= homework_common.end_time%>
</div>
</div>
<div class="homepagePostIntro upload_img break_word list_style">
<%= homework_common.description.html_safe %>
</div>
<div>
<%= render :partial => 'student_work/work_attachments', :locals => {:attachments => homework_common.attachments} %>
<div class="cl"></div>
</div>
<% if is_teacher%>
<%# if false%>
<div class="homepagePostSetting">
<ul>
<li class="homepagePostSettingIcon">
<ul class="homepagePostSettiongText">
<li>
<%= link_to l(:button_edit),edit_homework_common_path(homework_common,:is_in_course => is_in_course), :class => "postOptionLink"%>
</li>
<li>
<%= 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") %>
</li>
<li>
<%= link_to("匿评设置", start_evaluation_set_homework_common_path(homework_common),:class => "postOptionLink", :remote => true) if homework_common.homework_detail_manual.comment_status == 1%>
</li>
<li>
<%= homework_anonymous_comment homework_common %>
</li>
</ul>
</li>
</ul>
</div>
<% end%>
</div>
<div class="cl"></div>
</div>
</div><!----HomeWork end-->
<% end%> <% end%>
<% if homework_commons.count == 10%> <% if homework_commons.count == 10%>
<% if is_in_course == 1%> <% if is_in_course == 1%>

View File

@ -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 %>

View File

@ -855,6 +855,7 @@ RedmineApp::Application.routes.draw do
match 'projects/:id/feedback', :to => 'projects#feedback', :via => :get, :as => 'project_feedback' match 'projects/:id/feedback', :to => 'projects#feedback', :via => :get, :as => 'project_feedback'
match 'project/:id/share', :to => 'projects#share', :as => 'share_show' #share 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_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' post 'join_in/join', :to => 'courses#join', :as => 'join'
delete 'join_in/join', :to => 'courses#unjoin' delete 'join_in/join', :to => 'courses#unjoin'