All Downloads are FREE. Search and download functionalities are using the official Maven repository.

static.course.TaskActivity.js Maven / Gradle / Ivy

There is a newer version: 0.0.18
Show newest version
  var delimiter ="
" var weekCycle =[]; weekCycle[1]="";// "%u8FDE"; weekCycle[2]="%u5355"; weekCycle[3]="%u53CC"; var result = new String(""); var weeksPerYear = 53 ; function Dates(){ this.toDate=function(datestr){ var yearIdx = datestr.indexOf('-'); var monthIdx = datestr.indexOf('-',yearIdx+1); return new Date(Date.parse(datestr.substring(yearIdx+1,monthIdx) +"/"+datestr.substring(monthIdx+1)+"/"+datestr.substring(0,yearIdx))); }; this.weeksBetween = function(firstWeekday,date1,date2){ while(date1.getDay() != firstWeekday){ date1.setTime(date1.getTime() - 24 * 3600000); } while(date2.getDay() != firstWeekday){ date2.setTime(date2.getTime() - 24 * 3600000); } return (date2.getTime() - date1.getTime())/ (7 * 24 * 3600000); }; } var Dates = new Dates() // 输出教学活动信息 function activityInfo(){ return "teacherId:" + this.teacherId+"\n" +"teacherName:" + this.teacherName+"\n" +"courseId:"+this.courseId+"\n" +"courseName:"+this.courseName+"\n" +"roomId:"+this.roomId+"\n" +"roomName:"+this.roomName+"\n" +"vaildWeeks:"+this.vaildWeeks; } /** * 判断是否相同的活动 same acitivity [teacherId,courseId,roomId,vaildWeeks] */ function isSameActivity(other){ return this.canMergeWith(other)&&(this.vaildWeeks==other.vaildWeeks); } /** * 合并相同的教学活动 same [teacherId,courseId,roomId,remark] can merge */ function canMergeWith(other){ return ( this.teacherId == other.teacherId && this.courseId == other.courseId && this.roomId == other.roomId && this.courseName==other.courseName ); } // utility for repeat char function repeatChar(str,length){ if(length<=1){ return str; } var rs=""; for(var k=0;k1){ for(var j=1;j1){ // O(n^2) for(var j=0;j0){ this.marshalContents[k]=this.marshal(k); } } return this; } function marshalTableForAdminclass(){ for(var k=0;k0){ this.marshalContents[k]= this.marshalForAdminclass(k); } } } function marshalForAdminclass(index){ if(this.activities[index].length===0){return "";} if(this.activities[index].length==1){ var cname=this.activities[index][0].courseName; var tname=this.activities[index][0].teacherName; var roomOccupancy = "(" +this.activities[index][0].marshal()+")"; return tname+" "+cname + roomOccupancy; } else { var marshalString=""; var tempActivities=new Array(); tempActivities[0] = this.activities[index][0].clone(); // merge this.activities to tempActivities by same courseName and // roomId .start with 1. for(var i=1;i= 0; end --) { str = str + str0.charAt(end); } for(i=str0.length;i<53;i++){ str =str +"0"; } return str; } this.getCourseUnit=function(indexno){ return courseUnits[indexno-1]; } this.newActivity = function(teacherId,teacherName,courseId,courseName,roomId,roomName,startOn,weekstate,taskId,remark){ var weekstate_str=""; if(startOn){ var weeks = Dates.weeksBetween(this.beginOn.getDay(),this.beginOn,Dates.toDate(startOn)); if(weeks < 0){ weekstate >>= (0 - weeks); }else{ weekstate <<= weeks } weekstate_str=this.convertWeekstate2ReverseString(weekstate); } return new TaskActivity(teacherId,teacherName,courseId,courseName,roomId,roomName,weekstate_str,taskId,remark) } this.addActivityByUnit = function(activity,weekday,startUnit,endUnit){ for(i=startUnit-1;i beginAt && endAt > courseUnit[0]) { if ( (i+1) < startUnit) startUnit = i+1; if ((i+1) > endUnit) endUnit = i+1; } } this.addActivityByUnit(activity,weekday,startUnit,endUnit); } this.fillTable = function(tableStyle,tableIndex){ if(tableStyle=="WEEK_TABLE"){ this.fillWeekTable(tableIndex); }else{ this.fillUnitTable(tableIndex); } } /** * 填充星期作为列,小节作为行的表格 */ this.fillWeekTable = function (tableIndex){ var units= this.courseUnits.length; var weeks = this.weekdays.length; for(var i=0;i=units-1){ break; } index=index+1; nextTd=jQuery("#TD"+(index+1)+"_"+tableIndex); } } } for(var k = 0; k < this.unitCounts; k++){ var td=document.getElementById("TD" + k + "_" + tableIndex); if(td != null && this.marshalContents[k] != null) { td.innerHTML = this.marshalContents[k]; td.style.backgroundColor="#94aef3"; td.className = "infoTitle"; var activitiesInCell = this.activities[k]; if(this.detectCollisionInCell(activitiesInCell)) { td.style.backgroundColor="red"; } td.className="infoTitle"; td.title=this.marshalContents[k].replace(/
/g,";"); } } } /** * 填充小节作为列,星期作为行的表格 */ this.fillUnitTable =function (tableIndex){ var units= this.courseUnits.length; var weeks = this.weekdays.length; for(var i=0;i=units-1){ break; } index=index+1; nextTd=document.getElementById("TD"+(index+1)+"_"+tableIndex); } } } for(var k = 0; k < this.unitCounts; k++){ var td=document.getElementById("TD" + k + "_" + tableIndex); if(td != null && this.marshalContents[k] != null) { td.innerHTML = this.marshalContents[k]; td.style.backgroundColor="#94aef3"; td.className = "infoTitle"; var activitiesInCell = this.activities[k]; if(detectCollisionInCell(activitiesInCell)) { td.style.backgroundColor="red"; } td.className="infoTitle"; td.title=this.marshalContents[k].replace(/
/g,";"); } } } /** * 检测时间安排是否冲突 */ this.detectCollisionInCell = function (activitiesInCell) { if(activitiesInCell.length <=1) return false; //单元格的课程集合[courseId(seqNo)->true] var cellCourseIds=new Object(); var mergedValidWeeks = activitiesInCell[0].vaildWeeks.split(""); //登记第一个课程 cellCourseIds[ activitiesInCell[0].courseName]=true; for(var z = 1; z < activitiesInCell.length; z++) { var detectCollision = false; var tValidWeeks = activitiesInCell[z].vaildWeeks.split(""); if(mergedValidWeeks.length != tValidWeeks.length) { alert('mergedValidWeeks.length != tValidWeeks.length'); return; } for(var x = 0; x < mergedValidWeeks.length; x++) { //53代表53周 var m = new Number(mergedValidWeeks[x]); var t = new Number(tValidWeeks[x]); if(m + t <= 1) { mergedValidWeeks[x] = m + t; } else { //如果已经是登记过的,则不算冲突 if(!cellCourseIds[activitiesInCell[z].courseName]){ return true; //发现冲突 } } } //登记该课程 cellCourseIds[activitiesInCell[z].courseName]=true; } return false; } } /** * 合并课程表中相同的单元格 */ function mergeCellOfCourseTable(weeks,units){ for(var i=0;i=units-1){ break; } index=index+1; nextTd=document.getElementById("TD"+(index+1)); } } } } /** * all activities in each unit consists a ActivityCluster */ function ActivityCluster(date,courseId,courseName,weeks,remark){ this.courseId = courseId; this.courseName = courseName; this.weeks = weeks; this.remark = remark; this.weeksMap= {}; this.activityMap ={}; /*************************************************************************** * 添加一个小节中的教学活动组成一个活动集. * * **************************************************************************/ // add acitity to cluster.and weekInex from 0 to weeks-1 this.add = function (teacherId,teacherName,roomId,roomName,weekIndex){ // alert("addActivityToCluster:"+weekIndex) if(null==this.weeksMap[teacherId+roomId]){ this.weeksMap[teacherId+roomId]=new Array(this.weeks); this.activityMap[teacherId+roomId]=new TaskActivity(teacherId,teacherName,this.courseId,this.courseName,roomId,roomName,""); } this.weeksMap[teacherId+roomId][weekIndex]="1"; } /* * construct a valid Weeks from this.weeksMap by key teacherRoomId this * startweek is the position of this.weeksMap[teacherRoomId] in return * validWeekStr also it has mininal value 1; */ this.buildWeekstate = function (teacherRoomId){ var firstWeeks = new Array(weeksPerYear); var weekstates=""; for(var i=0;i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy