未设置考试时长时,只要还未到截止时间就可以一直提交试卷。

This commit is contained in:
cxt 2015-11-26 16:57:51 +08:00
parent ed9cef486f
commit f8621cac76
10 changed files with 47 additions and 29 deletions

View File

@ -34,17 +34,24 @@ class ExerciseController < ApplicationController
render_403
return
end
@can_edit_excercise = (!has_commit_exercise?(@exercise.id,User.current.id)) || User.current.admin?
exercise_end = Time.parse(format_time(@exercise.end_time)).strftime("%Y-%m-%d %H:%M:%S") > Time.now.strftime("%Y-%m-%d %H:%M:%S")
if @exercise.time == -1
@can_edit_excercise = exercise_end
else
@can_edit_excercise = (!has_commit_exercise?(@exercise.id,User.current.id)&& exercise_end) || User.current.admin?
end
@exercise_user = ExerciseUser.where("user_id=? and exercise_id=?", User.current.id, @exercise.id).first
# 学生点击的时候即创建关联,自动保存
#eu = ExerciseUser.create(:user_id => User.current, :exercise_id => @exercise.id, :start_at => Time.now, :status => false)
# 已提交问卷的用户不能再访问该界面
=begin
if has_commit_exercise?(@exercise.id, User.current.id) && (!User.current.admin?)
respond_to do |format|
format.html {render :layout => 'base_courses'}
end
else
=end
if !@is_teacher && !has_click_exercise?(@exercise.id, User.current.id)
eu = ExerciseUser.create(:user_id => User.current.id, :exercise_id => @exercise.id, :start_at => Time.now, :status => false)
@exercise_user = ExerciseUser.where("user_id=? and exercise_id=?", User.current.id, @exercise.id).first
@ -55,7 +62,7 @@ class ExerciseController < ApplicationController
respond_to do |format|
format.html {render :layout => 'base_courses'}
end
end
#end
end
def new
@ -82,7 +89,7 @@ class ExerciseController < ApplicationController
exercise ||= Exercise.new
exercise.exercise_name = params[:exercise][:exercise_name]
exercise.exercise_description = params[:exercise][:exercise_description]
exercise.end_time = params[:exercise][:end_time]
exercise.end_time = Time.at(params[:exercise][:end_time].to_time.to_i + 16*60*60 -1)
exercise.publish_time = params[:exercise][:publish_time]
exercise.user_id = User.current.id
exercise.time = params[:exercise][:time]
@ -107,7 +114,7 @@ class ExerciseController < ApplicationController
@exercise.exercise_name = params[:exercise][:exercise_name]
@exercise.exercise_description = params[:exercise][:exercise_description]
@exercise.time = params[:exercise][:time].blank? ? -1 : params[:exercise][:time]
@exercise.end_time = params[:exercise][:end_time]
@exercise.end_time = Time.at(params[:exercise][:end_time].to_time.to_i + 16*60*60 -1)
@exercise.publish_time = params[:exercise][:publish_time]
@exercise.show_result = params[:exercise][:show_result].blank? ? 1 : params[:exercise][:show_result]
if @exercise.save
@ -351,8 +358,8 @@ class ExerciseController < ApplicationController
# 学生提交答卷,选中答案的过程中提交
def commit_answer
eq = ExerciseQuestion.find(params[:exercise_question_id])
# 已提交过的则不允许答题
if has_commit_exercise?(@exercise.id,User.current.id) && (!User.current.admin?)
# 已提交过的且是限时的则不允许答题
if has_commit_exercise?(@exercise.id,User.current.id) && (!User.current.admin?) && @exercise.time != -1
render :json => {:text => "failure"}
return
end

View File

