新建课程时增加密码与课时的验证

This commit is contained in:
sw 2015-04-16 10:49:58 +08:00
parent 9905f91228
commit 94ca6cd2f9
4 changed files with 41 additions and 8 deletions

View File

@ -423,7 +423,7 @@ class CoursesController < ApplicationController
@course = cs.create_course(params,User.current)[:course]
if @course.new_record?
respond_to do |format|
format.html { render :action => 'new', :layout => 'base' } #Added by young
format.html { render :action => 'new', :layout => 'new_base' } #Added by young
format.api { render_validation_errors(@course) }
end
else
@ -493,7 +493,7 @@ class CoursesController < ApplicationController
respond_to do |format|
format.html {
render :layout => 'base'
render :layout => 'new_base'
}
format.api {
}

View File

@ -198,7 +198,7 @@ class CoursesService
@course.school_id = current_user.user_extensions.school_id
@course.setup_time = params[:setup_time]
@course.endup_time = params[:endup_time]
@course.class_period = params[:class_period]
@course.class_period = params[:class_period].to_i
params[:course][:is_public] ? @course.is_public = 1 : @course.is_public = 0
params[:course][:open_student] ? @course.open_student = 1 : @course.open_student = 0
end

View File

@ -25,8 +25,9 @@
<li class="ml45 mb10">
<label><span class="c_red">*</span>&nbsp;<%= l(:label_new_course_password)%>&nbsp;&nbsp;</label>
<input type="text" style="display: none;">
<input type="password" name="course[password]" id="course_course_password" class="hwork_input02">
<input type="password" name="course[password]" id="course_course_password" class="hwork_input02" onkeyup="regex_course_password();">
<a id="psw_btn" href="javascript:void(0)">显示明码</a>
<span class="c_red" id="course_course_password_notice"></span>
<div class="cl"></div>
<span class=" ml80 c_orange">学生或其他成员申请加入课程时候需要使用该口令,该口令可以由老师在课堂上公布。</span>
</li>

View File

@ -80,9 +80,18 @@ function regex_course_class_period()
return false;
}
else if (regex.test(class_period)) {
$("#course_class_period_notice").html("");
$("#course_class_period_notice").hide();
return true;
if(parseInt(class_period) > 0)
{
$("#course_class_period_notice").html("");
$("#course_class_period_notice").hide();
return true;
}
else
{
$("#course_class_period_notice").html("学时总数必须大于0");
$("#course_class_period_notice").show();
return false;
}
}
else
{
@ -91,10 +100,33 @@ function regex_course_class_period()
return false;
}
}
function regex_course_password()
{
var class_period = $.trim($("#course_course_password").val());
var regex = /^\w+$/;
if(class_period.length == 0)
{
$("#course_course_password_notice").html("课程密码不能为空");
$("#course_course_password_notice").show();
return false;
}
else if (regex.test(class_period)) {
$("#course_course_password_notice").html("");
$("#course_course_password_notice").hide();
return true;
}
else
{
$("#course_course_password_notice").html("课程密码有非法字符");
$("#course_course_password_notice").show();
return false;
}
}
//提交新建课程
function submit_new_course()
{
if(regex_course_name()&&regex_course_class_period())
if(regex_course_name()&&regex_course_class_period()&&regex_course_class_period()&&regex_course_password())
{
$("#new_course").submit();
}