diff --git a/app/controllers/exercise_controller.rb b/app/controllers/exercise_controller.rb
index c5ea5ba4..24bee1f8 100644
--- a/app/controllers/exercise_controller.rb
+++ b/app/controllers/exercise_controller.rb
@@ -164,36 +164,57 @@ class ExerciseController < ApplicationController
def shixun_question
@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
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 &&
- params[:ques_scores] && params[:ques_scores].length == 4
- shixuns = Shixun.where(id: params[:shixun_ids], status: 2, challenges_count: 1)
+ 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
+ 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|
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)
shixuns.where(trainee: index + 1).each do |shixun|
- ex_question = @exercise.exercise_questions.where(shixun_id: shixun.id).first
- if ex_question.present?
- ex_question.update_attributes(question_score: params[:ques_scores][index])
- ex_question.exercise_shixun_challenges.update_all(question_score: params[:ques_scores][index])
- else
- ex_question = ExerciseQuestion.create(exercise_id: @exercise.id, question_score: arams[:ques_scores][index],
- shixun_id: shixun.id, question_title: shixun.name, question_type: 5,
- question_number: 0, exercise_level_setting_id: level_setting.id)
- 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,
- question_score: params[:ques_scores][index], position: index + 1)
- ex_shixun_challenge.save
+ 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(question_score: params[:ques_scores][index], exercise_level_setting_id: level_setting.id)
+ ex_question.exercise_shixun_challenges.update_all(question_score: params[:ques_scores][index])
+ else
+ ex_question = ExerciseQuestion.create(exercise_id: @exercise.id, question_score: params[:ques_scores][index],
+ shixun_id: shixun.id, question_title: shixun.name, question_type: 5,
+ question_number: 0, exercise_level_setting_id: level_setting.id, level: index + 1)
+ 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,
+ question_score: params[:ques_scores][index], position: index + 1)
+ ex_shixun_challenge.save
+ end
end
end
end
end
end
end
+ redirect_to edit_exercise_path(@exercise)
end
def create
diff --git a/app/views/exercise/_new_question.html.erb b/app/views/exercise/_new_question.html.erb
index 2543b893..739f0870 100644
--- a/app/views/exercise/_new_question.html.erb
+++ b/app/views/exercise/_new_question.html.erb
@@ -6,7 +6,7 @@
+ 多选题
+ 填空题
+ 简答题
-<% 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 %>
+ 实训题
<% end %>
diff --git a/app/views/exercise/_new_shixun.html.erb b/app/views/exercise/_new_shixun.html.erb
index bcd85ba2..64bceba4 100644
--- a/app/views/exercise/_new_shixun.html.erb
+++ b/app/views/exercise/_new_shixun.html.erb
@@ -1,7 +1,7 @@
<% if exercise.id %>
- <%= form_for(ExerciseQuestion.new,
- :html => { :multipart => true, :id => "new_exercise_question"},
+ <%= form_for('',
+ :html => { :multipart => true, :id => "new_shixun_question"},
:url=>update_shixun_block_exercise_path(exercise.id)) do |f| %>
@@ -36,191 +36,63 @@
- <% end %>
实训题
- <% 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) %>
-
-
-
-
<%= shixun_question_level i %>
-
-
-
*分值:
分/题
-
*大于等于0,且不能大于100
-
*不能为空
-
*必须大于等于0
-
*不能大于100
-
-
-
-
*
- 随机出题量:
题
-
*不能为空
-
*必须为正整数
-
*不能大于可用题数
-
-
-
- 3
- 题可用
-
-
-
-
-
-
- <% end %>
- -
-
-
-
初级题
-
-
*分值:
-
分/题
-
*大于等于0,且不能大于100
-
*不能为空
-
*必须大于等于0
-
*不能大于100
-
+ <% for i in 1..4 %>
+ <% questions_list = exercise.exercise_questions.where(question_type: 5, level: i) %>
-
-
*
- 随机出题量:
题
-
*不能为空
-
*必须为正整数
-
*不能大于可用题数
-
+
-
+
-
- 3
- 题可用
-
+
<%= shixun_question_level i %>
+
+
*分值:
+
分/题
+
*大于等于0,且不能大于100
+
*不能为空
+
*必须大于等于0
+
*不能大于100
-
+
+
*
+ 随机出题量:
题
+
*不能为空
+
*必须为正整数
+
*不能大于可用题数
+
-
+
+ <%= questions_list.try(:count).to_i %>
+ 题可用
+
-
+
+
+ <% questions_list.each_with_index do |question, index| %>
-
-
-
-
-
-
-
-
-
-
-
中级题
-
-
-
*分值:
-
分/题
-
*大于等于0,且不能大于100
-
*不能为空
-
*必须大于等于0
-
*不能大于100
-
-
-
-
*
- 随机出题量:
题
-
*不能为空
-
*必须为正整数
-
*不能大于可用题数
-
-
-
- 3
- 题可用
-
-
-
-
-
-
-
-
+
+ <% end %>
@@ -237,7 +109,7 @@
-
+ <% end %>
<% end %>
@@ -245,58 +117,69 @@
$(function(){
//保存
$("#add_new_question").one('click', function(){
- // add_ex_question($(this),5);
- var Uarry=$("#ul li");//获取ul中所有的li元素
- var arr = [] //数组存放值
-
- for(var i = 0; i < Uarry.length; i++){
-
- var first = parseInt($("#minute"+i).val())
- var last = parseInt($("#topic"+i).val())
-
- console.log(first) //分数
- console.log(last) //题数
-
- if(first<0){
- $("#scorezero"+i).show()
-
- }else if(isNaN(first)){
- $("#scorenull"+i).show()
-
- }else if(first>100){
- $("#scoreone"+i).show()
-
- }
-
- if(last<0){
- $("#topicnull"+i).show()
-
- }else if(isNaN(last)){
- $("#topicinteger"+i).show()
-
- }else if(last>100){
- $("#topicreater"+i).show()
-
- }
-
+ add_shixun_question();
+ });
+ });
+ function add_shixun_question(){
+ var result = true;
+ var Uarry=$("#ul li:visible");//获取ul中所有的li元素
+
+ for(var i = 1; i <= Uarry.length; i++){
+
+ var first = parseInt($("#minute"+i).val());
+ var last = parseInt($("#topic"+i).val());
+ var available = parseInt($("#available"+i).html().trim());
+
+ console.log(first); //分数
+ console.log(last); //题数
+
+ if(first<0){
+ $("#scorezero"+i).show();
+ result = false;
+ }else if(isNaN(first)){
+ $("#scorenull"+i).show();
+ result = false;
+ }else if(first>100){
+ $("#scoreone"+i).show();
+ result = false;
+ } else {
+ $("#scorezero"+i).hide();
+ $("#scorenull"+i).hide();
+ $("#scoreone"+i).hide();
}
- 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){
var div=$("#shixunsbox"+num+" div");//获取所有子元素
- $("#shixunsbox"+num+" div")[key].remove();
- console.log(div)
+ $("#shixunsbox"+num+" div")[key].remove();
+ $("#available"+num).html($("#shixunsbox"+num+" div").length);
+ console.log($("#shixunsbox"+num+" div").length);
}
- function newshixuns(){
-
- var oDiv = document.getElementById('li');
-
- }
diff --git a/app/views/exercise/_new_shixun_exercise_list.html.erb b/app/views/exercise/_new_shixun_exercise_list.html.erb
index 8d841bdb..2b611f13 100644
--- a/app/views/exercise/_new_shixun_exercise_list.html.erb
+++ b/app/views/exercise/_new_shixun_exercise_list.html.erb
@@ -15,7 +15,7 @@
<%= link_to shixun.name, shixun_path(shixun), :class => "edu-info-dark task-hide mt3 ml20",:style=> "text-align:left", :target => "_blank" %>
- <%= link_to shixun.owner.try(:show_name), user_path(shixun.owner), :class => "mt3 task-hide" %> |
+ <%= link_to shixun.owner.try(:show_name), user_path(shixun.owner), :class => "mt3 task-hide", :target => "_blank" %> |
<%= shixun.shixun_level %> |
<% end %>
@@ -66,7 +66,6 @@
msg_list_loading = false;
var str = "";
$.each(json, function(index, array) {
- console.log(array);
str = '' +
' ' +
' ' +
diff --git a/app/views/exercise/shixun_question.js.erb b/app/views/exercise/shixun_question.js.erb
index c71a7851..52d03e55 100644
--- a/app/views/exercise/shixun_question.js.erb
+++ b/app/views/exercise/shixun_question.js.erb
@@ -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}) %>");
$("#quest_id").val(<%= params[:quest_id] %>);
<% else %>
$("#new_poll_question").html("<%= escape_javascript(render :partial => 'new_shixun', :locals => {:exercise=>@exercise}) %>");
-<% 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);
- }
- });
-});
\ No newline at end of file
+<% end %>
\ No newline at end of file
diff --git a/app/views/exercise/update_shixun_block.js.erb b/app/views/exercise/update_shixun_block.js.erb
deleted file mode 100644
index e69de29b..00000000
|