简单题更新,未完

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 = 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_title = params[:question_title].nil? || params[:question_title].empty? ? l(:label_enter_single_title) : params[:question_title]
@exercise_question.question_score = params[:question_score] @exercise_question.question_score = params[:question_score]
# 处理选项 # 处理选项:如果选了某个选项,那么则要删除之前的选项
if params[:question_answer] if params[:question_answer]
@exercise_question.exercise_choices.each do |answer| # @exercise_question.exercise_choices.each do |answer|
answer.destroy unless params[:question_answer].keys.include? answer.id.to_s # answer.destroy unless params[:question_answer].keys.include? answer.id.to_s
end # end
for i in 1..params[:question_answer].count for i in 1..params[:question_answer].count
question = @exercise_question.exercise_choices.find_by_id params[:question_answer].keys[i-1] 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] 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 if question
question.exercise_choices_id = i question.choice_position = i
question.answer_text = answer question.choice_text = answer
question.save question.save
else else
question_option = { question_option = {
:exercise_choice_id => i, :choice_position => i,
:answer_text => answer :choice_text => answer
} }
@exercise_question.exercise_answers.new question_option @exercise_question.exercise_choices.new question_option
end end
end end
end end
@exercise_question.save # 更新标准答案
respond_to do |format| if params[:exercise_choice]
format.js 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
end end
@ -231,7 +244,7 @@ class ExerciseController < ApplicationController
end end
end end
#发布问 # 发布试
def publish_excercise def publish_excercise
@exercise.exercise_status = 2 @exercise.exercise_status = 2
@exercise.publish_time = Time.now @exercise.publish_time = Time.now
@ -246,6 +259,19 @@ class ExerciseController < ApplicationController
end end
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 def student_exercise_list
@is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin? @is_teacher = User.current.allowed_to?(:as_teacher,@course) || User.current.admin?
@exercise = Exercise.find params[:id] @exercise = Exercise.find params[:id]
@ -264,7 +290,7 @@ class ExerciseController < ApplicationController
end end
end end
# 学生提交答卷,选着答案的课程中提交 # 学生提交答卷,选中答案的过程中提交
def commit_answer def commit_answer
eq = ExerciseQuestion.find(params[:exercise_question_id]) 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| %> <% exercise_question.exercise_choices.reorder("choice_position").each_with_index do |exercise_choice,index| %>
<li class="ur_item"> <li class="ur_item">
<label>选项<%=convert_to_char (index+1).to_s %><span class="ur_index"></span>&nbsp;&nbsp;&nbsp;</label> <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_add" title="向下插入选项" onclick="add_single_answer($(this));"></a>
<a class="icon_remove" title="删除" onclick="remove_single_answer($(this))"></a> <a class="icon_remove" title="删除" onclick="remove_single_answer($(this))"></a>
</li> </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| %>" + $("#poll_answers_<%=exercise_question.id%>").html("<% exercise_question.exercise_choices.reorder("choice_position").each_with_index do |exercise_choice,index| %>" +
"<li class='ur_item'>" + "<li class='ur_item'>" +
"<label>选项<%=convert_to_char (index+1).to_s %><span class='ur_index'></span>&nbsp;&nbsp;&nbsp;</label>" + "<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_add' title='向下插入选项' onclick='add_single_answer($(this));'></a>" +
"<a class='icon_remove' title='删除' onclick='remove_single_answer($(this))'></a>" + "<a class='icon_remove' title='删除' onclick='remove_single_answer($(this))'></a>" +
"</li>" + "</li>" +
@ -35,7 +35,7 @@
<% exercise_question.exercise_choices.reorder("choice_position").each_with_index do |exercise_choice,index| %> <% exercise_question.exercise_choices.reorder("choice_position").each_with_index do |exercise_choice,index| %>
<li class="ur_item"> <li class="ur_item">
<label>选项<%=convert_to_char (index+1).to_s %><span class="ur_index"></span>&nbsp;&nbsp;&nbsp;</label> <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_add" title="向下插入选项" onclick="add_single_answer($(this));"></a>
<a class="icon_remove" title="删除" onclick="remove_single_answer($(this))"></a> <a class="icon_remove" title="删除" onclick="remove_single_answer($(this))"></a>
</li> </li>

View File

@ -34,7 +34,7 @@
<% exercise_question.exercise_standard_answers.reorder("created_at").each_with_index do |exercise_choice,index| %> <% exercise_question.exercise_standard_answers.reorder("created_at").each_with_index do |exercise_choice,index| %>
<li class="ur_item"> <li class="ur_item">
<label>候选答案<span class="ur_index"></span>&nbsp;&nbsp;&nbsp;</label> <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_add" title="向下插入选项" onclick="add_single_answer($(this));"></a>
<a class="icon_remove" title="删除" onclick="remove_single_answer($(this));"></a> <a class="icon_remove" title="删除" onclick="remove_single_answer($(this));"></a>
</li> </li>