保存测验信息

This commit is contained in:
cxt 2015-11-17 18:22:31 +08:00
parent 034a92bb7b
commit cc08e5e32e
9 changed files with 101 additions and 40 deletions

View File

@ -1,7 +1,7 @@
class ExerciseController < ApplicationController
layout "base_courses"
before_filter :find_course, :only => [:index,:new,:create,:student_exercise_list]
before_filter :find_course, :only => [:index,:new,:create,:student_exercise_list,:edit]
def index
@is_teacher = User.current.allowed_to?(:as_teacher,@course)
if @is_teacher
@ -27,10 +27,28 @@ class ExerciseController < ApplicationController
end
def create
if params[:exercise]
exercise = Exercise.find(params[:exercise_id]) if params[:exercise_id]
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.publish_time = params[:exercise][:publish_time]
exercise.user_id = User.current.id
exercise.time = params[:exercise][:time]
exercise.course_id = params[:course_id]
exercise.exercise_status = 1
if exercise.save
@exercise = exercise
respond_to do |format|
format.js
end
end
end
end
def edit
@exercise = Exercise.find params[:id]
respond_to do |format|
format.html{render :layout => 'base_courses'}
end

View File

@ -1,24 +1,38 @@
<div class="testContainer">
<div>
<input class="testTitle mb10" type="text" placeholder="测验标题" />
</div>
<%# if edit_mode %>
<!--<label class="fl c_grey f14" style="margin-top: 4px;">截止日期:</label>-->
<%# end %>
<div class="calendar_div fl mr10">
<input type="text" name="homework_common[end_time]" id="homework_end_time" placeholder="截止日期" class="InputBox fl W120 calendar_input" readonly="readonly" value="<%= homework.end_time%>" >
<%= calendar_for('homework_end_time')%>
</div>
<%# if edit_mode %>
<!--<label class="fl c_grey f14" style="margin-top: 4px;">发布日期(可选)</label>-->
<%# end %>
<div class="calendar_div fl">
<input type="text" name="homework_common[publish_time]" id="homework_publish_time" placeholder="发布日期(可选)" class="InputBox fl W120 calendar_input" readonly="readonly" value="<%= homework.publish_time%>" >
<%= calendar_for('homework_publish_time')%>
</div>
<div class="fl ml10 f14 fontGrey2"><span class="mr5">考试时长:</span><input type="text" class="examTime mr5" />分钟</div>
<div class="cl"></div>
<textarea class="testDes mt10" placeholder="发布须知试题类型有选择和填空两种其中选择题包括单选题和多选题。多选题的答案格式为若标准答案为A,B,C在答案输入框填入ABC即可。填空题问题格式为”电脑的核心部件是”根据问题设置与答案相关的关键词系统会根据关键词匹配学生上交的答案关键词可设置多个。谢谢您的配合您可以在此处填写测验相关说明。" ></textarea>
<a href="javascript:void(0);" class="btn_submit c_white" >保存</a> <a href="javascript:void(0);" class="btn_cancel" >取消</a>
<div class="cl"></div>
</div>
<%= form_for(@exercise,
:html => { :multipart => true },
:url => {:controller => 'exercise',
:action => 'create',
:course_id => @course.id
},:remote=>true ) do |f| %>
<div class="testContainer">
<div>
<input name="exercise[exercise_name]" maxlength="100" id="exercise_name" class="testTitle mb10" type="text" placeholder="测验标题" value="<%=@exercise.exercise_name%>" />
</div>
<%# if edit_mode %>
<!--<label class="fl c_grey f14" style="margin-top: 4px;">发布日期(可选)</label>-->
<%# end %>
<div class="calendar_div fl mr10">
<input type="text" name="exercise[publish_time]" id="exercise_publish_time" placeholder="发布时间" class="InputBox fl W120 calendar_input" readonly="readonly" value="<%= exercise.publish_time%>" >
<%= calendar_for('exercise_publish_time')%>
</div>
<%# if edit_mode %>
<!--<label class="fl c_grey f14" style="margin-top: 4px;">截止日期:</label>-->
<%# end %>
<div class="calendar_div fl">
<input type="text" name="exercise[end_time]" id="exercise_end_time" placeholder="截止时间" class="InputBox fl W120 calendar_input" readonly="readonly" value="<%= exercise.end_time%>" >
<%= calendar_for('exercise_end_time')%>
</div>
<div class="fl ml10 f14 fontGrey2"><span class="mr5">考试时长:</span><input name="exercise[time]" id="exercise_time" type="text" class="examTime mr5" value="<%=exercise.time %>" />分钟</div>
<div class="cl"></div>
<textarea class="testDes mt10" name="exercise[exercise_description]" id="exercise_description" value="<%=exercise.exercise_description %>" placeholder="发布须知:试题类型有选择和填空两种,其中选择题包括单选题和多选题。您可以在此处填写测验相关说明。" ></textarea>
<div class="ur_editor_footer" style="padding-top: 10px;">
<a class="btn_submit c_white" data-button="ok" onclick="pollsSubmit($(this));">
保存
</a>
<a class="btn_cancel" data-button="cancel" onclick="pollsCancel();">
<%= l(:button_cancel)%>
</a>
</div>
<div class="cl"></div>
</div>
<% end %>

View File

@ -1,5 +1,5 @@
<% poll.exercise_questions.each do |poll_question|%>
<% exercise.exercise_questions.each do |poll_question|%>
<div id="poll_questions_<%= poll_question.id%>">
<!--<div id="show_poll_questions_<%= poll_question.id %>">
<%# if poll_question.question_type == 1%>

View File

@ -244,8 +244,21 @@
//问卷头
function pollsCancel(){$("#polls_head_edit").hide();$("#polls_head_show").show();}
function pollsSubmit(doc){
var title = $.trim($("#polls_title").val());
if(title.length == 0){alert("测验标题不能为空");}else{doc.parent().parent().parent().submit();}
var title = $.trim($("#exercise_name").val());
if(title.length == 0){
alert("测验标题不能为空");
} else if($.trim($("#exercise_publish_time").val()) =="") {
alert("发布时间不能为空");
} else if($.trim($("#exercise_end_time").val()) =="") {
alert("截止时间不能为空");
} else if($.trim($("#exercise_time").val()) =="") {
alert("考试时长不能为空");
} else if(Date.parse($("#exercise_end_time").val()) <= Date.parse($("#exercise_publish_time").val())) {
alert("截止时间必须大于发布时间");
}
else {
doc.parent().parent().parent().submit();
}
}
function pollsEdit(){$("#polls_head_edit").show();$("#polls_head_show").hide();}
//
@ -285,7 +298,7 @@
alert("测验标题不能为空");
}
else{
$('#ajax-modal').html('<%= escape_javascript(render :partial => 'poll_submit', locals: { :poll => @exercise,:is_remote => false}) %>');
$('#ajax-modal').html('<%#= escape_javascript(render :partial => 'poll_submit', locals: { :poll => @exercise,:is_remote => false}) %>');
showModal('ajax-modal', '310px');
$('#ajax-modal').css('height','120px');
$('#ajax-modal').siblings().remove();
@ -301,15 +314,15 @@
<div class="resources">
<!-- 头部 -->
<div id="polls_head_show" style="display: none;">
<%#= render :partial => 'show_head', :locals => {:poll => @exercise}%>
<%= render :partial => 'show_head', :locals => {:exercise => @exercise}%>
</div>
<div id="polls_head_edit">
<%= render :partial => 'edit_head', :locals => {:poll => @exercise}%>
<%= render :partial => 'edit_head', :locals => {:exercise => @exercise}%>
</div>
<!-- 问题 -->
<div id="poll_content">
<%= render :partial => 'exercise_content', :locals => {:poll => @exercise}%>
<%= render :partial => 'exercise_content', :locals => {:exercise => @exercise}%>
</div>
<div class="testQuestion">
@ -321,7 +334,11 @@
<div class="cl"></div>
</div><!--选项 end-->
<div class="ur_buttons"> <a class="ur_button_submit" onclick="poll_submit();"> 发布 </a>
<!-- 新增问题 -->
<div id="new_poll_question">
</div>
<div class="ur_buttons"> <a class="ur_button_submit" onclick="poll_submit();"> 提交 </a>
<div class="polls_cha">
<input name="" value="" type="checkbox">
<label for="">允许学生查看测验结果</label>

View File

@ -2,23 +2,23 @@
<div class="ur_editor_title">
<label>问题:&nbsp;&nbsp;</label>
<input name="question_type" value="1" type="hidden">
<input maxlength="250" class="questionTitle" name="poll_questions_title" id="poll_questions_title" placeholder="请输入填空题题目" type="text">
<input maxlength="250" class="questionTitle" name="poll_questions_title" id="poll_questions_title" placeholder="请输入填空题的内容(注意:目前填空题暂时仅支持一个空)" type="text">
</div>
<div class="ur_editor_content">
<ul>
<li class="ur_item">
<label>候选答案一<span class="ur_index"></span>&nbsp;&nbsp;&nbsp;</label>
<input name="question_answer[0]" placeholder="关键词一" type="text">
<input name="question_answer[0]" placeholder="请输入候选答案一" type="text">
<a class="icon_add" title="向下插入选项" onclick="add_single_answer($(this));"></a> <a class="icon_remove" title="删除" onclick="remove_single_answer($(this))"></a> </li>
<div class="cl"></div>
<li class="ur_item">
<label>候选答案二<span class="ur_index"></span>&nbsp;&nbsp;&nbsp;</label>
<input name="question_answer[1]" placeholder="关键词二(选填)" type="text">
<input name="question_answer[1]" placeholder="请输入候选答案二(选填)" type="text">
<a class="icon_add" title="向下插入选项" onclick="add_single_answer($(this));"></a> <a class="icon_remove" title="删除" onclick="remove_single_answer($(this))"></a> </li>
<div class="cl"></div>
<li class="ur_item">
<label>候选答案三<span class="ur_index"></span>&nbsp;&nbsp;&nbsp;</label>
<input name="question_answer[2]" placeholder="关键词三(选填)" type="text">
<input name="question_answer[2]" placeholder="请输入候选答案三(选填)" type="text">
<a class="icon_add" title="向下插入选项" onclick="add_single_answer($(this));"></a> <a class="icon_remove" title="删除" onclick="remove_single_answer($(this))"></a> </li>
<div class="cl"></div>
</ul>

View File

@ -0,0 +1,6 @@
<div class="ur_page_head ur_editor02" ><!--头部显示 start-->
<a href="javascript:" class="ur_icon_edit" title="编辑" onclick="pollsEdit();"></a>
<h1 class="ur_page_title" id="polls_name_h"><%= exercise.exercise_name%></h1>
<%= exercise.exercise_description.nil? ? "" : exercise.exercise_description.html_safe%>
<div class="cl"></div>
</div><!--头部显示 end-->

View File

@ -0,0 +1,4 @@
$("#polls_head_show").html("<%= escape_javascript(render :partial => 'show_head', :locals => {:exercise => @exercise}) %>");
$("#polls_head_edit").html("<%= escape_javascript(render :partial => 'edit_head', :locals => {:exercise => @exercise}) %>");
$("#polls_head_edit").hide();
$("#polls_head_show").show();

View File

@ -1 +1,2 @@
<%= render :partial => 'exercise_form'%>
<%#= render :partial => 'exercise_form'%>
111

View File

@ -713,6 +713,7 @@ img.ui-datepicker-trigger {
width:16px;
height:15px;
float:left;
margin: 7px;
}
.label{ width:80px; text-align:right; font-size:14px; display:block; float:left;}
@ -1146,7 +1147,7 @@ input.sendSourceText {
/*20151117在线测验byTim*/
.testContainer {width:698px; border:1px solid #cbcbcb;background:#eeeeee; padding:10px; margin-bottom:10px;}
.testTitle{ width:678px; height:40px; padding:0 10px; text-align:center; font-size:16px; font-weight:bold; background:#fff;border-style:solid; border:1px solid #CBCBCB;}
.testDes{ width:678px; height:120px; padding:10px; margin-bottom:10px; background:#fff; border-style:solid; border:1px solid #CBCBCB; resize:none;}
.testDes{ width:678px; height:60px; padding:10px; margin-bottom:10px; background:#fff; border-style:solid; border:1px solid #CBCBCB; resize:none;}
.btn_submit{ width:56px; height:24px; padding-top:4px;background:#269ac9; color:#fff; text-align:center; display:block; float:left; margin-right:10px;}
a:hover.btn_submit{background:#297fb8;}
.btn_cancel{width:54px; height:22px; padding-top:4px;background:#fff; color:#999; border:1px solid #999; text-align:center; display:block; float:left; }