新版实训TPM单选多选题
This commit is contained in:
parent
0a1e895dc2
commit
32eaaef9fc
|
@ -2,8 +2,8 @@
|
|||
class ChallengesController < ApplicationController
|
||||
layout "base_shixun"
|
||||
before_filter :check_authentication
|
||||
before_filter :find_shixun, :only => [:index, :new, :create, :destroy, :challenge_build, :update_evaluation, :add_choose_question, :new_choose_question, :choose_type_show]
|
||||
before_filter :find_challenge, :only => [:show, :edit, :update, :challenge_build, :index_up, :index_down, :destroy, :update_evaluation, :add_choose_question, :new_choose_question, :choose_type_show]
|
||||
before_filter :find_shixun, :only => [:index, :new, :create, :destroy, :challenge_build, :update_evaluation, :add_choose_question, :new_choose_question, :choose_type_show, :edit_choose_question, :update_choose_question, :destroy_challenge_choose]
|
||||
before_filter :find_challenge, :only => [:show, :edit, :update, :challenge_build, :index_up, :index_down, :destroy, :update_evaluation, :add_choose_question, :new_choose_question, :choose_type_show, :edit_choose_question, :update_choose_question, :destroy_challenge_choose]
|
||||
before_filter :build_challege_from_params, :only => [:new, :create]
|
||||
before_filter :tpi_manager_allowed, :only => [:challenge_build, :destroy, :edit, :new, :create]
|
||||
before_filter :allowed_view, :only => [:show]
|
||||
|
@ -143,6 +143,47 @@ class ChallengesController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def update_choose_question
|
||||
@challenge_choose = ChallengeChoose.where(:id => params[:choose_id]).first
|
||||
ActiveRecord::Base.transaction do
|
||||
@challenge_choose.update_attributes(:subject => params[:choose][:subject],
|
||||
:answer => params[:choose][:answer],
|
||||
:standard_answer => params[:standard_answer],
|
||||
:score => params[:challenge][:score].to_i,
|
||||
:difficult => params[:challenge][:difficulty].to_i)
|
||||
begin
|
||||
@challenge_choose.challenge_questions.delete_all
|
||||
params[:question][:cnt].each_with_index do |test, index|
|
||||
answer = params[:choice][:answer][index] == "0" ? false : true
|
||||
ChallengeQuestion.create(:option_name => test, :challenge_choose_id => @challenge_choose.id, :position => index, :right_key => answer)
|
||||
end
|
||||
@challenge_choose.challenge_tags.delete_all unless @challenge_choose.challenge_tags.blank?
|
||||
unless params[:knowledge].blank?
|
||||
params[:knowledge][:input].each do |input|
|
||||
ChallengeTag.create(:name => input, :challenge_choose_id => @challenge_choose.id, :challenge_id => @challenge.id)
|
||||
end
|
||||
end
|
||||
@challenge_choose = ChallengeChoose.where(:id => params[:choose_id]).first
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
rescue Exception => e
|
||||
flash[:error] = "#{e.message}"
|
||||
format.html{redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun)}
|
||||
raise ActiveRecord::Rollback
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def edit_choose_question
|
||||
@challenge_choose = ChallengeChoose.where(:id => params[:choose_id]).first
|
||||
@category = @challenge_choose.category
|
||||
@position = @challenge_choose.position.to_i
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
|
||||
def choose_type_show
|
||||
@challenge_choose = ChallengeChoose.where(:id => params[:choose_id]).first
|
||||
|
||||
|
@ -151,6 +192,13 @@ class ChallengesController < ApplicationController
|
|||
end
|
||||
end
|
||||
|
||||
def destroy_challenge_choose
|
||||
@challenge_choose = ChallengeChoose.where(:id => params[:choose_id]).first
|
||||
@challenge_choose.destroy
|
||||
|
||||
redirect_to edit_shixun_challenge_path(@challenge, :shixun_id => @shixun)
|
||||
end
|
||||
|
||||
def add_choose_question
|
||||
@category = params[:category].to_i
|
||||
@position = params[:position]
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
<div class="stage-part-2 mt20">
|
||||
<ul class="nav_check_item border-bottom-orange clearfix">
|
||||
<li class="fl check_nav">
|
||||
<a href="<%= edit_shixun_challenge_path(@challenge, :shixun_id => @shixun, :tab => 1) %>" class="color-black">本关任务</a>
|
||||
<a href="<%= edit_shixun_challenge_path(@challenge, :shixun_id => @shixun) %>" class="color-black">本关任务</a>
|
||||
</li>
|
||||
<% @challenge.challenge_chooses.each_with_index do |choose, index| %>
|
||||
<li class="fl">
|
||||
|
|
|
@ -51,7 +51,7 @@
|
|||
<% else%>
|
||||
<% @challenge_choose.challenge_questions.each_with_index do |question, index| %>
|
||||
<li class="clearfix pr">
|
||||
<label class="panel-form-label fl"><span class="option-item fr mr10 color-grey select-choice <%= question.right_key ? "check-option-bg" : "" %>" onclick="selectchoice(this, <%= @challenge_choose.category %>);" name="option_span" title="点击设置答案"><%= (question.try(:postion) + 65).chr %></span></label>
|
||||
<label class="panel-form-label fl"><span class="option-item fr mr10 color-grey select-choice <%= question.right_key ? "check-option-bg" : "" %>" onclick="selectchoice(this, <%= @challenge_choose.category %>);" name="option_span" title="点击设置答案"><%= (question.try(:position) + 65).chr %></span></label>
|
||||
<input type="hidden" name="choice[answer][]">
|
||||
<textarea class="panel-form-width2-690 fl panel-box-sizing" name="question[cnt][]" placeholder="请输入选项内容"><%= question.try(:option_name) %></textarea>
|
||||
<a title="移除" class="position-delete option_icon_remove"><i class="fa fa-times-circle color-orange font-16 fl"></i></a>
|
||||
|
@ -65,7 +65,7 @@
|
|||
</li>
|
||||
<span style="display: none" class="c_red ml95" id="choice_error_tip"></span>
|
||||
<li class="clearfix" ><label class="fl" style="margin-left: 10%">温馨提示:点击选项,可以直接设置答案</label><label class="fr">标准答案:<span id="current-option" class="color-orange"><%= @challenge_choose.blank? ? "请点击正确选项" : @challenge_choose.try(:standard_answer) %></span></label></li>
|
||||
<input type="hidden" name="standard_answer">
|
||||
<input type="hidden" name="standard_answer" value="<%= @challenge_choose.try(:standard_answer) %>">
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
|
@ -86,15 +86,15 @@
|
|||
<li class="clearfix">
|
||||
<label class="panel-form-label fl"><span class="c_red mr5">*</span>难易度:</label>
|
||||
<span class="fl mt3 mr10">
|
||||
<input id="challenge_difficulty_1" class="magic-radio" name="challenge[difficulty]" type="radio" value="1" <%= ((@challenge_choose.try(:difficulty) == 1 || @challenge_choose.nil?) ? "checked" : "")%> >
|
||||
<input id="challenge_difficulty_1" class="magic-radio" name="challenge[difficulty]" type="radio" value="1" <%= ((@challenge_choose.try(:difficult) == 1 || @challenge_choose.nil?) ? "checked" : "")%> >
|
||||
<label for="challenge_difficulty_1">简单</label>
|
||||
</span>
|
||||
<span class="fl mt3 mr10">
|
||||
<input id="challenge_difficulty_2" class="magic-radio" name="challenge[difficulty]" type="radio" value="2" <%= (@challenge_choose.try(:difficulty)== 2 ? "checked" : "")%> >
|
||||
<input id="challenge_difficulty_2" class="magic-radio" name="challenge[difficulty]" type="radio" value="2" <%= (@challenge_choose.try(:difficult)== 2 ? "checked" : "")%> >
|
||||
<label for="challenge_difficulty_2">中等</label>
|
||||
</span>
|
||||
<span class="fl mt3">
|
||||
<input id="challenge_difficulty_3" class="magic-radio" name="challenge[difficulty]" type="radio" value="3" <%= (@challenge_choose.try(:difficulty) == 3 ? "checked" : "")%> >
|
||||
<input id="challenge_difficulty_3" class="magic-radio" name="challenge[difficulty]" type="radio" value="3" <%= (@challenge_choose.try(:difficult) == 3 ? "checked" : "")%> >
|
||||
<label for="challenge_difficulty_3">困难</label>
|
||||
</span>
|
||||
</li>
|
||||
|
@ -144,7 +144,7 @@
|
|||
</div>
|
||||
</div>
|
||||
<li class="clearfix pr30 pb30">
|
||||
<a href="javascript:void(0);" class="task-btn task-btn-green fr" onclick="challenge_choose_update(<%= @category %>)">保存</a>
|
||||
<a href="javascript:void(0);" class="task-btn task-btn-green fr" onclick="challenge_choose_update(<%= @category %>, '<%= @challenge_choose.blank? ? "new" : 'edit' %>')">保存</a>
|
||||
<a href="javascript:void(0)" class="task-btn fr mr10" id="skill_cancel">取消</a>
|
||||
</li>
|
||||
<% end %>
|
||||
|
@ -323,7 +323,7 @@
|
|||
if($(".check-option-bg").length>0){
|
||||
for(var i=0;i<$(".check-option-bg").length;i++){
|
||||
$("#current-option").html($("#current-option").html()+$(".check-option-bg").eq(i).html());
|
||||
$("input[name='standard_answer']").val($(".check-option-bg").eq(i).html())
|
||||
$("input[name='standard_answer']").val($("#current-option").html())
|
||||
}
|
||||
}else{
|
||||
$("#current-option").html("请点击正确选项");
|
||||
|
@ -426,7 +426,7 @@
|
|||
$("#scroe_show").show();
|
||||
});
|
||||
|
||||
function challenge_choose_update(st){
|
||||
function challenge_choose_update(st, action){
|
||||
set_choice_answer();
|
||||
var error = $("#choice_error_tip");
|
||||
if($('#challenge_choose_subject textarea').val().trim() == ""){
|
||||
|
@ -446,15 +446,26 @@
|
|||
}else if(judge_choice_answer() == 0){
|
||||
error.html("请设置答案").show();
|
||||
}else{
|
||||
$.ajax({
|
||||
url: "<%= new_choose_question_shixun_challenge_path(@challenge, :shixun_id => @shixun, :category => @category, :position => @position) %>",
|
||||
data: $("#challenge_choose_update").serialize(),
|
||||
type: 'POST',
|
||||
dataType: "script",
|
||||
success: function(){
|
||||
if(action == "new"){
|
||||
$.ajax({
|
||||
url: "<%= new_choose_question_shixun_challenge_path(@challenge, :shixun_id => @shixun, :category => @category, :position => @position) %>",
|
||||
data: $("#challenge_choose_update").serialize(),
|
||||
type: 'POST',
|
||||
dataType: "script",
|
||||
success: function(){
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}else{
|
||||
$.ajax({
|
||||
url: "<%= update_choose_question_shixun_challenge_path(@challenge, :shixun_id => @shixun, :choose_id => @challenge_choose.try(:id)) %>",
|
||||
data: $("#challenge_choose_update").serialize(),
|
||||
type: 'POST',
|
||||
dataType: "script",
|
||||
success: function(){
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}else if(st == "2"){
|
||||
if(judge_choice_contents()) {
|
||||
|
@ -464,26 +475,46 @@
|
|||
}else if(judge_choice_answer() < 2){
|
||||
error.html("答案不能少于2个").show();
|
||||
}else{
|
||||
if(action == "new"){
|
||||
$.ajax({
|
||||
url: "<%= new_choose_question_shixun_challenge_path(@challenge, :shixun_id => @shixun, :category => @category, :position => @position) %>",
|
||||
data: $("#challenge_choose_update").serialize(),
|
||||
type: 'POST',
|
||||
dataType: "script",
|
||||
success: function(){
|
||||
}
|
||||
});
|
||||
}else{
|
||||
$.ajax({
|
||||
url: "<%= update_choose_question_shixun_challenge_path(@challenge, :shixun_id => @shixun, :choose_id => @challenge_choose.try(:id)) %>",
|
||||
data: $("#challenge_choose_update").serialize(),
|
||||
type: 'POST',
|
||||
dataType: "script",
|
||||
success: function(){
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}else{
|
||||
if(action == "new"){
|
||||
$.ajax({
|
||||
url: "<%= new_choose_question_shixun_challenge_path(@challenge, :shixun_id => @shixun, :category => @category, :position => @position) %>",
|
||||
data: $("#challenge_choose_update").serialize(),
|
||||
dataType: "script",
|
||||
type: 'POST',
|
||||
dataType: "script",
|
||||
success: function(){
|
||||
}
|
||||
});
|
||||
}else{
|
||||
$.ajax({
|
||||
url: "<%= update_choose_question_shixun_challenge_path(@challenge, :shixun_id => @shixun, :choose_id => @challenge_choose.try(:id)) %>",
|
||||
data: $("#challenge_choose_update").serialize(),
|
||||
type: 'POST',
|
||||
dataType: "script",
|
||||
success: function(){
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}else{
|
||||
$.ajax({
|
||||
url: "<%= new_choose_question_shixun_challenge_path(@challenge, :shixun_id => @shixun, :category => @category, :position => @position) %>",
|
||||
data: $("#challenge_choose_update").serialize(),
|
||||
dataType: "script",
|
||||
type: 'POST',
|
||||
success: function(){
|
||||
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
<div class="white_bg">
|
||||
<div class="panel-form">
|
||||
<li class="clearfix pr30">
|
||||
<a href="javascript:void(0);" class="task-btn task-btn-green fr">编辑</a>
|
||||
<a href="javascript:void(0)" class="task-btn fr mr10 deloption-btn" id="skill_cancel">删除</a>
|
||||
<a href="<%= edit_choose_question_shixun_challenge_path(@challenge, :shixun_id => @shixun, :choose_id => @challenge_choose.id) %>" data-remote="true" class="task-btn task-btn-green fr">编辑</a>
|
||||
<a href="<%= destroy_challenge_choose_shixun_challenge_path(@challenge, :shixun_id => @shixun, :choose_id => @challenge_choose.id) %>" data-method="delete" class="task-btn fr mr10 deloption-btn">删除</a>
|
||||
</li>
|
||||
<li class="clearfix">
|
||||
<label class="panel-form-label fl">题干: </label>
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
$("#task_content").html("<%= j(render :partial => "single_or_multiple_question") %>");
|
|
@ -0,0 +1 @@
|
|||
$("#task_content").html("<%= j(render :partial => 'single_or_multiple_question_show')%>");
|
|
@ -119,6 +119,9 @@ RedmineApp::Application.routes.draw do
|
|||
match 'add_choose_question', :via => [:get, :post]
|
||||
post 'new_choose_question'
|
||||
match 'choose_type_show', :via => [:get, :post]
|
||||
match 'edit_choose_question', :via => [:get, :post]
|
||||
match 'update_choose_question', :via => [:get, :post]
|
||||
delete 'destroy_challenge_choose'
|
||||
end
|
||||
end
|
||||
|
||||
|
|
Loading…
Reference in New Issue