实训题的新增

dev_local
cxt 6 years ago
parent 3bc33a2e0e
commit d9477f4b4b

@ -164,36 +164,57 @@ class ExerciseController < ApplicationController
def shixun_question def shixun_question
@shixuns = Shixun.where(id: params[:shixun_exercise]) @shixuns = Shixun.where(id: params[:shixun_exercise])
@shixuns.each do |shixun|
ActiveRecord::Base.transaction do
ex_question = @exercise.exercise_questions.where(question_type: 5, shixun_id: shixun.id).first
if ex_question.present?
ex_question.update_attributes(level: shixun.trainee)
else
ex_question = ExerciseQuestion.create(exercise_id: @exercise.id, shixun_id: shixun.id, question_title: shixun.name,
question_type: 5, question_number: 0, level: shixun.trainee)
shixun.challenges.each_with_index do |challenge, index|
ex_shixun_challenge = ExerciseShixunChallenge.new(challenge_id: challenge.id, shixun_id: shixun.id, exercise_question_id: ex_question.id,
position: index + 1)
ex_shixun_challenge.save
end
end
end
end
end end
def update_shixun_block def update_shixun_block
ActiveRecord::Base.transaction do if params[:shixun_ids] && params[:shixun_ids].length > 0 && params[:ques_nums] && params[:ques_nums].length == 4 &&
if params[:shixun_ids] && params[:shixun_ids].length > 0 && params[:ques_nums] && params[:ques_nums].length == 4 && params[:ques_scores] && params[:ques_scores].length == 4
params[:ques_scores] && params[:ques_scores].length == 4 shixuns = Shixun.where(id: params[:shixun_ids], status: 2, challenges_count: 1)
shixuns = Shixun.where(id: params[:shixun_ids], status: 2, challenges_count: 1) if shixuns.count > 0
shixun_ids = "(" + shixuns.pluck(:id).join(',') + ")"
@exercise.exercise_questions.where(question_type:5).where("shixun_id not in #{shixun_ids}").destroy_all
params[:ques_nums].each_with_index do |ques_num, index| params[:ques_nums].each_with_index do |ques_num, index|
level_setting = @exercise.exercise_level_settings.where(level: index + 1).first || level_setting = @exercise.exercise_level_settings.where(level: index + 1).first ||
ExerciseLevelSetting.create(exercise_id: @exercise.id) ExerciseLevelSetting.create(exercise_id: @exercise.id, level: index + 1)
level_setting.update_attributes(score: params[:ques_scores][index], num: ques_num) level_setting.update_attributes(score: params[:ques_scores][index], num: ques_num)
shixuns.where(trainee: index + 1).each do |shixun| shixuns.where(trainee: index + 1).each do |shixun|
ex_question = @exercise.exercise_questions.where(shixun_id: shixun.id).first ActiveRecord::Base.transaction do
if ex_question.present? ex_question = @exercise.exercise_questions.where(question_type:5, shixun_id: shixun.id).first
ex_question.update_attributes(question_score: params[:ques_scores][index]) if ex_question.present?
ex_question.exercise_shixun_challenges.update_all(question_score: params[:ques_scores][index]) ex_question.update_attributes(question_score: params[:ques_scores][index], exercise_level_setting_id: level_setting.id)
else ex_question.exercise_shixun_challenges.update_all(question_score: params[:ques_scores][index])
ex_question = ExerciseQuestion.create(exercise_id: @exercise.id, question_score: arams[:ques_scores][index], else
shixun_id: shixun.id, question_title: shixun.name, question_type: 5, ex_question = ExerciseQuestion.create(exercise_id: @exercise.id, question_score: params[:ques_scores][index],
question_number: 0, exercise_level_setting_id: level_setting.id) shixun_id: shixun.id, question_title: shixun.name, question_type: 5,
shixun.challenges.each_with_index do |challenge, index| question_number: 0, exercise_level_setting_id: level_setting.id, level: index + 1)
ex_shixun_challenge = ExerciseShixunChallenge.new(challenge_id: challenge.id, shixun_id: shixun.id, exercise_question_id: ex_question.id, shixun.challenges.each_with_index do |challenge, index|
question_score: params[:ques_scores][index], position: index + 1) ex_shixun_challenge = ExerciseShixunChallenge.new(challenge_id: challenge.id, shixun_id: shixun.id, exercise_question_id: ex_question.id,
ex_shixun_challenge.save question_score: params[:ques_scores][index], position: index + 1)
ex_shixun_challenge.save
end
end end
end end
end end
end end
end end
end end
redirect_to edit_exercise_path(@exercise)
end end
def create def create

@ -6,7 +6,7 @@
<a href="javascript:void(0);" class="fl mr20 add_item_part" onclick="add_MCQ();">+&nbsp;多选题</a> <a href="javascript:void(0);" class="fl mr20 add_item_part" onclick="add_MCQ();">+&nbsp;多选题</a>
<a href="javascript:void(0);" class="fl mr20 add_item_part" onclick="add_single();">+&nbsp;填空题</a> <a href="javascript:void(0);" class="fl mr20 add_item_part" onclick="add_single();">+&nbsp;填空题</a>
<a href="javascript:void(0);" class="fl mr20 add_item_part" onclick="add_multi();">+&nbsp;简答题</a> <a href="javascript:void(0);" class="fl mr20 add_item_part" onclick="add_multi();">+&nbsp;简答题</a>
<% if @exercise.try(:id).nil? || @exercise.exercise_questions.where(question_type: 5).count == 0 %> <% if @exercise.try(:id).nil? || @exercise.exercise_questions.where("question_type = 5 and exercise_level_setting_id != 0").count == 0 %>
<a href="javascript:void(0);" class="fl add_item_part" onclick="add_shixun();">+&nbsp;实训题</a> <a href="javascript:void(0);" class="fl add_item_part" onclick="add_shixun();">+&nbsp;实训题</a>
<% end %> <% end %>

@ -1,7 +1,7 @@
<% if exercise.id %> <% if exercise.id %>
<div nhname="new_exercise_mc_q"> <div nhname="new_exercise_mc_q">
<%= form_for(ExerciseQuestion.new, <%= form_for('',
:html => { :multipart => true, :id => "new_exercise_question"}, :html => { :multipart => true, :id => "new_shixun_question"},
:url=>update_shixun_block_exercise_path(exercise.id)) do |f| %> :url=>update_shixun_block_exercise_path(exercise.id)) do |f| %>
<!-- <div class="user_bg_shadow bor-grey-e pl15 pr30 mb20 answer_Temp" id="answer_Temp">--> <!-- <div class="user_bg_shadow bor-grey-e pl15 pr30 mb20 answer_Temp" id="answer_Temp">-->
<!-- <p class="fl mt15 font-16 mb10">实训题</p>--> <!-- <p class="fl mt15 font-16 mb10">实训题</p>-->
@ -36,191 +36,63 @@
<!-- </p>--> <!-- </p>-->
<!-- </li>--> <!-- </li>-->
<!-- </div>--> <!-- </div>-->
<% end %>
<div class="user_bg_shadow bor-grey-e mb20 answer_Temp edu-back-white practicalTemp" id="shixun_question_block"> <div class="user_bg_shadow bor-grey-e mb20 answer_Temp edu-back-white practicalTemp" id="shixun_question_block">
<div class="fl mt15 font-16 mb10 padding10 practicalTitlefont">实训题</div> <div class="fl mt15 font-16 mb10 padding10 practicalTitlefont">实训题</div>
<% second_questions = @exercise.level_setting(2).try(:exercise_questions) %>
<% third_questions = @exercise.level_setting(3).try(:exercise_questions) %>
<% fourth_questions = @exercise.level_setting(4).try(:exercise_questions) %>
<% for i in 1..5 %>
<% questions_list = @exercise.level_setting(i).try(:exercise_questions) %>
<div class="<%= questions_list.try(:count).to_i > 0 ? '' : 'none' %>" id="edit_first_block">
<div class="fl font-16 mb10 practicalTitle">
<span class="Titlefont"><%= shixun_question_level i %></span>
<div class="fr mr40 shixun-title-font">
<span class="color-red mr5 shixun-title-font">*</span>分值:<input class="borderFF8121" value=""/> 分/题
<div class="colorFF8121sum">*大于等于0且不能大于100</div>
<div class="colorFF8121sum">*不能为空</div>
<div class="colorFF8121sum">*必须大于等于0</div>
<div class="colorFF8121sum">*不能大于100</div>
</div>
<div class="fr mr40 shixun-title-font">
<span class="color-red mr5 shixun-title-font">*</span>
随机出题量:<input class="borderFF8121"/> 题
<div class="colorFF8121">*不能为空</div>
<div class="colorFF8121">*必须为正整数</div>
<div class="colorFF8121">*不能大于可用题数</div>
</div>
<div class="fr mr40 shixun-title-font">
<span class="color-orange mr5 shixun-title-font">3</span>
题可用
</div>
</div>
<div class="fl mb10 shixunsbox">
<div>
<a class="shixunsboxfont">命令加密ZPI压缩文件解压</a>
<span class="shixundelect">
<i data-tip-down="删除" class="fa fa-times-circle mr10 color-afafaf"></i>
</span>
</div>
<div>
<a class="shixunsboxfont">命令加密ZPI压缩文件解压</a>
<span class="shixundelect">
<i data-tip-down="删除" class="fa fa-times-circle mr10 color-afafaf"></i>
</span>
</div>
<div>
<a class="shixunsboxfont">命令加密ZPI压缩文件解压</a>
<span class="shixundelect">
<i data-tip-down="删除" class="fa fa-times-circle mr10 color-afafaf"></i>
</span>
</div>
</div>
</div>
<% end %>
<ul class="fl" id="ul"> <ul class="fl" id="ul">
<li id="0">
<div class="fl font-16 mb10 practicalTitle">
<span class="Titlefont">初级题</span>
<div class="fr mr40 shixun-title-font"> <% for i in 1..4 %>
<span class="color-red mr5 shixun-title-font">*</span>分值: <% questions_list = exercise.exercise_questions.where(question_type: 5, level: i) %>
<input id="minute0" class="borderFF8121"/> 分/题
<div class="colorFF8121sum none" id="scoregreater0">*大于等于0且不能大于100</div>
<div class="colorFF8121sum none" id="scorenull0">*不能为空</div>
<div class="colorFF8121sum none" id="scorezero0">*必须大于等于0</div>
<div class="colorFF8121sum none" id="scoreone0">*不能大于100</div>
</div>
<div class="fr mr40 shixun-title-font"> <li id="edit_shixun_ques_<%= i %>" class="<%= questions_list.try(:count).to_i > 0 ? '' : 'none' %>">
<span class="color-red mr5 shixun-title-font">*</span> <div class="fl font-16 mb10 practicalTitle">
随机出题量:<input id="topic0" class="borderFF8121"/> 题
<div class="colorFF8121 none" id="topicnull0">*不能为空</div>
<div class="colorFF8121 none" id="topicinteger0">*必须为正整数</div>
<div class="colorFF8121 none" id="topicreater0">*不能大于可用题数</div>
</div>
<div class="fr mr40 shixun-title-font"> <span class="Titlefont"><%= shixun_question_level i %></span>
<span class="color-orange mr5 shixun-title-font">3</span>
题可用
</div>
<div class="fr mr40 shixun-title-font">
<span class="color-red mr5 shixun-title-font">*</span>分值:
<input id="minute<%= i %>" value="<%= exercise.level_setting(i).try(:score) %>" name="ques_scores[]" class="borderFF8121"/> 分/题
<div class="colorFF8121sum none" id="scoregreater<%= i %>">*大于等于0且不能大于100</div>
<div class="colorFF8121sum none" id="scorenull<%= i %>">*不能为空</div>
<div class="colorFF8121sum none" id="scorezero<%= i %>">*必须大于等于0</div>
<div class="colorFF8121sum none" id="scoreone<%= i %>">*不能大于100</div>
</div> </div>
<div class="fl mb10 shixunsbox" id="shixunsbox0"> <div class="fr mr40 shixun-title-font">
<span class="color-red mr5 shixun-title-font">*</span>
随机出题量:<input id="topic<%= i %>" value="<%= exercise.level_setting(i).try(:num) || questions_list.try(:count) %>" name="ques_nums[]" class="borderFF8121"/> 题
<div class="colorFF8121 none" id="topicnull<%= i %>">*不能为空</div>
<div class="colorFF8121 none" id="topicinteger<%= i %>">*必须为正整数</div>
<div class="colorFF8121 none" id="topicreater<%= i %>">*不能大于可用题数</div>
</div>
<div> <div class="fr mr40 shixun-title-font">
<a class="shixunsboxfont">命令加密ZPI压缩文件解压</a> <span class="color-orange mr5 shixun-title-font" id="available<%= i %>"><%= questions_list.try(:count).to_i %></span>
<span class="shixundelect"> 题可用
<i data-tip-down="删除" class="fa fa-times-circle mr10 color-afafaf" onclick="shixunboxdelete(0,0)"></i> </div>
</span>
</div>
<div> </div>
<a class="shixunsboxfont">命令加密ZPI压缩文件解压</a>
<span class="shixundelect">
<i data-tip-down="删除" class="fa fa-times-circle mr10 color-afafaf" onclick="shixunboxdelete(0,1)"></i>
</span>
</div>
<div class="fl mb10 shixunsbox" id="shixunsbox<%= i %>">
<% questions_list.each_with_index do |question, index| %>
<div> <div>
<a class="shixunsboxfont">命令加密ZPI压缩文件解压</a> <input type="hidden" name="shixun_ids[]" value="<%= question.shixun_id %>">
<span class="shixunsboxfont"><%= question.question_title %></span>
<span class="shixundelect"> <span class="shixundelect">
<i data-tip-down="删除" class="fa fa-times-circle mr10 color-afafaf" onclick="shixunboxdelete(0,2)"></i> <i data-tip-down="删除" class="fa fa-times-circle mr10 color-afafaf" onclick="shixunboxdelete(<%= i %>, <%= index %>)"></i>
</span> </span>
</div> </div>
<% end %>
</div>
</li>
<li id="1">
<div class="fl font-16 mb10 practicalTitle">
<span class="Titlefont">中级题</span>
<div class="fr mr40 shixun-title-font">
<span class="color-red mr5 shixun-title-font">*</span>分值:
<input id="minute1" class="borderFF8121"/> 分/题
<div class="colorFF8121sum none" id="scoregreater1">*大于等于0且不能大于100</div>
<div class="colorFF8121sum none" id="scorenull1">*不能为空</div>
<div class="colorFF8121sum none" id="scorezero1">*必须大于等于0</div>
<div class="colorFF8121sum none" id="scoreone1">*不能大于100</div>
</div>
<div class="fr mr40 shixun-title-font">
<span class="color-red mr5 shixun-title-font">*</span>
随机出题量:<input id="topic1" class="borderFF8121"/> 题
<div class="colorFF8121 none" id="topicnull1">*不能为空</div>
<div class="colorFF8121 none" id="topicinteger1">*必须为正整数</div>
<div class="colorFF8121 none" id="topicreater1">*不能大于可用题数</div>
</div>
<div class="fr mr40 shixun-title-font">
<span class="color-orange mr5 shixun-title-font">3</span>
题可用
</div>
</div>
<div class="fl mb10 shixunsbox">
<div>
<a class="shixunsboxfont">命令加密ZPI压缩文件解压</a>
<span class="shixundelect">
<i data-tip-down="删除" class="fa fa-times-circle mr10 color-afafaf"></i>
</span>
</div>
<div>
<a class="shixunsboxfont">命令加密ZPI压缩文件解压</a>
<span class="shixundelect">
<i data-tip-down="删除" class="fa fa-times-circle mr10 color-afafaf"></i>
</span>
</div>
<div>
<a class="shixunsboxfont">命令加密ZPI压缩文件解压</a>
<span class="shixundelect">
<i data-tip-down="删除" class="fa fa-times-circle mr10 color-afafaf"></i>
</span>
</div> </div>
</li>
</div> <% end %>
</li>
</ul> </ul>
<div class="fl mb10 shixunsboxs"> <div class="fl mb10 shixunsboxs">
<div class="newshixunbox"> <div class="newshixunbox">
<div class="newshixunboxfont" onclick="newshixuns()">新增实训题</div> <div class="newshixunboxfont" onclick="add_shixun();">新增实训题</div>
</div> </div>
</div> </div>
@ -237,7 +109,7 @@
</div> </div>
<% end %>
</div> </div>
<% end %> <% end %>
@ -245,58 +117,69 @@
$(function(){ $(function(){
//保存 //保存
$("#add_new_question").one('click', function(){ $("#add_new_question").one('click', function(){
// add_ex_question($(this),5); add_shixun_question();
var Uarry=$("#ul li");//获取ul中所有的li元素 });
var arr = [] //数组存放值 });
function add_shixun_question(){
for(var i = 0; i < Uarry.length; i++){ var result = true;
var Uarry=$("#ul li:visible");//获取ul中所有的li元素
var first = parseInt($("#minute"+i).val())
var last = parseInt($("#topic"+i).val()) for(var i = 1; i <= Uarry.length; i++){
console.log(first) //分数 var first = parseInt($("#minute"+i).val());
console.log(last) //题数 var last = parseInt($("#topic"+i).val());
var available = parseInt($("#available"+i).html().trim());
if(first<0){
$("#scorezero"+i).show() console.log(first); //分数
console.log(last); //题数
}else if(isNaN(first)){
$("#scorenull"+i).show() if(first<0){
$("#scorezero"+i).show();
}else if(first>100){ result = false;
$("#scoreone"+i).show() }else if(isNaN(first)){
$("#scorenull"+i).show();
} result = false;
}else if(first>100){
if(last<0){ $("#scoreone"+i).show();
$("#topicnull"+i).show() result = false;
} else {
}else if(isNaN(last)){ $("#scorezero"+i).hide();
$("#topicinteger"+i).show() $("#scorenull"+i).hide();
$("#scoreone"+i).hide();
}else if(last>100){
$("#topicreater"+i).show()
}
} }
console.log(arr) if(last<0){
$("#topicnull"+i).show();
}); result = false;
}else if(isNaN(last)){
$("#topicinteger"+i).show();
result = false;
}else if(last>available){
$("#topicreater"+i).show();
result = false;
} else {
$("#topicnull"+i).hide();
$("#topicinteger"+i).hide();
$("#topicreater"+i).hide();
}
}); }
console.log(result);
if(result){
$("#new_shixun_question").submit();
} else{
$("#add_new_question").one('click', function(){
add_shixun_question();
});
}
}
function shixunboxdelete(num,key){ function shixunboxdelete(num,key){
var div=$("#shixunsbox"+num+" div");//获取所有子元素 var div=$("#shixunsbox"+num+" div");//获取所有子元素
$("#shixunsbox"+num+" div")[key].remove(); $("#shixunsbox"+num+" div")[key].remove();
console.log(div) $("#available"+num).html($("#shixunsbox"+num+" div").length);
console.log($("#shixunsbox"+num+" div").length);
} }
function newshixuns(){
var oDiv = document.getElementById('li');
}
</script> </script>

@ -15,7 +15,7 @@
<label style="top:2px" for="shixun_input_<%= shixun.id %>"></label> <label style="top:2px" for="shixun_input_<%= shixun.id %>"></label>
<%= link_to shixun.name, shixun_path(shixun), :class => "edu-info-dark task-hide mt3 ml20",:style=> "text-align:left", :target => "_blank" %> <%= link_to shixun.name, shixun_path(shixun), :class => "edu-info-dark task-hide mt3 ml20",:style=> "text-align:left", :target => "_blank" %>
</td> </td>
<td class="width100p"><%= link_to shixun.owner.try(:show_name), user_path(shixun.owner), :class => "mt3 task-hide" %></td> <td class="width100p"><%= link_to shixun.owner.try(:show_name), user_path(shixun.owner), :class => "mt3 task-hide", :target => "_blank" %></td>
<td class="width100p"><%= shixun.shixun_level %></td> <td class="width100p"><%= shixun.shixun_level %></td>
</tr> </tr>
<% end %> <% end %>
@ -66,7 +66,6 @@
msg_list_loading = false; msg_list_loading = false;
var str = ""; var str = "";
$.each(json, function(index, array) { $.each(json, function(index, array) {
console.log(array);
str = '<tr>' + str = '<tr>' +
' <td class="clearfix" style="padding-left: 20px">' + ' <td class="clearfix" style="padding-left: 20px">' +
' <input name="shixun_exercise[]" type="checkbox" class="magic-checkbox" id="shixun_input_'+array["id"]+'" value="'+array["id"]+'">' + ' <input name="shixun_exercise[]" type="checkbox" class="magic-checkbox" id="shixun_input_'+array["id"]+'" value="'+array["id"]+'">' +

@ -1,25 +1,6 @@
<% if params[:quest_id] && params[:quest_id] != "" %> <% if @exercise.exercise_questions.where("question_type = 5 and exercise_level_setting_id != 0").count > 0 %>
$("#insert_new_poll_question_<%= params[:quest_id] %>").html("<%= escape_javascript(render :partial => 'new_shixun', :locals => {:exercise=>@exercise}) %>"); $("#insert_new_poll_question_<%= params[:quest_id] %>").html("<%= escape_javascript(render :partial => 'new_shixun', :locals => {:exercise=>@exercise}) %>");
$("#quest_id").val(<%= params[:quest_id] %>); $("#quest_id").val(<%= params[:quest_id] %>);
<% else %> <% else %>
$("#new_poll_question").html("<%= escape_javascript(render :partial => 'new_shixun', :locals => {:exercise=>@exercise}) %>"); $("#new_poll_question").html("<%= escape_javascript(render :partial => 'new_shixun', :locals => {:exercise=>@exercise}) %>");
<% end %> <% end %>
$("#poll_questions_title").focus();
KindEditor.ready(function(K){
$("div[nhname='new_exercise_mc_q']").each(function(){
var params = {};
params.kindutil = K;
params.div_form = $(this);
params.form = $("form",params.div_form);
params.placeholder = "请输入实训题的完成要求";
if(params.form==undefined || params.form.length==0){
return;
}
params.textarea = $("textarea[name='question_title']",params.div_form);
if(params.textarea.data('init') == undefined) {
params.editor = init_exercise_quetison_editor(params);
new_quetion_title_editor = params.editor;
params.textarea.data('init', 1);
}
});
});
Loading…
Cancel
Save