2015-05-19 17:12:43 +08:00
|
|
|
class HomeworkCommonController < ApplicationController
|
|
|
|
layout "base_courses"
|
2015-05-20 16:49:19 +08:00
|
|
|
before_filter :find_course, :only => [:index,:new,:create]
|
|
|
|
before_filter :find_homework, :only => [:edit]
|
2015-05-19 17:12:43 +08:00
|
|
|
|
|
|
|
def index
|
|
|
|
homeworks = @course.homework_commons
|
|
|
|
@is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course))
|
|
|
|
@is_student = User.current.logged? && (User.current.admin? || (User.current.member_of_course?(@course) && !@is_teacher))
|
|
|
|
@homeworks = paginateHelper homeworks,10
|
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def new
|
2015-05-20 15:05:35 +08:00
|
|
|
@homework = HomeworkCommon.new
|
|
|
|
@homework.safe_attributes = params[:homework_common]
|
|
|
|
@homework.late_penalty = 2
|
|
|
|
@homework.end_time = (Time.now + 3600 * 24).strftime('%Y-%m-%d')
|
|
|
|
@homework.publish_time = Time.now.strftime('%Y-%m-%d')
|
2015-05-20 16:49:19 +08:00
|
|
|
|
|
|
|
#匿评作业相关属性
|
2015-05-20 15:05:35 +08:00
|
|
|
@homework_detail_manual = HomeworkDetailManual.new
|
|
|
|
@homework_detail_manual.ta_proportion = 0.6
|
|
|
|
@homework_detail_manual.absence_penalty = 2
|
|
|
|
@homework_detail_manual.evaluation_num = 3
|
|
|
|
@homework_detail_manual.evaluation_start = Time.now.strftime('%Y-%m-%d')
|
|
|
|
@homework_detail_manual.evaluation_end = (Time.now + 3600 * 24).strftime('%Y-%m-%d')
|
|
|
|
@homework.homework_detail_manual = @homework_detail_manual
|
2015-05-19 17:12:43 +08:00
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def create
|
2015-05-20 16:49:19 +08:00
|
|
|
if params[:homework_common]
|
|
|
|
homework = HomeworkCommon.new
|
|
|
|
homework.name = params[:homework_common][:name]
|
|
|
|
homework.description = params[:homework_common][:description]
|
|
|
|
homework.end_time = params[:homework_common][:end_time]
|
|
|
|
homework.publish_time = params[:homework_common][:publish_time]
|
|
|
|
homework.homework_type = params[:homework_common][:homework_type]
|
|
|
|
homework.late_penalty = params[:late_penalty]
|
|
|
|
homework.user_id = User.current.id
|
|
|
|
homework.course_id = @course.id
|
|
|
|
|
|
|
|
#匿评作业相关属性
|
|
|
|
homework_detail_manual = HomeworkDetailManual.new
|
|
|
|
homework_detail_manual.ta_proportion = params[:ta_proportion] || 0.6
|
|
|
|
homework_detail_manual.comment_status = 1
|
|
|
|
homework_detail_manual.evaluation_start = params[:evaluation_start]
|
|
|
|
homework_detail_manual.evaluation_end = params[:evaluation_end]
|
|
|
|
homework_detail_manual.evaluation_num = params[:evaluation_num]
|
|
|
|
homework_detail_manual.absence_penalty = params[:absence_penalty]
|
|
|
|
homework.homework_detail_manual = homework_detail_manual
|
|
|
|
|
|
|
|
if homework.save
|
|
|
|
respond_to do |format|
|
|
|
|
format.html {
|
|
|
|
flash[:notice] = l(:notice_successful_create)
|
|
|
|
redirect_to homework_common_index_path(:course => @course.id)
|
|
|
|
}
|
|
|
|
end
|
|
|
|
return
|
|
|
|
end
|
|
|
|
end
|
2015-05-19 17:12:43 +08:00
|
|
|
|
2015-05-20 16:49:19 +08:00
|
|
|
respond_to do |format|
|
|
|
|
format.html {
|
|
|
|
flash[:notice] = l(:notice_failed_create)
|
|
|
|
redirect_to new_homework_common_path(:course => @course.id)
|
|
|
|
}
|
|
|
|
end
|
2015-05-19 17:12:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def edit
|
2015-05-20 16:49:19 +08:00
|
|
|
respond_to do |format|
|
|
|
|
format.html
|
|
|
|
end
|
2015-05-19 17:12:43 +08:00
|
|
|
end
|
|
|
|
|
|
|
|
def update
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def destroy
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
#开启匿评
|
|
|
|
def start_anonymous_comment
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
#关闭匿评
|
|
|
|
def stop_anonymous_comment
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
#提示
|
|
|
|
def alert_anonymous_comment
|
|
|
|
respond_to do |format|
|
|
|
|
format.js
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
#获取课程
|
|
|
|
def find_course
|
|
|
|
@course = Course.find params[:course]
|
|
|
|
rescue
|
|
|
|
render_404
|
|
|
|
end
|
|
|
|
#获取作业
|
|
|
|
def find_homework
|
|
|
|
@homework = HomeworkCommon.find params[:id]
|
|
|
|
@course = @homework.course
|
|
|
|
rescue
|
|
|
|
render_404
|
|
|
|
end
|
|
|
|
end
|