@ -1,7 +1,10 @@
<div id="popbox" style="text-align: center;margin-top: 25px">
<% if status == 0 %>
<% if status == 0 && exercise.time != -1 %>
<h3 style="font-weight: normal;color: green">提交成功!您的分数是:<%=@score %>分。</h3>
<%= link_to "确定", exercise_path(),:class => 'commit'%>
<% elsif status == 0 && Time.parse(format_time(exercise.end_time)).strftime("%Y-%m-%d %H:%M:%S") > Time.now.strftime("%Y-%m-%d %H:%M:%S") %>
<h3 style="font-weight: normal;color: green">提交成功!</h3>
<%= link_to "确定", exercise_index_path(:course_id => @course.id),:class => 'commit'%>
<% elsif status == 1 %>
<h3 style="font-weight: normal;color: red">您还有尚未作答的题目请完成后再提交!</h3>
<%= link_to "确定", "javascript:void(0)",:onclick => 'hidden_atert_form();',:class => 'commit'%>

View File

@ -53,7 +53,7 @@
<!--li><%#= link_to poll_name, poll_result_poll_path(poll.id), :class => "polls_title polls_title_st fl c_dblue" %></li>
<li class="pollsbtn_tip fl ml5">已答</li-->
<%#else%>
<%= link_to exercise_name, exercise_path(exercise.id), :class => "polls_title polls_title_st fl c_dblue"%>
<%= link_to (index.to_i+1).to_s+". "+exercise_name, exercise_path(exercise.id), :class => "polls_title polls_title_st fl c_dblue"%>
<%#end%>
<% end%>
<li class="polls_date fr mr10">截止时间:<%= format_time(exercise.end_time.to_s)%></li>

View File

@ -136,14 +136,14 @@
alert("测验标题不能为空");
} else if($.trim($("#exercise_end_time").val()) =="") {
alert("截止时间不能为空");
} else if(Date.parse($("#exercise_end_time").val()) < Date.now()) {
} else if((Date.parse($("#exercise_end_time").val())+(24*60*60-1)*1000) < Date.now()) {
alert("截止时间不能小于当前时间");
} else if($.trim($("#exercise_time").val()) !="" && !/^[1-9][0-9]*$/.test($.trim($("#exercise_time").val()))) {
alert("测验时长必须为非零开头的数字");
} else if($.trim($("#exercise_publish_time").val()) !="" && Date.parse($("#exercise_publish_time").val()) < Date.now()) {
alert("发布时间不能小于当前时间");
} else if($.trim($("#exercise_publish_time").val()) !="" && Date.parse($("#exercise_end_time").val()) <= Date.parse($("#exercise_publish_time").val())) {
alert("截止时间必须大于发布时间");
} else if($.trim($("#exercise_publish_time").val()) !="" && Date.parse($("#exercise_end_time").val()) < Date.parse($("#exercise_publish_time").val())) {
alert("截止时间不能小于发布时间");
} else {
doc.parent().parent().parent().submit();
}

View File

@ -3,6 +3,8 @@
$("#RSide").removeAttr("id");
$("#homework_page_right").css("min-height",$("#LSide").height()-30);
$("#Container").css("width","1000px");
end_time = <%=exercise.end_time.to_i%>
getTime(end_time);
/*start_time = new Date();
start_time.setFullYear(<%#=exercise_user.start_at.year%>);
start_time.setMonth(<%#=exercise_user.start_at.month%>);
@ -17,11 +19,16 @@
function getTime(end_time) {
//alert(end_time);
now = new Date();
var total_seconds = (now.getTime() - end_time)/1000;
var total_seconds = now.getTime()/1000 - end_time;
if (total_seconds < 0) {
$("#exercise_submit_btn").click();
return;
}
setTimeout("getTime("+end_time+");", 1000);
//start = new Date(start_time);
//end_time = start_time;
//var total_seconds = total_seconds - 1;
var hours = total_seconds / 60 / 60;
/*var hours = total_seconds / 60 / 60;
var hoursRound = Math.floor(hours);
var minutes = total_seconds /60 - (60 * hoursRound);
var minutesRound = Math.floor(minutes);
@ -29,9 +36,9 @@
var secondsRound = Math.round(seconds);
$("#rest_hours").html(hoursRound);
$("#rest_minutes").html(minutesRound);
$("#rest_seconds").html(secondsRound);
$("#rest_seconds").html(secondsRound);*/
//if(total_seconds >0) {
setTimeout("getTime("+end_time+");", 1000);
//setTimeout("getTime("+end_time+");", 1000);
//}
}
</script>
@ -41,8 +48,8 @@
<h1 class="ur_page_title" id="polls_name_h"><%= exercise.exercise_name%></h1>
<div id="start_time" style="display: none"><%=exercise_user.start_at %></div>
<div class="fontGrey2">
<span class="mr130">开始时间:<%=format_time(exercise_user.start_at.to_s)%></span>
<span class="mr130">截止时间:<%=format_time(exercise.end_time.to_s)%></span>
<span class="mr100">开始时间:<%=Time.parse(h(exercise_user.start_at)).strftime("%Y-%m-%d %H:%M:%S")%></span>
<span class="mr100">截止时间:<%=Time.parse(h(exercise.end_time)).strftime("%Y-%m-%d %H:%M:%S")%></span>
<% unless exercise.time == -1 %>
<span class="fr">测验时长:<%=exercise.time %>分钟</span>
<% end %>
@ -194,7 +201,7 @@
}
</script>
<input class="fillInput" placeholder="在此填入答案" type="text" value="" onblur="onblur_<%= exercise_question.id %>(this);" <%= @can_edit_excercise?"":"disabled=disabled" %>>
<input class="fillInput" placeholder="在此填入答案" type="text" value="<%= get_anwser_vote_text(exercise_question.id,User.current.id).html_safe %>" onblur="onblur_<%= exercise_question.id %>(this);" <%= @can_edit_excercise?"":"disabled=disabled" %>>
</div>
</div>
</div>
@ -202,7 +209,7 @@
<% end %>
</div>
<div class="ur_buttons">
<%= link_to l(:button_submit),commit_exercise_exercise_path(exercise), :method => :post,:class => "ur_button_submit",:style => "margin-left:80px;",:format => 'js',:remote=>true %>
<%= link_to l(:button_submit),commit_exercise_exercise_path(exercise),:id=>"exercise_submit_btn", :method => :post,:class => "ur_button_submit",:style => "margin-left:80px;",:format => 'js',:remote=>true %>
</div>
<div class="cl"></div>
<!--contentbox end-->

View File

@ -10,8 +10,8 @@
<div class="testStatus"><!--头部显示 start-->
<h1 class="ur_page_title" id="polls_name_h"><%= exercise.exercise_name%></h1>
<div class="fontGrey2">
<span class="mr130">开始时间:<%=format_time(exercise_user.start_at.to_s) %></span>
<span class="mr130">截止时间:<%=format_time(exercise.end_time.to_s)%></span>
<span class="mr100">开始时间:<%=Time.parse(h(exercise_user.start_at)).strftime("%Y-%m-%d %H:%M:%S") %></span>
<span class="mr100">截止时间:<%=Time.parse(h(exercise.end_time)).strftime("%Y-%m-%d %H:%M:%S")%></span>
<% unless exercise.time == -1 %>
<span class="fr">测验时长:<%=exercise.time %>分钟</span>
<% end %>
@ -34,7 +34,7 @@
<span class="ml15 c_red">
<% answer = get_user_answer(exercise_question, User.current)%>
<% standard_answer = get_user_standard_answer(exercise_question, User.current)%>
<% if answer.first.exercise_choice.choice_position == standard_answer.first.exercise_choice_id %>
<% if !answer.empty? && !standard_answer.empty? && answer.first.exercise_choice.choice_position == standard_answer.first.exercise_choice_id %>
<% else %>
×
@ -73,7 +73,7 @@
<span class="ml15 c_red">
<% answer = get_user_answer(exercise_question, User.current)%>
<% standard_answer = get_user_standard_answer(exercise_question, User.current)%>
<% if get_mulscore(exercise_question, User.current).to_i == standard_answer.first.exercise_choice_id %>
<% if !standard_answer.empty? && get_mulscore(exercise_question, User.current).to_i == standard_answer.first.exercise_choice_id %>
<% else %>
×
@ -112,7 +112,7 @@
<span class="ml15 c_red">
<% answer = get_user_answer(exercise_question, User.current)%>
<% standard_answer = get_user_standard_answer(exercise_question, User.current)%>
<% if standard_answer.include?(answer.first.answer_text) %>
<% if !answer.empty? && !standard_answer.empty? && standard_answer.include?(answer.first.answer_text) %>
<% else %>
×

View File

@ -11,9 +11,9 @@
<h1 class="ur_page_title" id="polls_name_h"><%= exercise.exercise_name%></h1>
<div class="fontGrey2">
<% unless exercise.publish_time.nil? %>
<span class="mr130">发布时间:<%=format_time(exercise.publish_time.to_s) %></span>
<span class="mr100">发布时间:<%=Time.parse(h(exercise.publish_time)).strftime("%Y-%m-%d %H:%M:%S") %></span>
<% end %>
<span class="mr130">截止时间:<%=format_time(exercise.end_time.to_s) %></span>
<span class="mr100">截止时间:<%=Time.parse(h(exercise.end_time)).strftime("%Y-%m-%d %H:%M:%S") %></span>
<% if exercise.time != -1 %>
<span class="fr">测验时长:<%=exercise.time %>分钟</span>
<% end %>

View File

@ -4,9 +4,9 @@
<h1 class="ur_page_title" id="polls_name_h"><%= exercise.exercise_name%></h1>
<div class="fontGrey2">
<% unless exercise.publish_time.nil? %>
<span class="mr100">发布时间:<%=Time.parse(format_time(exercise.publish_time)).strftime("%Y-%m-%d %H:%M:%S") if exercise.publish_time%></span>
<span class="mr100">发布时间:<%=Time.parse(h(exercise.publish_time)).strftime("%Y-%m-%d %H:%M:%S") if exercise.publish_time%></span>
<% end %>
<span class="mr100">截止时间:<%=Time.parse(format_time(exercise.end_time)).strftime("%Y-%m-%d %H:%M:%S") if exercise.end_time %></span>
<span class="mr100">截止时间:<%=Time.parse(h(exercise.end_time)).strftime("%Y-%m-%d %H:%M:%S") if exercise.end_time %></span>
<% if exercise.time != -1 %>
<span>测验时长:<%= exercise.time %>分钟</span>
<% end %>

View File

@ -1,4 +1,4 @@
$('#ajax-modal').html('<%= escape_javascript(render :partial => 'commit_alert',:locals => {:status => @status}) %>');
$('#ajax-modal').html('<%= escape_javascript(render :partial => 'commit_alert',:locals => {:status => @status,:exercise =>@exercise}) %>');
showModal('ajax-modal', '270px');
$('#ajax-modal').css('height','110px');
$('#ajax-modal').siblings().remove();

View File

@ -1166,4 +1166,5 @@ a:hover.testEdit{ background:url(images/icons.png) -21px -272px no-repeat;}
.questionEditContainer {border:1px solid #cbcbcb;background:#eeeeee; padding:10px; margin-bottom:10px; margin-top:10px;}
.fillInput {border:1px solid #cbcbcb; padding-left:5px; background-color:#ffffff; width:693px; height:30px; color:#888888;}
.mr130 {margin-right:130px;}
.mr100 {margin-right:100px;}
.ur_button_submit{ display:block; width:106px; height:31px; margin:0 auto; background:#15bccf; color:#fff; font-size:16px; text-align:center; padding-top:4px; margin-bottom:10px; }