简单题更新,未完

This commit is contained in:
huang 2015-11-19 16:21:31 +08:00
parent cf4717278f
commit 841ebb7846
4 changed files with 44 additions and 18 deletions

View File

@ -188,30 +188,43 @@ class ExerciseController < ApplicationController
@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
# @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.exercise_choices_id = i
question.answer_text = answer
question.choice_position = i
question.choice_text = answer
question.save
else
question_option = {
:exercise_choice_id => i,
:answer_text => answer
:choice_position => i,
:choice_text => answer
}
@exercise_question.exercise_answers.new question_option
@exercise_question.exercise_choices.new question_option
end
end
end
@exercise_question.save
respond_to do |format|
format.js
# 更新标准答案
if params[:exercise_choice]
if @exercise_question.question_type == 3
for i in 1..params[:exercise_choice].count
question_standart = @exercise_question.exercise_standard_answers.find_by_id params[:exercise_choice].keys[i]
answer_standart = (params[:question_answer].values[i-1].nil? || params[:question_answer].values[i-1].empty?) ? l(:label_new_answer) : params[:question_answer].values[i-1]
end
else
answer_standart = @exercise_question.exercise_standard_answers.first
answer_standart.exercise_choice_id = params[:exercise_choice]
answer_standart.save
end
@exercise_question.save
respond_to do |format|
format.js
end
end
end
@ -231,7 +244,7 @@ class ExerciseController < ApplicationController
end
end
#发布问
# 发布试
def publish_excercise
@exercise.exercise_status = 2
@exercise.publish_time = Time.now
@ -246,6 +259,19 @@ class ExerciseController < ApplicationController
end
end
# 重新发布试卷
def republish_excercise
@exercise.exercise_questions.each do |exercise_question|
exercise_question.exercise_ansers.destroy_all
end
# @poll.poll_users.destroy_all
# @poll.polls_status = 1
# @poll.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]
@ -264,7 +290,7 @@ class ExerciseController < ApplicationController
end
end
# 学生提交答卷,选着答案的课程中提交
# 学生提交答卷,选中答案的过程中提交
def commit_answer
eq = ExerciseQuestion.find(params[:exercise_question_id])
# 已提交过的则不允许答题

View File

@ -35,7 +35,7 @@
<% 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>&nbsp;&nbsp;&nbsp;</label>
<input maxlength="200" type='text' name='question_answer[<%=index %>]' placeholder='输入选项内容' value="<%=exercise_choice.choice_text %>">
<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>

View File

@ -9,7 +9,7 @@
$("#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>&nbsp;&nbsp;&nbsp;</label>" +
"<input maxlength='200' type='text' name='question_answer[<%= index%>]' placeholder='输入选项内容' value='<%=exercise_choice.choice_text %>'/>" +
"<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>" +
@ -35,7 +35,7 @@
<% 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>&nbsp;&nbsp;&nbsp;</label>
<input maxlength="200" type='text' name='question_answer[0]' placeholder='输入选项内容' value="<%=exercise_choice.choice_text %>">
<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>

View File

@ -34,7 +34,7 @@
<% 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>&nbsp;&nbsp;&nbsp;</label>
<input name="exercise_choice[<%=index %>]" placeholder="请输入候选答案" type="text" value="<%=exercise_choice.answer_text %>"/>
<input name="exercise_choice[<%=exercise_choice.id %>]" placeholder="请输入候选答案" type="text" value="<%=exercise_choice.answer_text %>"/>
<a class="icon_add" title="向下插入选项" onclick="add_single_answer($(this));"></a>
<a class="icon_remove" title="删除" onclick="remove_single_answer($(this));"></a>
</li>