Merge branch 'dev_hjq' of http://repository.trustie.net/xianbo/trustie2 into dev_hjq
This commit is contained in:
commit
1cf774d6a5
|
@ -0,0 +1,3 @@
|
|||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
|
|
@ -0,0 +1,3 @@
|
|||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
|
|
@ -0,0 +1,3 @@
|
|||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
|
|
@ -0,0 +1,3 @@
|
|||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
|
|
@ -0,0 +1,3 @@
|
|||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
|
|
@ -0,0 +1,3 @@
|
|||
# Place all the behaviors and hooks related to the matching controller here.
|
||||
# All this logic will automatically be available in application.js.
|
||||
# You can use CoffeeScript in this file: http://jashkenas.github.com/coffee-script/
|
|
@ -0,0 +1,3 @@
|
|||
// Place all the styles related to the org_courses controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
|
@ -0,0 +1,3 @@
|
|||
// Place all the styles related to the org_document_comment controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
|
@ -0,0 +1,3 @@
|
|||
// Place all the styles related to the OrgMember controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
|
@ -0,0 +1,3 @@
|
|||
// Place all the styles related to the org_projects controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
|
@ -0,0 +1,3 @@
|
|||
// Place all the styles related to the org_subfields controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
|
@ -0,0 +1,3 @@
|
|||
// Place all the styles related to the organizations controller here.
|
||||
// They will automatically be included in application.css.
|
||||
// You can use Sass (SCSS) here: http://sass-lang.com/
|
|
@ -29,6 +29,30 @@ class CoursesController < ApplicationController
|
|||
before_filter :require_login, :only => [:join, :unjoin]
|
||||
#before_filter :allow_join, :only => [:join]
|
||||
|
||||
#查找组织
|
||||
def search_public_orgs_not_in_course
|
||||
condition = '%%'
|
||||
if !params[:name].nil?
|
||||
condition = "%#{params[:name].strip}%".gsub(" ","")
|
||||
end
|
||||
course_org_ids = OrgCourse.find_by_sql("select distinct organization_id from org_courses where course_id = #{params[:id]}").map(&:organization_id)
|
||||
if course_org_ids.empty?
|
||||
@orgs_not_in_course = Organization.where("(is_public or creator_id =?) and name like ?",User.current.id, condition).page((params[:page].to_i || 1)).per(10)
|
||||
@org_count = Organization.where("is_public = 1 or creator_id =?", User.current.id).where("name like ?", condition).count
|
||||
else
|
||||
course_org_ids = "(" + course_org_ids.join(',') + ")"
|
||||
@orgs_not_in_course = Organization.where("id not in #{course_org_ids} and (is_public = 1 or creator_id =?) and name like ?", User.current.id, condition).page((params[:page].to_i || 1)).per(10)
|
||||
@org_count = Organization.where("id not in #{course_org_ids} and (is_public = 1 or creator_id =?)", User.current.id).where("name like ?", condition).count
|
||||
end
|
||||
# @course_count = Project.course_entities.visible.like(params[:name]).page(params[:page]).count
|
||||
@orgs_page = Paginator.new @org_count, 10,params[:page]
|
||||
@hint_flag = params[:hint_flag]
|
||||
#render :json => {:orgs => @orgs_not_in_course, :count => @org_count}.to_json
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def join
|
||||
if User.current.logged?
|
||||
cs = CoursesService.new
|
||||
|
|
|
@ -0,0 +1,658 @@
|
|||
class ExerciseController < ApplicationController
|
||||
layout "base_courses"
|
||||
|
||||
before_filter :find_exercise_and_course, :only => [:create_exercise_question, :edit, :update, :show, :destroy, :commit_exercise, :commit_answer,:publish_exercise,:republish_exercise,:show_student_result]
|
||||
before_filter :find_course, :only => [:index,:new,:create,:student_exercise_list]
|
||||
include ExerciseHelper
|
||||
|
||||
def index
|
||||
if @course.is_public == 0 && !User.current.member_of_course?(@course)
|
||||
render_403
|
||||
return
|
||||
end
|
||||
remove_invalid_exercise(@course)
|
||||
@is_teacher = User.current.allowed_to?(:as_teacher,@course)
|
||||
if @is_teacher
|
||||
exercises = @course.exercises.order("created_at asc")
|
||||
else
|
||||
exercises = @course.exercises.where(:exercise_status => 2).order("created_at asc")
|
||||
end
|
||||
@exercises = paginateHelper exercises,20 #分页
|
||||
respond_to do |format|
|
||||
format.html
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
unless User.current.member_of_course?(@course)
|
||||
render_403
|
||||
return
|
||||
end
|
||||
@exercise = Exercise.find params[:id]
|
||||
@is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin?
|
||||
if @exercise.exercise_status != 2 && (!User.current.allowed_to?(:as_teacher,@course) || User.current.admin?)
|
||||
render_403
|
||||
return
|
||||
end
|
||||
exercise_end = @exercise.end_time > Time.now
|
||||
if @exercise.time == -1
|
||||
@can_edit_excercise = exercise_end
|
||||
else
|
||||
@can_edit_excercise = (!has_commit_exercise?(@exercise.id,User.current.id)&& exercise_end) || User.current.admin?
|
||||
end
|
||||
@exercise_user = ExerciseUser.where("user_id=? and exercise_id=?", User.current.id, @exercise.id).first
|
||||
# 学生点击的时候即创建关联,自动保存
|
||||
#eu = ExerciseUser.create(:user_id => User.current, :exercise_id => @exercise.id, :start_at => Time.now, :status => false)
|
||||
|
||||
# 已提交问卷的用户不能再访问该界面
|
||||
=begin
|
||||
if has_commit_exercise?(@exercise.id, User.current.id) && (!User.current.admin?)
|
||||
respond_to do |format|
|
||||
format.html {render :layout => 'base_courses'}
|
||||
end
|
||||
else
|
||||
=end
|
||||
if !@is_teacher && !has_click_exercise?(@exercise.id, User.current.id)
|
||||
eu = ExerciseUser.create(:user_id => User.current.id, :exercise_id => @exercise.id, :start_at => Time.now, :status => false)
|
||||
@exercise_user = ExerciseUser.where("user_id=? and exercise_id=?", User.current.id, @exercise.id).first
|
||||
end
|
||||
# @percent = get_percent(@exercise,User.current)
|
||||
exercise_questions = @exercise.exercise_questions
|
||||
@exercise_questions = paginateHelper exercise_questions,5 #分页
|
||||
score = calculate_student_score(@exercise, User.current)
|
||||
eu = get_exercise_user(@exercise.id, User.current.id)
|
||||
eu.update_attributes(:score => score)
|
||||
respond_to do |format|
|
||||
format.html {render :layout => 'base_courses'}
|
||||
end
|
||||
#end
|
||||
end
|
||||
|
||||
def new
|
||||
option = {
|
||||
:exercise_name => "",
|
||||
:course_id => @course.id,
|
||||
:exercise_status => 1,
|
||||
:user_id => User.current.id,
|
||||
:time => "",
|
||||
:end_time => "",
|
||||
:publish_time => "",
|
||||
:exercise_description => "",
|
||||
:show_result => 1
|
||||
}
|
||||
@exercise = Exercise.create option
|
||||
if @exercise
|
||||
redirect_to edit_exercise_url @exercise.id
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
if params[:exercise]
|
||||
exercise = Exercise.find(params[:exercise_id]) if params[:exercise_id]
|
||||
exercise ||= Exercise.new
|
||||
exercise.exercise_name = params[:exercise][:exercise_name]
|
||||
exercise.exercise_description = params[:exercise][:exercise_description]
|
||||
exercise.end_time = Time.at(params[:exercise][:end_time].to_time.to_i + 16*60*60 -1)
|
||||
exercise.publish_time = params[:exercise][:publish_time]
|
||||
exercise.user_id = User.current.id
|
||||
exercise.time = params[:exercise][:time]
|
||||
exercise.course_id = params[:course_id]
|
||||
exercise.exercise_status = 1
|
||||
if exercise.save
|
||||
@exercise = exercise
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
respond_to do |format|
|
||||
format.html{render :layout => 'base_courses'}
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
@exercise.exercise_name = params[:exercise][:exercise_name]
|
||||
@exercise.exercise_description = params[:exercise][:exercise_description]
|
||||
@exercise.time = params[:exercise][:time].blank? ? -1 : params[:exercise][:time]
|
||||
@exercise.end_time = Time.at(params[:exercise][:end_time].to_time.to_i + 16*60*60 -1)
|
||||
@exercise.publish_time = params[:exercise][:publish_time]
|
||||
@exercise.show_result = params[:exercise][:show_result].blank? ? 1 : params[:exercise][:show_result]
|
||||
if @exercise.save
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
else
|
||||
render_404
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin?
|
||||
if @exercise && @exercise.destroy
|
||||
if @is_teacher
|
||||
exercises = Exercise.where("course_id =?", @course.id)
|
||||
else
|
||||
exercises = Exercise.where("course_id =? and exercise_status =?", @course.id, 2)
|
||||
end
|
||||
@exercises = paginateHelper exercises,20 #分页
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# 统计结果
|
||||
def statistics_result
|
||||
@exercise = Exercise.find(params[:id])
|
||||
exercise_questions = @exercise.exercise_questions
|
||||
@exercise_questions = paginateHelper exercise_questions, 5
|
||||
respond_to do |format|
|
||||
format.html{render :layout => 'base_courses'}
|
||||
end
|
||||
end
|
||||
|
||||
# 添加题目
|
||||
# question_type 1:单选 2:多选 3:填空题
|
||||
def create_exercise_question
|
||||
question_title = params[:question_title].nil? || params[:question_title].empty? ? l(:label_enter_single_title) : params[:question_title]
|
||||
option = {
|
||||
:question_title => question_title,
|
||||
:question_type => params[:question_type] || 1,
|
||||
:question_number => params[:question_type] == "1"? @exercise.exercise_questions.where("question_type = 1").count + 1 :
|
||||
(params[:question_type] == "2" ? (@exercise.exercise_questions.where("question_type = 2").count + 1) :
|
||||
@exercise.exercise_questions.where("question_type = 3").count + 1),
|
||||
:question_score => params[:question_score]
|
||||
}
|
||||
@exercise_questions = @exercise.exercise_questions.new option
|
||||
# params[:question_answer] 题目选项
|
||||
if params[:question_answer]
|
||||
for i in 1..params[:question_answer].count
|
||||
answer = (params[:question_answer].values[i-1].nil? || params[:question_answer].values[i-1].empty?) ? l(:label_new_answer) : params[:question_answer].values[i-1]
|
||||
question_option = {
|
||||
:choice_position => i,
|
||||
:choice_text => answer
|
||||
}
|
||||
@exercise_questions.exercise_choices.new question_option
|
||||
end
|
||||
end
|
||||
# 如果是插入的话,那么从插入的这个id以后的question_num都将要+1
|
||||
if params[:quest_id]
|
||||
@is_insert = true
|
||||
if @exercise_questions.question_type == 1
|
||||
ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 1).update_all(" question_number = question_number + 1")
|
||||
#@exercise.exercise_questions.where("question_number > #{params[:quest_num].to_i} and question_type == 1").update_all(" question_number = question_number + 1")
|
||||
elsif @exercise_questions.question_type == 2
|
||||
ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 2).update_all(" question_number = question_number + 1")
|
||||
else
|
||||
ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 3).update_all(" question_number = question_number + 1")
|
||||
end
|
||||
# @exercise_question_num = params[:quest_num].to_i
|
||||
@exercise_questions.question_number = params[:quest_num].to_i + 1
|
||||
end
|
||||
if @exercise_questions.save
|
||||
# params[:exercise_choice] 标准答案参数
|
||||
# 问答题标准答案有三个,单独处理
|
||||
if @exercise_questions.question_type == 3
|
||||
for i in 1..params[:exercise_choice].count
|
||||
standart_answer = ExerciseStandardAnswer.new
|
||||
standart_answer.exercise_question_id = @exercise_questions.id
|
||||
standart_answer.answer_text = params[:exercise_choice].values[i-1]
|
||||
standart_answer.save
|
||||
end
|
||||
else
|
||||
standart_answer = ExerciseStandardAnswer.new
|
||||
standart_answer.exercise_question_id = @exercise_questions.id
|
||||
if @exercise_questions.question_type == 1
|
||||
standart_answer.exercise_choice_id = sigle_selection_standard_answer(params[:exercise_choice])
|
||||
else
|
||||
standart_answer.exercise_choice_id = multiselect_standard_answer(params[:exercise_choice])
|
||||
end
|
||||
standart_answer.save
|
||||
end
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
# 修改题目
|
||||
# params[:exercise_question] The id of exercise_question
|
||||
# params[:question_answer] eg:A、B、C选项
|
||||
def update_exercise_question
|
||||
@exercise_question = ExerciseQuestion.find params[:exercise_question]
|
||||
@exercise_question.question_title = params[:question_title].nil? || params[:question_title].empty? ? l(:label_enter_single_title) : params[:question_title]
|
||||
@exercise_question.question_score = params[:question_score]
|
||||
# 处理选项:如果选了某个选项,那么则要删除之前的选项
|
||||
if params[:question_answer]
|
||||
@exercise_question.exercise_choices.each do |answer|
|
||||
answer.destroy unless params[:question_answer].keys.include? answer.id.to_s
|
||||
end
|
||||
for i in 1..params[:question_answer].count
|
||||
question = @exercise_question.exercise_choices.find_by_id params[:question_answer].keys[i-1]
|
||||
answer = (params[:question_answer].values[i-1].nil? || params[:question_answer].values[i-1].empty?) ? l(:label_new_answer) : params[:question_answer].values[i-1]
|
||||
if question
|
||||
question.choice_position = i
|
||||
question.choice_text = answer
|
||||
question.save
|
||||
else
|
||||
question_option = {
|
||||
:choice_position => i,
|
||||
:choice_text => answer
|
||||
}
|
||||
@exercise_question.exercise_choices.new question_option
|
||||
end
|
||||
end
|
||||
end
|
||||
# 更新标准答案
|
||||
if params[:exercise_choice]
|
||||
if @exercise_question.question_type == 3
|
||||
# 删除不合理的选项
|
||||
@exercise_question.exercise_standard_answers.each do |answer|
|
||||
answer.destroy unless params[:exercise_choice].keys.include? answer.id.to_s
|
||||
end
|
||||
for i in 1..params[:exercise_choice].count
|
||||
# 找到对应的标准答案
|
||||
question_standart = @exercise_question.exercise_standard_answers.find_by_id params[:exercise_choice].keys[i-1]
|
||||
# 标准答案值
|
||||
answer_standart = (params[:exercise_choice].values[i-1].nil? || params[:exercise_choice].values[i-1].empty?) ? l(:label_new_answer) : params[:exercise_choice].values[i-1]
|
||||
if question_standart
|
||||
question_standart.answer_text = answer_standart
|
||||
question_standart.save
|
||||
else
|
||||
standart_answer_option = {
|
||||
:answer_text => answer_standart
|
||||
}
|
||||
@exercise_question.exercise_standard_answers.new standart_answer_option
|
||||
end
|
||||
end
|
||||
else
|
||||
answer_standart = @exercise_question.exercise_standard_answers.first
|
||||
answer_standart.exercise_choice_id = @exercise_question.question_type == 1 ? sigle_selection_standard_answer(params[:exercise_choice]) : multiselect_standard_answer(params[:exercise_choice])
|
||||
answer_standart.save
|
||||
end
|
||||
@exercise_question.save
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# 删除题目
|
||||
def delete_exercise_question
|
||||
@exercise_question = ExerciseQuestion.find params[:exercise_question]
|
||||
@exercise = @exercise_question.exercise
|
||||
|
||||
if @exercise_question.question_type == 1
|
||||
ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 1).update_all(" question_number = question_number - 1")
|
||||
#@exercise.exercise_questions.where("question_number > #{params[:quest_num].to_i} and question_type == 1").update_all(" question_number = question_number + 1")
|
||||
elsif @exercise_question.question_type == 2
|
||||
ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 2).update_all(" question_number = question_number - 1")
|
||||
else
|
||||
ExerciseQuestion.where("question_number>? and question_type=?",params[:quest_num].to_i, 3).update_all(" question_number = question_number - 1")
|
||||
end
|
||||
# @exercise_question_num = params[:quest_num].to_i
|
||||
# @exercise_questions.question_number = params[:quest_num].to_i - 1
|
||||
#
|
||||
# exercise_questions = @exercise.exercise_questions.where("question_number > #{@exercise_question.question_number}")
|
||||
# exercise_questions.each do |question|
|
||||
# question.question_number -= 1
|
||||
# question.save
|
||||
# end
|
||||
if @exercise_question && @exercise_question.destroy
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# 发布试卷
|
||||
def publish_exercise
|
||||
@is_teacher = User.current.allowed_to?(:as_teacher,@course)
|
||||
@index = params[:index]
|
||||
@exercise.exercise_status = 2
|
||||
@exercise.publish_time = Time.now
|
||||
if @exercise.save
|
||||
#redirect_to exercise_index_url(:course_id=> @course.id)
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# 重新发布试卷
|
||||
# 重新发布的时候会删除所有的答题
|
||||
def republish_exercise
|
||||
@is_teacher = User.current.allowed_to?(:as_teacher,@course)
|
||||
@index = params[:index]
|
||||
@exercise.exercise_questions.each do |exercise_question|
|
||||
exercise_question.exercise_answers.destroy_all
|
||||
end
|
||||
@exercise.exercise_users.destroy_all
|
||||
@exercise.exercise_status = 1
|
||||
@exercise.publish_time = nil
|
||||
@exercise.save
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def student_exercise_list
|
||||
@is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin?
|
||||
@exercise = Exercise.find params[:id]
|
||||
@all_exercises = @course.exercises.where("exercise_status > 1").order("created_at desc")
|
||||
@exercise_count = @exercise.exercise_users.where('score is not NULL').count
|
||||
if @is_teacher || (!@exercise.exercise_users.where(:user_id => User.current.id).empty? && @exercise.end_time <= Time.now)
|
||||
@exercise_users_list = @exercise.exercise_users.where('score is not NULL')
|
||||
@show_all = true;
|
||||
elsif !@exercise.exercise_users.where(:user_id => User.current.id).empty? && @exercise.end_time > Time.now
|
||||
@exercise_users_list = @exercise.exercise_users.where("user_id = ? and score is not NULL",User.current.id)
|
||||
else
|
||||
@exercise_users_list = []
|
||||
end
|
||||
respond_to do |format|
|
||||
format.html
|
||||
end
|
||||
end
|
||||
|
||||
# 学生提交答卷,选中答案的过程中提交
|
||||
def commit_answer
|
||||
eq = ExerciseQuestion.find(params[:exercise_question_id])
|
||||
# 已提交过的且是限时的则不允许答题
|
||||
if (has_commit_exercise?(@exercise.id,User.current.id) && (!User.current.admin?) && @exercise.time != -1) || @exercise.end_time < Time.now
|
||||
render :json => {:text => "failure"}
|
||||
return
|
||||
end
|
||||
if eq.question_type == 1
|
||||
# 单选题
|
||||
ea = ExerciseAnswer.find_by_exercise_question_id_and_user_id(params[:exercise_question_id],User.current.id)
|
||||
if ea.nil?
|
||||
# 尚未答该题,添加答案
|
||||
ea = ExerciseAnswer.new
|
||||
ea.user_id = User.current.id
|
||||
ea.exercise_question_id = params[:exercise_question_id]
|
||||
end
|
||||
#修改该题对应答案
|
||||
ea.exercise_choice_id = params[:exercise_choice_id]
|
||||
if ea.save
|
||||
# 保存成功返回成功信息及当前以答题百分比
|
||||
uncomplete_question = get_uncomplete_question(@exercise, User.current)
|
||||
if uncomplete_question.count < 1
|
||||
complete = 1;
|
||||
else
|
||||
complete = 0;
|
||||
end
|
||||
@percent = get_percent(@exercise,User.current)
|
||||
render :json => {:text => "ok" ,:complete => complete,:percent => format("%.2f" ,@percent)}
|
||||
else
|
||||
#返回失败信息
|
||||
render :json => {:text => "failure"}
|
||||
end
|
||||
elsif eq.question_type == 2
|
||||
#多选题
|
||||
ea = ExerciseAnswer.find_by_exercise_choice_id_and_user_id(params[:exercise_choice_id],User.current.id)
|
||||
if ea.nil?
|
||||
#尚未答该题,添加答案
|
||||
ea = ExerciseAnswer.new
|
||||
ea.user_id = User.current.id
|
||||
ea.exercise_question_id = params[:exercise_question_id]
|
||||
ea.exercise_choice_id = params[:exercise_choice_id]
|
||||
if ea.save
|
||||
uncomplete_question = get_uncomplete_question(@exercise, User.current)
|
||||
if uncomplete_question.count < 1
|
||||
complete = 1;
|
||||
else
|
||||
complete = 0;
|
||||
end
|
||||
@percent = get_percent(@exercise,User.current)
|
||||
render :json => {:text => "ok",:complete => complete,:percent => format("%.2f" ,@percent)}
|
||||
else
|
||||
render :json => {:text => "failure"}
|
||||
end
|
||||
else
|
||||
#pv不为空,则当前选项之前已被选择,再次点击则是不再选择该项,故删除该答案
|
||||
if ea.delete
|
||||
@percent = get_percent(@exercise, User.current)
|
||||
render :json => {:text => "false" ,:percent => format("%.2f" , @percent)}
|
||||
else
|
||||
render :json => {:text => "failure"}
|
||||
end
|
||||
end
|
||||
elsif eq.question_type == 3
|
||||
#单行文本,多行文本题
|
||||
ea = ExerciseAnswer.find_by_exercise_question_id_and_user_id(params[:exercise_question_id], User.current.id)
|
||||
if ea.nil?
|
||||
# ea为空之前尚未答题,添加答案
|
||||
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)}
|
||||
else
|
||||
#添加答案
|
||||
ea = ExerciseAnswer.new
|
||||
ea.user_id = User.current.id
|
||||
ea.exercise_question_id = params[:exercise_question_id]
|
||||
ea.answer_text = params[:answer_text]
|
||||
if ea.save
|
||||
uncomplete_question = get_uncomplete_question(@exercise, User.current)
|
||||
if uncomplete_question.count < 1
|
||||
complete = 1;
|
||||
else
|
||||
complete = 0;
|
||||
end
|
||||
@percent = get_percent(@exercise,User.current)
|
||||
render :json => {:text => ea.answer_text,:complete => complete,:percent => format("%.2f",@percent)}
|
||||
else
|
||||
render :json => {:text => "failure"}
|
||||
end
|
||||
end
|
||||
else
|
||||
# ea不为空说明用户之前已作答
|
||||
if params[:answer_text].nil? || params[:answer_text].blank?
|
||||
# 用户提交空答案,视为删除答案
|
||||
if ea.delete
|
||||
@percent = get_percent(@exercise,User.current)
|
||||
render :json => {:text => ea.answer_text,:percent => format("%.2f", @percent)}
|
||||
else
|
||||
render :json => {:text => "failure"}
|
||||
end
|
||||
else
|
||||
#用户修改答案
|
||||
ea.answer_text = params[:answer_text]
|
||||
if ea.save
|
||||
@percent = get_percent(@exercise,User.current)
|
||||
render :json => {:text => pv.vote_text,:percent => format("%.2f", @percent)}
|
||||
else
|
||||
render :json => {:text => "failure"}
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
else
|
||||
render :json => {:text => "failure"}
|
||||
end
|
||||
end
|
||||
|
||||
# 提交问卷
|
||||
def commit_exercise
|
||||
# 老师不需要提交
|
||||
if User.current.allowed_to?(:as_teacher,@course)
|
||||
if @exercise.publish_time.nil?
|
||||
@exercise.update_attributes(:show_result => params[:show_result])
|
||||
@exercise.update_attributes(:exercise_status => 2)
|
||||
@exercise.update_attributes(:publish_time => Time.now)
|
||||
redirect_to exercise_url(@exercise)
|
||||
return
|
||||
elsif @exercise.publish_time > Time.now
|
||||
@exercise.update_attributes(:show_result => params[:show_result])
|
||||
redirect_to exercise_url(@exercise)
|
||||
return
|
||||
end
|
||||
@exercise.update_attributes(:show_result => params[:show_result])
|
||||
redirect_to exercise_url(@exercise)
|
||||
# REDO: 提示提交成功
|
||||
else
|
||||
# 更新提交状态
|
||||
cur_exercise_user = ExerciseUser.where("user_id =? and exercise_id=?", User.current, @exercise.id).first
|
||||
cur_exercise_user.update_attributes(:status => 1)
|
||||
# 答题过程中需要统计完成量
|
||||
@uncomplete_question = get_uncomplete_question(@exercise, User.current)
|
||||
# 获取改学生的考试得分
|
||||
@score = calculate_student_score(@exercise, User.current)
|
||||
# @score = 100
|
||||
if @uncomplete_question.count < 1
|
||||
# 查看是否有已提交记录
|
||||
eu = get_exercise_user(@exercise.id, User.current.id)
|
||||
eu.user_id = User.current.id
|
||||
eu.exercise_id = @exercise.id
|
||||
eu.score = @score
|
||||
if eu.save
|
||||
#redirect_to poll_index_path(:polls_group_id => @course.id,:polls_type => 'Course')
|
||||
@status = 0 #提交成功
|
||||
else
|
||||
@status = 2 #未知错误
|
||||
end
|
||||
else
|
||||
@status = 1 #有未做得必答题
|
||||
end
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
#查看学生的答卷情况
|
||||
def show_student_result
|
||||
@user = User.find params[:user_id]
|
||||
@can_edit_excercise = false
|
||||
@exercise_user = ExerciseUser.where("user_id =? and exercise_id=?", @user.id, @exercise.id).first
|
||||
@exercise_questions = @exercise.exercise_questions
|
||||
score = calculate_student_score(@exercise, @user)
|
||||
eu = get_exercise_user(@exercise.id, @user.id)
|
||||
eu.update_attributes(:score => score)
|
||||
respond_to do |format|
|
||||
format.html {render :layout => 'base_courses'}
|
||||
end
|
||||
end
|
||||
|
||||
# 计算学生得分
|
||||
def calculate_student_score(exercise, user)
|
||||
score = 0
|
||||
score1 = 0
|
||||
score2 = 0
|
||||
score3 = 0
|
||||
exercise_qustions = exercise.exercise_questions
|
||||
exercise_qustions.each do |question|
|
||||
answer = get_user_answer(question, user)
|
||||
standard_answer = get_user_standard_answer(question, user)
|
||||
unless answer.empty?
|
||||
# 问答题有多个答案
|
||||
if question.question_type == 3
|
||||
if standard_answer.include?(answer.first.answer_text)
|
||||
score1 = score1+ question.question_score unless question.question_score.nil?
|
||||
end
|
||||
elsif question.question_type == 1
|
||||
if answer.first.exercise_choice.choice_position == standard_answer.exercise_choice_id
|
||||
score2 = score2 + question.question_score unless question.question_score.nil?
|
||||
end
|
||||
else
|
||||
arr = get_mulscore(question, user)
|
||||
if arr.to_i == standard_answer.exercise_choice_id
|
||||
score3 = score3 + question.question_score unless question.question_score.nil?
|
||||
end
|
||||
# ecs = ExerciseAnswer.where("user_id =? and exercise_question_id =?", user.id, question.id)
|
||||
# arr = []
|
||||
# ecs.each do |ec|
|
||||
# arr << ec.exercise_choice.choice_position
|
||||
# end
|
||||
# arr.sort
|
||||
# arr = arr.join("")
|
||||
# if arr.to_i == standard_answer.exercise_choice_id
|
||||
# score3 = score + question.question_score unless question.question_score.nil?
|
||||
# end
|
||||
end
|
||||
end
|
||||
end
|
||||
score = score1 + score2 + score3
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# ExerciseUser记录用户是否已提交问卷有对应的记录则已提交,没有则新建一个
|
||||
def get_exercise_user exercise_id,user_id
|
||||
eu = ExerciseUser.find_by_exercise_id_and_user_id(exercise_id,user_id)
|
||||
if eu.nil?
|
||||
eu = ExerciseUser.new
|
||||
end
|
||||
eu
|
||||
end
|
||||
|
||||
# 获取当前学生回答问题的答案
|
||||
def get_user_answer(question,user)
|
||||
# user_answer = ExerciseAnswer.where("user_id=? and exercise_question_id=?", user.id, question.id).first
|
||||
user_answer = question.exercise_answers.where("#{ExerciseAnswer.table_name}.user_id = #{user.id}")
|
||||
user_answer
|
||||
end
|
||||
|
||||
# 获取问题的标准答案
|
||||
def get_user_standard_answer(question,user)
|
||||
if question.question_type == 3
|
||||
standard_answer =[]
|
||||
question.exercise_standard_answers.each do |answer|
|
||||
standard_answer << answer.answer_text
|
||||
end
|
||||
else
|
||||
standard_answer = question.exercise_standard_answers.first
|
||||
end
|
||||
standard_answer
|
||||
end
|
||||
# 是否完成了答题
|
||||
def get_complete_question(exercise,user)
|
||||
questions = exercise.exercise_questions
|
||||
complete_question = []
|
||||
questions.each do |question|
|
||||
answers = get_user_answer(question,user)
|
||||
if !(answers.nil? || answers.count < 1)
|
||||
complete_question << question
|
||||
end
|
||||
end
|
||||
complete_question
|
||||
end
|
||||
|
||||
# 获取答题百分比
|
||||
def get_percent exercise,user
|
||||
complete_count = get_complete_question(exercise,user).count
|
||||
if exercise.exercise_questions.count == 0
|
||||
return 0
|
||||
else
|
||||
return (complete_count.to_f / exercise.exercise_questions.count.to_f)*100
|
||||
end
|
||||
end
|
||||
|
||||
def remove_invalid_exercise(course)
|
||||
exercises = course.exercises.where("exercise_name=?","")
|
||||
unless exercises.empty?
|
||||
exercises.each do |exercise|
|
||||
if exercise.exercise_questions.empty?
|
||||
exercise.destroy
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def find_exercise_and_course
|
||||
@exercise = Exercise.find params[:id]
|
||||
@course = Course.find @exercise.course_id
|
||||
rescue Exception => e
|
||||
render_404
|
||||
end
|
||||
|
||||
def find_course
|
||||
@course = Course.find params[:course_id]
|
||||
rescue Exception => e
|
||||
render_404
|
||||
end
|
||||
end
|
|
@ -24,7 +24,7 @@ class FilesController < ApplicationController
|
|||
before_filter :auth_login1, :only => [:index]
|
||||
before_filter :logged_user_by_apptoken,:only => [:index]
|
||||
before_filter :find_project_by_project_id#, :except => [:getattachtype]
|
||||
before_filter :authorize, :except => [:getattachtype,:quote_resource_show,:search,:searchone4reload,:search_project,:quote_resource_show_project,:search_tag_attachment]
|
||||
before_filter :authorize, :except => [:create,:getattachtype,:quote_resource_show,:search,:searchone4reload,:search_project,:quote_resource_show_project,:search_tag_attachment]
|
||||
|
||||
helper :sort
|
||||
include SortHelper
|
||||
|
@ -374,30 +374,32 @@ class FilesController < ApplicationController
|
|||
if !attachments.empty? && !attachments[:files].blank? && Setting.notified_events.include?('file_added')
|
||||
Mailer.run.attachments_added(attachments[:files])
|
||||
end
|
||||
|
||||
if params[:course_attachment_type] && params[:course_attachment_type] != "5"
|
||||
case params[:course_attachment_type]
|
||||
when "1"
|
||||
tag_name = l(:label_courseware)
|
||||
when "2"
|
||||
tag_name = l(:label_software)
|
||||
when "3"
|
||||
tag_name = l(:label_media)
|
||||
when "4"
|
||||
tag_name = l(:label_code)
|
||||
when "6"
|
||||
tag_name = "论文"
|
||||
else
|
||||
tag_name = ""
|
||||
# 更新课程英雄榜得分
|
||||
update_contributor_score(@course, attachments[:files].first)
|
||||
# end
|
||||
if params[:course_attachment_type] && params[:course_attachment_type].is_a?(Array)
|
||||
params[:course_attachment_type].each do |type|
|
||||
tag_name = get_tag_name_by_type_number type
|
||||
if !attachments.empty? && attachments[:files] && tag_name != ""
|
||||
attachments[:files].each do |attachment|
|
||||
attachment.tag_list.add(tag_name)
|
||||
attachment.save
|
||||
end
|
||||
end
|
||||
end
|
||||
if !attachments.empty? && attachments[:files] && tag_name != ""
|
||||
attachments[:files].each do |attachment|
|
||||
attachment.tag_list.add(tag_name)
|
||||
attachment.save
|
||||
else
|
||||
if params[:course_attachment_type] && params[:course_attachment_type] != "5"
|
||||
tag_name = get_tag_name_by_type_number params[:course_attachment_type]
|
||||
if !attachments.empty? && attachments[:files] && tag_name != ""
|
||||
attachments[:files].each do |attachment|
|
||||
attachment.tag_list.add(tag_name)
|
||||
attachment.save
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
# TODO: 临时用 nyan
|
||||
sort_init 'created_on', 'desc'
|
||||
sort_update 'created_on' => "#{Attachment.table_name}.created_on",
|
||||
|
@ -424,6 +426,37 @@ class FilesController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def update_contributor_score(course, file )
|
||||
unless file.author.allowed_to?(:as_teacher, course)
|
||||
course_contributor_score = CourseContributorScore.where("course_id =? and user_id =?", course.id, file.author.id).first
|
||||
if course_contributor_score.nil?
|
||||
CourseContributorScore.create(:course_id => course.id, :user_id => file.author.id, :message_num => 0, :message_reply_num => 0,
|
||||
:news_reply_num => 0, :resource_num => 5, :journal_num => 0, :journal_reply_num => 0, :total_score => 5)
|
||||
else
|
||||
score = course_contributor_score.resource_num + 5
|
||||
total_score = course_contributor_score.total_score + 5
|
||||
course_contributor_score.update_attributes(:resource_num => score, :total_score => total_score)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def get_tag_name_by_type_number type
|
||||
case type
|
||||
when "1"
|
||||
tag_name = l(:label_courseware)
|
||||
when "2"
|
||||
tag_name = l(:label_software)
|
||||
when "3"
|
||||
tag_name = l(:label_media)
|
||||
when "4"
|
||||
tag_name = l(:label_code)
|
||||
when "6"
|
||||
tag_name = "论文"
|
||||
else
|
||||
tag_name = ""
|
||||
end
|
||||
end
|
||||
|
||||
def tag_saveEx
|
||||
@tags = params[:tag_name][:name]
|
||||
@obj_id = params[:object_id]
|
||||
|
|
|
@ -20,11 +20,11 @@ class IssuesController < ApplicationController
|
|||
default_search_scope :issues
|
||||
|
||||
before_filter :authorize1, :only => [:show]
|
||||
before_filter :find_issue, :only => [:show, :edit, :update,:add_journal]
|
||||
before_filter :find_issue, :only => [:show, :edit, :update,:add_journal, :add_journal_in_org]
|
||||
before_filter :find_issues, :only => [:bulk_edit, :bulk_update, :destroy]
|
||||
before_filter :find_project, :only => [:new, :create, :update_form]
|
||||
#before_filter :authorize, :except => [:index, :show]
|
||||
before_filter :authorize, :except => [:index,:add_journal]
|
||||
before_filter :authorize, :except => [:index,:add_journal, :add_journal_in_org]
|
||||
|
||||
before_filter :find_optional_project, :only => [:index]
|
||||
before_filter :check_for_default_issue_status, :only => [:new, :create]
|
||||
|
@ -397,6 +397,23 @@ class IssuesController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def add_journal_in_org
|
||||
if User.current.logged?
|
||||
jour = Journal.new
|
||||
jour.user_id = User.current.id
|
||||
jour.notes = params[:notes]
|
||||
jour.journalized = @issue
|
||||
jour.save
|
||||
org_activity = OrgActivity.where("org_act_type='Issue' and org_act_id =#{@issue.id}").first
|
||||
org_activity.updated_at = jour.created_on
|
||||
org_activity.save
|
||||
@user_activity_id = params[:user_activity_id]
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_project
|
||||
|
|
|
@ -169,11 +169,21 @@ class MessagesController < ApplicationController
|
|||
course_activity.updated_at = Time.now
|
||||
course_activity.save
|
||||
end
|
||||
forge_activity = ForgeActivity.where("forge_act_type='Message' and forge_act_id=#{@topic.id}").first
|
||||
if forge_activity
|
||||
forge_activity.updated_at = Time.now
|
||||
forge_activity.save
|
||||
end
|
||||
user_activity = UserActivity.where("act_type='Message' and act_id =#{@topic.id}").first
|
||||
if user_activity
|
||||
user_activity.updated_at = Time.now
|
||||
user_activity.save
|
||||
end
|
||||
org_activity = OrgActivity.where("org_act_type='Message' and org_act_id =#{@topic.id}").first
|
||||
if org_activity
|
||||
org_activity.updated_at = Time.now
|
||||
org_activity.save
|
||||
end
|
||||
#@topic.update_attribute(:updated_on, Time.now)
|
||||
if !@reply.new_record?
|
||||
if params[:asset_id]
|
||||
|
|
|
@ -74,10 +74,10 @@ class NewsController < ApplicationController
|
|||
@q = params[:subject]
|
||||
if params[:subject].nil? || params[:subject].blank?
|
||||
scope_order = scope.all(:include => [:author, :course],
|
||||
:order => "#{News.table_name}.created_on DESC")
|
||||
:order => "#{News.table_name}.sticky DESC, #{News.table_name}.created_on DESC")
|
||||
else
|
||||
scope_order = scope.where("#{News.table_name}.title like '#{'%' << params[:subject].to_s << '%'}'").all(:include => [:author, :course],
|
||||
:order => "#{News.table_name}.created_on DESC")
|
||||
:order => "#{News.table_name}.sticky DESC, #{News.table_name}.created_on DESC")
|
||||
end
|
||||
|
||||
# :offset => @offset,
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
class OrgCoursesController < ApplicationController
|
||||
def create
|
||||
org_ids = params[:orgNames]
|
||||
@course = Course.find(params[:course_id])
|
||||
org_ids.each do |org_id|
|
||||
if OrgCourse.where("organization_id =? and course_id =?", org_id.to_i, params[:course_id].to_i).count == 0
|
||||
OrgCourse.create(:organization_id => org_id.to_i, :course_id => params[:course_id].to_i, :created_at => Time.now)
|
||||
end
|
||||
end
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def destroy
|
||||
@course = Course.find(params[:course_id])
|
||||
@org_course = OrgCourse.find(params[:id])
|
||||
@org_course.destroy
|
||||
end
|
||||
end
|
|
@ -0,0 +1,156 @@
|
|||
class OrgDocumentCommentsController < ApplicationController
|
||||
before_filter :find_organization, :only => [:new, :create, :show, :index]
|
||||
|
||||
layout 'base_org'
|
||||
|
||||
def new
|
||||
@org_document_comment = OrgDocumentComment.new
|
||||
end
|
||||
|
||||
def create
|
||||
@org_document_comment = OrgDocumentComment.new(:organization_id => @organization.id, :creator_id => User.current.id)
|
||||
@org_document_comment.title = params[:org_document_comment][:title]
|
||||
@org_document_comment.content = params[:org_document_comment][:content]
|
||||
if @org_document_comment.save
|
||||
flash.keep[:notice] = l(:notice_successful_create)
|
||||
EditorOfDocument.create(:editor_id => User.current.id, :org_document_comment_id => @org_document_comment.id, :created_at => @org_document_comment.updated_at)
|
||||
redirect_to organization_org_document_comments_path(@organization)
|
||||
else
|
||||
redirect_to new_org_document_comment_path(:organization_id => @organization.id)
|
||||
end
|
||||
end
|
||||
def show
|
||||
@document = OrgDocumentComment.find(params[:id])
|
||||
end
|
||||
|
||||
def index
|
||||
if @organization.is_public? || User.current.admin? || User.current.member_of_org?(@organization)
|
||||
@documents = @organization.org_document_comments.where("parent_id is null").order("created_at desc")
|
||||
else
|
||||
render_403
|
||||
end
|
||||
end
|
||||
def update
|
||||
@org_document = OrgDocumentComment.find(params[:id])
|
||||
@org_document.update_attributes(:title => params[:org_document_comment][:title], :content => params[:org_document_comment][:content])
|
||||
if @org_document.parent.nil?
|
||||
act = OrgActivity.where("org_act_type='OrgDocumentComment' and org_act_id =?", @org_document.id).first
|
||||
act.update_attributes(:updated_at => @org_document.updated_at)
|
||||
EditorOfDocument.create(:editor_id => User.current.id, :org_document_comment_id => @org_document.id, :created_at => Time.now)
|
||||
end
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
if params[:flag].to_i == 0
|
||||
redirect_to organization_org_document_comments_path(:organization_id => @org_document.organization.id)
|
||||
else
|
||||
if params[:flag].to_i == 1
|
||||
redirect_to org_document_comment_path(@org_document.root.id, :organization_id => @org_document.organization.id)
|
||||
else
|
||||
redirect_to organization_path(@org_document.organization.id)
|
||||
end
|
||||
end
|
||||
}
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
@org_document = OrgDocumentComment.find(params[:id])
|
||||
@flag = params[:flag]
|
||||
@organization = Organization.find(params[:organization_id])
|
||||
end
|
||||
|
||||
def add_reply
|
||||
@document = OrgDocumentComment.find(params[:id]).root
|
||||
@act = OrgActivity.find(params[:id])
|
||||
@comment = OrgDocumentComment.new(:organization_id => @document.organization_id, :creator_id => User.current.id, :reply_id => params[:id])
|
||||
@comment.content = params[:org_content]
|
||||
@document.children << @comment
|
||||
@document.save
|
||||
end
|
||||
|
||||
def add_reply_in_doc
|
||||
@document = OrgDocumentComment.find(params[:id]).root
|
||||
@comment = OrgDocumentComment.new(:organization_id => @document.organization_id, :creator_id => User.current.id, :reply_id => params[:id])
|
||||
@comment.content = params[:org_comment][:org_content]
|
||||
@document.children << @comment
|
||||
@document.save
|
||||
respond_to do |format|
|
||||
format.html {redirect_to org_document_comment_path(:id => @document.id, :organization_id => @document.organization_id)}
|
||||
end
|
||||
end
|
||||
|
||||
def find_organization
|
||||
@organization = Organization.find(params[:organization_id])
|
||||
end
|
||||
|
||||
def destroy
|
||||
@org_document_comment = OrgDocumentComment.find(params[:id])
|
||||
org = @org_document_comment.organization
|
||||
if @org_document_comment.id == org.home_id
|
||||
org.update_attributes(:home_id => nil)
|
||||
end
|
||||
if @org_document_comment.destroy
|
||||
end
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def delete_reply
|
||||
@org_document_comment = OrgDocumentComment.find(params[:id])
|
||||
@document = @org_document_comment.root
|
||||
org = @org_document_comment.organization
|
||||
@org_document_comment.destroy
|
||||
respond_to do |format|
|
||||
format.html {redirect_to org_document_comment_path(:id => @document.id, :organization_id => @document.organization_id)}
|
||||
end
|
||||
end
|
||||
def quote
|
||||
@org_comment = OrgDocumentComment.find(params[:id])
|
||||
@subject = @org_comment.content
|
||||
@subject = "RE: #{@subject}" unless @subject.starts_with?('RE:')
|
||||
|
||||
@content = "> #{ll(Setting.default_language, :text_user_wrote, User.find(@org_comment.creator_id).realname)}\n> "
|
||||
@temp = OrgDocumentComment.new
|
||||
#@course_id = params[:course_id]
|
||||
@temp.content = "<blockquote>#{ll(Setting.default_language, :text_user_wrote, User.find(@org_comment.creator_id).realname)} <br/>#{@org_comment.content.html_safe}</blockquote>".html_safe
|
||||
respond_to do | format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def reply
|
||||
@document = OrgDocumentComment.find(params[:id]).root
|
||||
@quote = params[:quote][:quote]
|
||||
@org_document = OrgDocumentComment.new(:creator_id => User.current.id, :reply_id => params[:id])
|
||||
|
||||
# params[:blog_comment][:sticky] = params[:blog_comment][:sticky] || 0
|
||||
# params[:blog_comment][:locked] = params[:blog_comment][:locked] || 0
|
||||
@org_document.title = params[:org_document_comment][:title]
|
||||
@org_document.content = params[:org_document_comment][:content]
|
||||
@org_document.content = @quote + @org_document.content
|
||||
#@org_document.title = "RE: #{@article.title}" unless params[:blog_comment][:title]
|
||||
@document.children << @org_document
|
||||
# @user_activity_id = params[:user_activity_id]
|
||||
# user_activity = UserActivity.where("act_type='BlogComment' and act_id =#{@article.id}").first
|
||||
# if user_activity
|
||||
# user_activity.updated_at = Time.now
|
||||
# user_activity.save
|
||||
# end
|
||||
# attachments = Attachment.attach_files(@org_document, params[:attachments])
|
||||
# render_attachment_warning_if_needed(@org_document)
|
||||
#@article.save
|
||||
# redirect_to user_blogs_path(:user_id=>params[:user_id])
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
# if params[:course_id] #如果呆了course_id过来了,那么这是要跳到课程大纲去的
|
||||
# redirect_to syllabus_course_path(:id=>params[:course_id])
|
||||
# else
|
||||
redirect_to org_document_comment_path(:id => @document.id, :organization_id => @document.organization_id)
|
||||
# end
|
||||
|
||||
}
|
||||
format.js
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,57 @@
|
|||
class OrgMemberController < ApplicationController
|
||||
|
||||
def org_member_autocomplete
|
||||
@org = Organization.find(params[:org])
|
||||
@flag = params[:flag] || false
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
@org = Organization.find(params[:org])
|
||||
if params[:membership].nil?
|
||||
@fail_hint = l(:label_blank_user_lists_for_org)
|
||||
else
|
||||
member_ids = params[:membership][:user_ids]
|
||||
role_id = params[:orgRole]
|
||||
member_ids.each do |user_id|
|
||||
member = OrgMember.create(:user_id=>user_id, :created_at => Time.now)
|
||||
@org.org_members << member
|
||||
OrgMemberRole.create(:org_member_id => member.id, :role_id => role_id)
|
||||
end
|
||||
end
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
@member = OrgMember.find(params[:id])
|
||||
#@member.change_role params[:org_member][:role_ids]
|
||||
@member_role = @member.org_member_roles[0]
|
||||
@member_role.role_id = params[:org_member][:role_ids][0]
|
||||
@member_role.save
|
||||
@org = @member.organization
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
|
||||
end
|
||||
|
||||
def destroy
|
||||
member = OrgMember.find(params[:id])
|
||||
@org = member.organization
|
||||
member.destroy
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def index
|
||||
|
||||
end
|
||||
end
|
|
@ -0,0 +1,19 @@
|
|||
class OrgProjectsController < ApplicationController
|
||||
def create
|
||||
org_ids = params[:orgNames]
|
||||
@project = Project.find(params[:project_id])
|
||||
org_ids.each do |org_id|
|
||||
if OrgProject.where("organization_id =? and project_id =?", org_id.to_i, @project.id).count == 0
|
||||
OrgProject.create(:organization_id => org_id.to_i, :project_id => params[:project_id].to_i, :created_at => Time.now)
|
||||
end
|
||||
end
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
def destroy
|
||||
@project = Project.find(params[:project_id])
|
||||
@org_project = OrgProject.find(params[:id])
|
||||
@org_project.destroy
|
||||
end
|
||||
end
|
|
@ -0,0 +1,19 @@
|
|||
class OrgSubfieldsController < ApplicationController
|
||||
def create
|
||||
@subfield = OrgSubfield.create(:name => params[:name])
|
||||
@organization = Organization.find(params[:organization_id])
|
||||
@organization.org_subfields << @subfield
|
||||
@subfield.update_attributes(:priority => @subfield.id)
|
||||
end
|
||||
|
||||
def destroy
|
||||
@subfield = OrgSubfield.find(params[:id])
|
||||
@organization = Organization.find(@subfield.organization_id)
|
||||
@subfield.destroy
|
||||
end
|
||||
|
||||
def update
|
||||
@subfield = OrgSubfield.find(params[:id])
|
||||
@subfield.update_attributes(:name => params[:name])
|
||||
end
|
||||
end
|
|
@ -1,55 +0,0 @@
|
|||
class OrganizationController < ApplicationController
|
||||
# layout 'base_projects'
|
||||
before_filter :require_admin, :except => [:index]
|
||||
|
||||
def index
|
||||
#@projects = Project.find_by_sql("SELECT * FROM projects WHERE id IN (select MAX(id) from projects GROUP BY enterprise_name)")
|
||||
@organizations = Organization.all
|
||||
respond_to do |format|
|
||||
format.html
|
||||
end
|
||||
end
|
||||
|
||||
def new
|
||||
@organizations = Organization.new
|
||||
respond_to do |format|
|
||||
format.html
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
@organizations = Organization.new
|
||||
@organizations.name = params[:organization][:name]
|
||||
if @organizations.save
|
||||
redirect_to admin_organization_url
|
||||
end
|
||||
end
|
||||
|
||||
def edit
|
||||
@organization = Organization.find params[:id]
|
||||
respond_to do |format|
|
||||
format.html
|
||||
end
|
||||
rescue Exception => e
|
||||
render_404
|
||||
end
|
||||
|
||||
def update
|
||||
@organization = Organization.find params[:id]
|
||||
@organization.name = params[:organization][:name]
|
||||
if @organization.save
|
||||
redirect_to admin_organization_url
|
||||
end
|
||||
rescue Exception => e
|
||||
render_404
|
||||
end
|
||||
|
||||
def destroy
|
||||
@organization = Organization.find params[:id]
|
||||
if @organization.destroy
|
||||
redirect_to admin_organization_url
|
||||
end
|
||||
rescue Exception => e
|
||||
render_404
|
||||
end
|
||||
end
|
|
@ -0,0 +1,271 @@
|
|||
# encoding: utf-8
|
||||
class OrganizationsController < ApplicationController
|
||||
|
||||
|
||||
helper :sort
|
||||
include SortHelper
|
||||
helper :custom_fields
|
||||
include CustomFieldsHelper
|
||||
include AvatarHelper
|
||||
include WordsHelper
|
||||
include GitlabHelper
|
||||
include UserScoreHelper
|
||||
|
||||
include PollHelper
|
||||
helper :user_score
|
||||
helper :journals
|
||||
|
||||
# added by liuping 关注
|
||||
|
||||
helper :watchers
|
||||
helper :activities
|
||||
|
||||
### added by william
|
||||
include ActsAsTaggableOn::TagsHelper
|
||||
|
||||
# fq
|
||||
helper :words
|
||||
helper :project_score
|
||||
helper :issues
|
||||
include UsersHelper
|
||||
before_filter :find_organization, :only => [:show, :members]
|
||||
layout 'base_org'
|
||||
def index
|
||||
|
||||
end
|
||||
def new
|
||||
@organization = Organization.new
|
||||
render :layout => 'new_base'
|
||||
end
|
||||
|
||||
def edit
|
||||
@organization = Organization.find(params[:id])
|
||||
end
|
||||
|
||||
def destroy
|
||||
@organization = Organization.find(params[:id])
|
||||
@organization.destroy
|
||||
respond_to do |format|
|
||||
format.html{ redirect_to admin_organization_path }
|
||||
end
|
||||
end
|
||||
|
||||
def create
|
||||
@organization = Organization.new
|
||||
@organization.name = params[:organization][:name]
|
||||
@organization.description = params[:organization][:description]
|
||||
@organization.is_public = params[:organization][:is_public]
|
||||
@organization.creator_id = User.current.id
|
||||
member = OrgMember.new(:user_id => User.current.id)
|
||||
|
||||
@organization.org_members << member
|
||||
if @organization.save
|
||||
OrgMemberRole.create(:org_member_id => member.id, :role_id => 11)
|
||||
redirect_to organization_path(@organization)
|
||||
end
|
||||
end
|
||||
|
||||
def show
|
||||
if @organization.is_public? || User.current.admin? || User.current.member_of_org?(@organization)
|
||||
@organization = Organization.find(params[:id])
|
||||
project_ids = @organization.projects.map(&:id) << 0
|
||||
course_ids = @organization.courses.map(&:id) << 0
|
||||
course_types = "('Message','News','HomeworkCommon','Poll','Course')"
|
||||
case params[:type]
|
||||
when nil
|
||||
@org_activities = OrgActivity.where("(container_id =? and container_type =?) " +
|
||||
"or (container_type ='Project' and org_act_type in ('Issue','Message','ProjectCreateInfo') and container_id in (#{project_ids.join(',')})) "+
|
||||
"or (container_type ='Course' and org_act_type in #{course_types} and container_id in (#{course_ids.join(',')}))",
|
||||
@organization.id, 'Organization').order('updated_at desc').page(params[:page] || 1).per(10)
|
||||
when 'project_issue'
|
||||
@org_activities = OrgActivity.where("container_type = 'Project' and org_act_type = 'Issue' and container_id in (#{project_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10)
|
||||
when 'project_message'
|
||||
@org_activities = OrgActivity.where("container_type = 'Project' and org_act_type = 'Message' and container_id in (#{project_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10)
|
||||
when 'org'
|
||||
@org_activities = OrgActivity.where("container_id =? and container_type =?",@organization.id, 'Organization').order('updated_at desc').page(params[:page] || 1).per(10)
|
||||
when 'course_homework'
|
||||
@org_activities = OrgActivity.where("container_type = 'Course' and org_act_type = 'HomeworkCommon' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10)
|
||||
when 'course_news'
|
||||
@org_activities = OrgActivity.where("container_type = 'Course' and org_act_type = 'News' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10)
|
||||
when 'course_message'
|
||||
@org_activities = OrgActivity.where("container_type = 'Course' and org_act_type = 'Message' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10)
|
||||
when 'course_poll'
|
||||
@org_activities = OrgActivity.where("container_type = 'Course' and org_act_type = 'Poll' and container_id in (#{course_ids.join(',')})").order('updated_at desc').page(params[:page] || 1).per(10)
|
||||
end
|
||||
@page = params[:page]
|
||||
respond_to do |format|
|
||||
format.html
|
||||
format.js
|
||||
end
|
||||
else
|
||||
render_403
|
||||
end
|
||||
end
|
||||
|
||||
def update
|
||||
@organization = Organization.find(params[:id])
|
||||
@organization.name = params[:organization][:name]
|
||||
@organization.description = params[:organization][:description]
|
||||
@organization.domain = params[:organization][:domain]
|
||||
@organization.is_public = params[:organization][:is_public] == 'on' ? 1 : 0
|
||||
#@organization.name = params[:organization][:name]
|
||||
@organization.save
|
||||
respond_to do |format|
|
||||
format.html { redirect_to setting_organization_path(@organization)}
|
||||
end
|
||||
end
|
||||
|
||||
def check_uniq
|
||||
@check = false;
|
||||
@org_name = params[:org_name].strip
|
||||
@config_page = params[:config_page]
|
||||
sameName = @config_page ? Organization.where('name = ? and id != ?',params[:org_name],params[:org_id].to_i).count == 0 : Organization.where('name = ?',params[:org_name]).count == 0
|
||||
if sameName == true
|
||||
@check = true
|
||||
end
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def find_organization
|
||||
@organization = Organization.find(params[:id])
|
||||
end
|
||||
|
||||
def setting
|
||||
@organization = Organization.find(params[:id])
|
||||
|
||||
if User.current.admin? || User.current.admin_of_org?(@organization)
|
||||
else
|
||||
render_403
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
def clear_org_avatar_temp
|
||||
|
||||
end
|
||||
|
||||
def set_homepage
|
||||
@org = Organization.find(params[:id])
|
||||
@org.home_id = params[:home_id]
|
||||
@org.save
|
||||
# respond_to do |format|
|
||||
# format.html {redirect_to organization_path(org)}
|
||||
# end
|
||||
end
|
||||
|
||||
def cancel_homepage
|
||||
@org = Organization.find(params[:id])
|
||||
@org.home_id = nil
|
||||
@org.save
|
||||
end
|
||||
|
||||
def autocomplete_search
|
||||
@project = Project.find(params[:project_id])
|
||||
#@flag = params[:flag] || false
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def members
|
||||
if @organization.is_public? || User.current.admin? || User.current.member_of_org?(@organization)
|
||||
@members = OrgMember.where("organization_id =?", @organization.id)
|
||||
else
|
||||
render_403
|
||||
end
|
||||
end
|
||||
|
||||
def more_org_projects
|
||||
@organization = Organization.find params[:id]
|
||||
@page = params[:page]
|
||||
@org_projects = @organization.projects.reorder('created_at').uniq.page((params[:page].to_i || 1) +1).per(5)
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def more_org_courses
|
||||
@organization = Organization.find(params[:id])
|
||||
@page = params[:page]
|
||||
@org_courses = @organization.courses.reorder('created_at').uniq.page((params[:page].to_i || 1) + 1 ).per(5)
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def join_course_menu
|
||||
@organization = Organization.find(params[:id])
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def search_courses
|
||||
@organization = Organization.find(params[:id])
|
||||
condition = '%%'
|
||||
if !params[:name].nil?
|
||||
condition = "%#{params[:name].strip}%".gsub(" ","")
|
||||
end
|
||||
sql = "select courses.* from courses inner join members on courses.id = members.course_id where members.user_id = #{User.current.id} and courses.name like '#{condition}'"+
|
||||
"and courses.id not in (select distinct org_courses.course_id from org_courses where org_courses.organization_id = #{@organization.id})"
|
||||
#user_courses = Course.find_by_sql(sql)
|
||||
@courses = Course.find_by_sql(sql)
|
||||
# @added_course_ids = @organization.courses.map(&:id)
|
||||
# @courses = []
|
||||
# user_courses.each do |course|
|
||||
# if !@added_course_ids.include?(course.id)
|
||||
# @courses << course
|
||||
# end
|
||||
# end
|
||||
end
|
||||
|
||||
def join_courses
|
||||
@organization = Organization.find(params[:id])
|
||||
course_ids = params[:courseNames]
|
||||
course_ids.each do |id|
|
||||
OrgCourse.create(:organization_id => @organization.id, :course_id => id.to_i, :created_at => Time.now)
|
||||
end
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def join_project_menu
|
||||
@organization = Organization.find(params[:id])
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def search_projects
|
||||
@organization = Organization.find(params[:id])
|
||||
condition = '%%'
|
||||
if !params[:name].nil?
|
||||
condition = "%#{params[:name].strip}%".gsub(" ","")
|
||||
end
|
||||
sql = "select projects.* from projects inner join members on projects.id = members.project_id where members.user_id = #{User.current.id} and projects.status != 9 and projects.name like '#{condition}'" +
|
||||
" and projects.id not in (select org_projects.project_id from org_projects where organization_id = #{@organization.id})"
|
||||
#user_projects = Course.find_by_sql(sql)
|
||||
@projects = Course.find_by_sql(sql)
|
||||
# @added_course_ids = @organization.projects.map(&:id)
|
||||
# @projects = []
|
||||
# user_projects.each do |project|
|
||||
# if !@added_course_ids.include?(project.id)
|
||||
# @projects << project
|
||||
# end
|
||||
# end
|
||||
end
|
||||
|
||||
def join_projects
|
||||
@organization = Organization.find(params[:id])
|
||||
project_ids = params[:projectNames]
|
||||
project_ids.each do |id|
|
||||
OrgProject.create(:organization_id => @organization.id, :project_id => id.to_i, :created_at => Time.now)
|
||||
end
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
end
|
|
@ -69,6 +69,30 @@ class ProjectsController < ApplicationController
|
|||
### added by william
|
||||
include ActsAsTaggableOn::TagsHelper
|
||||
|
||||
#查找组织
|
||||
def search_public_orgs_not_in_project
|
||||
condition = '%%'
|
||||
if !params[:name].nil?
|
||||
condition = "%#{params[:name].strip}%".gsub(" ","")
|
||||
end
|
||||
project_org_ids = OrgProject.find_by_sql("select distinct organization_id from org_projects where project_id = #{params[:id]}").map(&:organization_id)
|
||||
if project_org_ids.empty?
|
||||
@orgs_not_in_project = Organization.where("(is_public or creator_id =?) = 1 and name like ?",User.current.id, condition).page((params[:page].to_i || 1)).per(10)
|
||||
@org_count = Organization.where("is_public = 1 or creator_id =?", User.current.id).where("name like ?", condition).count
|
||||
else
|
||||
project_org_ids = "(" + project_org_ids.join(',') + ")"
|
||||
@orgs_not_in_project = Organization.where("id not in #{project_org_ids} and (is_public = 1 or creator_id =?) and name like ?", User.current.id, condition).page((params[:page].to_i || 1)).per(10)
|
||||
@org_count = Organization.where("id not in #{project_org_ids} and (is_public = 1 or creator_id =?)", User.current.id).where("name like ?", condition).count
|
||||
end
|
||||
# @project_count = Project.project_entities.visible.like(params[:name]).page(params[:page]).count
|
||||
@orgs_page = Paginator.new @org_count, 10,params[:page]
|
||||
@no_roll_hint = params[:hint_flag]
|
||||
#render :json => {:orgs => @orgs_not_in_project, :count => @org_count}.to_json
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def index
|
||||
render_404
|
||||
end
|
||||
|
@ -296,9 +320,20 @@ class ProjectsController < ApplicationController
|
|||
@activity.scope_select {|t| !has["show_#{t}"].nil?}
|
||||
=end
|
||||
|
||||
@page = params[:page] ? params[:page].to_i + 1 : 0
|
||||
# 根据私密性,取出符合条件的所有数据
|
||||
if User.current.member_of?(@project) || User.current.admin?
|
||||
@events_pages = ForgeActivity.where("project_id = ? and forge_act_type != ?",@project, "Document" ).order("created_at desc").page(params['page'|| 1]).per(20);
|
||||
case params[:type]
|
||||
when nil
|
||||
@events_pages = ForgeActivity.where("project_id = ? and forge_act_type in ('Issue', 'Message','News', 'ProjectCreateInfo')",@project).order("updated_at desc").limit(10).offset(@page * 10)
|
||||
when 'issue'
|
||||
@events_pages = ForgeActivity.where("project_id = ? and forge_act_type = 'Issue'",@project).order("updated_at desc").limit(10).offset(@page * 10)
|
||||
when 'news'
|
||||
@events_pages = ForgeActivity.where("project_id = ? and forge_act_type = 'News'",@project).order("updated_at desc").limit(10).offset(@page * 10)
|
||||
when 'message'
|
||||
@events_pages = ForgeActivity.where("project_id = ? and forge_act_type = 'Message'",@project).order("updated_at desc").limit(10).offset(@page * 10)
|
||||
end
|
||||
|
||||
#events = @activity.events(@date_from, @date_to)
|
||||
else
|
||||
@events_pages = ForgeActivity.includes(:project).where("forge_activities.project_id = ? and projects.is_public
|
||||
|
@ -338,6 +373,15 @@ class ProjectsController < ApplicationController
|
|||
@wiki ||= @project.wiki
|
||||
@select_tab = params[:tab]
|
||||
|
||||
#找出所有不属于项目的公共组织
|
||||
project_org_ids = OrgProject.find_by_sql("select distinct organization_id from org_projects where project_id = #{@project.id}")
|
||||
if project_org_ids.empty?
|
||||
@orgs_not_in_project = Organization.where("is_public = 1")
|
||||
else
|
||||
project_org_ids = "(" + project_org_ids.join(',') + ")"
|
||||
@orgs_not_in_project = Organization.where("id not in #{project_org_ids} and is_public = 1")
|
||||
end
|
||||
|
||||
# 处理从新建版本库返回来的错误信息
|
||||
if !params[:repository_error_message].to_s.blank?
|
||||
html = ""
|
||||
|
@ -607,6 +651,13 @@ class ProjectsController < ApplicationController
|
|||
@project.organization_id = params[:organization_id]
|
||||
params[:project][:is_public] ? @project.is_public = 1 : @project.is_public = 0
|
||||
params[:project][:hidden_repo] ? @project.hidden_repo = 1 : @project.hidden_repo = 0
|
||||
# 更新公开私有时同步gitlab公开私有
|
||||
unless @project.gpid.nil?
|
||||
g = Gitlab.client
|
||||
gproject = g.project(@project.gpid)
|
||||
params[:project][:is_public] ? g.edit_project(gproject.id, 20) : g.edit_project(gproject.id, 0)
|
||||
end
|
||||
# end
|
||||
if validate_parent_id && @project.save
|
||||
@project.set_allowed_parent!(params[:project]['parent_id']) if params[:project].has_key?('parent_id')
|
||||
if params[:project][:is_public] == '0'
|
||||
|
@ -826,5 +877,4 @@ class ProjectsController < ApplicationController
|
|||
end
|
||||
#gcmend
|
||||
|
||||
|
||||
end
|
||||
|
|
|
@ -34,7 +34,7 @@ class RepositoriesController < ApplicationController
|
|||
before_filter :find_repository, :only => [:edit, :update, :destroy, :committers]
|
||||
before_filter :find_project_repository, :except => [:new, :create, :newcreate, :edit, :update, :destroy, :committers, :newrepo,:to_gitlab]
|
||||
before_filter :find_changeset, :only => [:revision, :add_related_issue, :remove_related_issue]
|
||||
before_filter :authorize , :except => [:newrepo,:newcreate,:fork, :to_gitlab]
|
||||
before_filter :authorize , :except => [:newrepo,:newcreate,:fork, :to_gitlab, :forked]
|
||||
accept_rss_auth :revisions
|
||||
# hidden repositories filter // 隐藏代码过滤器
|
||||
before_filter :check_hidden_repo, :only => [:show, :stats, :revisions, :revision, :diff ]
|
||||
|
@ -42,7 +42,7 @@ class RepositoriesController < ApplicationController
|
|||
include RepositoriesHelper
|
||||
helper :project_score
|
||||
#@root_path = RepositoriesHelper::ROOT_PATH
|
||||
|
||||
$g=Gitlab.client
|
||||
|
||||
rescue_from Redmine::Scm::Adapters::CommandFailed, :with => :show_error_command_failed
|
||||
def new
|
||||
|
@ -63,6 +63,78 @@ class RepositoriesController < ApplicationController
|
|||
|
||||
end
|
||||
|
||||
def forked
|
||||
# 被forked的标识如果不满足单个用户唯一性,则不执行fork
|
||||
if is_sigle_identifier?(User.current, @repository.identifier)
|
||||
# REDO: 那些人有权限forked项目
|
||||
g = Gitlab.client
|
||||
gproject = g.post ("/projects/fork/#{@project.gpid}?user_id=#{User.current.gid}")
|
||||
if gproject
|
||||
copy_project(@project, gproject)
|
||||
end
|
||||
else
|
||||
flash[:notice] = l(:project_gitlab_fork_double_message)
|
||||
redirect_to settings_project_url(@project, :tab => 'repositories')
|
||||
end
|
||||
end
|
||||
|
||||
# copy a project for fork
|
||||
def copy_project(project, gproject)
|
||||
project = Project.new
|
||||
project.name = @project.name
|
||||
project.is_public = @project.is_public
|
||||
project.status = @project.status
|
||||
project.description = @project.description
|
||||
project.hidden_repo = @project.hidden_repo
|
||||
project.user_id = User.current.id
|
||||
project.project_type = 0
|
||||
project.project_new_type = @project.project_new_type
|
||||
project.gpid = gproject.id
|
||||
if project.save
|
||||
r = Role.givable.find_by_id(Setting.new_project_user_role_id.to_i) || Role.givable.first
|
||||
m = Member.new(:user => User.current, :roles => [r])
|
||||
project_info = ProjectInfo.new(:user_id => User.current.id, :project_id => project.id)
|
||||
user_grades = UserGrade.create(:user_id => User.current.id, :project_id => project.id)
|
||||
Rails.logger.debug "UserGrade created: #{user_grades.to_json}"
|
||||
project_status = ProjectStatus.create(:project_id => @project.id, :watchers_count => 0, :changesets_count => 0, :project_type => @project.project_type,:grade => 0)
|
||||
Rails.logger.debug "ProjectStatus created: #{project_status.to_json}"
|
||||
project.members << m
|
||||
project.project_infos << project_info
|
||||
copy_repository(project, gproject)
|
||||
respond_to do |format|
|
||||
format.html {
|
||||
flash[:notice] = l(:notice_successful_create)
|
||||
if params[:continue]
|
||||
attrs = {:parent_id => project.parent_id}.reject {|k,v| v.nil?}
|
||||
redirect_to new_project_url(attrs, :course => '0')
|
||||
else
|
||||
redirect_to settings_project_url(project)
|
||||
end
|
||||
}
|
||||
format.api { render :action => 'show', :status => :created, :location => url_for(:controller => 'projects', :action => 'show', :id => project.id) }
|
||||
format.js
|
||||
end
|
||||
else
|
||||
respond_to do |format|
|
||||
format.html { render :action => 'forked', :layout => 'base_projects'}
|
||||
format.api { render_validation_errors(@project) }
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def copy_repository(project, gproject)
|
||||
# 避免
|
||||
if is_sigle_identifier?(project.user_id, gproject.name)
|
||||
repository = Repository.factory('Git')
|
||||
repository.project_id = project.id
|
||||
repository.type = 'Repository::Gitlab'
|
||||
repository.url = gproject.name
|
||||
repository.identifier = gproject.name
|
||||
repository = repository.save
|
||||
else
|
||||
flash[:notice] = l(:project_gitlab_create_double_message)
|
||||
end
|
||||
end
|
||||
|
||||
def newrepo
|
||||
scm = params[:repository_scm] || (Redmine::Scm::Base.all & Setting.enabled_scm).first
|
||||
|
@ -115,21 +187,27 @@ update
|
|||
}
|
||||
|
||||
def create
|
||||
attrs = pickup_extra_info
|
||||
@repository = Repository.factory('Git')
|
||||
@repository.safe_attributes = params[:repository]
|
||||
if attrs[:attrs_extra].keys.any?
|
||||
@repository.merge_extra_info(attrs[:attrs_extra])
|
||||
end
|
||||
@repository.project = @project
|
||||
@repository.type = 'Repository::Gitlab'
|
||||
@repository.url = @repository.identifier
|
||||
if request.post? && @repository.save
|
||||
s = Trustie::Gitlab::Sync.new
|
||||
s.create_project(@project, @repository)
|
||||
# 判断版本库创建者是否有同名版本库,避免版本库路径一致问题
|
||||
unless is_sigle_identifier?(@project.user_id, params[:repository].first[1])
|
||||
flash[:notice] = l(:project_gitlab_create_double_message)
|
||||
redirect_to settings_project_url(@project, :tab => 'repositories')
|
||||
else
|
||||
redirect_to settings_project_url(@project, :tab => 'repositories',:repository_error_message=>@repository.errors.full_messages)
|
||||
attrs = pickup_extra_info
|
||||
@repository = Repository.factory('Git')
|
||||
@repository.safe_attributes = params[:repository]
|
||||
if attrs[:attrs_extra].keys.any?
|
||||
@repository.merge_extra_info(attrs[:attrs_extra])
|
||||
end
|
||||
@repository.project = @project
|
||||
@repository.type = 'Repository::Gitlab'
|
||||
@repository.url = @repository.identifier
|
||||
if request.post? && @repository.save
|
||||
s = Trustie::Gitlab::Sync.new
|
||||
s.create_project(@project, @repository)
|
||||
redirect_to settings_project_url(@project, :tab => 'repositories')
|
||||
else
|
||||
redirect_to settings_project_url(@project, :tab => 'repositories',:repository_error_message=>@repository.errors.full_messages)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -237,14 +315,34 @@ update
|
|||
#Modified by young
|
||||
# (show_error_not_found; return) unless @entries
|
||||
g = Gitlab.client
|
||||
count = 0
|
||||
(0..100).each do |page|
|
||||
if g.commits(@project.gpid,:page => page).count == 0
|
||||
break
|
||||
else
|
||||
count = count + g.commits(@project.gpid,:page => page).count
|
||||
end
|
||||
|
||||
# count = 0
|
||||
# (0..100).each do |page|
|
||||
# if g.commits(@project.gpid,:page => page).count == 0
|
||||
# break
|
||||
# else
|
||||
# count = count + g.commits(@project.gpid,:page => page).count
|
||||
# end
|
||||
# end
|
||||
|
||||
|
||||
#add by hx
|
||||
if g.commits(@project.gpid , :page=>25).count==0
|
||||
count = count_commits(@project.gpid , 0 , 25)
|
||||
elsif g.commits(@project.gpid , :page=>50).count ==0
|
||||
count = count_commits(@project.gpid , 25 , 50)+ 25 * 20
|
||||
elsif g.commits(@project.gpid , :page=>75).count ==0
|
||||
count = count_commits(@project.gpid , 50 , 75)+ 50 * 20
|
||||
elsif g.commits(@project.gpid , :page=>100).count== 0
|
||||
count = count_commits(@project.gpid , 75 , 100) + 75 * 20
|
||||
elsif g.commits(@project.gpid , :page=>125).count==0
|
||||
count = count_commits(@project.gpid , 100 , 125) + 100 * 20
|
||||
elsif g.commits(@project.gpid , :page=>150).count==0
|
||||
count = count_commits(@project.gpid , 125 , 150) + 125 * 20
|
||||
else
|
||||
count = count_commits(@project.gpid , 150 ,200) + 150 * 20
|
||||
end
|
||||
|
||||
@changesets = g.commits(@project.gpid)
|
||||
# @changesets = @repository.latest_changesets(@path, @rev)
|
||||
# @changesets_count = @repository.latest_changesets(@path, @rev).count
|
||||
|
@ -271,11 +369,30 @@ update
|
|||
|
||||
alias_method :browse, :show
|
||||
|
||||
#add by hx
|
||||
def count_commits(project_id , left , right)
|
||||
count = 0
|
||||
(left..right).each do |page|
|
||||
if $g.commits(project_id,:page => page).count == 0
|
||||
break
|
||||
else
|
||||
count = count + $g.commits(project_id,:page => page).count
|
||||
end
|
||||
end
|
||||
return count
|
||||
end
|
||||
|
||||
def changes
|
||||
@entry = @repository.entry(@path, @rev)
|
||||
(show_error_not_found; return) unless @entry
|
||||
g = Gitlab.client
|
||||
@commits = g.commits(@project.gpid, page:params[:pamge])
|
||||
limit = 20
|
||||
#每次页面的换回值从1开始,但是gitlab的页面查询是从0开始,所以先改变page的类型减一在改回来
|
||||
@commits = g.commits(@project.gpid, page:(params[:page].to_i - 1).to_s)
|
||||
#页面传递必须要str类型,但是Paginator的初始化必须要num类型,需要类型转化
|
||||
@commits_count = params[:commit_count].to_i
|
||||
@commits_pages = Redmine::Pagination::Paginator.new @commits_count,limit,params[:page]
|
||||
|
||||
@commit = g.commit(@project.gpid,@rev)
|
||||
# @changesets = g.get ("/projects/#{@project.gpid}/repository/commits?#{@rev}")
|
||||
#@changesets = @repository.latest_changesets(@path, @rev, Setting.repository_log_display_limit.to_i)
|
||||
|
@ -284,6 +401,7 @@ update
|
|||
render :layout => 'base_projects'
|
||||
end
|
||||
|
||||
|
||||
def revisions
|
||||
@changeset_count = @repository.changesets.count
|
||||
@changeset_pages = Paginator.new @changeset_count,
|
||||
|
@ -467,8 +585,8 @@ update
|
|||
def find_repository
|
||||
@repository = Repository.find(params[:id])
|
||||
@project = @repository.project
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
rescue ActiveRecord::RecordNotFound
|
||||
render_404
|
||||
end
|
||||
|
||||
REV_PARAM_RE = %r{\A[a-f0-9]*\Z}i
|
||||
|
|
|
@ -76,7 +76,7 @@ class StudentWorkController < ApplicationController
|
|||
end
|
||||
##################################################################################################################
|
||||
@order,@b_sort,@name,@group = params[:order] || "score",params[:sort] || "desc",params[:name] || "",params[:group]
|
||||
@homework_commons = @course.homework_commons.order("created_at desc")
|
||||
@homework_commons = @course.homework_commons.where("publish_time <= ?",Time.now.strftime("%Y-%m-%d")).order("created_at desc")
|
||||
@is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin?
|
||||
@is_evaluation = @homework.homework_detail_manual && @homework.homework_detail_manual.comment_status == 2 && !@is_teacher #是不是匿评
|
||||
@show_all = false
|
||||
|
@ -167,6 +167,18 @@ class StudentWorkController < ApplicationController
|
|||
end
|
||||
|
||||
def create
|
||||
# 提交作品前先判断是否已经提交
|
||||
@has_commit = false;
|
||||
if hsd_committed_work?(User.current.id, @homework.id)
|
||||
@work = StudentWork.where("user_id =? and homework_common_id =?", User.current.id, @homework.id).first
|
||||
@has_commit = true;
|
||||
#flash[:notice] = l(:notice_successful_create)
|
||||
#redirect_to edit_student_work_url(params[:student_work])
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
return
|
||||
end
|
||||
if params[:student_work]
|
||||
@submit_result = true
|
||||
student_work = StudentWork.find(params[:student_work_id]) if params[:student_work_id]
|
||||
|
@ -499,6 +511,12 @@ class StudentWorkController < ApplicationController
|
|||
end
|
||||
|
||||
private
|
||||
def hsd_committed_work?(user, homework)
|
||||
sw = StudentWork.where("user_id =? and homework_common_id =?", user, homework).first
|
||||
sw.nil? ? result = false : result = true
|
||||
result
|
||||
end
|
||||
|
||||
#获取作业
|
||||
def find_homework
|
||||
@homework = HomeworkCommon.find params[:homework]
|
||||
|
|
|
@ -1910,6 +1910,28 @@ class UsersController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def user_organizations
|
||||
@user = User.current
|
||||
@orgs = @user.organizations
|
||||
respond_to do |format|
|
||||
format.html {render :layout => 'static_base'}
|
||||
end
|
||||
end
|
||||
|
||||
def search_user_orgs
|
||||
name=""
|
||||
if !params[:search_orgs].nil?
|
||||
name = params[:search_orgs].strip
|
||||
end
|
||||
name = "%"+name+"%"
|
||||
@orgs = User.current.organizations.where("name like ?", name)
|
||||
@user = User.current
|
||||
respond_to do |format|
|
||||
format.html {render :layout => 'static_base'}
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def find_user
|
||||
|
|
|
@ -48,6 +48,15 @@ module ApplicationHelper
|
|||
end
|
||||
end
|
||||
end
|
||||
# 获取组织成员中文名字
|
||||
def get_org_member_role_name member
|
||||
case member.roles[0].name
|
||||
when 'orgManager'
|
||||
'管理人员'
|
||||
when 'orgMember'
|
||||
'组织成员'
|
||||
end
|
||||
end
|
||||
|
||||
# Time 2015-03-24 16:38:05
|
||||
# Author lizanle
|
||||
|
@ -66,6 +75,50 @@ module ApplicationHelper
|
|||
end
|
||||
end
|
||||
|
||||
# 更新课程英雄榜得分
|
||||
# user传过来必须是学生
|
||||
def course_member_score(course_id,user_id,type)
|
||||
course_contributor_score = CourseContributorScore.where("course_id =? and user_id =?", course_id, user_id).first
|
||||
case type
|
||||
when "JournalForMessage"
|
||||
if course_contributor_score.nil?
|
||||
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 0, :message_reply_num => 0,
|
||||
:news_reply_num => 0, :resource_num => 0, :journal_num => 1, :journal_reply_num => 0, :total_score => 1)
|
||||
else
|
||||
score = course_contributor_score.journal_num + 1
|
||||
total_score = course_contributor_score.total_score + 1
|
||||
course_contributor_score.update_attributes(:journal_num => score, :total_score => total_score)
|
||||
end
|
||||
when "Message"
|
||||
if course_contributor_score.nil?
|
||||
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 2, :message_reply_num => 0,
|
||||
:news_reply_num => 0, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0, :total_score => 2)
|
||||
else
|
||||
score = course_contributor_score.message_num + 2
|
||||
total_score = course_contributor_score.total_score + 2
|
||||
course_contributor_score.update_attributes(:message_num => score, :total_score => total_score)
|
||||
end
|
||||
when "MessageReply"
|
||||
if course_contributor_score.nil?
|
||||
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 0, :message_reply_num => 1,
|
||||
:news_reply_num => 0, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0, :total_score => 1)
|
||||
else
|
||||
score = course_contributor_score.message_reply_num + 1
|
||||
total_score = course_contributor_score.total_score + 1
|
||||
course_contributor_score.update_attributes(:message_reply_num => score, :total_score => total_score)
|
||||
end
|
||||
when "NewReply"
|
||||
if course_contributor_score.nil?
|
||||
CourseContributorScore.create(:course_id => course_id, :user_id => user_id, :message_num => 0, :message_reply_num => 0,
|
||||
:news_reply_num => 1, :resource_num => 0, :journal_num => 0, :journal_reply_num => 0, :total_score => 1)
|
||||
else
|
||||
score = course_contributor_score.news_reply_num + 1
|
||||
total_score = course_contributor_score.total_score + 1
|
||||
course_contributor_score.update_attributes(:news_reply_num => score, :total_score => total_score)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
# Added by young
|
||||
# Define the course menu's link class
|
||||
# 不是数组的转化成数组,然后判断当前menu_item是否在给定的列表
|
||||
|
@ -2365,8 +2418,10 @@ module ApplicationHelper
|
|||
link_to "作品(#{homework.student_works.count})",student_work_index_path(:homework => homework.id),:class => "c_blue"
|
||||
else #学生显示提交作品、修改作品等按钮
|
||||
work = cur_user_works_for_homework homework
|
||||
if work.nil?
|
||||
if work.nil? && Time.parse(homework.end_time.to_s).strftime("%Y-%m-%d") >= Time.now.strftime("%Y-%m-%d")
|
||||
link_to "提交作品(#{homework.student_works.count})", new_student_work_path(:homework => homework.id),:class => 'c_blue'
|
||||
elsif work.nil? && Time.parse(homework.end_time.to_s).strftime("%Y-%m-%d") < Time.now.strftime("%Y-%m-%d")
|
||||
link_to "补交作品(#{homework.student_works.count})", new_student_work_path(:homework => homework.id),:class => 'c_red'
|
||||
else
|
||||
if homework.homework_detail_manual && homework.homework_detail_manual.comment_status == 2 #匿评作业,且作业状态不是在开启匿评之前
|
||||
link_to "作品匿评", student_work_index_path(:homework => homework.id), :class => 'c_blue', :title => "开启匿评后不可修改作品"
|
||||
|
|
|
@ -25,6 +25,10 @@ module CoursesHelper
|
|||
# searchTeacherAndAssistant(project).count
|
||||
end
|
||||
|
||||
def show_nav?(count)
|
||||
count == 0 ? true : false
|
||||
end
|
||||
|
||||
#课程模块需要展示的模块
|
||||
def course_model
|
||||
@nav_dispaly_course_all_label = 1
|
||||
|
@ -733,4 +737,26 @@ module CoursesHelper
|
|||
end
|
||||
desc.html_safe
|
||||
end
|
||||
|
||||
# 学生按作业总分排序,取前8个
|
||||
def hero_homework_score(course, score_sort_by)
|
||||
sql_select = "SELECT members.*,(
|
||||
SELECT SUM(student_works.final_score)
|
||||
FROM student_works,homework_commons
|
||||
WHERE student_works.homework_common_id = homework_commons.id
|
||||
AND homework_commons.course_id = #{course.id}
|
||||
AND student_works.user_id = members.user_id
|
||||
) AS score
|
||||
FROM members
|
||||
JOIN students_for_courses
|
||||
ON students_for_courses.student_id = members.user_id AND students_for_courses.course_id = members.course_id
|
||||
WHERE members.course_id = #{course.id} ORDER BY score #{score_sort_by} limit 9"
|
||||
homework_scores = Member.find_by_sql(sql_select)
|
||||
end
|
||||
|
||||
def contributor_course_scor(course_id)
|
||||
ccs = CourseContributorScore.where("course_id =?", course_id).order("total_score desc") .limit(9)
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
|
|
|
@ -0,0 +1,152 @@
|
|||
# encoding: utf-8
|
||||
module ExerciseHelper
|
||||
|
||||
# 单选
|
||||
def sigle_selection_standard_answer(params)
|
||||
size = params.ord - 96
|
||||
if size > 0 # 小写字母答案
|
||||
answer = params.ord - 96
|
||||
else
|
||||
answer = params.ord - 64
|
||||
end
|
||||
end
|
||||
|
||||
# 多选
|
||||
def multiselect_standard_answer(params)
|
||||
size = params.ord - 96
|
||||
answer = []
|
||||
if size > 0 # 小写字母答案
|
||||
for i in 0..(params.length-1)
|
||||
answer << (params[i].ord - 96).to_s
|
||||
end
|
||||
else
|
||||
for i in 0..(params.length-1)
|
||||
answer << (params[i].ord - 64)
|
||||
end
|
||||
end
|
||||
answer = answer.sort
|
||||
answer.join("")
|
||||
end
|
||||
|
||||
#
|
||||
def fill_standart_answer(params, standart_answer)
|
||||
params.each do |param|
|
||||
standart_answer.answer_text = param.value
|
||||
standart_answer.save
|
||||
end
|
||||
end
|
||||
|
||||
# 获取多选的得分
|
||||
def get_mulscore(question, user)
|
||||
ecs = ExerciseAnswer.where("user_id =? and exercise_question_id =?", user.id, question.id)
|
||||
arr = []
|
||||
ecs.each do |ec|
|
||||
arr << ec.exercise_choice.choice_position
|
||||
end
|
||||
arr.sort
|
||||
arr = arr.join("")
|
||||
end
|
||||
|
||||
# 判断用户是否已经提交了问卷
|
||||
# status 为0的时候是用户点击试卷。为1表示用户已经提交
|
||||
def has_commit_exercise?(exercise_id, user_id)
|
||||
pu = ExerciseUser.where("exercise_id=? and user_id=? and status=?",exercise_id, user_id, true)
|
||||
if pu.empty?
|
||||
false
|
||||
else
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
# 判断学生是否点击过问卷,点击则为他保存一个记录,记录start_at
|
||||
def has_click_exercise?(exercise_id, user_id)
|
||||
pu = ExerciseUser.where("exercise_id=? and user_id=? and status=?",exercise_id, user_id, false)
|
||||
if pu.empty?
|
||||
false
|
||||
else
|
||||
true
|
||||
end
|
||||
end
|
||||
|
||||
def convert_to_char(str)
|
||||
result = ""
|
||||
length = str.length
|
||||
unless str.nil?
|
||||
if length === 1
|
||||
result += (str.to_i + 64).chr
|
||||
return result
|
||||
elsif length > 1
|
||||
for i in 0...length
|
||||
result += (str[i].to_i + 64).chr
|
||||
end
|
||||
return result
|
||||
end
|
||||
end
|
||||
return result
|
||||
end
|
||||
|
||||
def get_current_score exercise
|
||||
score = 0
|
||||
unless exercise.nil?
|
||||
exercise.exercise_questions.each do |exercise_question|
|
||||
unless exercise_question.question_score.nil?
|
||||
score += exercise_question.question_score
|
||||
end
|
||||
end
|
||||
return score
|
||||
end
|
||||
return score
|
||||
end
|
||||
|
||||
def answer_be_selected?(answer,user)
|
||||
pv = answer.exercise_answers.where("#{ExerciseAnswer.table_name}.user_id = #{user.id} ")
|
||||
if !pv.nil? && pv.count > 0
|
||||
true
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
|
||||
#获取未完成的题目
|
||||
def get_uncomplete_question exercise,user
|
||||
all_questions = exercise.exercise_questions
|
||||
uncomplete_question = []
|
||||
all_questions.each do |question|
|
||||
answers = get_user_answer(question, user)
|
||||
if answers.empty?
|
||||
uncomplete_question << question
|
||||
end
|
||||
end
|
||||
uncomplete_question
|
||||
end
|
||||
|
||||
#获取文本题答案
|
||||
def get_anwser_vote_text(question_id,user_id)
|
||||
pv = ExerciseAnswer.find_by_exercise_question_id_and_user_id(question_id,user_id)
|
||||
if pv.nil?
|
||||
''
|
||||
else
|
||||
pv.answer_text
|
||||
end
|
||||
end
|
||||
|
||||
# 获取当前学生回答问题的答案
|
||||
def get_user_answer(question,user)
|
||||
user_answer = question.exercise_answers.where("#{ExerciseAnswer.table_name}.user_id = #{user.id}")
|
||||
user_answer
|
||||
end
|
||||
|
||||
# 获取问题的标准答案
|
||||
def get_user_standard_answer(question,user)
|
||||
if question.question_type == 3
|
||||
standard_answer =[]
|
||||
question.exercise_standard_answers.each do |answer|
|
||||
standard_answer << answer.answer_text
|
||||
end
|
||||
else
|
||||
standard_answer = question.exercise_standard_answers
|
||||
end
|
||||
standard_answer
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,2 @@
|
|||
module OrgCoursesHelper
|
||||
end
|
|
@ -0,0 +1,2 @@
|
|||
module OrgDocumentCommentHelper
|
||||
end
|
|
@ -0,0 +1,16 @@
|
|||
module OrgMemberHelper
|
||||
include ApplicationHelper
|
||||
def find_user_not_in_current_org_by_name org
|
||||
if params[:q] && params[:q].lstrip.rstrip != ""
|
||||
scope = Principal.active.sorted.not_member_of_org(org).like(params[:q])
|
||||
else
|
||||
scope = []
|
||||
end
|
||||
principals = paginateHelper scope,10
|
||||
s = content_tag('ul', project_member_check_box_tags_ex('membership[user_ids][]', principals), :class => 'mb5', :id => 'principals')
|
||||
links = pagination_links_full(@obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true){|text, parameters, options|
|
||||
link_to text, org_member_autocomplete_org_member_index_path(parameters.merge(:q => params[:q],:flag => true,:org=> org, :format => 'js')), :remote => true
|
||||
}
|
||||
s + content_tag('ul', links,:class => 'wlist',:style=>'float:left !important', :id => "org_member_pagination_links" )
|
||||
end
|
||||
end
|
|
@ -0,0 +1,2 @@
|
|||
module OrgProjectsHelper
|
||||
end
|
|
@ -0,0 +1,2 @@
|
|||
module OrgSubfieldsHelper
|
||||
end
|
|
@ -1,2 +1,22 @@
|
|||
module EnterprisesHelper
|
||||
# encoding: utf-8
|
||||
module OrganizationsHelper
|
||||
include ApplicationHelper
|
||||
|
||||
|
||||
def find_user_not_in_current_org_by_name org
|
||||
if params[:q] && params[:q].lstrip.rstrip != ""
|
||||
scope = Principal.active.sorted.not_member_of_org(org).like(params[:q])
|
||||
else
|
||||
scope = []
|
||||
end
|
||||
principals = paginateHelper scope,10
|
||||
s = content_tag('ul', project_member_check_box_tags_ex('membership[user_ids][]', principals), :class => 'mb5', :id => 'principals')
|
||||
links = pagination_links_full(@obj_pages, @obj_count, :per_page_links => false, :remote => false, :flag => true){|text, parameters, options|
|
||||
link_to text, org_member_autocomplete_org_member_index_path( parameters.merge(:q => params[:q],:flag => true,:org=>org, :format => 'js')), :remote => true
|
||||
}
|
||||
s + content_tag('ul', links,:class => 'wlist',:style=>'float:left !important', :id => "org_member_pagination_links" )
|
||||
end
|
||||
|
||||
|
||||
|
||||
end
|
||||
|
|
|
@ -27,6 +27,20 @@ module RepositoriesHelper
|
|||
REPO_IP_ADDRESS = Setting.host_repository
|
||||
REPO_GITLAB_ADDRESS = "git.trustie.net"
|
||||
|
||||
# 某个成员不能拥有同名版本库,不同的成员可以创建同名版本库
|
||||
def is_sigle_identifier?(user_id, iden)
|
||||
projects = Project.where("user_id =?",user_id)
|
||||
identifiers = []
|
||||
projects.each do |project|
|
||||
# 只针对gitlab类型的,git类型的后期清掉
|
||||
repository = Repository.where("project_id =? and type =?", project.id, "Repository::Gitlab").first
|
||||
if repository
|
||||
identifiers << repository.identifier
|
||||
end
|
||||
end
|
||||
identifiers.include?(iden) ? false :true
|
||||
end
|
||||
|
||||
def format_revision(revision)
|
||||
if revision.respond_to? :format_identifier
|
||||
revision.format_identifier
|
||||
|
@ -47,7 +61,7 @@ module RepositoriesHelper
|
|||
|
||||
def user_commit_rep(mail)
|
||||
user = User.find_by_mail(mail)
|
||||
user.nil? ? User.find(2) : User.find_by_mail(mail)
|
||||
#user.nil? ? User.find(2) : User.find_by_mail(mail)
|
||||
end
|
||||
|
||||
def render_properties(properties)
|
||||
|
|
|
@ -560,4 +560,5 @@ class Attachment < ActiveRecord::Base
|
|||
self.course_acts << CourseActivity.new(:user_id => self.author_id,:course_id => self.container_id)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -35,7 +35,7 @@ class Comment < ActiveRecord::Base
|
|||
belongs_to :author, :class_name => 'User', :foreign_key => 'author_id'
|
||||
validates_presence_of :commented, :author, :comments
|
||||
safe_attributes 'comments'
|
||||
after_create :send_mail, :act_as_system_message
|
||||
after_create :send_mail, :act_as_system_message, :act_as_student_score
|
||||
|
||||
def act_as_system_message
|
||||
if self.commented.course
|
||||
|
@ -66,13 +66,24 @@ class Comment < ActiveRecord::Base
|
|||
def set_notify_id(notify_id)
|
||||
@notify_id= notify_id
|
||||
end
|
||||
|
||||
def get_notify_id()
|
||||
return @notify_id
|
||||
end
|
||||
|
||||
def set_notify_is_read(notify_is_read)
|
||||
@notify_is_read = notify_is_read
|
||||
end
|
||||
|
||||
def get_notify_is_read()
|
||||
return @notify_is_read
|
||||
end
|
||||
|
||||
# 课程成员得分(英雄榜)
|
||||
def act_as_student_score
|
||||
unless self.author.allowed_to?(:as_teacher, self.commented.course)
|
||||
course_member_score(self.commented.course.id, self.author_id, "NewReply")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -18,6 +18,8 @@ class Course < ActiveRecord::Base
|
|||
:conditions => "#{Principal.table_name}.type='Group' OR (#{Principal.table_name}.type='User' AND #{Principal.table_name}.status=#{Principal::STATUS_ACTIVE})"
|
||||
has_many :principals, :through => :member_principals, :source => :principal
|
||||
has_many :users, :through => :members
|
||||
has_many :org_courses, :dependent => :destroy
|
||||
has_many :organizations, :through => :org_courses
|
||||
# has_many :homeworks, :through => :homework_for_courses, :source => :bid, :dependent => :destroy
|
||||
has_many :journals_for_messages, :as => :jour, :dependent => :destroy
|
||||
# has_many :homework_for_courses, :dependent => :destroy
|
||||
|
@ -38,7 +40,10 @@ class Course < ActiveRecord::Base
|
|||
|
||||
has_many :course_activities
|
||||
# 课程消息
|
||||
has_many :course_messages, :class_name =>'CourseMessage', :as => :course_message, :dependent => :destroy
|
||||
has_many :course_messages, :class_name =>'CourseMessage', :as => :course_message, :dependent => :destroy
|
||||
has_many :exercises, :dependent => :destroy
|
||||
# 课程贡献榜
|
||||
has_many :course_contributor_scores, :dependent => :destroy
|
||||
|
||||
acts_as_taggable
|
||||
acts_as_nested_set :order => 'name', :dependent => :destroy
|
||||
|
|
|
@ -5,8 +5,8 @@ class CourseActivity < ActiveRecord::Base
|
|||
belongs_to :course
|
||||
belongs_to :user
|
||||
has_many :user_acts, :class_name => 'UserAcivity',:as =>:act
|
||||
after_save :add_user_activity
|
||||
before_destroy :destroy_user_activity
|
||||
after_save :add_user_activity, :add_course_activity
|
||||
before_destroy :destroy_user_activity, :destroy_org_activity
|
||||
|
||||
#在个人动态里面增加当前动态
|
||||
def add_user_activity
|
||||
|
@ -30,8 +30,34 @@ class CourseActivity < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def add_course_activity
|
||||
org_activity = OrgActivity.where("org_act_type = '#{self.course_act_type.to_s}' and org_act_id = '#{self.course_act_id}'").first
|
||||
if org_activity
|
||||
org_activity.save
|
||||
else
|
||||
if self.course_act_type == 'Message' && !self.course_act.parent_id.nil?
|
||||
org_activity = OrgActivity.where("org_act_type = 'Message' and org_act_id = #{self.course_act.parent.id}").first
|
||||
org_activity.created_at = self.created_at
|
||||
org_activity.save
|
||||
else
|
||||
OrgActivity.create(:user_id => self.user_id,
|
||||
:org_act_id => self.course_act_id,
|
||||
:org_act_type => self.course_act_type,
|
||||
:container_id => self.course_id,
|
||||
:container_type => 'Course',
|
||||
:created_at => self.created_at,
|
||||
:updated_at => self.updated_at)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def destroy_user_activity
|
||||
user_activity = UserActivity.where("act_type = '#{self.course_act_type.to_s}' and act_id = '#{self.course_act_id}'")
|
||||
user_activity.destroy_all
|
||||
end
|
||||
|
||||
def destroy_org_activity
|
||||
org_activity = OrgActivity.where("org_act_type = '#{self.course_act_type.to_s}' and org_act_id = '#{self.course_act_id}'")
|
||||
org_activity.destroy_all
|
||||
end
|
||||
end
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class CourseContributorScore < ActiveRecord::Base
|
||||
attr_accessible :course_id, :journal_num, :journal_reply_num, :message_num, :message_reply_num, :news_reply_num, :resource_num, :user_id, :total_score
|
||||
belongs_to :course
|
||||
belongs_to :user
|
||||
end
|
|
@ -0,0 +1,4 @@
|
|||
class EditorOfDocument < ActiveRecord::Base
|
||||
belongs_to :user, :class_name => 'User', :foreign_key => 'editor_id'
|
||||
belongs_to :org_document_comment
|
||||
end
|
|
@ -0,0 +1,8 @@
|
|||
class Exercise < ActiveRecord::Base
|
||||
#exercise_status: 1,新建;2,发布;3,关闭
|
||||
include Redmine::SafeAttributes
|
||||
belongs_to :user
|
||||
has_many :exercise_questions, :dependent => :destroy,:order => "#{ExerciseQuestion.table_name}.question_number"
|
||||
has_many :exercise_users, :dependent => :destroy
|
||||
has_many :users, :through => :exercise_users #该测试被哪些用户提交答案过
|
||||
end
|
|
@ -0,0 +1,8 @@
|
|||
class ExerciseAnswer < ActiveRecord::Base
|
||||
#学生答题
|
||||
include Redmine::SafeAttributes
|
||||
|
||||
belongs_to :user
|
||||
belongs_to :exercise_question
|
||||
belongs_to :exercise_choice
|
||||
end
|
|
@ -0,0 +1,7 @@
|
|||
class ExerciseChoice < ActiveRecord::Base
|
||||
include Redmine::SafeAttributes
|
||||
|
||||
belongs_to :exercise_question
|
||||
has_many :exercise_answers, :dependent => :destroy
|
||||
has_many :exercise_standard_answers, :dependent => :destroy
|
||||
end
|
|
@ -0,0 +1,8 @@
|
|||
class ExerciseQuestion < ActiveRecord::Base
|
||||
include Redmine::SafeAttributes
|
||||
|
||||
belongs_to :exercise
|
||||
has_many :exercise_choices, :order => "#{ExerciseChoice.table_name}.choice_position",:dependent => :destroy
|
||||
has_many :exercise_answers, :dependent => :destroy
|
||||
has_many :exercise_standard_answers, :dependent => :destroy
|
||||
end
|
|
@ -0,0 +1,7 @@
|
|||
class ExerciseStandardAnswer < ActiveRecord::Base
|
||||
#标准答案
|
||||
include Redmine::SafeAttributes
|
||||
|
||||
belongs_to :exercise_question
|
||||
belongs_to :exercise_choice
|
||||
end
|
|
@ -0,0 +1,6 @@
|
|||
class ExerciseUser < ActiveRecord::Base
|
||||
include Redmine::SafeAttributes
|
||||
|
||||
belongs_to :user
|
||||
belongs_to :exercise
|
||||
end
|
|
@ -20,8 +20,8 @@ class ForgeActivity < ActiveRecord::Base
|
|||
validates :forge_act_id,presence: true
|
||||
validates :forge_act_type, presence: true
|
||||
has_many :user_acts, :class_name => 'UserAcivity',:as =>:act
|
||||
after_save :add_user_activity
|
||||
before_destroy :destroy_user_activity
|
||||
after_save :add_user_activity, :add_org_activity
|
||||
before_destroy :destroy_user_activity, :destroy_org_activity
|
||||
|
||||
#在个人动态里面增加当前动态
|
||||
def add_user_activity
|
||||
|
@ -45,8 +45,31 @@ class ForgeActivity < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def add_org_activity
|
||||
if self.forge_act_type == 'Message' && !self.forge_act.parent_id.nil?
|
||||
org_activity = OrgActivity.where("org_act_type = 'Message' and org_act_id = #{self.forge_act.parent.id}").first
|
||||
if org_activity
|
||||
org_activity.created_at = self.created_at
|
||||
org_activity.save
|
||||
end
|
||||
else
|
||||
OrgActivity.create(:user_id => self.user_id,
|
||||
:org_act_id => self.forge_act_id,
|
||||
:org_act_type => self.forge_act_type,
|
||||
:container_id => self.project_id,
|
||||
:container_type => 'Project',
|
||||
:created_at => self.created_at,
|
||||
:updated_at => self.updated_at)
|
||||
end
|
||||
end
|
||||
|
||||
def destroy_user_activity
|
||||
user_activity = UserActivity.where("act_type = '#{self.forge_act_type.to_s}' and act_id = '#{self.forge_act_id}'")
|
||||
user_activity.destroy_all
|
||||
end
|
||||
|
||||
def destroy_org_activity
|
||||
org_acts = OrgActivity.where("org_act_type='#{self.forge_act_type.to_s}' and org_act_id = '#{self.forge_act_id}'")
|
||||
org_acts.destroy_all
|
||||
end
|
||||
end
|
||||
|
|
|
@ -64,7 +64,7 @@ class JournalsForMessage < ActiveRecord::Base
|
|||
has_many :user_feedback_messages, :class_name => 'UserFeedbackMessage', :as =>:journals_for_message, :dependent => :destroy
|
||||
|
||||
validates :notes, presence: true, if: :is_homework_jour?
|
||||
after_create :act_as_activity, :act_as_course_activity, :act_as_course_message, :act_as_user_feedback_message, :act_as_principal_activity
|
||||
after_create :act_as_activity, :act_as_course_activity, :act_as_course_message, :act_as_user_feedback_message, :act_as_principal_activity, :act_as_student_score
|
||||
after_create :reset_counters!
|
||||
after_destroy :reset_counters!
|
||||
after_save :be_user_score
|
||||
|
@ -263,4 +263,12 @@ class JournalsForMessage < ActiveRecord::Base
|
|||
|
||||
end
|
||||
end
|
||||
|
||||
# 课程成员得分(英雄榜)
|
||||
def act_as_student_score
|
||||
unless self.user.allowed_to?(:as_teacher, self.jour)
|
||||
course_member_score(self.jour_id, self.user_id, "JournalForMessage")
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -74,7 +74,7 @@ class Message < ActiveRecord::Base
|
|||
after_update :update_messages_board
|
||||
after_destroy :reset_counters!,:down_user_score,:delete_kindeditor_assets
|
||||
|
||||
after_create :act_as_activity,:act_as_course_activity,:be_user_score,:act_as_forge_activity, :act_as_system_message, :send_mail
|
||||
after_create :act_as_activity,:act_as_course_activity,:be_user_score,:act_as_forge_activity, :act_as_system_message, :send_mail, :act_as_student_score
|
||||
#before_save :be_user_score
|
||||
|
||||
scope :visible, lambda {|*args|
|
||||
|
@ -285,4 +285,16 @@ class Message < ActiveRecord::Base
|
|||
delete_kindeditor_assets_from_disk self.id,OwnerTypeHelper::MESSAGE
|
||||
end
|
||||
|
||||
# 课程成员得分(英雄榜)
|
||||
def act_as_student_score
|
||||
unless self.author.allowed_to?(:as_teacher, self.course)
|
||||
if self.parent_id.nil?
|
||||
# 发帖
|
||||
course_member_score(self.course.id, self.author_id, "Message")
|
||||
else
|
||||
# 回帖
|
||||
course_member_score(self.course.id, self.author_id, "MessageReply")
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
|
|
@ -66,7 +66,7 @@ class News < ActiveRecord::Base
|
|||
scope :course_visible, lambda {|*args|
|
||||
includes(:course).where(Course.allowed_to_condition(args.shift || User.current, :view_course_news, *args))
|
||||
}
|
||||
safe_attributes 'title', 'summary', 'description'
|
||||
safe_attributes 'title', 'summary', 'description', 'sticky'
|
||||
|
||||
def visible?(user=User.current)
|
||||
!user.nil? && user.allowed_to?(:view_news, project)
|
||||
|
|
|
@ -0,0 +1,5 @@
|
|||
class OrgActivity < ActiveRecord::Base
|
||||
# attr_accessible :title, :body
|
||||
belongs_to :org_act ,:polymorphic => true
|
||||
belongs_to :container,:polymorphic => true
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
class OrgCourse < ActiveRecord::Base
|
||||
#attr_accessible :organization, :course, :created_at
|
||||
belongs_to :organization
|
||||
belongs_to :course
|
||||
end
|
|
@ -0,0 +1,20 @@
|
|||
class OrgDocumentComment < ActiveRecord::Base
|
||||
attr_accessible :content, :creator_id, :organization_id, :parent_id, :reply_id, :title,:sticky,:locked
|
||||
include Redmine::SafeAttributes
|
||||
belongs_to :organization
|
||||
belongs_to :creator, :class_name => 'User', :foreign_key => 'creator_id'
|
||||
has_many :editor_of_documents, :dependent => :destroy
|
||||
acts_as_tree :order => "#{OrgDocumentComment.table_name}.sticky asc, #{OrgDocumentComment.table_name}.created_at desc"
|
||||
has_many :org_acts, :class_name => 'OrgActivity',:as =>:org_act ,:dependent => :destroy
|
||||
after_create :document_save_as_org_activity
|
||||
|
||||
def document_save_as_org_activity
|
||||
if(self.parent().nil?)
|
||||
self.org_acts << OrgActivity.new(:user_id => User.current.id, :container_id => self.organization.id, :container_type => 'Organization')
|
||||
else
|
||||
act = OrgActivity.where("org_act_type='OrgDocumentComment' and org_act_id =?", self.root.id).first
|
||||
act.update_attributes(:updated_at => self.updated_at)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
|
@ -0,0 +1,8 @@
|
|||
class OrgMember < ActiveRecord::Base
|
||||
attr_accessible :organization_id, :role, :user_id
|
||||
belongs_to :organization
|
||||
belongs_to :user
|
||||
has_many :roles ,:through => :org_member_roles,:foreign_key => 'role_id'
|
||||
has_many :org_member_roles,:dependent => :destroy
|
||||
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
class OrgMemberRole < ActiveRecord::Base
|
||||
# attr_accessible :title, :body
|
||||
belongs_to :org_member
|
||||
belongs_to :role
|
||||
end
|
|
@ -0,0 +1,5 @@
|
|||
class OrgProject < ActiveRecord::Base
|
||||
# attr_accessible :title, :body
|
||||
belongs_to :organization
|
||||
belongs_to :project
|
||||
end
|
|
@ -0,0 +1,3 @@
|
|||
class OrgSubfield < ActiveRecord::Base
|
||||
belongs_to :organization, :foreign_key => :organization_id
|
||||
end
|
|
@ -1,5 +1,17 @@
|
|||
class Organization < ActiveRecord::Base
|
||||
attr_accessible :logo_link, :name
|
||||
attr_accessible :name, :description, :creator_id, :home_id, :domain, :is_public
|
||||
has_many :org_members, :dependent => :destroy
|
||||
has_many :org_projects ,:dependent => :destroy
|
||||
has_many :projects,:through => :org_projects
|
||||
has_many :courses, :through => :org_courses
|
||||
has_many :org_document_comments, :dependent => :destroy
|
||||
has_many :org_courses, :dependent => :destroy
|
||||
has_many :org_subfields, :dependent => :destroy
|
||||
has_many :users, :through => :org_members
|
||||
validates_uniqueness_of :name
|
||||
after_create :save_as_org_activity
|
||||
|
||||
has_many :projects
|
||||
def save_as_org_activity
|
||||
OrgActivity.create(:user_id => User.current.id, :org_act_id => self.id, :org_act_type => 'CreateOrganization', :container_id => self.id, :container_type => 'Organization')
|
||||
end
|
||||
end
|
||||
|
|
|
@ -87,6 +87,16 @@ class Principal < ActiveRecord::Base
|
|||
end
|
||||
}
|
||||
|
||||
scope :not_member_of_org, lambda {|org|
|
||||
orgs = [org] unless org.is_a?(Array)
|
||||
if orgs.empty?
|
||||
where("1=0")
|
||||
else
|
||||
ids = orgs.map(&:id)
|
||||
where("#{Principal.table_name}.id NOT IN (SELECT DISTINCT user_id FROM #{OrgMember.table_name} WHERE organization_id IN (?))", ids)
|
||||
end
|
||||
}
|
||||
|
||||
scope :sorted, lambda { order(*Principal.fields_for_order_statement)}
|
||||
|
||||
scope :applied_members, lambda {|project|
|
||||
|
|
|
@ -69,6 +69,7 @@ class Project < ActiveRecord::Base
|
|||
has_many :applied_projects, :dependent => :destroy
|
||||
has_many :invite_lists, :dependent => :destroy
|
||||
has_one :dts
|
||||
has_many :organizations,:through => :org_projects
|
||||
|
||||
# end
|
||||
#ADDED BY NIE
|
||||
|
@ -96,7 +97,8 @@ class Project < ActiveRecord::Base
|
|||
# 关联虚拟表
|
||||
has_many :forge_messages, :class_name =>'ForgeMessage', :as => :forge_message, :dependent => :destroy
|
||||
|
||||
belongs_to :organization
|
||||
has_many :org_projects,:dependent => :destroy
|
||||
has_many :organization,:through => :org_projects
|
||||
|
||||
# has_many :journals
|
||||
|
||||
|
|
|
@ -40,7 +40,8 @@ class Repository < ActiveRecord::Base
|
|||
validates_length_of :identifier, :maximum => IDENTIFIER_MAX_LENGTH, :allow_blank => true
|
||||
validates_presence_of :identifier#, :unless => Proc.new { |r| r.is_default? || r.set_as_default? }
|
||||
#validates_uniqueness_of :identifier, :scope => :project_id, :allow_blank => true
|
||||
validates_uniqueness_of :identifier, :allow_blank => true
|
||||
# 改成同一用户不能有两个相同名字的版本库
|
||||
# validates_uniqueness_of :identifier, :allow_blank => true
|
||||
validates_exclusion_of :identifier, :in => %w(show entry raw changes annotate diff show stats graph)
|
||||
# donwcase letters, digits, dashes, underscores but not digits only
|
||||
validates_format_of :identifier, :with => /^[a-z0-9_\-]+$/, :allow_blank => true
|
||||
|
@ -52,7 +53,8 @@ class Repository < ActiveRecord::Base
|
|||
'password',
|
||||
'path_encoding',
|
||||
'log_encoding',
|
||||
'is_default'
|
||||
'is_default',
|
||||
'type'
|
||||
|
||||
safe_attributes 'url',
|
||||
:if => lambda {|repository, user| repository.new_record?}
|
||||
|
@ -63,6 +65,10 @@ class Repository < ActiveRecord::Base
|
|||
end
|
||||
|
||||
def repo_create_validation
|
||||
# 之所以可以这样改,是因为Fork的时候不需要从Trustie创建版本库,只需从Gitlab关联即可
|
||||
if self.class.name.demodulize == "Repository"
|
||||
return
|
||||
end
|
||||
unless Setting.enabled_scm.include?(self.class.name.demodulize)
|
||||
errors.add(:type, :invalid)
|
||||
end
|
||||
|
|
|
@ -55,6 +55,8 @@ class Role < ActiveRecord::Base
|
|||
|
||||
has_many :member_roles, :dependent => :destroy
|
||||
has_many :members, :through => :member_roles
|
||||
has_many :org_member_roles, :dependent => :destroy
|
||||
has_many :org_members,:through => :org_member_roles
|
||||
acts_as_list
|
||||
|
||||
serialize :permissions, ::Role::PermissionsAttributeCoder
|
||||
|
|
|
@ -81,6 +81,12 @@ class User < Principal
|
|||
has_many :poll, :dependent => :destroy #用户创建的问卷
|
||||
has_many :answers, :source => :poll, :through => :poll_users, :dependent => :destroy #用户已经完成问答的问卷
|
||||
# end
|
||||
#在线测验相关关系
|
||||
has_many :exercise_user, :dependent => :destroy #答卷中间表
|
||||
has_many :exercise_answer, :dependent => :destroy #针对每个题目学生的答案
|
||||
has_many :exercises, :dependent => :destroy #创建的试卷
|
||||
has_many :exercises_answers, :source => :exercise, :through => :exercise_user, :dependent => :destroy #用户已经完成问答的试卷
|
||||
#end
|
||||
#作业相关关系
|
||||
has_many :homework_commons, :dependent => :destroy
|
||||
has_many :student_works, :dependent => :destroy
|
||||
|
@ -94,8 +100,11 @@ class User < Principal
|
|||
has_one :preference, :dependent => :destroy, :class_name => 'UserPreference'
|
||||
has_one :rss_token, :class_name => 'Token', :conditions => "action='feeds'"
|
||||
has_one :blog, :class_name => 'Blog', :foreign_key => "author_id"
|
||||
has_many :org_document_comments, :dependent =>:destroy
|
||||
has_one :api_token, :class_name => 'Token', :conditions => "action='api'"
|
||||
belongs_to :auth_source
|
||||
has_many :org_members
|
||||
has_many :organizations, :through => :org_members
|
||||
belongs_to :ucourse, :class_name => 'Course', :foreign_key => :id #huang
|
||||
## added by xianbo for delete
|
||||
# has_many :biding_projects, :dependent => :destroy
|
||||
|
@ -144,6 +153,8 @@ class User < Principal
|
|||
# 邮件邀请状态
|
||||
has_many :invite_lists, :dependent => :destroy
|
||||
# end
|
||||
# 课程贡献榜
|
||||
has_many :course_contributor_scores, :dependent => :destroy
|
||||
|
||||
######added by nie
|
||||
has_many :project_infos, :dependent => :destroy
|
||||
|
@ -769,6 +780,21 @@ class User < Principal
|
|||
courses.to_a.include?(course)
|
||||
end
|
||||
|
||||
def member_of_org?(org)
|
||||
OrgMember.where("user_id =? and organization_id =?", self.id, org.id).count > 0
|
||||
end
|
||||
|
||||
def admin_of_org?(org)
|
||||
if OrgMember.where("user_id =? and organization_id =?", self.id, org.id).count == 0
|
||||
return false
|
||||
end
|
||||
role = OrgMember.where("user_id =? and organization_id =?", self.id, org.id)[0].roles[0]
|
||||
unless role.nil?
|
||||
role.name == 'orgManager' ? true : false
|
||||
else
|
||||
false
|
||||
end
|
||||
end
|
||||
def member_of_course_group?(course_group)
|
||||
course_groups.to_a.include?(course_group)
|
||||
end
|
||||
|
|
|
@ -186,6 +186,7 @@ class CoursesService
|
|||
#params[:setup_time]:暂不传(貌似已经没用了)
|
||||
#params[:endup_time]: 暂不传(貌似已经没用了)
|
||||
#params[:class_period]:学时总数
|
||||
#params[:course][:publish_resource]允许学生上传资源
|
||||
def create_course(params,current_user)
|
||||
if current_user.user_extensions.identity
|
||||
@course = Course.new
|
||||
|
@ -202,6 +203,7 @@ class CoursesService
|
|||
@course.class_period = params[:class_period].to_i
|
||||
params[:course][:is_public] ? @course.is_public = 1 : @course.is_public = 0
|
||||
params[:course][:open_student] ? @course.open_student = 1 : @course.open_student = 0
|
||||
params[:course][:publish_resource] ? @course.publish_resource = 1 : @course.publish_resource = 0
|
||||
else
|
||||
|
||||
end
|
||||
|
@ -243,6 +245,7 @@ class CoursesService
|
|||
#params[:term]:学期(秋季学期或春季学期)
|
||||
#params[:time]: 年份(例:2014)
|
||||
#params[:class_period]:学时总数
|
||||
#params[:publish_resource] 允许学生上传资源 0 不允许 1 允许
|
||||
def edit_course(params,course,current_user)
|
||||
course.send(:safe_attributes=, params[:course], current_user)
|
||||
#course.safe_attributes = params[:course]
|
||||
|
@ -251,6 +254,7 @@ class CoursesService
|
|||
course.class_period = params[:class_period].to_i
|
||||
params[:course][:is_public] ? course.is_public = 1 : course.is_public = 0
|
||||
params[:course][:open_student] ? course.open_student = 1 : course.open_student = 0
|
||||
params[:course][:publish_resource] ? course.publish_resource = 1 : course.publish_resource = 0
|
||||
if course.save
|
||||
if params[:course][:is_public] == '0'
|
||||
course_status = CourseStatus.find_by_course_id(course.id)
|
||||
|
|
|
@ -62,6 +62,7 @@
|
|||
:field_is_public => l(:field_is_public),
|
||||
:are_you_sure => l(:text_are_you_sure),
|
||||
:file_count => l(:label_file_count),
|
||||
:lebel_file_uploding => l(:lebel_file_uploding),
|
||||
:delete_all_files => l(:text_are_you_sure_all)
|
||||
} %>
|
||||
<span id="upload_file_count">
|
||||
|
|
|
@ -60,7 +60,9 @@
|
|||
:field_is_public => l(:field_is_public),
|
||||
:are_you_sure => l(:text_are_you_sure),
|
||||
:file_count => l(:label_file_count),
|
||||
:delete_all_files => l(:text_are_you_sure_all)
|
||||
:delete_all_files => l(:text_are_you_sure_all),
|
||||
:lebel_file_uploding => l(:lebel_file_uploding),
|
||||
:containerid => "#{container.id}"
|
||||
} %>
|
||||
<% if container.nil? %>
|
||||
<span id="upload_file_count" :class="c_grey"><%= l(:label_no_file_uploaded)%></span>
|
||||
|
|
|
@ -60,7 +60,9 @@
|
|||
:field_is_public => l(:field_is_public),
|
||||
:are_you_sure => l(:text_are_you_sure),
|
||||
:file_count => l(:label_file_count),
|
||||
:lebel_file_uploding => l(:lebel_file_uploding),
|
||||
:delete_all_files => l(:text_are_you_sure_all),
|
||||
:lebel_file_uploding => l(:lebel_file_uploding),
|
||||
:containerid => "#{container.id}"
|
||||
} %>
|
||||
<span id="upload_file_count<%=container.id %>" :class="c_grey"><%= l(:label_no_file_uploaded)%></span>
|
||||
|
|
|
@ -42,6 +42,7 @@
|
|||
:field_is_public => l(:field_is_public),
|
||||
:are_you_sure => l(:text_are_you_sure),
|
||||
:file_count => l(:label_file_count),
|
||||
:lebel_file_uploding => l(:lebel_file_uploding),
|
||||
:delete_all_files => l(:text_are_you_sure_all)
|
||||
} %>
|
||||
<span id="upload_file_count">
|
||||
|
|
|
@ -62,6 +62,7 @@
|
|||
:field_is_public => l(:field_is_public),
|
||||
:are_you_sure => l(:text_are_you_sure),
|
||||
:file_count => l(:label_file_count),
|
||||
:lebel_file_uploding => l(:lebel_file_uploding),
|
||||
:delete_all_files => l(:text_are_you_sure_all)
|
||||
} %>
|
||||
<span id="upload_file_count">
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<div id="new_course_topic">
|
||||
<div class="homepagePostBrief c_grey">
|
||||
<div>
|
||||
<input type="text" value="<%= article.title%>" name="blog_comment[title]" id="message_subject" class="InputBox w713" style="width: 720px !important;" maxlength="255" onkeyup="regexTopicSubject();" placeholder="发布文章,请先输入文章标题" " />
|
||||
<input type="text" value="<%= article.title%>" name="blog_comment[title]" id="message_subject" class="InputBox w713" maxlength="255" onkeyup="regexTopicSubject();" placeholder="发布文章,请先输入文章标题" " />
|
||||
<p id="subjectmsg"></p>
|
||||
</div>
|
||||
<div id="topic_editor" style="display: block;">
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
<div id="new_course_topic">
|
||||
<div class="homepagePostBrief c_grey">
|
||||
<div>
|
||||
<input type="text" name="blog_comment[title]" id="message_subject" class="InputBox w713" style="width: 720px !important;" maxlength="255" onfocus="$('#topic_editor').show()" onkeyup="regexTopicSubject();" placeholder="发布文章,请先输入文章标题" " >
|
||||
<input type="text" name="blog_comment[title]" id="message_subject" class="InputBox w713" maxlength="255" onfocus="$('#topic_editor').show()" onkeyup="regexTopicSubject();" placeholder="发布文章,请先输入文章标题" " >
|
||||
<p id="subjectmsg"></p>
|
||||
</div>
|
||||
<div id="topic_editor" style="display: none;">
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
showNormalImage('message_description_<%= @article.id %>');
|
||||
});
|
||||
</script>
|
||||
<div class="postRightContainer ml10" onmouseover="$('#message_setting_<%= @article.id%>').show();" onmouseout="$('#message_setting_<%= @article.id%>').hide();">
|
||||
<div class="postRightContainer" onmouseover="$('#message_setting_<%= @article.id%>').show();" onmouseout="$('#message_setting_<%= @article.id%>').hide();">
|
||||
<div class="postThemeContainer">
|
||||
<div class="postDetailPortrait">
|
||||
<%= link_to image_tag(url_to_avatar(@article.author),:width=>50,:height => 50,:alt=>'图像' ),user_path(@article.author) %>
|
||||
|
@ -165,7 +165,7 @@
|
|||
<%= form_for :blog_comment, :url => {:action => 'reply',:controller => 'blog_comments',:user_id=>@article.author.id,:blog_id=>@article.blog_id, :id => @article.id}, :html => {:multipart => true, :id => 'message_form'} do |f| %>
|
||||
<%= render :partial => 'blog_comments/reply_form', :locals => {:f => f,:user=>@user,:article=>@article} %>
|
||||
<%= link_to l(:button_cancel), "javascript:void(0)", :onclick => 'message_content_editor.html("");', :class => " grey_btn fr c_white mt10 mr5" %>
|
||||
<%= link_to l(:button_submit), "javascript:void(0)", :onclick => 'submit_message_replay();', :class => "blue_btn fr c_white mt10", :style => "margin-right: 5px;" %>
|
||||
<%= link_to l(:button_submit), "javascript:void(0)", :onclick => 'submit_message_replay();', :class => "blue_btn fr c_white mt10 mb10", :style => "margin-right: 5px;" %>
|
||||
<% end %>
|
||||
<div class="cl"></div>
|
||||
</div>
|
||||
|
|
|
@ -32,7 +32,7 @@
|
|||
<%#end%>
|
||||
</script>
|
||||
|
||||
<div class="homepageRight mt0 ml10">
|
||||
<div class="homepageRight mt0">
|
||||
<div class="homepageRightBanner">
|
||||
<div class="NewsBannerName">
|
||||
<%= @user.name%>的博客
|
||||
|
|
|
@ -1,3 +1,6 @@
|
|||
<% if @course %>
|
||||
$("#user_activity_<%= @user_activity_id%>").replaceWith("<%= escape_javascript(render :partial => 'users/course_news', :locals => {:activity => @news,:user_activity_id =>@user_activity_id}) %>");
|
||||
|
||||
<% else %>
|
||||
$("#user_activity_<%= @user_activity_id%>").replaceWith("<%= escape_javascript(render :partial => 'projects/project_news', :locals => {:activity => @news,:user_activity_id =>@user_activity_id}) %>");
|
||||
<% end %>
|
||||
init_activity_KindEditor_data('<%= @user_activity_id%>',"","87%");
|
||||
|
|
|
@ -0,0 +1,47 @@
|
|||
<% course_file_num = visable_attachemnts_incourse(@course).count%>
|
||||
<% is_teacher = User.current.logged? && (User.current.admin? || User.current.allowed_to?(:as_teacher,@course)) %>
|
||||
<% if show_nav?(@course.homework_commons.count) %>
|
||||
<div class="subNav">
|
||||
<%= link_to l(:label_homework), homework_common_index_path(:course => @course.id), :class => "f14 c_blue02 ml10"%>
|
||||
<%= link_to( "", homework_common_index_path(:course => @course.id,:is_new => 1), :class => 'courseMenuSetting', :title =>"#{l(:label_course_homework_new)}") if is_teacher %>
|
||||
</div>
|
||||
<% end %>
|
||||
<% if show_nav?(@course.news.count) %>
|
||||
<div class="subNav">
|
||||
<%= link_to l(:label_course_news), course_news_index_path(@course), :class => "f14 c_blue02 ml10" %>
|
||||
<%= link_to( "", new_course_news_path(@course), :class => 'courseMenuSetting', :title =>"#{l(:label_course_news_new)}") if is_teacher %>
|
||||
</div>
|
||||
<% end %>
|
||||
<% if show_nav?(course_file_num) %>
|
||||
<div class="subNav">
|
||||
<%= link_to l(:label_course_file), course_files_path(@course), :class => "f14 c_blue02 ml10" %>
|
||||
<% if is_teacher || (@course.publish_resource == 1 && User.current.member_of_course?(@course)) %>
|
||||
<!--link_to( "+#{l(:label_upload_files)}", course_files_path(@course), :class => 'subnav_green ml95 c_white')-->
|
||||
<a class="courseMenuSetting" title="上传资源" href="javascript:void(0);" onclick="course_files_upload();"> </a>
|
||||
<% end %>
|
||||
</div>
|
||||
<% end %>
|
||||
<% if show_nav?(@course.boards.first ? @course.boards.first.topics.count : 0) %>
|
||||
<div class="subNav">
|
||||
<%= link_to l(:label_course_board), course_boards_path(@course), :class => "f14 c_blue02 ml10" %>
|
||||
<%= link_to( "",course_boards_path(@course, :flag => true, :is_new => 1), :class => 'courseMenuSetting', :title =>"#{l(:label_message_new)}") if User.current.member_of_course?(@course) && @course.boards.first %>
|
||||
</div>
|
||||
<% end %>
|
||||
<% if show_nav?(course_feedback_count) %>
|
||||
<div class="subNav">
|
||||
<%= link_to l(:label_course_feedback), course_feedback_path(@course), :class => "f14 c_blue02 ml10" %>
|
||||
<%= link_to "", course_feedback_path(@course), :class => 'courseMenuSetting', :title =>"#{l(:label_course_feedback)}", :id => "course_jour_count"%>
|
||||
</div>
|
||||
<% end %>
|
||||
<% if show_nav?(course_poll_count) %>
|
||||
<div class="subNav">
|
||||
<%= link_to l(:label_poll), poll_index_path(:polls_type => "Course", :polls_group_id => @course.id), :class => " f14 c_blue02 ml10"%>
|
||||
<%= link_to( "", new_poll_path(:polls_type => "Course",:polls_group_id => @course.id), :class => 'courseMenuSetting', :title =>"#{l(:label_new_poll)}") if is_teacher %>
|
||||
</div>
|
||||
<% end %>
|
||||
<% if show_nav?(User.current.allowed_to?(:as_teacher,@course)? @course.exercises.count : @course.exercises.where("exercise_status=2").count) %>
|
||||
<div class="subNav">
|
||||
<%= link_to "在线测验", exercise_index_path(:course_id => @course.id), :class => " f14 c_blue02 ml10"%>
|
||||
<%= link_to( "", new_exercise_path(:course_id => @course.id), :class => 'courseMenuSetting', :title =>"新建试卷") if is_teacher %>
|
||||
</div>
|
||||
<% end %>
|
|
@ -50,6 +50,12 @@
|
|||
<span class="c_grey">(打钩为"学生列表公开",不打钩为不公开,若不公开,则课程外部人员看不到学生列表)</span>
|
||||
<div class="cl"></div>
|
||||
</li>
|
||||
<li class=" mb5 ml30">
|
||||
<label >学生上传资源 :</label>
|
||||
<input <%= @course.publish_resource == 1 ? 'checked' : ''%> id="course_publish_resource" name="course[publish_resource]" type="checkbox" />
|
||||
<span class="c_grey">(打钩为"允许学生上传资源",不打钩为"不允许学生上传资源")</span>
|
||||
<div class="cl"></div>
|
||||
</li>
|
||||
<li class=" ml90" >
|
||||
<a href="javascript:void(0)" class="blue_btn fl c_white" onclick="submit_new_course();" >提交</a>
|
||||
<%= link_to "取消",user_activities_path(User.current.id),:class => "blue_btn grey_btn fl c_white"%>
|
||||
|
|
|
@ -0,0 +1,19 @@
|
|||
<% if @hint_flag.nil? %>
|
||||
if($("#join_orgs_for_course input:checked").size() > 0)
|
||||
{
|
||||
alert("翻页或搜索后将丢失当前选择的用户数据");
|
||||
}
|
||||
<% end %>
|
||||
$("#search_orgs_result_list").html("");
|
||||
$("#search_orgs_result_list").append('<ul class="ml20">');
|
||||
<% @orgs_not_in_course.each do |org|%>
|
||||
link = "<li><label><input type='checkbox'class='mr5 fl mt3' name='orgNames[]' value='<%=org.id%>'/><span class='relateOrgName fl'> <%=org.name %> </span></label></li><div class='cl mt5'></div>";
|
||||
$("#search_orgs_result_list").append(link );
|
||||
<%end %>
|
||||
$("#search_orgs_result_list").append('</ul>')
|
||||
<% if @org_count > 10 %>
|
||||
$("#paginator").html(' <%= pagination_links_full @orgs_page, @org_count ,:per_page_links => true,:remote =>true,:flag=>true%>');
|
||||
$("#paginator").css("display", "block");
|
||||
<% else %>
|
||||
$("#paginator").css("display", "none");
|
||||
<% end %>
|
|
@ -10,6 +10,9 @@
|
|||
<li id="tb_2" class="hwork_normaltab" onclick="course_setting(2);">
|
||||
成员
|
||||
</li>
|
||||
<li id="tb_3" class="hwork_normaltab" onclick="course_setting(3);">
|
||||
组织
|
||||
</li>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="hwork_dis" id="tbc_01" style="padding-top: 10px;">
|
||||
|
@ -65,6 +68,12 @@
|
|||
<span class="c_grey">(打钩为"学生列表公开",不打钩为不公开,若不公开,则课程外部人员看不到学生列表)</span>
|
||||
<div class="cl"></div>
|
||||
</li>
|
||||
<li class=" mb5 ml30">
|
||||
<label >学生上传资源 :</label>
|
||||
<input <%= @course.publish_resource == 1 ? 'checked' : ''%> id="course_publish_resource" name="course[publish_resource]" type="checkbox" style="margin-left: 1px;"/>
|
||||
<span class="c_grey">(打钩为"允许学生上传资源",不打钩为"不允许学生上传资源")</span>
|
||||
<div class="cl"></div>
|
||||
</li>
|
||||
<li class=" ml90" >
|
||||
<a href="javascript:void(0)" class="blue_btn fl c_white" onclick="submit_edit_course(<%= @course.id%>);" >提交</a>
|
||||
<%= link_to l(:button_cancel), course_path(@course), :class => "blue_btn grey_btn fl c_white" %>
|
||||
|
@ -91,6 +100,10 @@
|
|||
<%= render :partial => "course_members" %>
|
||||
</div>
|
||||
</div><!---成员结束-->
|
||||
|
||||
<div class="hwork_undis" id="tbc_03">
|
||||
<%= render :partial => 'courses/settings/join_org' %>
|
||||
</div>
|
||||
</div><!--talknew end-->
|
||||
<div class="cl"></div>
|
||||
<script type="text/javascript">
|
||||
|
@ -105,4 +118,4 @@
|
|||
}
|
||||
$("#time_selected").click(select);
|
||||
$("#term_selected").click(select);
|
||||
</script>
|
||||
</script>
|
||||
|
|
|
@ -0,0 +1,12 @@
|
|||
<ul>
|
||||
<li><span class="relatedListName fb fl">名称</span><span class="relatedListOption fb fl">操作</span></li>
|
||||
<% orgs.each do |org| %>
|
||||
<li>
|
||||
<a href="<%= organization_path(org) %>" class="relatedListName linkBlue fl"><%= org.name %></a>
|
||||
<a href="javascript:void(0);" onclick="cancel_org_course_relation(<%= OrgCourse.where(:organization_id => org.id, :course_id => course_id).first.id %>, '<%= course_id %>');"
|
||||
class = "relatedListOption fl linkGrey3">取消关联</a>
|
||||
<%#= link_to "取消关联", org_course_path(:id => OrgCourse.where(:organization_id => org.id, :course_id => course_id).first.id, :course_id => course_id),
|
||||
:method => 'delete',:remote => true, :class => "relatedListOption fl linkGrey3" %>
|
||||
</li>
|
||||
<% end %>
|
||||
</ul>
|
|
@ -0,0 +1,85 @@
|
|||
<!--<div class="members_left">-->
|
||||
<!--<input type="text" id="orgs_not_course_member_search" name="orgAddSearch" placeholder="支持姓名、邮箱、昵称搜索" class="orgAddSearch mb20" />-->
|
||||
<!--<%#= javascript_tag "observeSearchfield('orgs_not_course_member_search', null, '#{ escape_javascript autocomplete_search_organizations_path(:course_id=> @course.id, :format => 'js') }')" %>-->
|
||||
<!--<div id="new_orgs_for_course">-->
|
||||
|
||||
<!--</div>-->
|
||||
<!--</div>-->
|
||||
<%= stylesheet_link_tag 'org' %>
|
||||
|
||||
<div>
|
||||
<div class="relateOrg fl">
|
||||
<span class="pic_add fl mr5 mt3"></span><span class="f14 fontBlue fl">关联组织</span>
|
||||
<div class="cl mb5"></div>
|
||||
<%= form_tag url_for(:controller => 'org_courses', :action => 'create', :course_id => @course.id), :id => 'join_orgs_for_course', :remote => true do %>
|
||||
<input type="text" name="orgs" class="searchOrg mb5 ml20" placeholder="请输入组织名称" />
|
||||
<div id="search_orgs_result_list" class="ml20"></div>
|
||||
<ul id="paginator" class="wlist ml20" style="float:none;"></ul>
|
||||
<a href="javascript:void(0);" class="saveBtn db fl ml20 mr15 mb5" onclick="course_join_org(<%= @course.id %>);">关联</a>
|
||||
<a href="javascript:void(0);" class="cancelBtn db fl" onclick="cancel_join_orgs();">取消</a>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="relatedList fr">
|
||||
<div class="fr mr15">
|
||||
<span class="f14 fontBlue">已关联组织</span>
|
||||
<div id="added_orgs">
|
||||
<%= render :partial => 'courses/settings/added_orgs', :locals => {:orgs => @course.organizations, :course_id => params[:id]} %>
|
||||
</div>
|
||||
<div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script type="text/javascript">
|
||||
var lastSearchCondition = '';
|
||||
var page = 1;
|
||||
var count = 0;
|
||||
var maxPage = 0;
|
||||
function search_orgs(e){
|
||||
if($(e.target).val().trim() == lastSearchCondition && lastSearchCondition != '')
|
||||
{
|
||||
return;
|
||||
}
|
||||
lastSearchCondition = $(e.target).val().trim();
|
||||
page = 1;
|
||||
$.ajax({
|
||||
url: '<%= url_for(:controller => 'courses', :action => 'search_public_orgs_not_in_course') %>'+'?name='+ e.target.value+'&page='+page,
|
||||
type:'get'
|
||||
});
|
||||
}
|
||||
|
||||
function throttle(method,context,e){
|
||||
clearTimeout(method.tId);
|
||||
method.tId=setTimeout(function(){
|
||||
method.call(context,e);
|
||||
},500);
|
||||
}
|
||||
|
||||
//查询组织
|
||||
$("input[name='orgs']").on('input', function (e) {
|
||||
throttle(search_orgs,window,e);
|
||||
});
|
||||
|
||||
$(document).ready(function(){
|
||||
$.ajax({
|
||||
url: '<%= url_for(:controller => 'courses', :action => 'search_public_orgs_not_in_course') %>'+'?page=1',
|
||||
type:'get'
|
||||
});
|
||||
});
|
||||
function cancel_join_orgs() {
|
||||
$("#join_orgs_for_course input:checked").attr("checked", false);
|
||||
}
|
||||
function course_join_org(courseId) {
|
||||
$.ajax({
|
||||
url: "/org_courses?" + $("#join_orgs_for_course").serialize() + "&course_id=" + courseId,
|
||||
type: "post",
|
||||
success: function (data) {
|
||||
$.ajax({
|
||||
url: "/courses/" + courseId + "/search_public_orgs_not_in_course?hint_flag=true&name=" + $("input[name='orgs']").val().trim(),
|
||||
type: "get"
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
|
@ -0,0 +1,27 @@
|
|||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<script type="text/javascript">
|
||||
function close_alert_form(){hideModal("#alert_form");}
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="alert_form">
|
||||
<div class="upload_con">
|
||||
<div class="polls_alert_upload_box">
|
||||
<p class="polls_alert_box_p">
|
||||
<%= message%>
|
||||
</p>
|
||||
<div class="polls_alert_btn_box">
|
||||
<a class="upload_btn" onclick="close_alert_form();">
|
||||
确 定
|
||||
</a>
|
||||
</div>
|
||||
<div class="cl"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,21 @@
|
|||
<div id="popbox" style="text-align: center;margin-top: 25px">
|
||||
<% if status == 0 && exercise.time != -1%>
|
||||
<h3 style="font-weight: normal;color: green">提交成功!您的分数是:<%=@score %>分。</h3>
|
||||
<%= link_to "确定", exercise_path(),:class => 'commit'%>
|
||||
<% elsif status == 0 && Time.parse(format_time(exercise.end_time)).strftime("%Y-%m-%d %H:%M:%S") > Time.now.strftime("%Y-%m-%d %H:%M:%S") %>
|
||||
<h3 style="font-weight: normal;color: green">提交成功!</h3>
|
||||
<%= link_to "确定", exercise_index_path(:course_id => @course.id),:class => 'commit'%>
|
||||
<% elsif status == 1 && Time.parse(format_time(exercise.end_time)).strftime("%Y-%m-%d %H:%M:%S") > Time.now.strftime("%Y-%m-%d %H:%M:%S")%>
|
||||
<h3 style="font-weight: normal;color: red">保存成功!</h3>
|
||||
<%= link_to "确定",exercise_index_path(:course_id => @course.id),:class => 'commit'%>
|
||||
<% elsif status == 1 && Time.parse(format_time(exercise.end_time)).strftime("%Y-%m-%d %H:%M:%S") <= Time.now.strftime("%Y-%m-%d %H:%M:%S")%>
|
||||
<h3 style="font-weight: normal;color: red">时间已到!</h3>
|
||||
<%= link_to "确定", exercise_path(),:class => 'commit'%>
|
||||
<% elsif status == 2 %>
|
||||
<h3 style="font-weight: normal;color: red">发生未知错误,请检查您的网络。</h3>
|
||||
<%= link_to "确定", "javascript:void(0)",:onclick => 'hidden_atert_form();',:class => 'commit'%>
|
||||
<% else %>
|
||||
<h3 style="font-weight: normal;color: green">时间已到!您的分数是:<%=@score %>分。</h3>
|
||||
<%= link_to "确定", exercise_path(),:class => 'commit'%>
|
||||
<% end %>
|
||||
</div>
|
|
@ -0,0 +1,63 @@
|
|||
<%= form_for("",:url => update_exercise_question_exercise_index_path(:exercise_question => exercise_question.id),:remote => true) do |f|%>
|
||||
<!--编辑单选start-->
|
||||
<script type="text/javascript">
|
||||
function resetQuestion<%=exercise_question.id%>()
|
||||
{
|
||||
$("#poll_questions_title_<%=exercise_question.id%>").val("<%= exercise_question.question_title%>")
|
||||
$("#poll_question_score_<%=exercise_question.id %>").val("<%= exercise_question.question_score%>")
|
||||
$("#poll_question_standard_answer_<%=exercise_question.id %>").val("<%= convert_to_char(exercise_question.exercise_standard_answers.first.exercise_choice_id.to_s)%>")
|
||||
$("#poll_answers_<%=exercise_question.id%>").html("<% exercise_question.exercise_choices.reorder("choice_position").each_with_index do |exercise_choice,index| %>" +
|
||||
"<li class='ur_item'>" +
|
||||
"<label>选项<%=convert_to_char (index+1).to_s %><span class='ur_index'></span>: </label>" +
|
||||
"<input maxlength='200' type='text' name='question_answer[<%=exercise_choice.id %>]' placeholder='输入选项内容' value='<%=exercise_choice.choice_text %>'/>" +
|
||||
"<a class='icon_add' title='向下插入选项' onclick='add_single_answer($(this));'></a>" +
|
||||
"<a class='icon_remove' title='删除' onclick='remove_single_answer($(this))'></a>" +
|
||||
"</li>" +
|
||||
"<div class='cl'></div>" +
|
||||
"<% end%>");
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="questionContainer" style="width: 680px;">
|
||||
<div class="ur_editor_title">
|
||||
<label>问题: </label>
|
||||
<input name="question_type" value="<%=exercise_question.question_type %>" type="hidden">
|
||||
<input name="question_title" id="poll_questions_title_<%=exercise_question.id %>" class="questionTitle" placeholder="请输入单选题题目" type="text" value="<%=exercise_question.question_title %>">
|
||||
</div>
|
||||
<div class="ur_editor_content">
|
||||
<ul>
|
||||
<li class="ur_item">
|
||||
<label>分数<span class="ur_index"></span>: </label>
|
||||
<input type="text" id="poll_question_score_<%=exercise_question.id %>" name="question_score" style="width:40px; text-align:center; padding-left:0px;" value="<%= exercise_question.question_score %>">分
|
||||
</li>
|
||||
<div class="cl"></div>
|
||||
<div id="poll_answers_<%=exercise_question.id%>">
|
||||
<% exercise_question.exercise_choices.reorder("choice_position").each_with_index do |exercise_choice,index| %>
|
||||
<li class="ur_item">
|
||||
<label>选项<%=convert_to_char (index+1).to_s %><span class="ur_index"></span>: </label>
|
||||
<input maxlength="200" type='text' name='question_answer[<%=exercise_choice.id %>]' placeholder='输入选项内容' value="<%=exercise_choice.choice_text %>">
|
||||
<a class="icon_add" title="向下插入选项" onclick="add_single_answer($(this));"></a>
|
||||
<a class="icon_remove" title="删除" onclick="remove_single_answer($(this))"></a>
|
||||
</li>
|
||||
<div class="cl"></div>
|
||||
<% end %>
|
||||
</div>
|
||||
<li class="ur_item">
|
||||
<label>标准答案<span class="ur_index"></span>: </label>
|
||||
<input id="poll_question_standard_answer_<%=exercise_question.id %>" name="exercise_choice" placeholder="若标准答案为A,在此输入A即可" type="text" value="<%=convert_to_char(exercise_question.exercise_standard_answers.first.exercise_choice_id.to_s) %>">
|
||||
</li>
|
||||
<div class="cl"></div>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="ur_editor_footer">
|
||||
<a class="btn btn_dark btn_submit c_white" data-button="ok" onclick="edit_poll_question($(this),<%= exercise_question.id %>,1);">
|
||||
保存
|
||||
</a>
|
||||
<a class="btn btn_light btn_cancel" data-button="cancel" onclick="resetQuestion<%=exercise_question.id%>();pollQuestionCancel(<%= exercise_question.id%>);">
|
||||
<%= l(:button_cancel)%>
|
||||
</a>
|
||||
</div>
|
||||
<div class="cl"></div>
|
||||
</div>
|
||||
<!--编辑单选 end-->
|
||||
<% end%>
|
|
@ -0,0 +1,63 @@
|
|||
<%= form_for("",:url => update_exercise_question_exercise_index_path(:exercise_question => exercise_question.id),:remote => true) do |f|%>
|
||||
<!--编辑单选start-->
|
||||
<script type="text/javascript">
|
||||
function resetQuestion<%=exercise_question.id%>()
|
||||
{
|
||||
$("#poll_questions_title_<%=exercise_question.id%>").val("<%= exercise_question.question_title%>")
|
||||
$("#poll_question_score_<%=exercise_question.id %>").val("<%= exercise_question.question_score%>")
|
||||
$("#poll_question_standard_answer_<%=exercise_question.id %>").val("<%= convert_to_char(exercise_question.exercise_standard_answers.first.exercise_choice_id.to_s)%>")
|
||||
$("#poll_answers_<%=exercise_question.id%>").html("<% exercise_question.exercise_choices.reorder("choice_position").each_with_index do |exercise_choice,index| %>" +
|
||||
"<li class='ur_item'>" +
|
||||
"<label>选项<%=convert_to_char (index+1).to_s %><span class='ur_index'></span>: </label>" +
|
||||
"<input maxlength='200' type='text' name='question_answer[<%= exercise_choice.id %>]' placeholder='输入选项内容' value='<%=exercise_choice.choice_text %>'/>" +
|
||||
"<a class='icon_add' title='向下插入选项' onclick='add_single_answer($(this));'></a>" +
|
||||
"<a class='icon_remove' title='删除' onclick='remove_single_answer($(this))'></a>" +
|
||||
"</li>" +
|
||||
"<div class='cl'></div>" +
|
||||
"<% end%>");
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="questionContainer" style="width: 680px;">
|
||||
<div class="ur_editor_title">
|
||||
<label>问题: </label>
|
||||
<input name="question_type" value="<%=exercise_question.question_type %>" type="hidden">
|
||||
<input name="question_title" id="poll_questions_title_<%=exercise_question.id %>" class="questionTitle" placeholder="请输入多选题题目" type="text" value="<%=exercise_question.question_title %>">
|
||||
</div>
|
||||
<div class="ur_editor_content">
|
||||
<ul>
|
||||
<li class="ur_item">
|
||||
<label>分数<span class="ur_index"></span>: </label>
|
||||
<input type="text" id="poll_question_score_<%=exercise_question.id %>" name="question_score" style="width:40px; text-align:center; padding-left:0px;" value="<%= exercise_question.question_score %>">分
|
||||
</li>
|
||||
<div class="cl"></div>
|
||||
<div id="poll_answers_<%=exercise_question.id%>">
|
||||
<% exercise_question.exercise_choices.reorder("choice_position").each_with_index do |exercise_choice,index| %>
|
||||
<li class="ur_item">
|
||||
<label>选项<%=convert_to_char (index+1).to_s %><span class="ur_index"></span>: </label>
|
||||
<input maxlength="200" type='text' name='question_answer[<%= exercise_choice.id %>]' placeholder='输入选项内容' value="<%=exercise_choice.choice_text %>">
|
||||
<a class="icon_add" title="向下插入选项" onclick="add_single_answer($(this));"></a>
|
||||
<a class="icon_remove" title="删除" onclick="remove_single_answer($(this))"></a>
|
||||
</li>
|
||||
<div class="cl"></div>
|
||||
<% end %>
|
||||
</div>
|
||||
<li class="ur_item">
|
||||
<label>标准答案<span class="ur_index"></span>: </label>
|
||||
<input id="poll_question_standard_answer_<%=exercise_question.id %>" name="exercise_choice" placeholder="若标准答案为A,B,C,在答案输入框填入ABC即可" type="text" value="<%=convert_to_char(exercise_question.exercise_standard_answers.first.exercise_choice_id.to_s) %>">
|
||||
</li>
|
||||
<div class="cl"></div>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="ur_editor_footer">
|
||||
<a class="btn btn_dark btn_submit c_white" data-button="ok" onclick="edit_poll_question($(this),<%= exercise_question.id %>,2);">
|
||||
保存
|
||||
</a>
|
||||
<a class="btn btn_light btn_cancel" data-button="cancel" onclick="resetQuestion<%=exercise_question.id%>();pollQuestionCancel(<%= exercise_question.id%>);">
|
||||
<%= l(:button_cancel)%>
|
||||
</a>
|
||||
</div>
|
||||
<div class="cl"></div>
|
||||
</div>
|
||||
<!--编辑单选 end-->
|
||||
<% end%>
|
|
@ -0,0 +1,40 @@
|
|||
<%= form_for @exercise, :remote=>true do |f| %>
|
||||
<div class="testContainer">
|
||||
<div>
|
||||
<input name="exercise[exercise_name]" maxlength="100" id="exercise_name" class="testTitle mb10" type="text" placeholder="测验标题" value="<%=@exercise.exercise_name%>" />
|
||||
</div>
|
||||
<label class="fl c_grey f14" style="margin-top: 4px;">截止时间:</label>
|
||||
<div class="calendar_div fl">
|
||||
<input type="text" name="exercise[end_time]" id="exercise_end_time" placeholder="截止时间" class="InputBox fl W120 calendar_input" readonly="readonly" value="<%= Time.parse(format_time(exercise.end_time)).strftime("%Y-%m-%d") if exercise.end_time %>"/>
|
||||
<%= calendar_for('exercise_end_time')%>
|
||||
</div>
|
||||
<div class="fl ml15 f14 fontGrey2"><span class="mr5">测验时长:</span><input name="exercise[time]" id="exercise_time" type="text" class="examTime mr5" placeholder="不填即不限时" value="<%=exercise.time if exercise.time!= -1 %>" />分钟</div>
|
||||
<label class="fl c_grey ml15 f14" style="margin-top: 4px;">发布时间(可选):</label>
|
||||
<div class="calendar_div fl">
|
||||
<input type="text" name="exercise[publish_time]" id="exercise_publish_time" placeholder="发布时间(可选)" class="InputBox fl W120 calendar_input" readonly="readonly" value="<%= Time.parse(format_time(exercise.publish_time)).strftime("%Y-%m-%d") if !exercise.publish_time.nil? %>"/>
|
||||
<%= calendar_for('exercise_publish_time')%>
|
||||
</div>
|
||||
<div class="cl"></div>
|
||||
<textarea class="testDes mt10" name="exercise[exercise_description]" id="exercise_description" placeholder="发布须知:试题类型有选择和填空两种,其中选择题包括单选题和多选题。您可以在此处填写测验相关说明。" ><%=exercise.exercise_description %></textarea>
|
||||
<div class="ur_editor_footer" style="padding-top: 10px;">
|
||||
<a class="btn_submit c_white" data-button="ok" onclick="pollsSubmit($(this));">
|
||||
保存
|
||||
</a>
|
||||
<a class="btn_cancel" data-button="cancel" onclick="resetHead();pollsCancel();">
|
||||
<%= l(:button_cancel)%>
|
||||
</a>
|
||||
</div>
|
||||
<div class="cl"></div>
|
||||
</div>
|
||||
<% end %>
|
||||
<script type="text/javascript">
|
||||
function resetHead()
|
||||
{
|
||||
$("#exercise_name").val("<%=exercise.exercise_name%>");
|
||||
$("#exercise_end_time").val("<%= Time.parse(format_time(exercise.end_time)).strftime("%Y-%m-%d") if exercise.end_time %>");
|
||||
$("#exercise_time").val("<%=exercise.time if exercise.time!= -1 %>");
|
||||
$("#exercise_publish_time").val("<%= Time.parse(format_time(exercise.publish_time)).strftime("%Y-%m-%d") if !exercise.publish_time.nil?%>");
|
||||
/*$("#exercise_description").text("<%#=exercise.exercise_description.html_safe %>");*/
|
||||
document.getElementById("exercise_description").innerText = <%=exercise.exercise_description.html_safe %>;
|
||||
}
|
||||
</script>
|
|
@ -0,0 +1,59 @@
|
|||
<%= form_for("",:url => update_exercise_question_exercise_index_path(:exercise_question => exercise_question.id),:remote => true) do |f|%>
|
||||
<!--编辑单选start-->
|
||||
<script type="text/javascript">
|
||||
function resetQuestion<%=exercise_question.id%>()
|
||||
{
|
||||
$("#poll_questions_title_<%=exercise_question.id%>").val("<%= exercise_question.question_title%>")
|
||||
$("#poll_question_score_<%=exercise_question.id %>").val("<%= exercise_question.question_score%>")
|
||||
$("#poll_answers_<%=exercise_question.id%>").html("<% exercise_question.exercise_standard_answers.reorder("created_at").each_with_index do |exercise_choice,index| %>" +
|
||||
"<li class='ur_item'>" +
|
||||
"<label>候选答案<span class='ur_index'></span>: </label>" +
|
||||
"<input class='candiate_answer' name='exercise_choice[<%=exercise_choice.id %>]' placeholder='请输入候选答案' type='text' value='<%=exercise_choice.answer_text %>'/>" +
|
||||
|
||||
"<a class='icon_add' title='向下插入选项' onclick='add_candidate_answer($(this));'></a>" +
|
||||
"<a class='icon_remove' title='删除' onclick='remove_single_answer($(this))'></a>" +
|
||||
"</li>" +
|
||||
"<div class='cl'></div>" +
|
||||
"<% end%>");
|
||||
}
|
||||
</script>
|
||||
|
||||
<div class="questionContainer" style="width: 680px;">
|
||||
<div class="ur_editor_title">
|
||||
<label>问题: </label>
|
||||
<input name="question_type" value="<%=exercise_question.question_type %>" type="hidden">
|
||||
<input name="question_title" id="poll_questions_title_<%=exercise_question.id %>" class="questionTitle" placeholder="请输入填空题的内容(注意:目前填空题暂时仅支持一个空)" type="text" value="<%=exercise_question.question_title %>">
|
||||
</div>
|
||||
<div class="ur_editor_content" id="edit_single">
|
||||
<ul>
|
||||
<li class="ur_item">
|
||||
<label>分数<span class="ur_index"></span>: </label>
|
||||
<input type="text" id="poll_question_score_<%=exercise_question.id %>" name="question_score" style="width:40px; text-align:center; padding-left:0px;" value="<%= exercise_question.question_score %>">分
|
||||
</li>
|
||||
<div class="cl"></div>
|
||||
<div id="poll_answers_<%=exercise_question.id%>">
|
||||
<% exercise_question.exercise_standard_answers.reorder("created_at").each_with_index do |exercise_choice,index| %>
|
||||
<li class="ur_item">
|
||||
<label>候选答案<span class="ur_index"></span>: </label>
|
||||
<input class="candiate_answer" name="exercise_choice[<%=exercise_choice.id %>]" placeholder="请输入候选答案" type="text" value="<%=exercise_choice.answer_text %>"/>
|
||||
<a class="icon_add" title="向下插入选项" onclick="add_candidate_answer($(this));"></a>
|
||||
<a class="icon_remove" title="删除" onclick="remove_single_answer($(this));"></a>
|
||||
</li>
|
||||
<div class="cl"></div>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="cl"></div>
|
||||
</ul>
|
||||
</div>
|
||||
<div class="ur_editor_footer">
|
||||
<a class="btn btn_dark btn_submit c_white" data-button="ok" onclick="edit_poll_question($(this),<%= exercise_question.id %>,3);">
|
||||
保存
|
||||
</a>
|
||||
<a class="btn btn_light btn_cancel" data-button="cancel" onclick="resetQuestion<%=exercise_question.id%>();pollQuestionCancel(<%= exercise_question.id%>);">
|
||||
<%= l(:button_cancel)%>
|
||||
</a>
|
||||
</div>
|
||||
<div class="cl"></div>
|
||||
</div>
|
||||
<!--编辑单选 end-->
|
||||
<% end%>
|
|
@ -0,0 +1,60 @@
|
|||
<%# has_commit = has_commit_poll?(poll.id ,User.current)%>
|
||||
<% exercise_name = exercise.exercise_name.empty? ? l(:label_poll_new) : exercise.exercise_name%>
|
||||
<% if @is_teacher%>
|
||||
<li title="<%= exercise.exercise_name %>">
|
||||
<div style="width: 310px;float: left;">
|
||||
<%# if has_commit %>
|
||||
<%#= link_to poll_name, poll_result_poll_path(poll.id), :class => "polls_title polls_title_w fl c_dblue"%>
|
||||
<%# else %>
|
||||
<%#= link_to poll_name, exercise_path(poll.id), :class => "polls_title polls_title_w fl c_dblue" %>
|
||||
<%# end %>
|
||||
<%= link_to (index.to_i+1).to_s+". "+exercise_name, exercise_path(exercise.id), :class => "polls_title polls_title_w fl c_dblue" %>
|
||||
</div>
|
||||
</li>
|
||||
|
||||
<%# if exercise.exercise_status == 2 %>
|
||||
<!--<li><a class="polls_de fr ml5" onclick="" href="javascript:">关闭</a></li>-->
|
||||
<%# else %>
|
||||
<!--<li class="polls_de_grey fr ml5" title="发布的问卷才能进行关闭">关闭</li>-->
|
||||
<%# end%>
|
||||
|
||||
<%# if exercise.exercise_status == 1%>
|
||||
<!--<li class="polls_de_grey fr ml5">导出</li>-->
|
||||
<%# elsif exercise.exercise_status == 2 || exercise.exercise_status == 3 %>
|
||||
<!--<li><%#= link_to "导出", export_exercise_exercise_path(exercise.id,:format => "xls"), :class => "polls_de fr ml5"%></li>-->
|
||||
<%# end%>
|
||||
<% if exercise.exercise_status == 1 %>
|
||||
<li><a href="javascript:" class="pollsbtn btn_pu fr mr5" onclick="exercise_submit(<%= exercise.id%>,<%= exercise.exercise_name.length %>,<%=index.to_i %>);">发布试卷</a></li>
|
||||
<% elsif exercise.exercise_status == 2%>
|
||||
<li><a href="javascript:" class="pollsbtn btn_de fr mr5" onclick="republish_exercise(<%= exercise.id%>,<%=index.to_i %>);">取消发布</a></li>
|
||||
<% else%>
|
||||
<li class="pollsbtn fr mr10 pollsbtn_grey" style="margin-left: 5px;" >发布试卷</li>
|
||||
<% end%>
|
||||
|
||||
<% if exercise.exercise_status == 1%>
|
||||
<li class="pollsbtn fr mr10 pollsbtn_grey">统计结果</li>
|
||||
<% else %>
|
||||
<li><%= link_to l(:label_statistical_results), student_exercise_list_exercise_path(exercise.id,:course_id => @course.id), :class => "pollsbtn fr mr10"%></li>
|
||||
<% end%>
|
||||
|
||||
<%= link_to(l(:button_delete), exercise,:method => :delete, :confirm => l(:text_are_you_sure), :remote => true, :class => "polls_de fr ml5 mr10") %>
|
||||
|
||||
<% if exercise.exercise_status == 1 %>
|
||||
<li><%= link_to l(:button_edit), edit_exercise_path(exercise.id), :class => "polls_de fr ml10"%></li>
|
||||
<li class="polls_date fr"><%=exercise.publish_time.nil? ? "未发布" : "将于"+format_time(exercise.publish_time.to_s)+"发布"%></li>
|
||||
<% else%>
|
||||
<li class="polls_de_grey fr ml10" title="未发布的试卷才能进行编辑">编辑</li>
|
||||
<li class="polls_date fr">已发布</li>
|
||||
<% end%>
|
||||
|
||||
<% else%>
|
||||
<% if exercise.exercise_status == 2%>
|
||||
<%# if has_commit%>
|
||||
<!--li><%#= link_to poll_name, poll_result_poll_path(poll.id), :class => "polls_title polls_title_st fl c_dblue" %></li>
|
||||
<li class="pollsbtn_tip fl ml5">已答</li-->
|
||||
<%#else%>
|
||||
<%= link_to (index.to_i+1).to_s+". "+exercise_name, exercise_path(exercise.id), :class => "polls_title polls_title_st fl c_dblue"%>
|
||||
<%#end%>
|
||||
<% end%>
|
||||
<li class="polls_date fr mr10">截止时间:<%= format_time(exercise.end_time.to_s)%></li>
|
||||
<% end%>
|
|
@ -0,0 +1,42 @@
|
|||
<% mc_question_list = exercise.exercise_questions.where("question_type=1") %>
|
||||
<% mcq_question_list = exercise.exercise_questions.where("question_type=2") %>
|
||||
<% single_question_list = exercise.exercise_questions.where("question_type=3") %>
|
||||
<div class="testStatus" id="mc_question_list" style="display: <%=mc_question_list.count > 0 ? "" : "none" %>">
|
||||
<h3 class="fontGrey3">单选题</h3>
|
||||
<% mc_question_list.each do |exercise_question| %>
|
||||
<div id="poll_questions_<%= exercise_question.id%>">
|
||||
<div id="show_poll_questions_<%= exercise_question.id %>">
|
||||
<%= render :partial => 'show_MC', :locals => {:exercise_question => exercise_question} %>
|
||||
</div>
|
||||
<div id="edit_poll_questions_<%= exercise_question.id %>" style="display: none;">
|
||||
<%= render :partial => 'edit_MC', :locals => {:exercise_question => exercise_question} %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="testStatus" id="mcq_question_list" style="display: <%=mcq_question_list.count > 0 ? "" : "none" %>">
|
||||
<h3 class="fontGrey3">多选题</h3>
|
||||
<% mcq_question_list.each do |exercise_question| %>
|
||||
<div id="poll_questions_<%= exercise_question.id%>">
|
||||
<div id="show_poll_questions_<%= exercise_question.id %>">
|
||||
<%= render :partial => 'show_MCQ', :locals => {:exercise_question => exercise_question} %>
|
||||
</div>
|
||||
<div id="edit_poll_questions_<%= exercise_question.id %>" style="display: none;">
|
||||
<%= render :partial => 'edit_MCQ', :locals => {:exercise_question => exercise_question} %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="testStatus" id="single_question_list" style="display: <%=single_question_list.count > 0 ? "" : "none" %>">
|
||||
<h3 class="fontGrey3">填空题</h3>
|
||||
<% single_question_list.each do |exercise_question| %>
|
||||
<div id="poll_questions_<%= exercise_question.id%>">
|
||||
<div id="show_poll_questions_<%= exercise_question.id %>">
|
||||
<%= render :partial => 'show_single', :locals => {:exercise_question => exercise_question} %>
|
||||
</div>
|
||||
<div id="edit_poll_questions_<%= exercise_question.id %>" style="display: none;">
|
||||
<%= render :partial => 'edit_single', :locals => {:exercise_question => exercise_question} %>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
|
@ -0,0 +1,219 @@
|
|||
<%= stylesheet_link_tag 'polls', :media => 'all' %>
|
||||
<script type="text/javascript">
|
||||
$(function(){
|
||||
$("#RSide").removeAttr("id");
|
||||
$("#homework_page_right").css("min-height",$("#LSide").height()-30);
|
||||
$("#Container").css("width","1000px");
|
||||
});
|
||||
//编辑问卷描述之后
|
||||
var popWindow ; //弹出框的引用
|
||||
var importPollPopWindow; //选择导入的弹出框引用
|
||||
function edit_head(){
|
||||
$("#exercise_description").val($("#exercise_description_div").html());
|
||||
}
|
||||
$(function(){
|
||||
//点击空白处
|
||||
$(document).bind('click',function(e){
|
||||
//弹出框非空 不是a标签 点击的不是弹出框 ,那么弹出框就会隐藏
|
||||
if(popWindow && e.target.nodeName != 'A' && !popWindow.is(e.target) && popWindow.has(e.target).length === 0){ // Mark 1
|
||||
popWindow.css('display', 'none');
|
||||
}
|
||||
if(importPollPopWindow && e.target.nodeName != 'A' && !importPollPopWindow.is(e.target) && importPollPopWindow.has(e.target).length === 0){
|
||||
importPollPopWindow.css('display', 'none');
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
function dismiss(quest_type,quest_id){
|
||||
popWindow = $("#div_"+quest_type+"_"+quest_id);
|
||||
if(popWindow){
|
||||
popWindow.css('display', 'none');
|
||||
}
|
||||
}
|
||||
|
||||
function chooseQuestionType(quest_type,quest_id){
|
||||
//quest_type 分为 mc mcq single multi
|
||||
//quest_id 是quetion的id 下同
|
||||
if(popWindow){
|
||||
popWindow.css('display', 'none');
|
||||
}
|
||||
popWindow = $("#div_"+quest_type+"_"+quest_id);
|
||||
$("#div_"+quest_type+"_"+quest_id).click(function(e){
|
||||
e.stopPropagation(); //组织冒泡到document.body中去
|
||||
});
|
||||
$("#div_"+quest_type+"_"+quest_id).css("position", "absolute");
|
||||
|
||||
$("#div_"+quest_type+"_"+quest_id).css("top", $("#add_"+quest_type+"_"+quest_id).offset().top+30);
|
||||
|
||||
$("#div_"+quest_type+"_"+quest_id).css("left", $("#add_"+quest_type+"_"+quest_id).offset().left-10);
|
||||
if( $("#div_"+quest_type+"_"+quest_id).css('display') == 'block') {
|
||||
$("#div_"+quest_type+"_"+quest_id).css('display', 'none');
|
||||
}
|
||||
else{
|
||||
$("#div_"+quest_type+"_"+quest_id).css('display', 'block');
|
||||
}
|
||||
}
|
||||
|
||||
//选择导入调查问卷
|
||||
function importPoll(){
|
||||
importPollPopWindow = $("#import_poll");
|
||||
$("#import_poll").css("position", "absolute");
|
||||
|
||||
$("#import_poll").css("top", $("#import_btn").offset().top+30);
|
||||
|
||||
$("#import_poll").css("left", $("#import_btn").offset().left-65);
|
||||
$("#import_poll").css("display","block")
|
||||
}
|
||||
|
||||
function remote_import(){
|
||||
importPollPopWindow.css('display', 'none');
|
||||
if($("#import_poll").val() === 0){
|
||||
return;
|
||||
}else{
|
||||
if(confirm("确认导入问卷"+$("#import_poll").find("option:selected").text()+"?")){
|
||||
$("#import_form").submit();
|
||||
}else{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//添加标题时确定按钮
|
||||
function add_poll_question(doc,quest_type)
|
||||
{
|
||||
var title = $.trim($("#poll_questions_title").val());
|
||||
var score = $.trim($("#question_score").val());
|
||||
var standard_ans = $.trim($("#question_standard_ans").val());
|
||||
if(title.length == 0 || score.length == 0){
|
||||
alert("题目标题/分数不能为空");
|
||||
}else if(!/^[1-9][0-9]*$/.test(score)) {
|
||||
alert("分数必须是非零开头的数字");
|
||||
}else if(quest_type !=3 && standard_ans.length == 0) {
|
||||
alert("标准答案不能为空");
|
||||
}else{
|
||||
doc.parent().parent().parent().submit();}
|
||||
}
|
||||
//修改标题时确定按钮
|
||||
function edit_poll_question(doc,id,quest_type)
|
||||
{
|
||||
var title = $.trim($("#poll_questions_title_" + id).val());
|
||||
var score = $.trim($("#poll_question_score_"+ id).val());
|
||||
var standard_ans = $.trim($("#poll_question_standard_answer_" + id).val());
|
||||
if(title.length == 0 || score.length == 0){
|
||||
alert("题目标题/分数不能为空");
|
||||
}else if(!/^[1-9][0-9]*$/.test(score)) {
|
||||
alert("分数必须是非零开头的数字");
|
||||
}else if(quest_type !=3 && standard_ans.length == 0) {
|
||||
alert("标准答案不能为空");
|
||||
}else if(quest_type ==3) {
|
||||
var div = $("#poll_answers_" + id);
|
||||
var candiate_answer = $(".candiate_answer",div);
|
||||
if(candiate_answer.length > 0) {
|
||||
for(i=0;i<candiate_answer.length;i++) {
|
||||
if(i<candiate_answer.length-1 && $.trim($(candiate_answer[i]).val()) == "") {
|
||||
continue;
|
||||
} else if(i == (candiate_answer.length-1) && $.trim($(candiate_answer[i]).val()) == "") {
|
||||
alert("候选答案不能为空");
|
||||
} else if($.trim($(candiate_answer[i]).val()) != ""){
|
||||
doc.parent().parent().parent().submit();
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
} else{
|
||||
alert("候选答案不能为空");
|
||||
}
|
||||
}else{
|
||||
doc.parent().parent().parent().submit();}
|
||||
}
|
||||
|
||||
//问卷头
|
||||
function pollsCancel(){$("#polls_head_edit").hide();$("#polls_head_show").show();}
|
||||
function pollsSubmit(doc){
|
||||
var title = $.trim($("#exercise_name").val());
|
||||
if(title.length == 0){
|
||||
alert("测验标题不能为空");
|
||||
} else if($.trim($("#exercise_end_time").val()) =="") {
|
||||
alert("截止时间不能为空");
|
||||
} else if((Date.parse($("#exercise_end_time").val())+(24*60*60-1)*1000) < Date.now()) {
|
||||
alert("截止时间不能小于当前时间");
|
||||
} else if($.trim($("#exercise_time").val()) !="" && !/^[1-9][0-9]*$/.test($.trim($("#exercise_time").val()))) {
|
||||
alert("测验时长必须为非零开头的数字");
|
||||
} else if($.trim($("#exercise_publish_time").val()) !="" && Date.parse($("#exercise_publish_time").val()) < Date.now()) {
|
||||
alert("发布时间不能小于当前时间");
|
||||
} else if($.trim($("#exercise_publish_time").val()) !="" && Date.parse($("#exercise_end_time").val()) < Date.parse($("#exercise_publish_time").val())) {
|
||||
alert("截止时间不能小于发布时间");
|
||||
} else {
|
||||
doc.parent().parent().parent().submit();
|
||||
}
|
||||
}
|
||||
function pollsEdit(){$("#polls_head_edit").show();$("#polls_head_show").hide();}
|
||||
//
|
||||
function pollQuestionCancel(question_id){
|
||||
$("#show_poll_questions_"+question_id).show();
|
||||
$("#edit_poll_questions_"+question_id).hide();
|
||||
}
|
||||
function pollQuestionEdit(question_id){
|
||||
$("#show_poll_questions_"+question_id).hide();
|
||||
$("#edit_poll_questions_"+question_id).show();
|
||||
$("#poll_questions_title_"+question_id).focus();
|
||||
}
|
||||
//单选题
|
||||
function add_single_answer(doc)
|
||||
{
|
||||
doc.parent().after("<li class='ur_item'><label>选项<span class='ur_index'></span>: </label><input maxlength='200' type='text' name='question_answer["+new Date().getTime()+"]' placeholder='输入选项内容'/>" +
|
||||
"<a class='icon_add' title='向下插入选项' onclick='add_single_answer($(this));'></a><a class='icon_remove' title='删除' onclick='remove_single_answer($(this))'></a>"+
|
||||
"</li><div class='cl'></div>");
|
||||
}
|
||||
function add_candidate_answer(doc)
|
||||
{
|
||||
doc.parent().after("<li class='ur_item'><label>候选答案<span class='ur_index'></span>: </label><input maxlength='200' type='text' name='exercise_choice["+new Date().getTime()+"]' placeholder='请输入候选答案(选填)'/>" +
|
||||
"<a class='icon_add' title='向下插入选项' onclick='add_candidate_answer($(this));'></a><a class='icon_remove' title='删除' onclick='remove_single_answer($(this))'></a>"+
|
||||
"</li><div class='cl'></div>");
|
||||
}
|
||||
function remove_single_answer(doc)
|
||||
{
|
||||
if(doc.parent().siblings("li").length == 0)
|
||||
{
|
||||
alert("至少有一个选项或一个候选答案");
|
||||
}
|
||||
else
|
||||
{
|
||||
doc.parent().remove();
|
||||
}
|
||||
}
|
||||
</script>
|
||||
<div class="homepageRight mt0 ml10">
|
||||
<div class="resources">
|
||||
<!-- 头部 -->
|
||||
<div id="polls_head_show" style="display: none;">
|
||||
<%= render :partial => 'show_head', :locals => {:exercise => @exercise} %>
|
||||
</div>
|
||||
<div id="polls_head_edit">
|
||||
<%= render :partial => 'edit_head', :locals => {:exercise => @exercise} %>
|
||||
</div>
|
||||
<% current_score = get_current_score @exercise %>
|
||||
<div class="mb5" style="display: <%= current_score == 0 ? "none" : "" %>" id="current_score_div">目前试卷总分:<span class="c_red" id="current_score"><%= current_score %>
|
||||
分</span></div>
|
||||
<!-- 问题 -->
|
||||
<div id="poll_content">
|
||||
<%= render :partial => 'exercise_content', :locals => {:exercise => @exercise} %>
|
||||
</div>
|
||||
|
||||
<div class="testQuestion" id="new_exercise_question">
|
||||
<%= render :partial => 'new_question', :locals => {:exercise => @exercise} %>
|
||||
</div>
|
||||
<!--选项 end-->
|
||||
|
||||
<!-- 新增问题 -->
|
||||
<div id="new_poll_question">
|
||||
</div>
|
||||
|
||||
<div id="exercise_submit">
|
||||
<%= render :partial => 'exercise_submit', :locals => {:exercise => @exercise} %>
|
||||
</div>
|
||||
<div class="cl"></div>
|
||||
<!--contentbox end-->
|
||||
</div>
|
||||
</div><!--编辑end-->
|
|
@ -0,0 +1,237 @@
|
|||
<script type="text/javascript">
|
||||
$(function(){
|
||||
$("#RSide").removeAttr("id");
|
||||
$("#homework_page_right").css("min-height",$("#LSide").height()-30);
|
||||
$("#Container").css("width","1000px");
|
||||
<%uncomplete_question =get_uncomplete_question(exercise, User.current) %>;
|
||||
<% if (uncomplete_question.count < 1) %>
|
||||
$("#exercise_submit_btn").html("提交");
|
||||
<% end %>
|
||||
var end_time = <%=exercise.end_time.to_i%>;
|
||||
getTime(end_time);
|
||||
/*start_time = new Date();
|
||||
start_time.setFullYear(<%#=exercise_user.start_at.year%>);
|
||||
start_time.setMonth(<%#=exercise_user.start_at.month%>);
|
||||
start_time.setDate(<%#=exercise_user.start_at.day%>);
|
||||
start_time.setHours(<%#=exercise_user.start_at.hour%>);
|
||||
start_time.setMinutes(<%#=exercise_user.start_at.min%>);
|
||||
start_time.setSeconds(<%#=exercise_user.start_at.sec%>);
|
||||
//alert(start_time);
|
||||
end_time = start_time.getTime() + 1000*60*<%#=exercise.time %>;
|
||||
getTime(end_time);*/
|
||||
});
|
||||
function getTime(end_time) {
|
||||
//alert(end_time);
|
||||
now = new Date();
|
||||
var total_seconds = now.getTime()/1000 - end_time;
|
||||
if (total_seconds > 0) {
|
||||
$("#exercise_submit_btn").click();
|
||||
return;
|
||||
}
|
||||
setTimeout("getTime("+end_time+");", 1000);
|
||||
//start = new Date(start_time);
|
||||
//end_time = start_time;
|
||||
//var total_seconds = total_seconds - 1;
|
||||
/*var hours = total_seconds / 60 / 60;
|
||||
var hoursRound = Math.floor(hours);
|
||||
var minutes = total_seconds /60 - (60 * hoursRound);
|
||||
var minutesRound = Math.floor(minutes);
|
||||
var seconds = total_seconds - (60 * 60 * hoursRound) - (60 * minutesRound);
|
||||
var secondsRound = Math.round(seconds);
|
||||
$("#rest_hours").html(hoursRound);
|
||||
$("#rest_minutes").html(minutesRound);
|
||||
$("#rest_seconds").html(secondsRound);*/
|
||||
//if(total_seconds >0) {
|
||||
//setTimeout("getTime("+end_time+");", 1000);
|
||||
//}
|
||||
}
|
||||
</script>
|
||||
<div class="homepageRight mt0 ml10">
|
||||
<div class="resources">
|
||||
<div class="testStatus"><!--头部显示 start-->
|
||||
<h1 class="ur_page_title" id="polls_name_h"><%= exercise.exercise_name%></h1>
|
||||
<div id="start_time" style="display: none"><%=exercise_user.start_at %></div>
|
||||
<div class="fontGrey2">
|
||||
<span class="mr100">开始时间:<%=Time.parse(h(exercise_user.start_at)).strftime("%Y-%m-%d %H:%M:%S")%></span>
|
||||
<span class="mr100">截止时间:<%=Time.parse(h(exercise.end_time)).strftime("%Y-%m-%d %H:%M:%S")%></span>
|
||||
<% unless exercise.time == -1 %>
|
||||
<span class="fr">测验时长:<%=exercise.time %>分钟</span>
|
||||
<% end %>
|
||||
<!--
|
||||
<span class="fr">剩余时长:<span class="c_red" id="rest_hours"></span> 小时 <span class="c_red" id="rest_minutes"></span> 分钟 <span class="c_red" id="rest_seconds"></span> 秒</span>
|
||||
-->
|
||||
</div>
|
||||
<div class="testDesEdit mt5"><%= exercise.exercise_description.nil? ? "" : exercise.exercise_description.html_safe%></div>
|
||||
<div class="cl"></div>
|
||||
<div class="cl"></div>
|
||||
</div>
|
||||
<% mc_question_list = exercise.exercise_questions.where("question_type=1").shuffle %>
|
||||
<% mcq_question_list = exercise.exercise_questions.where("question_type=2").shuffle %>
|
||||
<% single_question_list = exercise.exercise_questions.where("question_type=3").shuffle %>
|
||||
<div class="testStatus" id="mc_question_list" style="display: <%=mc_question_list.count > 0 ? "" : "none" %>">
|
||||
<h3 class="fontGrey3">单选题</h3>
|
||||
<% mc_question_list.each_with_index do |exercise_question, list_index| %>
|
||||
<div id="poll_questions_<%= exercise_question.id%>">
|
||||
<div id="show_poll_questions_<%= exercise_question.id %>">
|
||||
<div>
|
||||
<div class="testEditTitle"> 第<%= list_index+1%>题:<%= exercise_question.question_title %> (<%= exercise_question.question_score %>分)
|
||||
</div>
|
||||
<div class="cl"></div>
|
||||
<div class="ur_inputs">
|
||||
<table class="ur_table" style="width:675px;">
|
||||
<tbody>
|
||||
<% exercise_question.exercise_choices.reorder("choice_position").each_with_index do |exercise_choice,index| %>
|
||||
<tr>
|
||||
<td>
|
||||
<label>
|
||||
<script>
|
||||
function click_<%= exercise_choice.id %>(obj)
|
||||
{
|
||||
$.ajax({
|
||||
type: "post",
|
||||
url: "<%= commit_answer_exercise_path(exercise) %>",
|
||||
data: {
|
||||
exercise_choice_id: <%= exercise_choice.id %>,
|
||||
exercise_question_id: <%= exercise_question.id %>
|
||||
},
|
||||
success: function (data) {
|
||||
var dataObj = eval(data);
|
||||
if(dataObj.text == "ok")
|
||||
{
|
||||
obj.checked = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
obj.checked = false;
|
||||
}
|
||||
if(dataObj.complete == 1) {
|
||||
$("#exercise_submit_btn").html("提交");
|
||||
} else {
|
||||
$("#exercise_submit_btn").html("保存");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
<%= radio_button "exercise",exercise_question.id.to_s+"exercise_choice_id",exercise_choice.id,:class=>"ur_radio",:onclick =>"click_#{exercise_choice.id}(this);return false;",:checked => answer_be_selected?(exercise_choice,User.current),:disabled => !@can_edit_excercise %>
|
||||
<%= convert_to_char((index+1).to_s)%> <%= exercise_choice.choice_text%>
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="testStatus" id="mcq_question_list" style="display: <%=mcq_question_list.count > 0 ? "" : "none" %>">
|
||||
<h3 class="fontGrey3">多选题</h3>
|
||||
<% mcq_question_list.each_with_index do |exercise_question,list_index| %>
|
||||
<div id="poll_questions_<%= exercise_question.id%>">
|
||||
<div id="show_poll_questions_<%= exercise_question.id %>">
|
||||
<div>
|
||||
<div class="testEditTitle"> 第<%= list_index+1%>题:<%= exercise_question.question_title %> (<%= exercise_question.question_score %>分)
|
||||
</div>
|
||||
<div class="cl"></div>
|
||||
<div class="ur_inputs">
|
||||
<table class="ur_table" style="width:675px;">
|
||||
<tbody>
|
||||
<% exercise_question.exercise_choices.reorder("choice_position").each_with_index do |exercise_choice,index| %>
|
||||
<tr>
|
||||
<td>
|
||||
<label>
|
||||
<script>
|
||||
function click_<%= exercise_choice.id %>(obj)
|
||||
{
|
||||
$.ajax({
|
||||
type: "post",
|
||||
url: "<%= commit_answer_exercise_path(exercise) %>",
|
||||
data: {
|
||||
exercise_choice_id: <%= exercise_choice.id %>,
|
||||
exercise_question_id: <%= exercise_question.id %>
|
||||
},
|
||||
success: function (data) {
|
||||
var dataObj = eval(data);
|
||||
if(dataObj.text == "ok")
|
||||
{
|
||||
obj.checked = true;
|
||||
}
|
||||
else
|
||||
{
|
||||
obj.checked = false;
|
||||
}
|
||||
if(dataObj.complete == 1) {
|
||||
$("#exercise_submit_btn").html("提交");
|
||||
} else {
|
||||
$("#exercise_submit_btn").html("保存");
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
</script>
|
||||
<input class="ur_radio" type="checkbox" onclick="click_<%= exercise_choice.id %>(this);return false;" <%= answer_be_selected?(exercise_choice,User.current) ? "checked":"" %> <%= @can_edit_excercise?"":"disabled=disabled" %> >
|
||||
<%= convert_to_char((index+1).to_s)%> <%= exercise_choice.choice_text%>
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div><!--多选题显示 end-->
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="testStatus" id="single_question_list" style="display: <%=single_question_list.count > 0 ? "" : "none" %>">
|
||||
<h3 class="fontGrey3">填空题</h3>
|
||||
<% single_question_list.each_with_index do |exercise_question, list_index| %>
|
||||
<div id="poll_questions_<%= exercise_question.id%>">
|
||||
<div id="show_poll_questions_<%= exercise_question.id %>">
|
||||
<div>
|
||||
<div class="testEditTitle"> 第<%= list_index+1%>题:<%= exercise_question.question_title %> (<%= exercise_question.question_score %>分)
|
||||
</div>
|
||||
<div class="cl"></div>
|
||||
<div>
|
||||
<script>
|
||||
function onblur_<%= exercise_question.id %>(obj)
|
||||
{
|
||||
$(window).unbind('beforeunload');
|
||||
$.ajax({
|
||||
type: "post",
|
||||
url: "<%= commit_answer_exercise_path(exercise) %>",
|
||||
data: {
|
||||
exercise_question_id: <%= exercise_question.id %> ,
|
||||
answer_text: obj.value
|
||||
},
|
||||
success: function (data) {
|
||||
var dataObj = eval(data);
|
||||
obj.value = dataObj.text;
|
||||
if(dataObj.complete == 1) {
|
||||
$("#exercise_submit_btn").html("提交");
|
||||
} else {
|
||||
$("#exercise_submit_btn").html("保存");
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
</script>
|
||||
<input class="fillInput" placeholder="在此填入答案" type="text" value="<%= get_anwser_vote_text(exercise_question.id,User.current.id).html_safe %>" onblur="onblur_<%= exercise_question.id %>(this);" <%= @can_edit_excercise?"":"disabled=disabled" %>>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="ur_buttons">
|
||||
<%= link_to "保存",commit_exercise_exercise_path(exercise),:id=>"exercise_submit_btn", :method => :post,:class => "ur_button_submit",:style => "margin-left:80px;",:format => 'js',:remote=>true %>
|
||||
</div>
|
||||
<div class="cl"></div>
|
||||
<!--contentbox end-->
|
||||
</div>
|
||||
<!--RSide end-->
|
||||
</div>
|
|
@ -0,0 +1,140 @@
|
|||
<script type="text/javascript">
|
||||
$(function(){
|
||||
$("#RSide").removeAttr("id");
|
||||
$("#homework_page_right").css("min-height",$("#LSide").height()-30);
|
||||
$("#Container").css("width","1000px");
|
||||
});
|
||||
</script>
|
||||
<div class="homepageRight mt0 ml10">
|
||||
<div class="resources">
|
||||
<div class="testStatus"><!--头部显示 start-->
|
||||
<h1 class="ur_page_title" id="polls_name_h"><%= exercise.exercise_name%></h1>
|
||||
<div class="fontGrey2">
|
||||
<span class="mr100">开始时间:<%=Time.parse(h(exercise_user.start_at)).strftime("%Y-%m-%d %H:%M:%S") %></span>
|
||||
<span class="mr100">截止时间:<%=Time.parse(h(exercise.end_time)).strftime("%Y-%m-%d %H:%M:%S")%></span>
|
||||
<% unless exercise.time == -1 %>
|
||||
<span class="fr">测验时长:<%=exercise.time %>分钟</span>
|
||||
<% end %>
|
||||
<%# time = exercise_user.end_at - exercise_user.start_at %>
|
||||
</div>
|
||||
<div class="testDesEdit mt5"><%= exercise.exercise_description.nil? ? "" : exercise.exercise_description.html_safe%></div>
|
||||
<div class="cl"></div>
|
||||
</div>
|
||||
<div class="mb5">得分:<span class="c_red"><%=exercise_user.score %>分</span></div>
|
||||
<% mc_question_list = exercise.exercise_questions.where("question_type=1") %>
|
||||
<% mcq_question_list = exercise.exercise_questions.where("question_type=2") %>
|
||||
<% single_question_list = exercise.exercise_questions.where("question_type=3") %>
|
||||
<div class="testStatus" id="mc_question_list" style="display: <%=mc_question_list.count > 0 ? "" : "none" %>">
|
||||
<h3 class="fontGrey3">单选题</h3>
|
||||
<% mc_question_list.each_with_index do |exercise_question, list_index| %>
|
||||
<div id="poll_questions_<%= exercise_question.id%>">
|
||||
<div id="show_poll_questions_<%= exercise_question.id %>">
|
||||
<div>
|
||||
<div class="testEditTitle"> 第<%= list_index+1%>题:<%= exercise_question.question_title %> (<%= exercise_question.question_score %>分)
|
||||
<span class="ml15 c_red">
|
||||
<% answer = get_user_answer(exercise_question, user)%>
|
||||
<% standard_answer = get_user_standard_answer(exercise_question, user)%>
|
||||
<% if !answer.empty? && !standard_answer.empty? && answer.first.exercise_choice.choice_position == standard_answer.first.exercise_choice_id %>
|
||||
√
|
||||
<% else %>
|
||||
×
|
||||
<% end %></span><br />
|
||||
标准答案:<%= convert_to_char(exercise_question.exercise_standard_answers.first.exercise_choice_id.to_s) if exercise_question.exercise_standard_answers.first %>
|
||||
</div>
|
||||
<div class="cl"></div>
|
||||
<div class="ur_inputs">
|
||||
<table class="ur_table" style="width:675px;">
|
||||
<tbody>
|
||||
<% exercise_question.exercise_choices.reorder("choice_position").each_with_index do |exercise_choice,index| %>
|
||||
<tr>
|
||||
<td>
|
||||
<label>
|
||||
<%= radio_button "exercise",exercise_question.id.to_s+"exercise_choice_id",exercise_choice.id,:class=>"ur_radio",:checked => answer_be_selected?(exercise_choice,user),:disabled => !@can_edit_excercise %>
|
||||
<%= convert_to_char((index+1).to_s)%> <%= exercise_choice.choice_text%>
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="testStatus" id="mcq_question_list" style="display: <%=mcq_question_list.count > 0 ? "" : "none" %>">
|
||||
<h3 class="fontGrey3">多选题</h3>
|
||||
<% mcq_question_list.each_with_index do |exercise_question, list_index| %>
|
||||
<div id="poll_questions_<%= exercise_question.id%>">
|
||||
<div id="show_poll_questions_<%= exercise_question.id %>">
|
||||
<div>
|
||||
<div class="testEditTitle"> 第<%= list_index+1%>题:<%= exercise_question.question_title %> (<%= exercise_question.question_score %>分)
|
||||
<span class="ml15 c_red">
|
||||
<% answer = get_user_answer(exercise_question, user)%>
|
||||
<% standard_answer = get_user_standard_answer(exercise_question, user)%>
|
||||
<% if !standard_answer.empty? && get_mulscore(exercise_question, user).to_i == standard_answer.first.exercise_choice_id %>
|
||||
√
|
||||
<% else %>
|
||||
×
|
||||
<% end %></span><br />
|
||||
标准答案:<%= convert_to_char(exercise_question.exercise_standard_answers.first.exercise_choice_id.to_s) %>
|
||||
</div>
|
||||
<div class="cl"></div>
|
||||
<div class="ur_inputs">
|
||||
<table class="ur_table" style="width:675px;">
|
||||
<tbody>
|
||||
<% exercise_question.exercise_choices.reorder("choice_position").each_with_index do |exercise_choice,index| %>
|
||||
<tr>
|
||||
<td>
|
||||
<label>
|
||||
<input class="ur_radio" type="checkbox" <%= answer_be_selected?(exercise_choice,user) ? "checked":"" %> <%= @can_edit_excercise?"":"disabled=disabled" %> >
|
||||
<%= convert_to_char((index+1).to_s)%> <%= exercise_choice.choice_text%>
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div><!--多选题显示 end-->
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="testStatus" id="single_question_list" style="display: <%=single_question_list.count > 0 ? "" : "none" %>">
|
||||
<h3 class="fontGrey3">填空题</h3>
|
||||
<% single_question_list.each_with_index do |exercise_question,list_index| %>
|
||||
<div id="poll_questions_<%= exercise_question.id%>">
|
||||
<div id="show_poll_questions_<%= exercise_question.id %>">
|
||||
<div>
|
||||
<div class="testEditTitle"> 第<%= list_index+1%>题:<%= exercise_question.question_title %> (<%= exercise_question.question_score %>分)
|
||||
<span class="ml15 c_red">
|
||||
<% answer = get_user_answer(exercise_question, user)%>
|
||||
<% standard_answer = get_user_standard_answer(exercise_question, user)%>
|
||||
<% if !answer.empty? && !standard_answer.empty? && standard_answer.include?(answer.first.answer_text) %>
|
||||
√
|
||||
<% else %>
|
||||
×
|
||||
<% end %></span><br />
|
||||
标准答案:<%= convert_to_char(exercise_question.exercise_standard_answers.first.exercise_choice_id.to_s) if exercise_question.exercise_standard_answers.first %>
|
||||
</div>
|
||||
<div class="cl"></div>
|
||||
<div>
|
||||
<% exercise_question.exercise_standard_answers.reorder("created_at").each_with_index do |exercise_choice,index| %>
|
||||
候选答案:<%= exercise_choice.answer_text%><br />
|
||||
<% end %>
|
||||
</div>
|
||||
<div>
|
||||
<input class="fillInput" placeholder="在此填入答案" type="text" value="<%= get_anwser_vote_text(exercise_question.id,user.id).html_safe %>" <%= @can_edit_excercise?"":"disabled=disabled" %>>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="cl"></div>
|
||||
<!--contentbox end-->
|
||||
</div>
|
||||
<!--RSide end-->
|
||||
</div>
|
|
@ -0,0 +1,37 @@
|
|||
<%= form_for('',
|
||||
:html => { :multipart => true },
|
||||
:url => {:controller => 'exercise',
|
||||
:action => 'commit_exercise',
|
||||
:id => exercise.id
|
||||
},:remote=>true ) do |f| %>
|
||||
<div class="ur_buttons">
|
||||
<a class="ur_button_submit" onclick="poll_submit();"> 提交 </a>
|
||||
<div class="polls_cha">
|
||||
<%= f.check_box 'show_result', :value => exercise.show_result%>
|
||||
<%= label_tag '_show_result', '允许学生查看测验结果' %>
|
||||
<!--<input name="exercise[show_result]" value="<%#exercise.show_result %>" type="checkbox" checked="true">
|
||||
<label for="">允许学生查看测验结果</label>-->
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
|
||||
<script type="text/javascript">
|
||||
function poll_submit() {
|
||||
var question_form = $("form.new_exercise_question");
|
||||
if($("#polls_head_edit").is(":visible")){
|
||||
alert("请先保存测验标题及测验基本信息。");
|
||||
} else if(question_form.length > 0) {
|
||||
alert("请先保存正在编辑的题目。");
|
||||
} else{
|
||||
$('#ajax-modal').html('<%= escape_javascript(render :partial => 'exercise_submit_info', locals: { :exercise => exercise}) %>');
|
||||
showModal('ajax-modal', '400px');
|
||||
//$('#ajax-modal').css('height','120px');
|
||||
$('#ajax-modal').siblings().remove();
|
||||
$('#ajax-modal').before("<span style='float: right;cursor:pointer;'>" +
|
||||
"<a href='javascript:' onclick='clickCanel();'><img src='/images/bid/close.png' width='26px' height='26px' /></a></span>");
|
||||
$('#ajax-modal').parent().removeClass("alert_praise");
|
||||
$('#ajax-modal').parent().css("top","").css("left","");
|
||||
$('#ajax-modal').parent().addClass("popbox_polls");
|
||||
}
|
||||
}
|
||||
</script>
|
|
@ -0,0 +1,40 @@
|
|||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
|
||||
<script type="text/javascript">
|
||||
function clickCanel(){hideModal("#popbox02");}
|
||||
function exercise_submit(){
|
||||
$("#exercise_submit>form")[0].submit();
|
||||
hideModal("#popbox02");
|
||||
}
|
||||
</script>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<div id="popbox02">
|
||||
<div class="upload_con">
|
||||
<div class="upload_box">
|
||||
<% current_score = get_current_score exercise %>
|
||||
<% question_count = exercise.exercise_questions.count %>
|
||||
<% mc_count = exercise.exercise_questions.where("question_type=1").count %>
|
||||
<% mcq_count = exercise.exercise_questions.where("question_type=2").count %>
|
||||
<% single_count = exercise.exercise_questions.where("question_type=3").count %>
|
||||
<p class="f14">当前测验<%if question_count >0%>共有<%= question_count %>道题,其中<%end%><%if mc_count > 0%><%=mc_count %>道单选、<%end%><%if mcq_count > 0%><%=mcq_count %>道多选、<%end%><%if single_count > 0%><%=single_count %>道填空,<%end%>总分为<span class="c_red"><%=current_score %></span>分。
|
||||
<br /><br />
|
||||
<% if exercise.publish_time.nil? %>点击提交后测验将立即发布,<% end %>是否确定提交该测验?
|
||||
</p>
|
||||
<div class="polls_btn_box">
|
||||
<a class="upload_btn" onclick="exercise_submit();">
|
||||
确 定
|
||||
</a>
|
||||
<a class="upload_btn upload_btn_grey" onclick="clickCanel();">
|
||||
取 消
|
||||
</a>
|
||||
</div>
|
||||
<div class="cl"></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</body>
|
||||
</html>
|
||||
|
|
@ -0,0 +1,125 @@
|
|||
<script type="text/javascript">
|
||||
$(function(){
|
||||
$("#RSide").removeAttr("id");
|
||||
$("#homework_page_right").css("min-height",$("#LSide").height()-30);
|
||||
$("#Container").css("width","1000px");
|
||||
});
|
||||
</script>
|
||||
<div class="homepageRight mt0 ml10">
|
||||
<div class="resources">
|
||||
<div class="testStatus"><!--头部显示 start-->
|
||||
<h1 class="ur_page_title" id="polls_name_h"><%= exercise.exercise_name%></h1>
|
||||
<div class="fontGrey2">
|
||||
<% unless exercise.publish_time.nil? %>
|
||||
<span class="mr100">发布时间:<%=Time.parse(h(exercise.publish_time)).strftime("%Y-%m-%d %H:%M:%S") %></span>
|
||||
<% end %>
|
||||
<span class="mr100">截止时间:<%=Time.parse(h(exercise.end_time)).strftime("%Y-%m-%d %H:%M:%S") %></span>
|
||||
<% if exercise.time != -1 %>
|
||||
<span class="fr">测验时长:<%=exercise.time %>分钟</span>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="testDesEdit mt5"><%= exercise.exercise_description.nil? ? "" : exercise.exercise_description.html_safe%></div>
|
||||
<div class="cl"></div>
|
||||
</div>
|
||||
<% mc_question_list = exercise.exercise_questions.where("question_type=1") %>
|
||||
<% mcq_question_list = exercise.exercise_questions.where("question_type=2") %>
|
||||
<% single_question_list = exercise.exercise_questions.where("question_type=3") %>
|
||||
<div class="testStatus" id="mc_question_list" style="display: <%=mc_question_list.count > 0 ? "" : "none" %>">
|
||||
<h3 class="fontGrey3">单选题</h3>
|
||||
<% mc_question_list.each_with_index do |exercise_question, list_index| %>
|
||||
<div id="poll_questions_<%= exercise_question.id%>">
|
||||
<div id="show_poll_questions_<%= exercise_question.id %>">
|
||||
<div>
|
||||
<div class="testEditTitle"> 第<%= list_index+1%>题:<%= exercise_question.question_title %> (<%= exercise_question.question_score %>分)
|
||||
<br />
|
||||
标准答案:<%= convert_to_char(exercise_question.exercise_standard_answers.first.exercise_choice_id.to_s) %>
|
||||
</div>
|
||||
<div class="cl"></div>
|
||||
<div class="ur_inputs">
|
||||
<table class="ur_table" style="width:675px;">
|
||||
<tbody>
|
||||
<% exercise_question.exercise_choices.reorder("choice_position").each_with_index do |exercise_choice,index| %>
|
||||
<tr>
|
||||
<td>
|
||||
<label>
|
||||
<input class="ur_radio" type="radio" name="<%= exercise_question %>" value="<%= exercise_choice.choice_text%>" >
|
||||
<%= convert_to_char((index+1).to_s)%> <%= exercise_choice.choice_text%>
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="testStatus" id="mcq_question_list" style="display: <%=mcq_question_list.count > 0 ? "" : "none" %>">
|
||||
<h3 class="fontGrey3">多选题</h3>
|
||||
<% mcq_question_list.each_with_index do |exercise_question, list_index| %>
|
||||
<div id="poll_questions_<%= exercise_question.id%>">
|
||||
<div id="show_poll_questions_<%= exercise_question.id %>">
|
||||
<div>
|
||||
<div class="testEditTitle"> 第<%= list_index+1%>题:<%= exercise_question.question_title %> (<%= exercise_question.question_score %>分)
|
||||
<br />
|
||||
标准答案:<%= convert_to_char(exercise_question.exercise_standard_answers.first.exercise_choice_id.to_s) %>
|
||||
</div>
|
||||
<div class="cl"></div>
|
||||
<div class="ur_inputs">
|
||||
<table class="ur_table" style="width:675px;">
|
||||
<tbody>
|
||||
<% exercise_question.exercise_choices.reorder("choice_position").each_with_index do |exercise_choice,index| %>
|
||||
<tr>
|
||||
<td>
|
||||
<label>
|
||||
<input class="ur_radio" type="checkbox" name="<%= exercise_question %>" value="<%= exercise_choice.choice_text%>" >
|
||||
<%= convert_to_char((index+1).to_s)%> <%= exercise_choice.choice_text%>
|
||||
</label>
|
||||
</td>
|
||||
</tr>
|
||||
<% end %>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div><!--多选题显示 end-->
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="testStatus" id="single_question_list" style="display: <%=single_question_list.count > 0 ? "" : "none" %>">
|
||||
<h3 class="fontGrey3">填空题</h3>
|
||||
<% single_question_list.each_with_index do |exercise_question, list_index| %>
|
||||
<div id="poll_questions_<%= exercise_question.id%>">
|
||||
<div id="show_poll_questions_<%= exercise_question.id %>">
|
||||
<div>
|
||||
<div class="testEditTitle"> 第<%= list_index+1%>题:<%= exercise_question.question_title %> (<%= exercise_question.question_score %>分)
|
||||
<br />
|
||||
标准答案:<%= convert_to_char(exercise_question.exercise_standard_answers.first.exercise_choice_id.to_s) if exercise_question.exercise_standard_answers.first%>
|
||||
</div>
|
||||
<div class="cl"></div>
|
||||
<div>
|
||||
<% exercise_question.exercise_standard_answers.reorder("created_at").each_with_index do |exercise_choice,index| %>
|
||||
候选答案:<%= exercise_choice.answer_text%><br />
|
||||
<% end %>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="ur_buttons">
|
||||
<%= link_to "确定",exercise_index_path(:course_id => @course.id),:class => "ur_button_submit" %>
|
||||
<% if exercise.exercise_status == 1 %>
|
||||
<%= link_to l(:button_edit), edit_exercise_path(exercise.id), :class => "ur_button_submit", :style => "float:right"%>
|
||||
<% else %>
|
||||
<span class="ur_button_submit" style="float:right; background:#a3a3a3" title="测验已发布,不可再编辑">编辑</span>
|
||||
<%#= link_to l(:button_edit), '', :class => "ur_button_submit", :style => "float:right; background:#a3a3a3"%>
|
||||
<% end %>
|
||||
</div>
|
||||
<div class="cl"></div>
|
||||
<!--contentbox end-->
|
||||
</div>
|
||||
<!--RSide end-->
|
||||
</div>
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue