socialforge/public/javascripts/course.js

810 lines
23 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

//配置课程信息
function course_setting(id)
{
//alert(id);
$('#tb_'+id).removeClass().addClass("hwork_hovertab");
$('#tbc_0'+id).removeClass().addClass("dis");
$('#tb_'+(3-id)).removeClass().addClass("hwork_normaltab");
$('#tbc_0'+(3-id)).removeClass().addClass("undis");
}
$(function(){
$("img").removeAttr("align");
});
///////////////////////////////////////////////////////////////
//添加分班
function add_group(url,course_id) {
var group_name = $('#group_name').val();
$.get(
url,
{ valid: "name",
value: group_name,
course_id: course_id },
function (data) {
if (data.valid) {
$("#add_group_name").submit();
}
else
{
alert(data.message);
}
}
);
}
//修改分班:修改分班时得考虑什么都不改但是点击确定的情况
function edit_group(id,url,course_id,group_id)
{
var group_name = $('#'+id).val();
$.get(
url,
{
valid: "name",
value: group_name,
course_id: course_id,
group_id: group_id
},
function (data) {
if (data.valid) {
$("#update_group_"+group_id).submit();
}
else
{
alert(data.message);
}
}
);
}
function hidden_homework_score_form()
{
hideModal($("#user_score"));
}
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////新建课程相关
//验证课程名称
function regex_course_name()
{
var name = $.trim($("#course_name").val());
if(name.length == 0)
{
$("#course_name_notice").show();
return false;
}
else
{
$("#course_name_notice").hide();
return true;
}
}
//验证课程学时
function regex_course_class_period()
{
var class_period = $.trim($("#class_period").val());
var regex = /^\d*$/;
if(class_period.length == 0)
{
$("#course_class_period_notice").html("学时总数不能为空");
$("#course_class_period_notice").show();
return false;
}
else if (regex.test(class_period)) {
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
{
$("#course_class_period_notice").html("学时总数必须为数字");
$("#course_class_period_notice").show();
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()&&regex_course_password())
{
$("#new_course").submit();
}
}
function submit_edit_course(id)
{
if(regex_course_name()&&regex_course_class_period()&&regex_course_password())
{
$("#edit_course_"+id).submit();
}
}
///////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////课程讨论区
function regexSubject(id) {
var subjectid = "#message_subject" + id ;
var content = $.trim($(subjectid).val());
var message = "#subject_span" + id;
if (content.length == 0) {
$(message).text("主题不能为空");
$(message).css('color', '#ff0000');
return false;
}
else {
$(message).text("填写正确");
$(message).css('color', '#008000');
return true;
}
return false;
}
function regexContent(id) {
var contentid = "#message_content" + id;
var message = "#message_content_span"+ id;
var content = $.trim($(contentid).val());
if (content.length == 0) {
$(message).text("描述不能为空");
$(message).css('color', '#ff0000');
return false;
}
else {
$(message).text("填写正确");
$(message).css('color', '#008000');
return true;
}
return false;
}
// 项目讨论区编辑和提交
function submitProjectsBoard(id) {
var formid = "#message-form" + id;
if (regexSubject(id) && regexContent(id)) {
$(formid).submit();
}
}
///////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////// 课程通知
function regexTitle()
{
var name = $("#news_title").val();
if(name.length ==0)
{
$("#title_notice_span").text("标题不能为空");
$("#title_notice_span").css('color','#ff0000');
$("#news_title").focus();
return false;
}
else if(name.length <= 60)
{
$("#title_notice_span").text("填写正确");
$("#title_notice_span").css('color','#008000');
return true;
}
else
{
$("#title_notice_span").text("标题超过60个字符");
$("#title_notice_span").css('color','#ff0000');
$("#news_title").focus();
return false;
}
}
function regexDescription()
{
var name = news_description_editor.html();
if(name.length ==0)
{
$("#description_notice_span").text("描述不能为空");
$("#description_notice_span").css('color','#ff0000');
$("#description_notice_span").focus();
return false;
}
else if(name.length >=6000){
$("#description_notice_span").text("描述最多3000个汉字(或6000个英文字符)");
$("#description_notice_span").css('color','#ff0000');
$("#description_notice_span").focus();
return false;
}
else
{
$("#description_notice_span").text("填写正确");
$("#description_notice_span").css('color','#008000');
return true;
}
}
function submitNews()
{
if(regexTitle() && regexDescription())
{
news_description_editor.sync();
$("#news-form").submit();
}
}
function submitFocus(obj)
{
$(obj).focus();
}
function submitComment()
{
comment_editor.sync();
$("#add_comment_form").submit();
}
/////////////////////////////////////////////////课程讨论区
function course_board_submit_message_replay()
{
if(MessageReplayVevify())
{
message_content_editor.sync();//提交内容之前要sync不然服务器端取不到值
$("#message_form").submit();
}
}
function course_board_canel_message_replay()
{
$("#reply").hide(200);
$("#message_quote").html("");
}
function MessageReplayVevify() {
var content = message_content_editor.html();//$.trim($("#message_content").val());
if (content.length == 0) {
$("#message_content_span").text("回复不能为空");
$("#message_content_span").css('color', '#ff0000');
return false;
}
else {
$("#message_content_span").text("填写正确");
$("#message_content_span").css('color', '#008000');
return true;
}
}
//////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////
//验证搜索时输入名字
function regexName(content)
{
var name = $.trim($("#name").val());
if(name.length == 0)
{
$("#project_name_span").text(content);
$("#project_name_span").css('color','#ff0000');
$("#project_name_span").focus();
return false;
}
else
{
$("#project_name_span").text("");
return true;
}
}
//提交搜索
function submitSerch(content)
{
if(regexName(content)){$("#course_search_form").submit();}
}
//验证搜索时输入名字
function regexQ(content)
{
var name = $.trim($("#q").val());
if(name.length == 0)
{
$("#course_member_name_span").text(content);
$("#course_member_name_span").css('color','#ff0000');
$("#course_member_name_span").focus();
return false;
}
else
{
$("#course_member_name_span").text("");
return true;
}
}
//提交课程成员搜索
function submitMemberSerch(content)
{
//if(regexQ(content)){$("#course_member_search_form").submit();}
$("#course_member_search_form").submit();
}
//课程描述显示更多信息
function show_more_msg()
{
$("#course_description").toggleClass("course_description_none");
}
//作业描述显示更多信息
function news_show_more_des(id)
{
$('#news_description_' + id).toggleClass("news_description_none");
}
function bid_show_more_des(id)
{
$("#bid_description_" + id).toggleClass("news_description_none");
}
//课程作业结束时间倒计时
function show_bid_dead_line(year,month,day,divname)
{
var now = new Date();
var endDate = new Date(year, month-1, day);
var leftTime=endDate.getTime()-now.getTime();
var leftsecond = parseInt(leftTime/1000);
var day1=Math.floor(leftsecond/(60*60*24));
var hour=Math.floor((leftsecond-day1*24*60*60)/3600);
var minute=Math.floor((leftsecond-day1*24*60*60-hour*3600)/60);
var second=Math.floor(leftsecond-day1*24*60*60-hour*3600-minute*60);
$("#"+divname).html("<form name='formnow' class='fr'>"
+ "<input class='c_orange' type='text' style='border:0;' size='1' value='"+day1+"' > 天"
+ "<input class='c_orange' type='text' style='border:0;' size='1' value='"+hour+"' > 小时"
+ "<input class='c_orange' type='text' style='border:0;' size='1' value='"+minute+"' > 分"
+ "<input class='c_orange' type='text' style='border:0;' size='1' value='"+second+"' > 秒"
+ "</form>"
+ "<p class='fr'>作品提交还剩:</p>");
}
//验证新建作业的名字
function regex_homework_name()
{
var name = $.trim($("#homework_name").val());
if(name=="")
{
$("#homework_name_span").text("名称不能为空");
return false;
}
else
{
$("#homework_name_span").text("");
return true;
}
}
//验证匿评数量
function regex_evaluation_num()
{
var evaluation_num = $.trim($("#evaluation_num").val());
var regex = /^\d+$/;
if(evaluation_num=="")
{
$("#evaluation_num_notice").html("匿评分配数量不能为空");
$("#evaluation_num_notice").removeClass("c_red").addClass("c_red");
return false;
}
else if(regex.test(evaluation_num))
{
if(evaluation_num > 0)
{
$("#evaluation_num_notice").html("每个学生将收到<span class='c_red'>&nbsp;"+ parseInt(evaluation_num) + "&nbsp;</span>份待匿评作品");
$("#evaluation_num_notice").removeClass("c_red");
return true;
}
else
{
$("#evaluation_num_notice").html("匿评分配数量必须为大于0");
$("#evaluation_num_notice").removeClass("c_red").addClass("c_red");
return false;
}
}
else
{
$("#evaluation_num_notice").html("匿评分配数量只能为数字");
$("#evaluation_num_notice").removeClass("c_red").addClass("c_red");
return false;
}
}
//点击是否开启匿评单选框效果
$(function(){
$("#homework_common_homework_type").click(function(){
if($("#homework_common_homework_type").attr("checked") == "checked")
{
$("#evaluation_setting").slideDown();
$("#ta_proportion").removeAttr("disabled");
}
else
{
$("#evaluation_setting").slideUp();
$("#ta_proportion").attr("disabled","disabled");
}
});
$("#absence_penalty").change(function(){
$("#absence_penalty_notice").html("&nbsp;"+ $("#absence_penalty").val() +"&nbsp;");
});
$("#ta_proportion").change(function(){
var ta_proportion = $("#ta_proportion").val();
$("#student_proportion").val((100 - parseInt(ta_proportion * 100)) + "%");
});
});
//第一次加载时,如果未开启匿评作业,隐藏显示匿评配置信息
$(function(){
if($("#homework_common_homework_type").attr("checked") == "checked")
{
$("#evaluation_setting").show();
$("#ta_proportion").removeAttr("disabled");
}
else
{
$("#evaluation_setting").hide();
$("#ta_proportion").attr("disabled","disabled");
}
});
//老师提交 新建/修改 作业
function submit_homework(id)
{
if(!regex_homework_name())
{
$("#homework_name").focus();
}
else if(!regex_evaluation_num())
{
$("#evaluation_num").focus();
}
else
{
homework_description_editor.sync();
$("#"+id).submit();
}
}
function show_window (id1,id2,top,left) {
$('#'+ id1).css('top',top);
$('#'+ id1).css('left',left);
$('#'+ id1).css('display','block');
$('#' + id2).css('display','block');
}
function close_window(id1,id2){
$('#' + id1).css('display','none');
$('#' + id2).css('display','none');
}
//隐藏提示狂
function hidden_atert_form(cur_page,cur_type)
{
hideModal($("#popbox"));
}
//当课程描述长度小于112px时不显示更多按钮
$(function(){
if($("#course_description_content").height()>112)
{
$("#lg-foot").show();
}
});
//将右侧的最小高度设置成左侧高度,美化界面
// firefox pre标签换行
$(document).ready(function () {
$("#RSide").css("min-height",$("#LSide").height()-30);
var userAgent = navigator.userAgent.toLowerCase();
var browser = {
version: (userAgent.match(/.+(?:rv|it|ra|ie)[/: ]([d.]+)/) || [])[1],
safari: /webkit/.test(userAgent),
opera: /opera/.test(userAgent),
msie: /msie/.test(userAgent) && !/opera/.test(userAgent),
mozilla: /mozilla/.test(userAgent) && !/(compatible|webkit)/.test(userAgent)
};
if (browser.mozilla || browser.opera){
$("pre").addClass("break_word_firefox");
}
else{
$("pre").addClass("break_word");
}
});
// 日历选择日期后关闭
function regexDeadLine()
{
('#ui-datepicker-div').hide;
}
//新建、修改课程明码显示
$(function(){
$("#psw_btn").click(function() {
alert("密码: "+$("#course_course_password").val());
});
});
//查找TAG资源
function search_tag_attachment(url,tag_name,q,course_id,sort)
{
//alert("111");
$.get(
url,
{
tag_name: tag_name,
q: q,
course_id:course_id
},
function (data) {
}
);
}
// 课程讨论区
function showhelpAndScrollToMessage(id, id1, count) {
$('#' + id).toggle();
if(cookieget("repositories_visiable") == "true")
{
cookiesave("repositories_visiable", false,'','','');
}
else
{
cookiesave("repositories_visiable", true,'','','');
}
var information = $(id1);
var val = information.attr("value");
if(val=="show_help")
{
$(id1).text("收起回复(" + count + ")" );
information.attr("value", "hide_help");
}
else
{
$(id1).text("展开回复(" + count + ")");
information.attr("value", "show_help");
}
}
function show_more_reply(contentid, id2, id3) {
$(contentid).toggleClass("course_description_none");
var information = $(id2);
var arrow = $(id3);
var val = information.attr("value");
if (val == "show_more") {
$(id2).text("[收起]");
information.attr("value", "hide_more");
arrow.attr("src", "/images/jiantouup.jpg")
}
else {
$(id2).text("[展开]");
information.attr("value", "show_more");
arrow.attr("src", "/images/jiantou.jpg")
}
}
///////////////////////////////////////////////
//学生作品
function show_project()
{
$("#about_project").slideToggle();
}
//验证作品名称
function regexStudentWorkName()
{
var name = $.trim($("#student_work_name").val());
if(name=="")
{
$("#student_work_name_span").text("作品名称不能为空");
return false;
}
else
{
$("#student_work_name_span").text("");
return true;
}
}
function regexStudentWorkDescription()
{
var name = $.trim($("#student_work_description").val());
if(name=="")
{
$("#student_work_description_textarea").text("作品描述不能为空");
return false;
}
else
{
$("#student_work_description_textarea").text("");
return true;
}
}
//提交新建作品
function new_student_work()
{
if(regexStudentWorkName()&&regexStudentWorkDescription())
{$("#new_student_work").submit();}
}
function edit_student_work(id)
{
if(regexStudentWorkName()&&regexStudentWorkDescription())
{$("#edit_student_work_" + id).submit();}
}
//滑动打分
$.fn.peSlider = function(settings){
//configurable options (none so far)
var o = $.extend({},settings);
if( !$('body').is('[role]') ){ $('body').attr('role','application'); }
return $(this).each(function(){
var thisLabel = $('label[for=' + $(this).attr('id') + ']').attr('id', $(this).attr('id') + '-label').attr('id');
var thisUnits = $(this).attr('data-units') || '';
var slider = $('<div></div>');
if( $(this).is('input') ){
var input = $(this);
var thisUnits = input.attr('data-units');
var friendlyVal = input.val() + ' ' + thisUnits;
var sliderOptions = $.extend(o,{
min: parseFloat(input.attr('min')),
max: parseFloat(input.attr('max')),
value: parseFloat(input.val())
});
slider
.insertBefore(input)
.slider(sliderOptions)
.bind('slide', function(e, ui){
input.val(ui.value);
friendlyVal = input.val() + ' ' + thisUnits;
slider.find('a').attr({
'aria-valuenow': ui.value,
'aria-valuetext': friendlyVal
});
})
.find('a')
.attr({
'role': 'slider',
'aria-valuemin': input.attr('min'),
'aria-valuemax': input.attr('max'),
'aria-valuenow': input.val(),
'aria-valuetext': friendlyVal,
'aria-labelledby': thisLabel
});
input
.keyup(function(){
var inVal = parseFloat(input.val());
if( !isNaN(inVal) ){
slider.slider('value', inVal);
input.val(slider.slider('value'));
}
})
.change(function(){
var inVal = parseFloat(input.val());
if( !isNaN(inVal) ){
slider.slider('value', inVal);
input.val(slider.slider('value'));
}
})
.blur(function(){
var inVal = parseFloat(input.val());
if( isNaN(inVal) ){
input.val(0);
}
});
if( !settings.step ){
var step = Math.round( parseFloat(input.attr('max')) / slider.width());
if(step > 1){ slider.slider('option','step',step); }
}
}
});
};
//返回顶部
$(function(){goTopEx();});
var Sys = {};
var ua = navigator.userAgent.toLowerCase();
var s;
(s = ua.match(/msie ([\d.]+)/)) ? Sys.ie = s[1] :
(s = ua.match(/firefox\/([\d.]+)/)) ? Sys.firefox = s[1] :
(s = ua.match(/chrome\/([\d.]+)/)) ? Sys.chrome = s[1] :
(s = ua.match(/opera.([\d.]+)/)) ? Sys.opera = s[1] :
(s = ua.match(/version\/([\d.]+).*safari/)) ? Sys.safari = s[1] : 0;
function goTopEx() {
var obj = document.getElementById("goTopBtn");
if(obj != null)
{
var scrollTop = window.pageYOffset || document.documentElement.scrollTop || document.body.scrollTop || 0;
function getScrollTop() {
var xsun = document.documentElement.scrollTop;
if (Sys.chrome) {
xsun=document.body.scrollTop;
}
return xsun;
}
function setScrollTop(value) {
if (Sys.chrome) {
document.body.scrollTop = value;
}
else {
document.documentElement.scrollTop = value;
}
}
window.onscroll = function () { getScrollTop() > 0 ? obj.style.display = "" : obj.style.display = "none"; };
obj.onclick = function () {
var goTop = setInterval(scrollMove, 10);
function scrollMove() {
setScrollTop(getScrollTop() / 1.1);
if (getScrollTop() < 1) clearInterval(goTop);
}
}
}
}
$(function(){
//匿评评分提示
$(".student_score_info").bind("mouseover",function(e){
//alert($(this).html());
$(this).find("div").show();
$(this).find("div").css("top",e.pageY);
$(this).find("div").css("left",e.pageX);
});
$(".student_score_info").bind("mouseout",function(e){
//alert($(this).html());
$(this).find("div").hide();
});
$("#about_project label").eq(1).remove();
});
//匿评弹框取消按钮
function clickCanel(){hideModal("#popbox02");}
//匿评弹框确定按钮
function clickOK(path)
{
clickCanel();
$.ajax({
type: "GET",
url: path,
data: 'text',
success: function (data) {
}
});
}
//查询
function SearchByName(obj,url,event)
{
var keycode = (event.keyCode ? event.keyCode : event.which);
if(keycode == '13'){
location.href = url + "&name=" + obj.val();
}
}
function SearchByName_1(obj,url)
{
location.href = url + "&name=" + obj.val();
}