123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241 |
- var calendarView;
- var emptyWeeks;
- var emptyWeeksEnd;
- var totalWeeks;
- function SchCalendar_Export() {
- $("#formQuery").submit();
- }
- function getCalendarView() {
- if ($("#SchoolYearDropdown").length > 0 && $.data($("#SchoolYearDropdown")[0], "combobox")) {
- var schoolYearID = $("#SchoolYearDropdown").combobox("getValue");
- $.post(calenderUrl, { schoolYearID: schoolYearID }, function (data) {
- if (data.IsSuccess) {
- calendarView = data.Data;
- draw();
- } else {
- $.messager.alert("系统提示", data.Message);
- }
- })
- }
- }
- //需要在getTotalWeeks方法调用之后才调用,有依赖关系
- function getWeeksOfMonth(month) {
- //var isParaMonth = false;
- var startDate = eval('new ' + eval(calendarView.StartDate).source);
- var beginDate = startDate.addDay(-1);
- var weekCount = 0;
- for (var i = 0; i < totalWeeks; i++) {
- var curWeekStart = beginDate.addDay(1 + (i * 7));
- var curWeekEnd = beginDate.addDay((i + 1) * 7);
- if (curWeekEnd.getMonth() == (month - 1)) { //javascript的月份是从0开始的
- //isParaMonth = true;
- weekCount++;
- }
- // else if (isParaMonth && (curWeekStart.getMonth() == (month - 1))) {
- // weekCount++;
- // break;
- // }
- }
- return weekCount;
- }
- function getTotalWeeks() {
- var startDate = eval('new ' + eval(calendarView.StartDate).source);
- var endDate = eval('new ' + eval(calendarView.EndDate).source);
- var firstWeek = eval('new ' + eval(calendarView.SchoolYear.FirstWeek).source);
- emptyWeeks = Math.ceil(firstWeek.substractDay(startDate) / 7);
- emptyWeeksEnd = Math.floor(endDate.substractDay(firstWeek.addDay(calendarView.SchoolYear.WeeksNum * 7)) / 7);
- totalWeeks = calendarView.SchoolYear.WeeksNum + emptyWeeks + emptyWeeksEnd;
- }
- function draw() {
- var html = new Array();
- getTotalWeeks();
- html.push('<table class="calendarview-table" width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">');
- html.push(getTitleRow());
- html.push(getMonthTitleRow());
- html.push(getDayRows());
- html.push(getWeekTitleRow());
- html.push('</table>');
- html.push('<br>注:表上有★者为法定节假日,停课,不补课;有阴影的为寒暑假时间。<br/>');
- html.push('<br>法定节假日:' + calendarView.HolidayStr + '<br/>');
- html.push('<br>校内安排:' + calendarView.ScalendarStr + '<br/>');
- $("#calendarviewcontent").html(html.join("\n"));
- drawSplashLine($(".calendarview-monthtitle-left")[0]);
- }
- function getTitleRow() {
- var html = new Array();
- html.push(' <tr>');
- // html.push(' <td class="calendarview-title" colspan="' + (totalWeeks + 1) + '">'
- // .concat(calendarView.UniversityName, calendarView.SchoolYear.Years, '学年', calendarView.SchoolYear.SchoolcodeName, '校历</td>'));
- html.push(' <td class="calendarview-title" colspan="' + (totalWeeks + 1) + '">'
- .concat(calendarView.UniversityName, calendarView.SchoolYear.Code, '学期校历</td>'));
- html.push(' </tr>');
- return html.join("\n");
- }
- function getConner() {
- var html = new Array();
-
- html.push('<table width="100%" height="100%" border="0" cellpadding="0" cellspacing="0">');
- html.push(' <tr>');
- html.push(' <td></td>');
- html.push(' <td>月份</td>');
- html.push(' </tr>');
- html.push(' <tr>');
- html.push(' <td>星期</td>');
- html.push(' <td></td>');
- html.push(' </tr>');
- html.push('</table>');
- return html.join("\n");
- }
- function getMonthTitleRow() {
- var html = new Array();
- var endDate = eval('new ' + eval(calendarView.EndDate).source);
- html.push(' <tr>');
- html.push(' <td class="calendarview-monthtitle-left">' + getConner() + '</td>');
- for (var i = 0; i < calendarView.Months.length; i++) {
- var monthWeekCount = getWeeksOfMonth(calendarView.Months[i].Month);
- if (i == (calendarView.Months.length - 1) && endDate.getMonth() > (calendarView.Months[i].Month - 1)) monthWeekCount++;
- html.push(' <td class="calendarview-monthtitle" colspan="' + monthWeekCount + '">');
- html.push(' '.concat(calendarView.Months[i].ChineseName, '</td>'));
- }
- html.push(' </tr>');
- return html.join("\n");
- }
- function getWeekTitleRow() {
- var html = new Array();
- html.push(' <tr>');
- html.push(' <td class="calendarview-weektitle-left">周次</td>');
- for (var i = 0; i < totalWeeks; i++) {
- html.push(' <td class="calendarview-weektitle">');
- if (i >= emptyWeeks && i < (emptyWeeks + calendarView.SchoolYear.WeeksNum)) {
- html.push(calendarView.WeekNums[i - emptyWeeks].ChineseName);
- } else {
- html.push(' ');
- }
- html.push('</td>');
- }
- html.push(' </tr>');
- return html.join("\n");
- }
- function getDayRows() {
- var html = new Array();
- var startDate = eval('new ' + eval(calendarView.StartDate).source);
- var firstWeek = eval('new ' + eval(calendarView.SchoolYear.FirstWeek).source);
- for (var i = 0; i < 7; i++) {
- html.push(' <tr>');
- html.push(' <td class="calendarview-days-left">' + calendarView.WeekDays[i].ChineseName + '</td>');
- var rowStartDate = startDate.addDay(i);
- for (var j = 0; j < totalWeeks; j++) {
- var curDate = rowStartDate.addDay(j * 7);
- html.push(' <td class="calendarview-days');
- if (curDate < firstWeek ||
- curDate > firstWeek.addDay(calendarView.SchoolYear.WeeksNum * 7)) {
- html.push(' calendar-emptyday');
- }
- html.push('">');
- html.push(curDate.getDate());
- if ($.grep(calendarView.Holidays, function (val, index) { return eval('new ' + eval(val).source).valueOf() == curDate.valueOf(); }).length > 0) {
- html.push('★');
- }
- html.push('</td>');
- }
- html.push(' </tr>');
- }
- return html.join("\n");
- }
- function getTop(tdobj) {
- vParent = tdobj.offsetParent;
- t = tdobj.offsetTop;
- while (vParent.tagName.toUpperCase() != "BODY") {
- t += vParent.offsetTop;
- vParent = vParent.offsetParent;
- }
- return t;
- }
- function getLeft(tdobj) {
- vParent = tdobj.offsetParent;
- t = tdobj.offsetLeft;
- while (vParent.tagName.toUpperCase() != "BODY") {
- t += vParent.offsetLeft;
- vParent = vParent.offsetParent;
- }
- return t;
- }
- function line(startX, startY, endX, endY, container) {
- if (startX == endX) {
- if (startY > endY) {
- var tempY = startY;
- startY = endY;
- endY = tempY;
- }
- for (var k = startY; k < endY; k++) {
- createPoint(container, startX, k);
- }
- }
- // y = ax + b
- var a = (startY - endY) / (startX - endX);
- var b = startY - ((startY - endY) / (startX - endX)) * startX;
- if (Math.abs(startX - endX) > Math.abs(startY - endY)) {
- if (startX > endX) {
- var tempX = endX;
- endX = startX;
- startX = tempX;
- }
- var left = $(container).offset().left;
- var top = $(container).offset().top;
- for (var i = startX; i <= endX; i++) {
- createPoint(container, i, a * i + b);
- }
- } else {
- if (startY > endY) {
- var tempY = startY;
- startY = endY;
- endY = tempY;
- }
- for (var j = startY; j <= endY; j++) {
- createPoint(container, (j - b) / a, j);
- }
- }
- }
- function createPoint(container, x, y) {
- var node = document.createElement('div');
- node.className = 'line';
- container.appendChild(node);
- $(node).offset({
- left: x,
- top: y
- });
- }
- //line(1,1,100,100,"000000");
- function drawSplashLine(container) {
- line(getLeft(container), getTop(container), getLeft(container) + container.offsetWidth,
- getTop(container) + container.offsetHeight, container);
- }
|