var currentItem = null; var currentCell = null; var currentSchedulingWeekList = null; var usedClassroomList = new Array(); var teacherScheduleContinuousCount = 0; var classScheduleContinuousCount = 0; var classCourseScheduleContinuousCount = 0; var mnu = ""; var colorGroup = ["timeSpanCell1", "timeSpanCell2", "timeSpanCell3"]; var isZoomOuted = false; var zoomRate = 5; var schedulingClassSelectedWeekList = []; $(function () { mnu = $.SystemGeneral.getUrlParam("MNU"); $(".middleBar").mousedown(middleStartDrag); $(document).mousemove(middleDragging); }); function EducationScheduling_ZoomOut() { if (!isZoomOuted) { $(".schedulingHeaderCell").width($(".schedulingHeaderCell").width() * zoomRate); $(".schedulingHeader").width($(".schedulingHeader").width() * zoomRate); $(".schedulingRow").width($(".schedulingRow").width() * zoomRate); $(".schedulingCell").width($(".schedulingCell").width() * zoomRate); $(".schedulingCellHeader").height($(".schedulingCellHeader").height() * zoomRate); $(".schedulingRow").height($(".schedulingRow").height() * zoomRate); $(".schedulingCell").height($(".schedulingCell").height() * zoomRate); $(".schedulingItem").each(function (i, x) { $(x).width($(x).width() * zoomRate); $(x).height($(x).height() * zoomRate); }); isZoomOuted = true; } } function EducationScheduling_ZoomIn() { if (isZoomOuted) { $(".schedulingHeaderCell").width($(".schedulingHeaderCell").width() / zoomRate); $(".schedulingHeader").width($(".schedulingHeader").width() / zoomRate); $(".schedulingRow").width($(".schedulingRow").width() / zoomRate); $(".schedulingCell").width($(".schedulingCell").width() / zoomRate); $(".schedulingCellHeader").height($(".schedulingCellHeader").height() / zoomRate); $(".schedulingRow").height($(".schedulingRow").height() / zoomRate); $(".schedulingCell").height($(".schedulingCell").height() / zoomRate); $(".schedulingItem").each(function (i, x) { $(x).width($(x).width() / zoomRate); $(x).height($(x).height() / zoomRate); }); isZoomOuted = false; } } var mouseXStart; var vmiddleBar; var isDragging = false; function middleStartDrag(event) { mouseXStart = $(".middleBar").offset().left; vmiddleBar = $(".middleBar").clone(); vmiddleBar.removeClass("middleBar"); vmiddleBar.css("border-style", "dashed"); vmiddleBar.mouseup(middleEndDrag); vmiddleBar.appendTo(".popupWindowContent"); isDragging = true; } function middleDragging(event) { if (isDragging) { event = event || window.event; event.cancelBubble = true; var x = event.clientX || event.originalEvent.layerX; var offset = $(".middleBar").offset(); if ((mouseXStart - x) <= offset.left && (x - mouseXStart) <= $("#scheduleContainer").width()) { offset.left = offset.left - (mouseXStart - x); vmiddleBar.offset(offset); } return false; } } function middleEndDrag(event) { if (vmiddleBar) { event = event || window.event; var x = event.clientX || event.originalEvent.layerX; var middleBarOffset = $(".middleBar").offset(); var containerWidth = $("#scheduleContainer").width(); var containerOffset = $("#scheduleContainer").offset(); if ((mouseXStart - x) <= middleBarOffset.left && (x - mouseXStart) <= containerWidth) { middleBarOffset.left = middleBarOffset.left - (mouseXStart - x); } else if ((mouseXStart - x) > middleBarOffset.left) { middleBarOffset.left = 1; } else if ((x - mouseXStart) > containerWidth) { middleBarOffset.left = containerWidth - 3; } $("#leftContainer").width(middleBarOffset.left); $(".middleBar").offset(middleBarOffset); $("#scheduleContainer").width(containerWidth + (mouseXStart - x) - 2); if ($("#scheduleContainer").width() - 100 > 0) { $(".schedulingHeaderContainer").width($("#scheduleContainer").width() - 100); $(".schedulingCellContainer").width($(".schedulingHeaderContainer").width()); } else { $(".schedulingHeaderContainer").width(1); $(".schedulingCellContainer").width(1); } containerOffset.left = middleBarOffset.left + 2; $("#scheduleContainer").offset(containerOffset); vmiddleBar.css("display", "none"); $(".popupWindowContent").remove(vmiddleBar); vmiddleBar = null; isDragging = false; } } function popupTeacherReport(userID) { var schoolYearID = $("#SchoolYearDropdown").combobox("getValue"); var fullUrl = CMS_SystemConfig.ReportPagePath + "?ReportFolder=%2fEducationScheduling%2fTeacherSchedulingView&CollegeID_RAP=&UserID_RAP=" + userID + "&SchoolyearID_RAP=" + schoolYearID; $.popupTopWindowOutsite('教师课表', fullUrl, 1024, 600); } function popupClassroomReport(ClassroomID) { var schoolYearID = $("#SchoolYearDropdown").combobox("getValue"); var fullUrl = CMS_SystemConfig.ReportPagePath + "?ReportFolder=%2fEducationScheduling%2fClassroomSchedulingView&BuildingsInfoID_RAP=&ClassroomID_RAP=" + ClassroomID + "&SchoolyearID_RAP=" + schoolYearID; $.popupTopWindowOutsite('教室课表', fullUrl, 1024, 600); } function showClassroomScheduleView(classroomID) { var schoolYearID = $("#SchoolYearDropdown").combobox("getValue"); $.popupTopWindowOutsite('教室课表', CMS_SystemConfig.VirtualDirectoryPath + '/EducationSchedule/ClassroomScheduleView?SchoolyearID=' + schoolYearID + '&ClassroomID=' + classroomID, 800, 400); } function EducationScheduling_Submit() { var collegeID = $("#CollegeDropdown").combobox("getValue"); $.popupTopWindow('提交课表', CMS_SystemConfig.VirtualDirectoryPath + '/EducationSchedule/Submit', 300, 200, reload, { collegeID: collegeID }); } function gridLoaded() { //加载中间内容 loadScheduleContainer(); } function loadScheduleContainer() { $.post(CMS_SystemConfig.VirtualDirectoryPath + '/EducationSchedule/GetContinuousLimitView', null, function (data) { teacherScheduleContinuousCount = data.TeacherScheduleContinuousCount; classScheduleContinuousCount = data.ClassScheduleContinuousCount; classCourseScheduleContinuousCount = data.ClassCourseScheduleContinuousCount; loadScheduleData(); }); } function getCoursesTimeList(schedulingData) { $.post(CMS_SystemConfig.VirtualDirectoryPath + '/CoursesTime/ListAll', null, function (courseTimeData) { drawScheduleContainer(courseTimeData, schedulingData); }); } function checkWeekTimeOverflowAndSetWeekList(weekList) { var workhours = parseInt(currentCell.attr("workhours")); weekList = $.grep(weekList, function (x) { return x.Times >= workhours }); if (weekList.length == 0) { $.messager.alert("系统提示", "该时段需要排" + workhours.toString() + "个学时,该任务班的剩余学时不足,不能排课。"); return false; } currentSchedulingWeekList = weekList; var isDup = false; //只有同一个排课班才需要判断周次冲突 $.each(currentCell.find('.schedulingItem'), function (i, x) { if (currentItem.EducationSchedulingClassID == $(x).attr("EducationSchedulingClassID")) { var weeklyNumList = eval($(x).attr("WeeklyNums")); $.each(currentSchedulingWeekList, function (n, w) { if (weeklyNumList.contains(w.Week)) { $.messager.alert("系统提示", "上课周次冲突。"); isDup = true; return false; } }); } }); if (isDup) { return false; } return true; } function getScheduledItemRemainWeekNums(scheduleItem, allScheduled) { var weekList = $.map(scheduleItem.CourseProcessViewList, function (x) { return { Week: x.Week, Times: x.Times, CourseProcessTeacherViewList: x.CourseProcessTeacherViewList, StaffNames: x.StaffNames, ClassroomTypeID: x.ClassroomTypeID, ClassroomTypeName: x.ClassroomTypeName, ClassroomID: x.ClassroomID, ClassroomName: x.ClassroomName }; }); $.each(allScheduled, function (i, x) { var weeklyNumList = eval($(x).attr("WeeklyNums")); var workhours = parseInt($(x).parent().attr("workhours")); var teacherTeachingViewList = eval(unescape($(x).attr("TeacherTeachingViewList"))); weekList = $.map(weekList, function (m) { var newTimes = m.Times; if (weeklyNumList.contains(m.Week) && $.map(m.CourseProcessTeacherViewList, function (w) { return w.UserID + '|' + w.TeachingMethod.toString(); }).join(',') == $.map(teacherTeachingViewList, function (w) { return w.UserID + '|' + w.TeachingMethod.toString(); }).join(',')) { newTimes = newTimes - workhours; } return { Week: m.Week, Times: newTimes, CourseProcessTeacherViewList: m.CourseProcessTeacherViewList, StaffNames: m.StaffNames, ClassroomTypeID: m.ClassroomTypeID, ClassroomTypeName: m.ClassroomTypeName, ClassroomID: m.ClassroomID, ClassroomName: m.ClassroomName }; }); }); weekList = $.grep(weekList, function (x) { return x.Times > 0; }); return weekList; } //输入一个列表上的排课班,和已排有这个排课班的格子匹配,获取这个排课班剩余可以排的周次 function getScheduleItemWeekNums(scheduleItem, allScheduled, splitWeeks) { var weekList = $.map(scheduleItem.CourseProcessViewList, function (x) { return { Week: x.Week, Times: x.Times, CourseProcessTeacherViewList: x.CourseProcessTeacherViewList, StaffNames: x.StaffNames, ClassroomTypeID: x.ClassroomTypeID, ClassroomTypeName: x.ClassroomTypeName, ClassroomID: x.ClassroomID, ClassroomName: x.ClassroomName }; }); if (!splitWeeks && schedulingClassSelectedWeekList[scheduleItem.EducationSchedulingClassID] != null) { weekList = $.grep(weekList, function (x) { return schedulingClassSelectedWeekList[scheduleItem.EducationSchedulingClassID].contains(x.Week); }); } $.each(allScheduled, function (i, x) { var weeklyNumList = eval($(x).attr("WeeklyNums")); var workhours = parseInt($(x).parent().attr("workhours")); var teacherTeachingViewList = eval(unescape($(x).attr("TeacherTeachingViewList"))); // var classroomTypeID = $(x).attr("ClassroomTypeID"); // var classroomID = $(x).attr("ClassroomID"); weekList = $.map(weekList, function (m) { var newTimes = m.Times; if (weeklyNumList.contains(m.Week) && $.map(m.CourseProcessTeacherViewList, function (w) { return w.UserID + '|' + w.TeachingMethod.toString(); }).join(',') == $.map(teacherTeachingViewList, function (w) { return w.UserID + '|' + w.TeachingMethod.toString(); }).join(',') // && m.ClassroomTypeID == classroomTypeID // && m.ClassroomID == classroomID ) { newTimes = newTimes - workhours; } return { Week: m.Week, Times: newTimes, CourseProcessTeacherViewList: m.CourseProcessTeacherViewList, StaffNames: m.StaffNames, ClassroomTypeID: m.ClassroomTypeID, ClassroomTypeName: m.ClassroomTypeName, ClassroomID: m.ClassroomID, ClassroomName: m.ClassroomName }; }); }); weekList = $.grep(weekList, function (x) { return x.Times > 0; }) .sort(function (a, b) { return a.Times - b.Times; }); var weekListMap = {}; var weekListGroup = []; for (var i = 0; i < weekList.length; i++) { var existModifyGroup = $.grep(weekListGroup, function (x) { return x.CourseProcessTeacherViewList.length == weekList[i].CourseProcessTeacherViewList.length && $.map(x.CourseProcessTeacherViewList, function (w) { return w.UserID + '|' + w.TeachingMethod.toString(); }).join(',') == $.map(weekList[i].CourseProcessTeacherViewList, function (w) { return w.UserID + '|' + w.TeachingMethod.toString(); }).join(',') && x.ClassroomTypeID == weekList[i].ClassroomTypeID && x.ClassroomID == weekList[i].ClassroomID && x.Times <= weekList[i].Times }); if (existModifyGroup.length > 0) { $.each(weekListGroup, function (n, x) { if ($.map(x.CourseProcessTeacherViewList, function (w) { return w.UserID + '|' + w.TeachingMethod.toString(); }).join(',') == $.map(weekList[i].CourseProcessTeacherViewList, function (w) { return w.UserID + '|' + w.TeachingMethod.toString(); }).join(',') && x.ClassroomTypeID == weekList[i].ClassroomTypeID && x.ClassroomID == weekList[i].ClassroomID && x.Times <= weekList[i].Times) { x.WeekNums.push(weekList[i].Week); } }); } var existGroup = $.grep(weekListGroup, function (x) { return x.CourseProcessTeacherViewList.length == weekList[i].CourseProcessTeacherViewList.length && $.map(x.CourseProcessTeacherViewList, function (w) { return w.UserID + '|' + w.TeachingMethod.toString(); }).join(',') == $.map(weekList[i].CourseProcessTeacherViewList, function (w) { return w.UserID + '|' + w.TeachingMethod.toString(); }).join(',') && x.ClassroomTypeID == weekList[i].ClassroomTypeID && x.ClassroomID == weekList[i].ClassroomID && x.Times == weekList[i].Times }); if (existGroup.length == 0) { weekListGroup.push({ CourseProcessTeacherViewList: weekList[i].CourseProcessTeacherViewList, ClassroomTypeID: weekList[i].ClassroomTypeID, ClassroomTypeName: weekList[i].ClassroomTypeName, ClassroomID: weekList[i].ClassroomID, ClassroomName: weekList[i].ClassroomName, Times: weekList[i].Times, TeacherNameColumn: $.map(weekList[i].CourseProcessTeacherViewList, function (x) { return x.Name + '(' + x.TeachingMethodName + ')'; }).join(','), WeekNums: [weekList[i].Week] }); } } $.each(weekListGroup, function (i, x) { x.WeekNumString = getWeekNumString(x.WeekNums); }); if (weekListGroup.length == 0) { $.messager.alert("系统提示", "任务班的周学时已经排满。"); return; } if (weekListGroup) { if (splitWeeks) { if (weekListGroup.length > 1) { $.popupTopWindow('选择排课组', CMS_SystemConfig.VirtualDirectoryPath + '/EducationSchedule/SelectGroup', 650, 320, preSelectWeek, { weekList: weekList, weekListGroup: weekListGroup }); } else { preSelectWeek({ weekList: weekList, weekListGroup: weekListGroup[0] }); } } else { if (weekListGroup.length > 1) { $.popupTopWindow('选择排课组', CMS_SystemConfig.VirtualDirectoryPath + '/EducationSchedule/SelectGroup', 650, 320, selectGroupConfirm, { weekList: weekList, weekListGroup: weekListGroup }); } else { selectGroupConfirm({ weekList: weekList, weekListGroup: weekListGroup[0] }); } } } } function selectGroupConfirm(weekListGroupData) { if (!weekListGroupData) return; var weekday = currentCell.attr("weekday"); var courseTimeID = currentCell.attr("coursesTimeID"); weekList = $.grep(weekListGroupData.weekList, function (x) { return x.CourseProcessTeacherViewList.length == weekListGroupData.weekListGroup.CourseProcessTeacherViewList.length && $.map(x.CourseProcessTeacherViewList, function (w) { return w.UserID + '|' + w.TeachingMethod.toString(); }).join(',') == $.map(weekListGroupData.weekListGroup.CourseProcessTeacherViewList, function (w) { return w.UserID + '|' + w.TeachingMethod.toString(); }).join(',') && x.ClassroomTypeID == weekListGroupData.weekListGroup.ClassroomTypeID && x.ClassroomID == weekListGroupData.weekListGroup.ClassroomID && x.Times >= weekListGroupData.weekListGroup.Times }); if (!checkWeekTimeOverflowAndSetWeekList(weekList)) { resetSelection(); return; } checkTeacherIsOnWork(weekday, courseTimeID); } function isTeacherOverflow(teacherWorkTimeList, weekday) { var teacherDayClasses = new Array(); var isOverflow = false; $.each(teacherWorkTimeList, function (i, x) { var teacherDayClass = $.grep(teacherDayClasses, function (y) { return y.UserID == x.UserID && y.WeekNum == x.WeekNum; }); if (teacherDayClass.length == 0) { teacherDayClasses.push({ UserID: x.UserID, Name: x.Name, WeekNum: x.WeekNum, WorkTime: x.WorkTime }); } else { $.each(teacherDayClasses, function (o, y) { if (y.UserID == x.UserID && y.WeekNum == x.WeekNum) { y.WorkTime += x.WorkTime; } }); } }); //再循环一次,加入待排课程的上课时间 var cellworkhours = parseInt(currentCell.attr("workhours")); $.each(currentSchedulingWeekList, function (i, x) { $.each(x.CourseProcessTeacherViewList, function (n, w) { var teacherDayClass = $.grep(teacherDayClasses, function (y) { return y.UserID == w.UserID && y.WeekNum == x.Week; }); if (teacherDayClass.length == 0) { teacherDayClasses.push({ UserID: w.UserID, Name: w.Name, WeekNum: x.Week, WorkTime: cellworkhours }); } else { $.each(teacherDayClasses, function (o, y) { if (y.UserID == w.UserID && y.WeekNum == x.Week) { y.WorkTime += cellworkhours; } if (y.WorkTime > teacherScheduleContinuousCount) { isOverflow = true; } }); } }); }); return isOverflow; } function schedulingCellClicked() { if ($(event.srcElement).hasClass("scheduleItemTeacherLink")) { return; } if (currentItem != null) { currentCell = $(this); var weekday = currentCell.attr("weekday"); var courseTimeID = currentCell.attr("coursesTimeID"); var allScheduled = $('.schedulingItem[EducationSchedulingClassID=' + currentItem.EducationSchedulingClassID + ']'); //先看当前时间点是否可以排课 $.post(CMS_SystemConfig.VirtualDirectoryPath + '/Arrangements/IsOnWork', { weekday: weekday, courseTimeID: courseTimeID }, function (data) { if (!data) { $.messager.alert("系统提示", "该时间点不是工作时间,不能排课,请与校历管理员联系咨询。"); } else { //选教室之前,需要判断是否可以排在这一格 $.post(CMS_SystemConfig.VirtualDirectoryPath + '/EducationSchedule/IsCourseOnWork', { coursematerialID: currentItem.CoursematerialID, weekday: weekday, courseTimeID: courseTimeID }, function (data) { if (!data.IsSuccess) { $.messager.confirm("系统提示", data.Message + "是否继续将课程排在该节次?", function (r) { if (r) { getScheduleItemWeekNums(currentItem, allScheduled, false); } else { resetSelection(); } }); } else { getScheduleItemWeekNums(currentItem, allScheduled, false); } }); } }) } else { if ($(this).children('.schedulingItem').length == 0) { var selectedItems = $('.schedulingItemSelected'); selectedItems.removeClass('schedulingItemSelected'); } } } function checkTeacherIsOnWork(weekday, courseTimeID) { $.post(CMS_SystemConfig.VirtualDirectoryPath + '/EducationSchedule/IsTeacherOnWork', { educationScheduleClassID: currentItem.EducationSchedulingClassID, schedulingWeekListStr: JSON.stringify(currentSchedulingWeekList), weekday: weekday, courseTimeID: courseTimeID }, function (data) { isContinue = true; if (!data.IsSuccess) { $.messager.confirm("系统提示", data.Message + "是否继续将课程排在该节次?", function (r) { if (r) { checkIsBusy(weekday, courseTimeID); } else { resetSelection(); } }); } else { checkIsBusy(weekday, courseTimeID); } }); } function checkIsBusy(weekday, courseTimeID) { var schoolYearID = $("#SchoolYearDropdown").combobox("getValue"); $.post(CMS_SystemConfig.VirtualDirectoryPath + '/EducationSchedule/IsEducationSchedulingClassCanAddManualSchedule', { educationScheduleClassID: currentItem.EducationSchedulingClassID, schedulingWeekListStr: JSON.stringify(currentSchedulingWeekList), schoolYearID: schoolYearID, weekday: weekday, courseTimeID: courseTimeID }, function (data) { if (data.IsSuccess) { checkTeacherWorktimeLimit(schoolYearID, weekday); } else { var reportLink = ""; if (data.Message.indexOf('教师') >= 0) { reportLink += "点击下列链接查看相关教师的课表:
"; $.each(data.Data, function (i, x) { reportLink += ''; reportLink += x.Value + "课表"; reportLink += " "; }); } $.messager.alert("系统提示", data.Message + reportLink); resetSelection(); return; } }); } function checkTeacherWorktimeLimit(schoolYearID, weekday) { //再判断教师连续工作时间、班级连续工作时间是否超限 $.post(CMS_SystemConfig.VirtualDirectoryPath + '/EducationSchedule/GetTeacherContinuousWorkTime', { educationScheduleClassID: currentItem.EducationSchedulingClassID, schedulingWeekListStr: JSON.stringify(currentSchedulingWeekList), schoolYearID: schoolYearID, weekday: weekday }, function (teacherWorkTimeList) { if (isTeacherOverflow(teacherWorkTimeList, weekday)) { var reportLink = ""; var teacherList = []; $.each(teacherWorkTimeList, function (i, x) { if (!teacherList.contains(x.UserID)) { teacherList.push(x.UserID); reportLink += ''; reportLink += x.Name + "课表"; reportLink += " "; } }); $.messager.confirm("系统提示", "教师连续工作时间超限,是否继续将课程排在该节次?点击下列链接查看相关教师的课表:
" + reportLink, function (r) { if (r) { checkCourseContinuousLimit(weekday); } else { resetSelection(); } }); } else { checkCourseContinuousLimit(weekday); } }); } function checkCourseContinuousLimit(weekday) { var weekCourseTimes = new Array(); var currentCellWorkhours = parseInt(currentCell.attr("workhours")); var courses = $('.schedulingCell[weekday=' + weekday + '] .schedulingItem'); $.each(courses, function (i, x) { var weekNums = eval($(x).attr("WeeklyNums")); var workhours = parseInt($(x).parent().attr("workhours")); $.each(weekNums, function (n, w) { var isContain = false; $.each(weekCourseTimes, function (m, v) { if (v.WeekNum == w) { isContain = true; v.Times += workhours; } }); if (isContain == false) { weekCourseTimes.push({ WeekNum: w, Times: workhours }); } }); }); $.each(currentSchedulingWeekList, function (n, w) { var isContain = false; $.each(weekCourseTimes, function (m, v) { if (v.WeekNum == w.Week) { isContain = true; v.Times += currentCellWorkhours; } }); if (isContain == false) { weekCourseTimes.push({ WeekNum: w.Week, Times: currentCellWorkhours }); } }); if ($.grep(weekCourseTimes, function (x) { return x.Times > classScheduleContinuousCount; }).length > 0) { $.messager.confirm("系统提示", "班级连续上课时间超限。是否继续将课程排在该节次?", function (r) { if (r) { checkCourseScheduleContinuousLimit(weekday); } else { resetSelection(); } }); } else { checkCourseScheduleContinuousLimit(weekday); } } function checkCourseScheduleContinuousLimit(weekday) { var weekCourseTimes = new Array(); var currentCellWorkhours = parseInt(currentCell.attr("workhours")); var courses = $('.schedulingCell[weekday=' + weekday + '] .schedulingItem[CoursematerialID=' + currentItem.CoursematerialID + ']'); $.each(courses, function (i, x) { var weekNums = eval($(x).attr("WeeklyNums")); var workhours = parseInt($(x).parent().attr("workhours")); var coursematerialID = $(x).attr("CoursematerialID"); $.each(weekNums, function (n, w) { var isContain = false; $.each(weekCourseTimes, function (m, v) { if (v.WeekNum == w && v.CoursematerialID == coursematerialID) { isContain = true; v.Times += workhours; } }); if (isContain == false) { weekCourseTimes.push({ WeekNum: w, CoursematerialID: coursematerialID, Times: workhours }); } }); }); $.each(currentSchedulingWeekList, function (n, w) { var isContain = false; $.each(weekCourseTimes, function (m, v) { if (v.WeekNum == w.Week && v.CoursematerialID == currentItem.CoursematerialID) { isContain = true; v.Times += currentCellWorkhours; } }); if (isContain == false) { weekCourseTimes.push({ WeekNum: w.Week, CoursematerialID: currentItem.CoursematerialID, Times: currentCellWorkhours }); } }); if ($.grep(weekCourseTimes, function (x) { return x.Times > classCourseScheduleContinuousCount; }).length > 0) { $.messager.confirm("系统提示", "班级连续上同一课程时间超限。是否继续将课程排在该节次?", function (r) { if (r) { loadClassroom(); } else { resetSelection(); } }); } else { loadClassroom(); } } function loadClassroom() { var fixClassroomID = currentSchedulingWeekList[0].ClassroomID; var fixClassroomName = currentSchedulingWeekList[0].ClassroomName; if (fixClassroomID) { var schoolYearID = $("#SchoolYearDropdown").combobox("getValue"); var collegeID = $("#CollegeDropdown").combobox("getValue"); var schedulingWeekListStr = $.map(currentSchedulingWeekList, function (x) { return x.Week; }).join(','); var weekday = currentCell.attr("weekday"); var courseTimeID = currentCell.attr("coursesTimeID"); $.post(CMS_SystemConfig.VirtualDirectoryPath + '/EducationSchedule/IsClassroomIsAvailable', { collegeID: collegeID, schoolYearID: schoolYearID, schedulingWeekListStr: schedulingWeekListStr, weekday: weekday, courseTimeID: courseTimeID, classroomID: fixClassroomID }, function (data) { if (data.IsSuccess) { addSchdulingCellItemWithClassroom({ ClassroomID: fixClassroomID, Name: fixClassroomName }); } else { var reportLink = ""; if (data.Data) { reportLink += '点击下列链接查看教室课表:
'; reportLink += ''; reportLink += fixClassroomName + "课表"; reportLink += " "; } $.messager.alert("系统提示", data.Message + reportLink); } } ); } else { popupClassroomSelector(); } } function drawScheduleContainer(courseTimeData, schedulingData) { var container = $('#scheduleContainer'); drawSchedulingCells(container, courseTimeData); drawSchedulingData(container, schedulingData); $(".schedulingCell").click(schedulingCellClicked); } function popupClassroomSelector() { var schoolYearID = $("#SchoolYearDropdown").combobox("getValue"); var collegeID = $("#CollegeDropdown").combobox("getValue"); var weekday = currentCell.attr("weekday"); var courseTimeID = currentCell.attr("coursesTimeID"); var availableClassroomList = $.grep(usedClassroomList, function (x) { return x.weekday == weekday && x.courseTimeID == courseTimeID }); var classroomTypeID = currentSchedulingWeekList[0].ClassroomTypeID; $.popupTopWindow('选择教室', CMS_SystemConfig.VirtualDirectoryPath + '/EducationSchedule/Setting', 650, 320, addSchdulingCellItemWithClassroom, { schoolYearID: schoolYearID, collegeID: collegeID, weekday: weekday, courseTimeID: courseTimeID, classroomTypeID: classroomTypeID, studentNum: currentItem.StudentNum, schedulingWeekList: $.map(currentSchedulingWeekList, function (x) { return x.Week; }), usedClassroomIDList: $.map(availableClassroomList, function (x) { return x.classroomID; }) }); } function addSchdulingCellItemWithClassroom(classroom) { if (classroom) { var schoolYearID = $("#SchoolYearDropdown").combobox("getValue"); var weekday = currentCell.attr("weekday"); var courseTimeID = currentCell.attr("coursesTimeID"); $.post(CMS_SystemConfig.VirtualDirectoryPath + '/EducationSchedule/AddScheduling', { schoolYearID: schoolYearID, educationSchedulingClassID: currentItem.EducationSchedulingClassID, weekListStr: $.map(currentSchedulingWeekList, function (x) { return x.Week }).join(','), teacherStr: JSON.stringify(currentSchedulingWeekList[0].CourseProcessTeacherViewList), weekday: weekday, courseTimeID: courseTimeID, classroomID: classroom.ClassroomID }, function (data) { if (!data.IsSuccess) { $.messager.alert("系统提示", "排课失败:" + data.Message); } else { schedulingClassSelectedWeekList[currentItem.EducationSchedulingClassID] = null; currentItem = null; currentCell = null; currentSchedulingWeekList = null; usedClassroomList = new Array(); teacherScheduleContinuousCount = 0; classScheduleContinuousCount = 0; classCourseScheduleContinuousCount = 0; reload(); // var schedulingItem = { // EducationSchedulingClassID: currentItem.EducationSchedulingClassID, // TeachingModeName: currentItem.TeachingModeName, // CoursematerialID: currentItem.CoursematerialID, // CoursematerialName: currentItem.CoursematerialName, // ClassroomTypeID: currentItem.ClassroomTypeID, // ClassroomID: classroom.ClassroomID, // ClassroomName: classroom.Name, // WeekNumList: currentSchedulingWeekList, // WeeklyNumString: currentItem.WeeklyNumString, // TaskGroupName: currentItem.TaskGroupName, // TeacherNames: currentItem.TeacherNames, // CourseProcessViewList: currentItem.CourseProcessViewList, // StudentCount: currentItem.StudentNum // }; // usedClassroomList.push({ weekday: weekday, courseTimeID: courseTimeID, classroomID: classroom.ClassroomID }); // var listSchedulingClassList = $("#dgEducationSchedulingClassList").cmsXDataTable("getRows"); // $.each(listSchedulingClassList, function () { // if (this.EducationSchedulingClassID == currentItem.EducationSchedulingClassID) { // this.RemainCourseTime -= currentSchedulingWeekList.length; // } // }); // $("#dgEducationSchedulingClassList").cmsXDataTable("loadData", { rows: listSchedulingClassList, total: listSchedulingClassList.length }); // var html = drawSchedulingCellItem(currentCell, schedulingItem); // resetSelection(); } }); } } function resetSelection() { currentCell = null; currentItem = null; currentSchedulingWeekList = null; $("#dgEducationSchedulingClassList").find('tr.row>td').removeClass('selectedSchedulingClass'); } function drawSchedulingCells(container, courseTimeData) { var html = new Array(); html.push('
'); html.push('
'); html.push('
'); html.push('
星期一
'); html.push('
星期二
'); html.push('
星期三
'); html.push('
星期四
'); html.push('
星期五
'); html.push('
星期六
'); html.push('
星期日
'); html.push('
'); html.push('
'); var timesSegment = $.map(courseTimeData, function (x) { return x.TimesSegment; }).unique().sort(); var schedulingCellHeaderContainerHtml = new Array(); var schedulingCellContainerHtml = new Array(); schedulingCellHeaderContainerHtml.push('
'); schedulingCellContainerHtml.push('
'); $.each(courseTimeData, function () { var colorStyleString = ''; var i; for (i = 0; i < timesSegment.length; i++) { if (timesSegment[i] == this.TimesSegment) { colorStyleString = " " + colorGroup[i % colorGroup.length]; } } schedulingCellHeaderContainerHtml.push('
'); schedulingCellHeaderContainerHtml.push(this.StartDate + "-" + this.EndDate); schedulingCellHeaderContainerHtml.push('
'); schedulingCellContainerHtml.push('
'); schedulingCellContainerHtml.push('
'); schedulingCellContainerHtml.push('
'); schedulingCellContainerHtml.push('
'); schedulingCellContainerHtml.push('
'); schedulingCellContainerHtml.push('
'); schedulingCellContainerHtml.push('
'); schedulingCellContainerHtml.push('
'); schedulingCellContainerHtml.push('
'); schedulingCellContainerHtml.push('
'); schedulingCellContainerHtml.push('
'); schedulingCellContainerHtml.push('
'); schedulingCellContainerHtml.push('
'); schedulingCellContainerHtml.push('
'); schedulingCellContainerHtml.push('
'); schedulingCellContainerHtml.push('
'); }); schedulingCellHeaderContainerHtml.push('
'); schedulingCellContainerHtml.push('
') html.push("
"); html.push(schedulingCellHeaderContainerHtml.join('')); html.push(schedulingCellContainerHtml.join('')); html.push("
"); container.html(html.join('')); var containerWith = $(document).width() - $("#scheduleContainer").position().left - $(".schedulingCellHeader").width() - 18; var containerHeight = $(document).height() - $("#scheduleContainer").position().top - $(".schedulingCellHeader").height(); var mainContainer = $(".schedulingCellContainer").parent(); //mainContainer.css("line-height", containerHeight + "px"); mainContainer.height(containerHeight); $(".schedulingCellHeaderContainer").width($(".schedulingCellHeader").width() + 2); $(".schedulingCellHeaderContainer").height(containerHeight); $(".schedulingHeaderContainer").width(containerWith); $(".schedulingHeaderContainer").css("margin-left", "100px"); $(".schedulingRow").width($(".schedulingHeader").width() - 16); $(".schedulingCellContainer").width(containerWith); $(".schedulingCellContainer").height(containerHeight); $(".schedulingCellContainer").css("margin-left", ($(".schedulingCellHeader").width() + 2) + "px"); $(".schedulingCellContainer").scroll(function () { $(".schedulingHeaderContainer").scrollLeft($(".schedulingCellContainer").scrollLeft()); $(".schedulingCellHeaderContainer").scrollTop($(".schedulingCellContainer").scrollTop()); }); } function drawSchedulingData(container, schedulingData) { $.each(schedulingData, function () { var queryString = '.schedulingCell'; queryString += '[coursesTimeID="' + this.CoursesTimeID + '"]'; queryString += '[weekday="' + this.Weekday + '"]'; var currentCell = container.find(queryString); drawSchedulingCellItem(currentCell, this); }); } function drawSchedulingCellItem(cell, schedulingItem) { var html = new Array(); var itemCount = cell.children('.schedulingItem').length; var eachWidth = cell.width() / (itemCount + 1); var tooltip = ""; var text = ""; var availableSchedulingClass = $("#dgEducationSchedulingClassList").cmsXDataTable("getRows"); var isAvailable = true; if ($.grep(availableSchedulingClass, function (x) { return x.EducationSchedulingClassID == schedulingItem.EducationSchedulingClassID; }).length == 0) { isAvailable = false; } if (!schedulingItem.IsCanEdit) { isAvailable = false; } cell.children('.schedulingItem').width(eachWidth); html.push(cell.html()); html.push('
'); if (!schedulingItem.TeachingModeName || schedulingItem.TeachingModeName == "") { tooltip += schedulingItem.CoursematerialName; } else { tooltip += '【' + schedulingItem.TeachingModeName + '】' + schedulingItem.CoursematerialName; } tooltip += '(' + schedulingItem.TaskGroupName + ')'; tooltip += '
'; text = tooltip; if (schedulingItem.ClassroomName) { text += '' text += schedulingItem.ClassroomName; text += '' tooltip += schedulingItem.ClassroomName; } text += ','; tooltip += ','; text += schedulingItem.WeeklyNumString; tooltip += schedulingItem.WeeklyNumString; text += '
'; tooltip += '
'; if (schedulingItem.TeacherNames) { tooltip += schedulingItem.TeacherNames; text += schedulingItem.TeracherNamesWithLink; } html.push('
'); html.push(text); html.push('
'); html.push('
'); cell.html(html.join('')); setSchedulingItemUsed(schedulingItem); cell.children('.schedulingItem:not(.disabledItem)').click(function () { selectScheduleItem($(this)); }); cell.children('.schedulingItem').on('contextmenu', function (e) { e.preventDefault(); var isDisable = false; if ($(this).hasClass('disabledItem')) { isDisable = true; } if (!isDisable) { selectScheduleItem($(this)); } else { var selectedItems = $('.schedulingItemSelected'); selectedItems.removeClass('schedulingItemSelected'); } $("#popupMenu").css('display', 'block'); if (!isDisable) { $("#popupMenu div:not(.commonMenu)").css('display', 'block'); } else { $("#popupMenu div:not(.commonMenu)").css('display', 'none'); } $("#popupMenu").offset({ left: e.pageX, top: e.pageY }); }); } function selectScheduleItem(scheduleItem) { if ($(event.srcElement).hasClass("scheduleItemTeacherLink")) { return; } if ($(event.srcElement).hasClass("scheduleItemClassroomLink")) { return; } if (currentItem != null) return; var selectedItems = $('.schedulingItemSelected'); selectedItems.removeClass('schedulingItemSelected'); scheduleItem.addClass('schedulingItemSelected'); } function setSchedulingItemUsed(schedulingItem) { var data = $("#dgEducationSchedulingClassList").cmsXDataTable("options").data.rows; var i; var allScheduled = $('.schedulingItem[EducationSchedulingClassID=' + schedulingItem.EducationSchedulingClassID + ']'); var remainWeekNum = $.map(getScheduledItemRemainWeekNums(schedulingItem, allScheduled), function (x) { return x.Week }); for (i = 0; i < data.length; i++) { if (data[i].EducationSchedulingClassID == schedulingItem.EducationSchedulingClassID) { if (remainWeekNum.length == 0) { $("#dgEducationSchedulingClassList").find('tr.row[xRowIndex=' + i + ']>td').addClass('finishedSchedulingClass'); } else { $("#dgEducationSchedulingClassList").find('tr.row[xRowIndex=' + i + ']>td').addClass('usedSchedulingClass'); } return; } } } function clearSchedulingItemUsed(schedulingItem) { var usedCells = $('.schedulingItem[EducationSchedulingClassID=' + schedulingItem.EducationSchedulingClassID + ']'); var data = $("#dgEducationSchedulingClassList").cmsXDataTable("options").data.rows; var i; for (i = 0; i < data.length; i++) { if (data[i].EducationSchedulingClassID == schedulingItem.EducationSchedulingClassID) { $("#dgEducationSchedulingClassList").find('tr.row[xRowIndex=' + i + ']>td').removeClass('finishedSchedulingClass'); if (usedCells.length == 0) { $("#dgEducationSchedulingClassList").find('tr.row[xRowIndex=' + i + ']>td').removeClass('usedSchedulingClass'); } return; } } } function selectItem(rowIndex, rowData) { if (rowData.IsCanEdit) { if (currentItem != null && currentItem.EducationSchedulingClassID == rowData.EducationSchedulingClassID) { resetSelection(); } else { $(this).find('tr.row>td').removeClass('selectedSchedulingClass'); $(this).find('tr.row[xRowIndex=' + rowIndex + ']>td').addClass('selectedSchedulingClass'); currentItem = rowData; } } } function EducationScheduling_Close() { top.$('#' + windowID).window('close'); } function EducationScheduling_WeekModify() { var selectedItems = $('.schedulingItemSelected'); if (selectedItems.length > 1) { $.messager.alert("系统提示", "不能同时操作多条记录。"); return; } var educationSchedulingID = selectedItems.attr("EducationSchedulingID"); var weekNums = eval(selectedItems.attr("WeeklyNums")); $.popupTopWindow('编辑上课周次', CMS_SystemConfig.VirtualDirectoryPath + '/EducationSchedule/WeekModify', 200, 500, popupClose, { EducationSchedulingID: educationSchedulingID, WeeklyNums: weekNums }); } function popupClose() { if (top.$.data(this, "isSuccess")) { top.$.data(this, "isSuccess", false) reload(); } } function EducationScheduling_ModifyTeacher() { var selectedItems = $('.schedulingItemSelected'); if (selectedItems.length == 0) { $.messager.alert("系统提示", "请选择需要修改的排课记录。"); return; } if (selectedItems.length > 1) { $.messager.alert("系统提示", "不能同时操作多条记录。"); return; } var schoolYearID = $("#SchoolYearDropdown").combobox("getValue"); var educationSchedulingID = selectedItems.attr('EducationSchedulingID'); var redirectTo = CMS_SystemConfig.VirtualDirectoryPath + "/EducationSchedule/SetTeacher?EducationSchedulingID=" + educationSchedulingID + "&SchoolYearID=" + schoolYearID; $.popupTopWindow('设置教师', redirectTo, 800, 300, popupClose, null); } function EducationScheduling_ModifyClassroom() { var selectedItems = $('.schedulingItemSelected'); if (selectedItems.length == 0) { $.messager.alert("系统提示", "请选择需要修改的排课记录。"); return; } if (selectedItems.length > 1) { $.messager.alert("系统提示", "不能同时操作多条记录。"); return; } var cell = selectedItems.parent(".schedulingCell"); var schoolYearID = $("#SchoolYearDropdown").combobox("getValue"); var collegeID = $("#CollegeDropdown").combobox("getValue"); var weekday = cell.attr("weekday"); var courseTimeID = cell.attr("coursesTimeID"); var classroomTypeID = selectedItems.attr("ClassroomTypeID"); var studentCount = selectedItems.attr("StudentCount"); var availableClassroomList = $.grep(usedClassroomList, function (x) { return x.weekday == weekday && x.courseTimeID == courseTimeID }); var weekNums = eval(selectedItems.attr("WeeklyNums")); var courseTimeID = cell.attr("coursesTimeID"); $.popupTopWindow('选择教室', CMS_SystemConfig.VirtualDirectoryPath + '/EducationSchedule/Setting', 650, 320, modifyClassroom, { schoolYearID: schoolYearID, collegeID: collegeID, weekday: weekday, courseTimeID: courseTimeID, classroomTypeID: classroomTypeID, studentNum: studentCount, schedulingWeekList: weekNums, usedClassroomIDList: $.map(availableClassroomList, function (x) { return x.classroomID; }) }); } function modifyClassroom(classroom) { if (classroom) { var selectedItems = $('.schedulingItemSelected'); var classroomID = classroom.ClassroomID; var educationSchedulingID = selectedItems.attr('EducationSchedulingID'); $.post(CMS_SystemConfig.VirtualDirectoryPath + '/EducationSchedule/ChangeClassroom', { educationSchedulingID: educationSchedulingID, classroomID: classroomID }, function (data) { if (!data.IsSuccess) { $.messager.alert("系统提示", "修改教室失败:" + data.Message); } else { reload(); } }); } } function EducationScheduling_DeleteItem() { var selectedItems = $('.schedulingItemSelected'); $.each(selectedItems, function (i, w) { var cell = $(w).parent(); var itemCount = cell.children('.schedulingItem').length; var eachWidth = cell.width() / (itemCount - 1); var weekday = cell.attr("weekday"); var courseTimeID = selectedItems.parent().attr("coursesTimeID"); var workhours = parseInt(selectedItems.parent().attr("workhours")); var schoolYearID = $("#SchoolYearDropdown").combobox("getValue"); var weekNums = eval($(w).attr("WeeklyNums")); $.post(CMS_SystemConfig.VirtualDirectoryPath + '/EducationSchedule/DelScheduling', { educationSchedulingID: $(w).attr('EducationSchedulingID') }, function (data) { if (!data.IsSuccess) { $.messager.alert("系统提示", "删除失败:" + data.Message); } else { usedClassroomList = $.grep(usedClassroomList, function (x) { return !(x.weekday == weekday && x.courseTimeID == courseTimeID && x.classroomID == $(w).attr("ClassroomID")); }); cell.children('.schedulingItem').width(eachWidth); var classdata = $("#dgEducationSchedulingClassList").cmsXDataTable("options").data.rows; var schedulingItem = $.grep(classdata, function (v) { return v.EducationSchedulingClassID == $(w).attr('EducationSchedulingClassID'); }); $(w).remove(); if (schedulingItem.length > 0) { var listSchedulingClassList = $("#dgEducationSchedulingClassList").cmsXDataTable("getRows"); $.each(listSchedulingClassList, function () { if (this.EducationSchedulingClassID == schedulingItem[0].EducationSchedulingClassID) { this.RemainCourseTime += weekNums.length * workhours; } }); $("#dgEducationSchedulingClassList").cmsXDataTable("loadData", { rows: listSchedulingClassList, total: listSchedulingClassList.length }); clearSchedulingItemUsed(schedulingItem[0]); } } }); }); } function isScheduleEnable(rowIndex, rowData) { if (!rowData.IsCanEdit) { var rowObj = $("#dgEducationSchedulingClassList").find('tr.row[xRowIndex=' + rowIndex + ']'); return "color: #cccccc;"; } else { return ""; } } function EducationSchedulingClass_SelectWeeks(rowIndex, rowData) { if (rowData.IsCanEdit) { $("#dgEducationSchedulingClassList").find('tr.row>td').removeClass('selectedSchedulingClass'); $("#dgEducationSchedulingClassList").find('tr.row[xRowIndex=' + rowIndex + ']>td').addClass('selectedSchedulingClass'); currentItem = rowData; } var allScheduled = $('.schedulingItem[EducationSchedulingClassID=' + currentItem.EducationSchedulingClassID + ']'); getScheduleItemWeekNums(rowData, allScheduled, true); } function preSelectWeek(weekListGroupData) { if (!weekListGroupData) return; var selectedWeekList = $.grep(weekListGroupData.weekList, function (x) { return x.CourseProcessTeacherViewList.length == weekListGroupData.weekListGroup.CourseProcessTeacherViewList.length && $.map(x.CourseProcessTeacherViewList, function (w) { return w.UserID + '|' + w.TeachingMethod.toString(); }).join(',') == $.map(weekListGroupData.weekListGroup.CourseProcessTeacherViewList, function (w) { return w.UserID + '|' + w.TeachingMethod.toString(); }).join(',') && x.ClassroomTypeID == weekListGroupData.weekListGroup.ClassroomTypeID && x.ClassroomID == weekListGroupData.weekListGroup.ClassroomID && x.Times >= weekListGroupData.weekListGroup.Times }) var selectedWeekNumList = $.map(selectedWeekList, function (x) { return x.Week; }); $.popupTopWindow('选择周次', CMS_SystemConfig.VirtualDirectoryPath + '/EducationSchedule/PreSelectWeeks', 200, 500, preSelectWeekConfirm, selectedWeekNumList); } function preSelectWeekConfirm(selectedWeekList) { schedulingClassSelectedWeekList[currentItem.EducationSchedulingClassID] = selectedWeekList; } (function ($) { $('.easyui-menu').menu('hide'); $(document).keydown(function (e) { if (e.keyCode == 46) { EducationScheduling_DeleteItem(); } }); $(document).on('contextmenu', function (e) { $("#popupMenu").css('display', 'block'); if ($(e.srcElement).parent().hasClass("row") && !$(e.srcElement).hasClass("finishedSchedulingClass")) { var rowIndex = parseInt($(e.srcElement).parent().attr("xRowIndex")); var rowData = $("#dgEducationSchedulingClassList").cmsXDataTable("getRows")[rowIndex]; if (rowData.IsCanEdit) { $("#popupMenu div").css('display', 'none'); $("#popupMenu div.schedulingClassMenu").css('display', 'block'); $("#popupMenu div.commonMenu").css('display', 'block'); $("#popupMenu div.editWeek").unbind(); $("#popupMenu div.editWeek").click(function () { EducationSchedulingClass_SelectWeeks(rowIndex, rowData); $('#popupMenu').css('display', 'none'); }); } else { $("#popupMenu div:not(.commonMenu)").css('display', 'none'); } $("#popupMenu").offset({ left: e.pageX, top: e.pageY }); } else if (!$(e.srcElement).parents().hasClass('schedulingItem') && !$(e.srcElement).parents().hasClass("row") && !$(e.srcElement).hasClass('scheduleMenu')) { $("#popupMenu div:not(.commonMenu)").css('display', 'none'); $("#popupMenu").offset({ left: e.pageX, top: e.pageY }); } else { $("#popupMenu div.schedulingClassMenu").css('display', 'none'); $("#popupMenu").offset({ left: e.pageX, top: e.pageY }); } e.preventDefault(); }); $(document).click(function () { $("#popupMenu").css('display', 'none'); }); })(jQuery);